Skip to content

Instantly share code, notes, and snippets.

@pmedcraft
Last active April 16, 2019 16:01
Show Gist options
  • Save pmedcraft/fbe912f2f8fa129f50421d27ff54ca29 to your computer and use it in GitHub Desktop.
Save pmedcraft/fbe912f2f8fa129f50421d27ff54ca29 to your computer and use it in GitHub Desktop.
Returns the list of active Projects available in SDL WorldServer using the REST API
public class Project {
private int id;
private int projectGroupId;
private String name;
private String description;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public int getProjectGroupId() {
return projectGroupId;
}
public void setProjectGroupId(int projectGroupId) {
this.projectGroupId = projectGroupId;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
}
public static List<Project> getActiveProjects(String wsBaseUrl, String token) throws IOException, URISyntaxException {
List<Project> activeProjects = new ArrayList<>();
URI getUri = new URIBuilder(wsBaseUrl + "/ws-api/v1/projects")
.addParameter("token", token)
.addParameter("onlyActive", "true")
.build();
JsonObject jsonObject = getItems(getUri);
JsonArray items = jsonObject.getAsJsonArray("items");
Iterator<JsonElement> itemIterator = items.iterator();
while (itemIterator.hasNext()) {
JsonObject item = itemIterator.next().getAsJsonObject();
Project project = new Project();
project.setId(item.getAsJsonPrimitive("id").getAsInt());
project.setProjectGroupId(item.getAsJsonPrimitive("projectGroupId").getAsInt());
project.setName(item.getAsJsonPrimitive("name").getAsString());
project.setDescription(item.getAsJsonPrimitive("description").getAsString());
activeProjects.add(project);
}
return activeProjects;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment