-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Yong Sheng Tan
authored and
Yong Sheng
committed
Jul 29, 2019
1 parent
5a2a608
commit 2835414
Showing
8 changed files
with
453 additions
and
1 deletion.
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
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
134 changes: 134 additions & 0 deletions
134
src/main/java/clients/symphony/api/InformationBarriersClient.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,134 @@ | ||
package clients.symphony.api; | ||
|
||
import clients.ISymClient; | ||
import clients.symphony.api.constants.CommonConstants; | ||
import clients.symphony.api.constants.PodConstants; | ||
import exceptions.SymClientException; | ||
import exceptions.UnauthorizedException; | ||
import model.InformationBarrierGroup; | ||
import model.InformationBarrierGroupStatus; | ||
import model.Policy; | ||
import javax.ws.rs.client.Entity; | ||
import javax.ws.rs.client.Invocation; | ||
import javax.ws.rs.core.GenericType; | ||
import javax.ws.rs.core.MediaType; | ||
import javax.ws.rs.core.Response; | ||
import java.util.List; | ||
|
||
public class InformationBarriersClient extends APIClient { | ||
private ISymClient botClient; | ||
private static String podTarget; | ||
|
||
public InformationBarriersClient(ISymClient client) { | ||
botClient = client; | ||
podTarget = CommonConstants.HTTPS_PREFIX + botClient.getConfig().getPodHost(); | ||
if (botClient.getConfig().getPodPort() != 443) { | ||
podTarget += ":" + botClient.getConfig().getPodPort(); | ||
} | ||
} | ||
|
||
public List<InformationBarrierGroup> listGroups() throws SymClientException { | ||
Invocation.Builder builder = botClient.getPodClient() | ||
.target(podTarget) | ||
.path(PodConstants.LISTIBGROUPS) | ||
.request(MediaType.APPLICATION_JSON) | ||
.header("sessionToken", botClient.getSymAuth().getSessionToken()); | ||
|
||
try (Response response = builder.get()) { | ||
if (response.getStatusInfo().getFamily() != Response.Status.Family.SUCCESSFUL) { | ||
try { | ||
handleError(response, botClient); | ||
} catch (UnauthorizedException ex) { | ||
return listGroups(); | ||
} | ||
return null; | ||
} else { | ||
return response.readEntity(new GenericType<List<InformationBarrierGroup>>() {}); | ||
} | ||
} | ||
} | ||
|
||
public List<Long> listGroupMembers(String groupId) throws SymClientException { | ||
Invocation.Builder builder = botClient.getPodClient() | ||
.target(podTarget) | ||
.path(PodConstants.LISTIBGROUPMEMBERS.replace("{gid}", groupId)) | ||
.request(MediaType.APPLICATION_JSON) | ||
.header("sessionToken", botClient.getSymAuth().getSessionToken()); | ||
|
||
try (Response response = builder.get()) { | ||
if (response.getStatusInfo().getFamily() != Response.Status.Family.SUCCESSFUL) { | ||
try { | ||
handleError(response, botClient); | ||
} catch (UnauthorizedException ex) { | ||
return listGroupMembers(groupId); | ||
} | ||
return null; | ||
} else { | ||
return response.readEntity(new GenericType<List<Long>>() {}); | ||
} | ||
} | ||
} | ||
|
||
public InformationBarrierGroupStatus addGroupMembers(String groupId, List<Long> members) throws SymClientException { | ||
Invocation.Builder builder = botClient.getPodClient() | ||
.target(podTarget) | ||
.path(PodConstants.ADDIBGROUPMEMBERS.replace("{gid}", groupId)) | ||
.request(MediaType.APPLICATION_JSON) | ||
.header("sessionToken", botClient.getSymAuth().getSessionToken()); | ||
|
||
try (Response response = builder.post(Entity.entity(members, MediaType.APPLICATION_JSON))) { | ||
if (response.getStatusInfo().getFamily() != Response.Status.Family.SUCCESSFUL) { | ||
try { | ||
handleError(response, botClient); | ||
} catch (UnauthorizedException ex) { | ||
return addGroupMembers(groupId, members); | ||
} | ||
return null; | ||
} else { | ||
return response.readEntity(InformationBarrierGroupStatus.class); | ||
} | ||
} | ||
} | ||
|
||
public InformationBarrierGroupStatus removeGroupMembers(String groupId, List<Long> members) throws SymClientException { | ||
Invocation.Builder builder = botClient.getPodClient() | ||
.target(podTarget) | ||
.path(PodConstants.REMOVEIBGROUPMEMBERS.replace("{gid}", groupId)) | ||
.request(MediaType.APPLICATION_JSON) | ||
.header("sessionToken", botClient.getSymAuth().getSessionToken()); | ||
|
||
try (Response response = builder.post(Entity.entity(members, MediaType.APPLICATION_JSON))) { | ||
if (response.getStatusInfo().getFamily() != Response.Status.Family.SUCCESSFUL) { | ||
try { | ||
handleError(response, botClient); | ||
} catch (UnauthorizedException ex) { | ||
return removeGroupMembers(groupId, members); | ||
} | ||
return null; | ||
} else { | ||
return response.readEntity(InformationBarrierGroupStatus.class); | ||
} | ||
} | ||
} | ||
|
||
public List<Policy> listPolicies() throws SymClientException { | ||
Invocation.Builder builder = botClient.getPodClient() | ||
.target(podTarget) | ||
.path(PodConstants.LISTPOLICIES) | ||
.request(MediaType.APPLICATION_JSON) | ||
.header("sessionToken", botClient.getSymAuth().getSessionToken()); | ||
|
||
try (Response response = builder.get()) { | ||
if (response.getStatusInfo().getFamily() != Response.Status.Family.SUCCESSFUL) { | ||
try { | ||
handleError(response, botClient); | ||
} catch (UnauthorizedException ex) { | ||
return listPolicies(); | ||
} | ||
return null; | ||
} else { | ||
return response.readEntity(new GenericType<List<Policy>>() {}); | ||
} | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package model; | ||
|
||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; | ||
import java.util.List; | ||
|
||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
public class InformationBarrierGroup { | ||
private String id; | ||
private String name; | ||
private boolean active; | ||
private int memberCount; | ||
private List<String> policies; | ||
private long createdDate; | ||
private long modifiedDate; | ||
|
||
public String getId() { | ||
return id; | ||
} | ||
|
||
public void setId(String id) { | ||
this.id = id; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
public boolean isActive() { | ||
return active; | ||
} | ||
|
||
public void setActive(boolean active) { | ||
this.active = active; | ||
} | ||
|
||
public int getMemberCount() { | ||
return memberCount; | ||
} | ||
|
||
public void setMemberCount(int memberCount) { | ||
this.memberCount = memberCount; | ||
} | ||
|
||
public List<String> getPolicies() { | ||
return policies; | ||
} | ||
|
||
public void setPolicies(List<String> policies) { | ||
this.policies = policies; | ||
} | ||
|
||
public long getCreatedDate() { | ||
return createdDate; | ||
} | ||
|
||
public void setCreatedDate(long createdDate) { | ||
this.createdDate = createdDate; | ||
} | ||
|
||
public long getModifiedDate() { | ||
return modifiedDate; | ||
} | ||
|
||
public void setModifiedDate(long modifiedDate) { | ||
this.modifiedDate = modifiedDate; | ||
} | ||
} |
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,26 @@ | ||
package model; | ||
|
||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; | ||
import java.util.List; | ||
|
||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
public class InformationBarrierGroupStatus { | ||
private String overallResult; | ||
private List<String> results; | ||
|
||
public String getOverallResult() { | ||
return overallResult; | ||
} | ||
|
||
public void setOverallResult(String overallResult) { | ||
this.overallResult = overallResult; | ||
} | ||
|
||
public List<String> getResults() { | ||
return results; | ||
} | ||
|
||
public void setResults(List<String> results) { | ||
this.results = results; | ||
} | ||
} |
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,62 @@ | ||
package model; | ||
|
||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; | ||
import java.util.List; | ||
|
||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
public class Policy { | ||
private String id; | ||
private String policyType; | ||
private boolean active; | ||
private List<String> groups; | ||
private long createdDate; | ||
private long modifiedDate; | ||
|
||
public String getId() { | ||
return id; | ||
} | ||
|
||
public void setId(String id) { | ||
this.id = id; | ||
} | ||
|
||
public String getPolicyType() { | ||
return policyType; | ||
} | ||
|
||
public void setPolicyType(String policyType) { | ||
this.policyType = policyType; | ||
} | ||
|
||
public boolean isActive() { | ||
return active; | ||
} | ||
|
||
public void setActive(boolean active) { | ||
this.active = active; | ||
} | ||
|
||
public List<String> getGroups() { | ||
return groups; | ||
} | ||
|
||
public void setGroups(List<String> groups) { | ||
this.groups = groups; | ||
} | ||
|
||
public long getCreatedDate() { | ||
return createdDate; | ||
} | ||
|
||
public void setCreatedDate(long createdDate) { | ||
this.createdDate = createdDate; | ||
} | ||
|
||
public long getModifiedDate() { | ||
return modifiedDate; | ||
} | ||
|
||
public void setModifiedDate(long modifiedDate) { | ||
this.modifiedDate = modifiedDate; | ||
} | ||
} |
Oops, something went wrong.