Last active
April 16, 2019 16:01
-
-
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
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
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; | |
} | |
} |
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
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