Search in sources :

Example 31 with Comment

use of org.wso2.carbon.apimgt.api.model.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();
}
Also used : BaseTaskService(org.wso2.carbon.bpmn.rest.service.base.BaseTaskService)

Example 32 with Comment

use of org.wso2.carbon.apimgt.api.model.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();
}
Also used : RestResponseFactory(org.wso2.carbon.bpmn.rest.common.RestResponseFactory) BaseTaskService(org.wso2.carbon.bpmn.rest.service.base.BaseTaskService)

Example 33 with Comment

use of org.wso2.carbon.apimgt.api.model.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();
}
Also used : Comment(org.activiti.engine.task.Comment) CommentResponse(org.wso2.carbon.bpmn.rest.model.runtime.CommentResponse) RestResponseFactory(org.wso2.carbon.bpmn.rest.common.RestResponseFactory) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance)

Example 34 with Comment

use of org.wso2.carbon.apimgt.api.model.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);
    }
}
Also used : ScriptException(org.jaggeryjs.scriptengine.exceptions.ScriptException) RegistryException(org.wso2.carbon.registry.api.RegistryException)

Example 35 with Comment

use of org.wso2.carbon.apimgt.api.model.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()]);
}
Also used : Comment(org.wso2.carbon.apimgt.api.model.Comment) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Aggregations

Comment (org.wso2.carbon.apimgt.core.models.Comment)36 APIStore (org.wso2.carbon.apimgt.core.api.APIStore)28 ApiDAO (org.wso2.carbon.apimgt.core.dao.ApiDAO)23 Test (org.testng.annotations.Test)22 SQLException (java.sql.SQLException)18 BeforeTest (org.testng.annotations.BeforeTest)18 API (org.wso2.carbon.apimgt.core.models.API)17 CompositeAPI (org.wso2.carbon.apimgt.core.models.CompositeAPI)17 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)16 Comment (org.wso2.carbon.apimgt.api.model.Comment)16 APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)15 PreparedStatement (java.sql.PreparedStatement)13 Connection (java.sql.Connection)12 HashMap (java.util.HashMap)12 Map (java.util.Map)12 ArrayList (java.util.ArrayList)10 CommentDTO (org.wso2.carbon.apimgt.rest.api.store.dto.CommentDTO)9 URI (java.net.URI)8 URISyntaxException (java.net.URISyntaxException)8 Test (org.junit.Test)8