The method takes three parameters:
- wsBaseUrl
- token
- completeTaskStepRequestBody
The second parameter is a security token, which can be retrieved by using the SDL WorldServer REST API as explained here.
The third parameter is a CompleteTaskStepRequestBody object containing the data to support the task step completion. This includes the id (task id), the transitionId and an optional comment to set as metadata. The task id and transition id can be retrieved by invoking the REST call described here for retrieving the tasks from a specified Project. The returned TaskDetails object provides the data.
The method returns a boolean value specifying whether the task step completion was successful.
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); | |
} |
No comments:
Post a Comment