Last active
April 16, 2019 15:55
-
-
Save pmedcraft/28fde3193b397e155e3a0d15d152f0a9 to your computer and use it in GitHub Desktop.
Completes a Task Step 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 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; | |
} | |
} |
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 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