Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refresh user context bunq/sdk_java#79 #83

Merged
merged 3 commits into from
May 4, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions src/main/java/com/bunq/sdk/context/UserContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,22 @@ public class UserContext {
private static final String ERROR_PRIMARY_MONETARY_ACCOUNT_IS_NOT_SET = "Primary monetaryAccount is not set.";

private static final String MONETARY_ACCOUNT_STATUS_ACTIVE = "ACTIVE";
private static final int INDEX_FIRST = 0;

private UserCompany userCompany;
private UserPerson userPerson;
private MonetaryAccountBank primaryMonetaryAccountBank;
private Integer userId;

public UserContext(Integer userId) {
BunqModel userObject = User.list().getValue().get(0).getReferencedObject();

this.setUser(userObject);
this.setUser(this.getUserObject());
this.userId = userId;
}

private BunqModel getUserObject() {
return User.list().getValue().get(INDEX_FIRST).getReferencedObject();
}

private void setUser(BunqModel user) {
if (user instanceof UserPerson) {
this.userPerson = (UserPerson) user;
Expand All @@ -56,6 +59,11 @@ public void initMainMonetaryAccount() {
throw new BunqException(ERROR_NO_ACTIVE_MONETARY_ACCOUNT_FOUND);
}

public void refreshContext() {
this.setUser(this.getUserObject());
this.initMainMonetaryAccount();
}

public Integer getUserId() {
return this.userId;
}
Expand Down