Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into develop-93-headers…
Browse files Browse the repository at this point in the history
…-enum
  • Loading branch information
OGKevin committed Aug 17, 2018
2 parents d2eed2e + 4eb2482 commit 2569218
Show file tree
Hide file tree
Showing 39 changed files with 507 additions and 4,135 deletions.
61 changes: 54 additions & 7 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,68 @@
# Change Log

## [0.13.1](https://github.com/bunq/sdk_java/tree/0.13.1)
## [Unreleased](https://github.com/bunq/sdk_java/tree/1.0.0)

[Full Changelog](https://github.com/bunq/sdk_java/compare/0.13.1...1.0.0)

**Implemented enhancements:**

- Add optional parameters to constructor  [\#50](https://github.com/bunq/sdk_java/issues/50)
- Monetary account joint cannot be retrieved. [\#45](https://github.com/bunq/sdk_java/issues/45)
- Add java 7 compatibility  [\#42](https://github.com/bunq/sdk_java/issues/42)

**Fixed bugs:**

- SDK build fails on jitpack [\#6](https://github.com/bunq/sdk_java/issues/6)

**Closed issues:**

- Add oauth support [\#107](https://github.com/bunq/sdk_java/issues/107)
- Java 7 compatibility: java.util.Base64 [\#104](https://github.com/bunq/sdk_java/issues/104)
- Please share code formatter [\#103](https://github.com/bunq/sdk_java/issues/103)
- expose ApiEnvironmentType members and add pinnedKey [\#100](https://github.com/bunq/sdk_java/issues/100)
- Update Sandbox API key procedure [\#96](https://github.com/bunq/sdk_java/issues/96)
- Can not construct a BunqMeTabEntry to create a BunqMeTab [\#77](https://github.com/bunq/sdk_java/issues/77)

**Merged pull requests:**

- Oauth bunq/sdk\_java\#107 [\#108](https://github.com/bunq/sdk_java/pull/108) ([OGKevin](https://github.com/OGKevin))
- Add java 7 support bunq/sdk\_java\#42 [\#106](https://github.com/bunq/sdk_java/pull/106) ([OGKevin](https://github.com/OGKevin))
- \#100 moved pinnedKey to ApiEnvironmentType [\#101](https://github.com/bunq/sdk_java/pull/101) ([tubbynl](https://github.com/tubbynl))
- UserContext building without static references. \(bunq/sdk\_java\#93\) [\#99](https://github.com/bunq/sdk_java/pull/99) ([tubbynl](https://github.com/tubbynl))
- Update Sandbox API key procedure. \(bunq/sdk\_java\#96\) [\#97](https://github.com/bunq/sdk_java/pull/97) ([sandervdo](https://github.com/sandervdo))
- Add constructor with request field bunq/sdk\_java\#50 [\#95](https://github.com/bunq/sdk_java/pull/95) ([OGKevin](https://github.com/OGKevin))
- Fix monetary account joint retrieval bunq/sdk\_java\#45 [\#91](https://github.com/bunq/sdk_java/pull/91) ([OGKevin](https://github.com/OGKevin))

## [0.13.1](https://github.com/bunq/sdk_java/tree/0.13.1) (2018-05-30)
[Full Changelog](https://github.com/bunq/sdk_java/compare/0.13.0...0.13.1)

**Implemented enhancements:**

- \[Java\] Update examples in readme [\#81](https://github.com/bunq/sdk_java/issues/81)
- Add test CI [\#80](https://github.com/bunq/sdk_java/issues/80)
- It is not possible to refresh userContext data [\#79](https://github.com/bunq/sdk_java/issues/79)
- Optimise test framework [\#78](https://github.com/bunq/sdk_java/issues/78)
- Add more example scripts [\#66](https://github.com/bunq/sdk_java/issues/66)
- Auto save the session after automatic session reset has been executed  [\#60](https://github.com/bunq/sdk_java/issues/60)
- Endpoint HTTP methods should not be static [\#34](https://github.com/bunq/sdk_java/issues/34)
- Remove the examples from the published artifacts [\#2](https://github.com/bunq/sdk_java/issues/2)

**Closed issues:**

- Move to new sandbox [\#89](https://github.com/bunq/sdk_java/issues/89)

- Android issue: HttpClient was deprecated in API Level 22 and removed in API Level 23 [\#69](https://github.com/bunq/sdk_java/issues/69)

**Merged pull requests:**

- Changed sandbox url and pinned key. [\#92](https://github.com/bunq/sdk_java/pull/92) ([OGKevin](https://github.com/OGKevin))

## [0.13.0](https://github.com/bunq/sdk_java/tree/0.13.0) [(2017-12-21)](https://github.com/bunq/sdk_java/tree/0.13.0)
- Changed sandbox url and pinned key. \(bunq/sdk\_java\#89\) [\#92](https://github.com/bunq/sdk_java/pull/92) ([OGKevin](https://github.com/OGKevin))
- Auto update bunq context bunq/sdk\_java\#60 [\#90](https://github.com/bunq/sdk_java/pull/90) ([OGKevin](https://github.com/OGKevin))
- Add travis ci bunq/sdk\_java\#80 [\#87](https://github.com/bunq/sdk_java/pull/87) ([OGKevin](https://github.com/OGKevin))
- Optimise test framework \(bunq/sdk\_java\#78\) [\#85](https://github.com/bunq/sdk_java/pull/85) ([OGKevin](https://github.com/OGKevin))
- Updated read me to point to tinker for examples. \(bunq/sdk\_java\#81\) [\#84](https://github.com/bunq/sdk_java/pull/84) ([OGKevin](https://github.com/OGKevin))
- Refresh user context bunq/sdk\_java\#79 [\#83](https://github.com/bunq/sdk_java/pull/83) ([OGKevin](https://github.com/OGKevin))
- Replace examples with tinker bunq/sdk\_java\#66 [\#82](https://github.com/bunq/sdk_java/pull/82) ([OGKevin](https://github.com/OGKevin))

## [0.13.0](https://github.com/bunq/sdk_java/tree/0.13.0) (2018-03-20)
[Full Changelog](https://github.com/bunq/sdk_java/compare/0.12.4...0.13.0)

**Implemented enhancements:**
Expand Down Expand Up @@ -153,7 +201,6 @@

**Fixed bugs:**

- SDK build fails on jitpack [\#6](https://github.com/bunq/sdk_java/issues/6)
- Fix Jitpack build, add misssing fields, fix field types in generated \[\#6\] [\#8](https://github.com/bunq/sdk_java/pull/8) ([dnl-blkv](https://github.com/dnl-blkv))

## [0.9.1](https://github.com/bunq/sdk_java/tree/0.9.1) (2017-08-08)
Expand All @@ -164,4 +211,4 @@



\* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*
\* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*
13 changes: 12 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
group 'com.bunq.sdk'
version '0.13.1'
version '1.0.0'

apply plugin: 'java'
apply plugin: 'maven'
sourceCompatibility = 1.7


sourceSets {
main {
java {
srcDir 'src/main/java'
exclude '**/examples/**'
exclude '**/test/**'
}
}
}

repositories {
mavenCentral()
}
Expand Down
47 changes: 28 additions & 19 deletions src/main/java/com/bunq/sdk/context/SessionContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
import com.bunq.sdk.exception.BunqException;
import com.bunq.sdk.model.core.BunqModel;
import com.bunq.sdk.model.core.SessionServer;
import com.bunq.sdk.model.generated.endpoint.UserApiKey;
import com.bunq.sdk.model.generated.endpoint.UserCompany;
import com.bunq.sdk.model.generated.endpoint.UserPerson;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;

import java.util.Date;

/**
Expand All @@ -17,12 +19,7 @@ public class SessionContext implements java.io.Serializable {
/**
* Error constants.
*/
private static final String ERROR_UNEXPECTED_USER_TYPE = "Unexpected user type.";

/**
* Default assumed value for session timeout.
*/
private static final int SESSION_TIMEOUT_DEFAULT = 0;
private static final String ERROR_UNEXPECTED_USER_TYPE = "'%s' is an unexpected user type.";

/**
* Constant for converting milliseconds to seconds.
Expand Down Expand Up @@ -53,16 +50,22 @@ public class SessionContext implements java.io.Serializable {
SessionContext(SessionServer sessionServer) {
this.token = sessionServer.getSessionToken().getToken();
this.expiryTime = calculateExpiryTime(sessionServer);
this.userId = getUserId(sessionServer.getReferencedObject());
this.userId = getUserId(sessionServer.getReferencedUser());
}

private Integer getUserId(BunqModel user) {
private int getUserId(BunqModel user) {
if (user instanceof UserPerson) {
return ((UserPerson) user).getId();
} else if (user instanceof UserCompany) {
return ((UserCompany) user).getId();
return ((UserCompany) user).getId();
} else if (user instanceof UserApiKey) {
return ((UserApiKey) user).getId();
} else {
throw new BunqException(ERROR_UNEXPECTED_USER_TYPE);
throw new BunqException(
String.format(
ERROR_UNEXPECTED_USER_TYPE, user.getClass().toString()
)
);
}
}

Expand All @@ -75,19 +78,25 @@ private static Date calculateExpiryTime(SessionServer sessionServer) {
}

private static int getSessionTimeout(SessionServer sessionServer) {
UserCompany userCompany = sessionServer.getUserCompany();

if (userCompany != null) {
return userCompany.getSessionTimeout();
}
BunqModel user = sessionServer.getReferencedUser();

UserPerson userPerson = sessionServer.getUserPerson();
if (user instanceof UserApiKey) {
BunqModel referencedUser = ((UserApiKey) user).getRequestedByUser().getReferencedObject();

if (userPerson != null) {
return userPerson.getSessionTimeout();
return getSessionTimeOutFromUser(referencedUser);
} else {
return getSessionTimeOutFromUser(user);
}
}

return SESSION_TIMEOUT_DEFAULT;
private static int getSessionTimeOutFromUser(BunqModel user) {
if (user instanceof UserCompany) {
return ((UserCompany) user).getSessionTimeout();
} else if (user instanceof UserPerson) {
return ((UserPerson) user).getSessionTimeout();
} else {
throw new BunqException(ERROR_UNEXPECTED_USER_TYPE);
}
}

String getToken() {
Expand Down
35 changes: 24 additions & 11 deletions src/main/java/com/bunq/sdk/context/UserContext.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package com.bunq.sdk.context;

import com.bunq.sdk.exception.BunqException;
import com.bunq.sdk.model.core.BunqModel;
import com.bunq.sdk.model.core.UserContextHelper;
import com.bunq.sdk.model.generated.endpoint.MonetaryAccountBank;
import com.bunq.sdk.model.generated.endpoint.User;
import com.bunq.sdk.model.generated.endpoint.UserApiKey;
import com.bunq.sdk.model.generated.endpoint.UserCompany;
import com.bunq.sdk.model.generated.endpoint.UserPerson;

Expand All @@ -18,20 +20,23 @@ public class UserContext {
private final ApiContext apiContext;
private UserCompany userCompany;
private UserPerson userPerson;
private UserApiKey userApiKey;
private MonetaryAccountBank primaryMonetaryAccountBank;

public UserContext(ApiContext apiContext) {
this.apiContext = apiContext;
refreshContext();
}

private void initUser(User user) {
if (user.getUserPerson() != null) {
this.userPerson = user.getUserPerson();
} else if (user.getUserCompany() != null) {
this.userCompany = user.getUserCompany();
private void initUser(BunqModel user) {
if (user instanceof UserPerson) {
this.userPerson = (UserPerson) user;
} else if (user instanceof UserCompany) {
this.userCompany = (UserCompany) user;
} else if (user instanceof UserApiKey) {
this.userApiKey = (UserApiKey) user;
} else {
throw new BunqException(ERROR_UNEXPECTED_USER_INSTANCE);
throw new BunqException(String.format(ERROR_UNEXPECTED_USER_INSTANCE, user.getClass().toString()));
}
}

Expand All @@ -41,7 +46,7 @@ private void initMainMonetaryAccount(MonetaryAccountBank monetaryAccountBank) {

public void refreshContext() {
UserContextHelper helper = new UserContextHelper(this.apiContext);
this.initUser(helper.getFirstUser());
this.initUser(helper.getFirstUser().getReferencedObject());
this.initMainMonetaryAccount(helper.getFirstActiveMonetaryAccountBankByUserId(getUserId()));
}

Expand All @@ -50,15 +55,19 @@ public Integer getUserId() {
}

public boolean isOnlyUserPersonSet() {
return this.userCompany == null && this.userPerson != null;
return this.userCompany == null && this.userApiKey == null &&this.userPerson != null;
}

public boolean isOnlyUserCompanySet() {
return this.userPerson == null && this.userCompany != null;
return this.userPerson == null && this.userApiKey == null &&this.userCompany != null;
}

public boolean isBothUserTypeSet() {
return this.userPerson != null && this.userCompany != null;
public boolean isOnlyUserApiKeySet() {
return this.userPerson == null && this.userCompany == null && this.userApiKey != null;
}

public boolean areAllUserSet() {
return this.userPerson != null && this.userCompany != null && this.userApiKey != null;
}

public Integer getMainMonetaryAccountId() {
Expand All @@ -77,6 +86,10 @@ public UserCompany getUserCompany() {
return this.userCompany;
}

public UserApiKey getUserApiKey() {
return userApiKey;
}

public MonetaryAccountBank getPrimaryMonetaryAccountBank() {
return this.primaryMonetaryAccountBank;
}
Expand Down
18 changes: 17 additions & 1 deletion src/main/java/com/bunq/sdk/json/SessionServerAdapter.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.bunq.sdk.json;

import com.bunq.sdk.exception.BunqException;
import com.bunq.sdk.model.core.Id;
import com.bunq.sdk.model.core.SessionServer;
import com.bunq.sdk.model.core.SessionToken;
import com.bunq.sdk.model.generated.endpoint.UserApiKey;
import com.bunq.sdk.model.generated.endpoint.UserCompany;
import com.bunq.sdk.model.generated.endpoint.UserPerson;
import com.google.gson.JsonArray;
Expand All @@ -18,6 +20,10 @@
* SessionServer POST response.
*/
public class SessionServerAdapter implements JsonDeserializer<SessionServer> {
/**
* Error constatns.
*/
private static final String ERROR_COULD_NOT_DETERMINE_USER = "Could not determine user.";

private static final int INDEX_ID = 0;
private static final String FIELD_ID = "Id";
Expand All @@ -28,6 +34,7 @@ public class SessionServerAdapter implements JsonDeserializer<SessionServer> {
private static final int INDEX_USER = 2;
private static final String FIELD_USER_COMPANY = "UserCompany";
private static final String FIELD_USER_PERSON = "UserPerson";
private static final String FIELD_USER_API_KEY = "UserApiKey";

@Override
public SessionServer deserialize(JsonElement json, Type typeOfT,
Expand All @@ -51,13 +58,22 @@ public SessionServer deserialize(JsonElement json, Type typeOfT,
);

return new SessionServer(id, token, userCompany);
} else {
} else if (userBody.has(FIELD_USER_PERSON)) {
UserPerson userPerson = context.deserialize(
userBody.get(FIELD_USER_PERSON),
UserPerson.class
);

return new SessionServer(id, token, userPerson);
} else if (userBody.has(FIELD_USER_API_KEY)) {
UserApiKey userApiKey = context.deserialize(
userBody.get(FIELD_USER_API_KEY),
UserApiKey.class
);

return new SessionServer(id, token, userApiKey);
} else {
throw new BunqException(ERROR_COULD_NOT_DETERMINE_USER);
}
}

Expand Down
Loading

0 comments on commit 2569218

Please sign in to comment.