11package com .bunq .sdk .model .core ;
22
33import com .bunq .sdk .context .ApiContext ;
4- import com .bunq .sdk .exception .BunqException ;
54import com .bunq .sdk .http .ApiClient ;
65import com .bunq .sdk .http .BunqResponse ;
76import com .bunq .sdk .http .BunqResponseRaw ;
87import com .bunq .sdk .model .generated .endpoint .UserApiKey ;
98import com .bunq .sdk .model .generated .endpoint .UserCompany ;
109import com .bunq .sdk .model .generated .endpoint .UserPaymentServiceProvider ;
1110import com .bunq .sdk .model .generated .endpoint .UserPerson ;
11+ import com .bunq .sdk .util .BunqUtil ;
1212
1313import java .util .HashMap ;
1414
1515public class SessionServer extends BunqModel {
16- /**
17- * Error constants.
18- */
19- private static final String ERROR_ALL_FIELD_NULL = "All fields of an extended model or object are null." ;
20-
2116 /**
2217 * Endpoint name.
2318 */
@@ -94,12 +89,20 @@ public SessionToken getSessionToken() {
9489 return sessionToken ;
9590 }
9691
97- public UserCompany getUserCompany () {
92+ public UserPerson getUserPersonOrNull () {
93+ return userPerson ;
94+ }
95+
96+ public UserCompany getUserCompanyOrNull () {
9897 return userCompany ;
9998 }
10099
101- public UserPerson getUserPerson () {
102- return userPerson ;
100+ public UserApiKey getUserApiKeyOrNull () {
101+ return userApiKey ;
102+ }
103+
104+ public UserPaymentServiceProvider getUserPaymentServiceProviderOrNull () {
105+ return userPaymentServiceProvider ;
103106 }
104107
105108 @ Override
@@ -124,16 +127,6 @@ public boolean isAllFieldNull() {
124127 }
125128
126129 public BunqModel getReferencedUser () {
127- if (this .userCompany == null && this .userApiKey == null && this .userPerson != null && this .userPaymentServiceProvider == null ) {
128- return this .userPerson ;
129- } else if (this .userPerson == null && this .userApiKey == null && this .userCompany != null && this .userPaymentServiceProvider == null ) {
130- return this .userCompany ;
131- } else if (this .userPerson == null && this .userCompany == null && this .userApiKey != null && this .userPaymentServiceProvider == null ) {
132- return this .userApiKey ;
133- } else if (this .userPerson == null && this .userCompany == null && this .userApiKey == null && this .userPaymentServiceProvider != null ) {
134- return this .userPaymentServiceProvider ;
135- } else {
136- throw new BunqException (ERROR_ALL_FIELD_NULL );
137- }
130+ return BunqUtil .getReferencedUser (userPerson , userCompany , userApiKey , userPaymentServiceProvider );
138131 }
139132}
0 commit comments