Skip to content

Instantly share code, notes, and snippets.

@pmedcraft
Last active April 16, 2019 15:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pmedcraft/28fde3193b397e155e3a0d15d152f0a9 to your computer and use it in GitHub Desktop.
Save pmedcraft/28fde3193b397e155e3a0d15d152f0a9 to your computer and use it in GitHub Desktop.
Completes a Task Step in SDL WorldServer using the REST API
public class CompleteTaskStepRequestBody {
private int id;
private int transitionId;
private String comment;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public int getTransitionId() {
return transitionId;
}
public void setTransitionId(int transitionId) {
this.transitionId = transitionId;
}
public String getComment() {
return comment;
}
public void setComment(String comment) {
this.comment = comment;
}
}
public static boolean completeTaskStep(String wsBaseUrl, String token, CompleteTaskStepRequestBody completeTaskStepRequestBody)
throws IOException, URISyntaxException {
JsonObject jsonObject = doPost(wsBaseUrl, "/ws-api/v1/tasks/complete", token, Arrays.asList(completeTaskStepRequestBody));
return StringUtils.equals(jsonObject.getAsJsonPrimitive("status").getAsString(), "OK");
}
public static JsonObject doPost(String wsBaseUrl, String restPath, String token, Object pojo)
throws IOException, URISyntaxException {
URI postUri = new URIBuilder(wsBaseUrl + restPath)
.addParameter("token", token)
.addParameter("content-type", "application/json")
.build();
HttpClient httpClient = HttpClientBuilder.create().build();
HttpPost httpPost = new HttpPost(postUri);
httpPost.setEntity(getStringEntity(pojo));
HttpResponse response = httpClient.execute(httpPost);
Gson gson = new GsonBuilder().create();
return gson.fromJson(new InputStreamReader(response.getEntity().getContent()), JsonObject.class);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment