The method takes two parameters:
- wsBaseUrl
- token
The second parameter is a security token, which can be retrieved by using the SDL WorldServer REST API as explained here.
The method returns a List of Project objects, one for each active project, containing a subset of the JSON response data.
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; | |
} |
No comments:
Post a Comment