-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
using base org client to contain common methods
- Loading branch information
Showing
5 changed files
with
80 additions
and
138 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
src/main/java/com/impactupgrade/nucleus/client/OrgConfiguredClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package com.impactupgrade.nucleus.client; | ||
|
||
import com.impactupgrade.nucleus.dao.HibernateDao; | ||
import com.impactupgrade.nucleus.entity.Organization; | ||
import com.impactupgrade.nucleus.environment.Environment; | ||
import com.impactupgrade.nucleus.util.OAuth2; | ||
import org.json.JSONObject; | ||
|
||
public class OrgConfiguredClient { | ||
|
||
protected final Environment env; | ||
protected final HibernateDao<Long, Organization> organizationDao; | ||
|
||
public OrgConfiguredClient(Environment env) { | ||
this.env = env; | ||
this.organizationDao = new HibernateDao<>(Organization.class); | ||
} | ||
|
||
protected JSONObject getEnvJson() { | ||
return getOrganization(env.getConfig().apiKey).getEnvironmentJson(); | ||
} | ||
|
||
protected void updateEnvJson(String clientConfigKey, OAuth2.Context context) { | ||
Organization org = getOrganization(env.getConfig().apiKey); | ||
JSONObject envJson = org.getEnvironmentJson(); | ||
JSONObject clientConfigJson = envJson.getJSONObject(clientConfigKey); | ||
|
||
clientConfigJson.put("accessToken", context.accessToken()); | ||
clientConfigJson.put("expiresAt", context.expiresAt() != null ? context.expiresAt() : null); | ||
clientConfigJson.put("refreshToken", context.refreshToken()); | ||
|
||
org.setEnvironmentJson(envJson); | ||
organizationDao.update(org); | ||
} | ||
|
||
private Organization getOrganization(String apiKey) { | ||
return organizationDao.getQueryResult( | ||
"from Organization o where o.nucleusApiKey=:apiKey", | ||
query -> query.setParameter("apiKey", apiKey) | ||
).get(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters