use of org.wso2.carbon.apimgt.core.models.Comment in project carbon-business-process by wso2.
the class WorkflowTaskService method deleteComment.
@DELETE
@Path("/{taskId}/comments/{commentId}")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response deleteComment(@PathParam("taskId") String taskId, @PathParam("commentId") String commentId) {
// Check if task exists
Task task = getTaskFromRequest(taskId);
TaskService taskService = BPMNOSGIService.getTaskService();
Comment comment = taskService.getComment(commentId);
if (comment == null || comment.getTaskId() == null || !comment.getTaskId().equals(task.getId())) {
throw new ActivitiObjectNotFoundException("Task '" + task.getId() + "' doesn't have a comment with id '" + commentId + "'.", Comment.class);
}
taskService.deleteComment(commentId);
return Response.ok().status(Response.Status.NO_CONTENT).build();
}
use of org.wso2.carbon.apimgt.core.models.Comment in project carbon-business-process by wso2.
the class WorkflowTaskService method createComment.
@POST
@Path("/{taskId}/comments")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response createComment(@PathParam("taskId") String taskId, CommentRequest comment) {
Task task = getTaskFromRequest(taskId);
if (comment.getMessage() == null) {
throw new ActivitiIllegalArgumentException("Comment text is required.");
}
String processInstanceId = null;
TaskService taskService = BPMNOSGIService.getTaskService();
if (comment.isSaveProcessInstanceId()) {
Task taskEntity = taskService.createTaskQuery().taskId(task.getId()).singleResult();
processInstanceId = taskEntity.getProcessInstanceId();
}
Comment createdComment = taskService.addComment(task.getId(), processInstanceId, comment.getMessage());
CommentResponse commentResponse = new RestResponseFactory().createRestComment(createdComment, uriInfo.getBaseUri().toString());
return Response.ok().status(Response.Status.CREATED).entity(commentResponse).build();
}
use of org.wso2.carbon.apimgt.core.models.Comment in project carbon-business-process by wso2.
the class HistoricProcessInstanceService method getComment.
@GET
@Path("/{processInstanceId}/comments/{commentId}")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response getComment(@PathParam("processInstanceId") String processInstanceId, @PathParam("commentId") String commentId) {
HistoricProcessInstance instance = getHistoricProcessInstanceFromRequest(processInstanceId);
TaskService taskService = BPMNOSGIService.getTaskService();
Comment comment = taskService.getComment(commentId);
if (comment == null || comment.getProcessInstanceId() == null || !comment.getProcessInstanceId().equals(instance.getId())) {
throw new ActivitiObjectNotFoundException("Process instance '" + instance.getId() + "' doesn't have a comment with id '" + commentId + "'.", Comment.class);
}
CommentResponse commentResponse = new RestResponseFactory().createRestComment(comment, uriInfo.getBaseUri().toString());
return Response.ok().entity(commentResponse).build();
}
use of org.wso2.carbon.apimgt.core.models.Comment in project jaggery by wso2.
the class RegistryHostObject method jsFunction_getComments.
public static Scriptable jsFunction_getComments(Context cx, Scriptable thisObj, Object[] args, Function funObj) throws ScriptException {
String functionName = "getComments";
int argsCount = args.length;
if (argsCount != 1) {
HostObjectUtil.invalidNumberOfArgs(hostObjectName, functionName, argsCount, false);
}
if (!(args[0] instanceof String)) {
HostObjectUtil.invalidArgsError(hostObjectName, functionName, "1", "string", args[0], false);
}
try {
List<ScriptableObject> commentsArray = new ArrayList<ScriptableObject>();
RegistryHostObject registryHostObject = (RegistryHostObject) thisObj;
Comment[] comments = registryHostObject.registry.getComments((String) args[0]);
for (Comment comment : comments) {
ScriptableObject commentObj = (ScriptableObject) cx.newObject(thisObj);
commentObj.put("cid", commentObj, comment.getCommentID());
commentObj.put("author", commentObj, comment.getUser());
commentObj.put("content", commentObj, comment.getText());
commentObj.put("created", commentObj, comment.getCreatedTime().getTime());
commentsArray.add(commentObj);
}
return cx.newArray(thisObj, commentsArray.toArray());
} catch (RegistryException e) {
throw new ScriptException(e);
}
}
use of org.wso2.carbon.apimgt.core.models.Comment in project carbon-apimgt by wso2.
the class ApiMgtDAO method getComments.
/**
* Returns all the Comments on an API
*
* @param uuid API uuid
* @param parentCommentID Parent Comment ID
* @return Comment Array
* @throws APIManagementException
*/
public Comment[] getComments(String uuid, String parentCommentID) throws APIManagementException {
List<Comment> commentList = new ArrayList<Comment>();
Connection connection = null;
ResultSet resultSet = null;
PreparedStatement prepStmt = null;
int id = -1;
String sqlQuery;
if (parentCommentID == null) {
sqlQuery = SQLConstantManagerFactory.getSQlString("GET_ROOT_COMMENTS_SQL");
} else {
sqlQuery = SQLConstantManagerFactory.getSQlString("GET_REPLIES_SQL");
}
try {
connection = APIMgtDBUtil.getConnection();
id = getAPIID(uuid, connection);
if (id == -1) {
String msg = "Could not load API record for API with UUID: " + uuid;
throw new APIManagementException(msg);
}
prepStmt = connection.prepareStatement(sqlQuery);
prepStmt.setString(1, uuid);
if (parentCommentID != null) {
prepStmt.setString(2, parentCommentID);
}
resultSet = prepStmt.executeQuery();
while (resultSet.next()) {
Comment comment = new Comment();
comment.setId(resultSet.getString("COMMENT_ID"));
comment.setText(resultSet.getString("COMMENT_TEXT"));
comment.setUser(resultSet.getString("CREATED_BY"));
comment.setCreatedTime(resultSet.getTimestamp("CREATED_TIME"));
comment.setUpdatedTime(resultSet.getTimestamp("UPDATED_TIME"));
comment.setApiId(resultSet.getString("API_ID"));
comment.setParentCommentID(resultSet.getString("PARENT_COMMENT_ID"));
comment.setEntryPoint(resultSet.getString("ENTRY_POINT"));
comment.setCategory(resultSet.getString("CATEGORY"));
commentList.add(comment);
}
} catch (SQLException e) {
try {
if (connection != null) {
connection.rollback();
}
} catch (SQLException e1) {
log.error("Failed to retrieve comments ", e1);
}
handleException("Failed to retrieve comments for API with UUID " + uuid, e);
} finally {
APIMgtDBUtil.closeAllConnections(prepStmt, connection, resultSet);
}
return commentList.toArray(new Comment[commentList.size()]);
}
Aggregations