Search in sources :

Example 71 with Comment

use of org.wso2.carbon.apimgt.api.model.Comment in project carbon-business-process by wso2.

the class TaskOperationsImpl method updateComment.

/**
 * Updates the identified comment with the supplied new text.
 * @param taskIdURI : task identifier
 * @param commentId : comment identifier
 * @param s : new comment in plain text.
 * @throws IllegalStateFault
 * @throws IllegalOperationFault
 * @throws IllegalArgumentFault
 * @throws IllegalAccessFault
 */
public void updateComment(final URI taskIdURI, final URI commentId, final String s) throws IllegalStateFault, IllegalOperationFault, IllegalArgumentFault, IllegalAccessFault {
    try {
        final Long taskId = validateTaskId(taskIdURI);
        HumanTaskServiceComponent.getHumanTaskServer().getTaskEngine().getScheduler().execTransaction(new Callable<Object>() {

            public Object call() throws Exception {
                UpdateComment updateCommentCommand = new UpdateComment(getCaller(), taskId, new Long(commentId.toString()), s);
                updateCommentCommand.execute();
                return null;
            }
        });
    } catch (Exception ex) {
        handleException(ex);
    }
}
Also used : UpdateComment(org.wso2.carbon.humantask.core.engine.commands.UpdateComment) HumanTaskIllegalArgumentException(org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskIllegalArgumentException) RegistryException(org.wso2.carbon.registry.core.exceptions.RegistryException) HumanTaskIllegalStateException(org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskIllegalStateException) HumanTaskIllegalOperationException(org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskIllegalOperationException) UserStoreException(org.wso2.carbon.user.core.UserStoreException) HumanTaskException(org.wso2.carbon.humantask.core.engine.HumanTaskException) HumanTaskIllegalAccessException(org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskIllegalAccessException) HumanTaskRuntimeException(org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskRuntimeException)

Example 72 with Comment

use of org.wso2.carbon.apimgt.api.model.Comment in project carbon-business-process by wso2.

the class TaskOperationsImpl method addComment.

/**
 * Add a comment to a task.
 * @param taskIdURI : task identifier
 * @param commentString : comment in plain text
 * @return an identifier that can be used to later update or delete the comment.
 * @throws IllegalStateFault
 * @throws IllegalOperationFault
 * @throws IllegalArgumentFault
 * @throws IllegalAccessFault
 */
public URI addComment(final URI taskIdURI, final String commentString) throws IllegalStateFault, IllegalOperationFault, IllegalArgumentFault, IllegalAccessFault {
    try {
        validateTaskId(taskIdURI);
        Validate.notEmpty(commentString, "The comment string cannot be empty");
        return HumanTaskServiceComponent.getHumanTaskServer().getTaskEngine().getScheduler().execTransaction(new Callable<URI>() {

            public URI call() throws Exception {
                AddComment addComment = new AddComment(getCaller(), new Long(taskIdURI.toString()), commentString);
                addComment.execute();
                CommentDAO persisted = addComment.getPersistedComment();
                if (persisted != null) {
                    return ConverterUtil.convertToURI(persisted.getId().toString());
                } else {
                    throw new IllegalStateFault("The persisted comment is null. " + "See error log for more details.");
                }
            }
        });
    } catch (Exception ex) {
        handleException(ex);
    }
    return null;
}
Also used : CommentDAO(org.wso2.carbon.humantask.core.dao.CommentDAO) AddComment(org.wso2.carbon.humantask.core.engine.commands.AddComment) URI(org.apache.axis2.databinding.types.URI) HumanTaskIllegalArgumentException(org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskIllegalArgumentException) RegistryException(org.wso2.carbon.registry.core.exceptions.RegistryException) HumanTaskIllegalStateException(org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskIllegalStateException) HumanTaskIllegalOperationException(org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskIllegalOperationException) UserStoreException(org.wso2.carbon.user.core.UserStoreException) HumanTaskException(org.wso2.carbon.humantask.core.engine.HumanTaskException) HumanTaskIllegalAccessException(org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskIllegalAccessException) HumanTaskRuntimeException(org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskRuntimeException)

Example 73 with Comment

use of org.wso2.carbon.apimgt.api.model.Comment in project carbon-apimgt by wso2.

the class ApiMgtDAO method editComment.

/**
 *********
 * Edit a comment
 *
 * @param apiTypeWrapper API Type Wrapper
 * @param commentId Comment ID
 * @param comment Comment object
 * @throws APIManagementException
 */
public boolean editComment(ApiTypeWrapper apiTypeWrapper, String commentId, Comment comment) throws APIManagementException {
    try (Connection connection = APIMgtDBUtil.getConnection()) {
        int id = -1;
        String editCommentQuery = SQLConstants.EDIT_COMMENT;
        Identifier identifier;
        String uuid;
        if (apiTypeWrapper.isAPIProduct()) {
            identifier = apiTypeWrapper.getApiProduct().getId();
            uuid = apiTypeWrapper.getApiProduct().getUuid();
        } else {
            identifier = apiTypeWrapper.getApi().getId();
            uuid = apiTypeWrapper.getApi().getUuid();
        }
        id = getAPIID(uuid, connection);
        if (id == -1) {
            String msg = "Could not load API record for: " + identifier.getName();
            throw new APIManagementException(msg);
        }
        connection.setAutoCommit(false);
        try (PreparedStatement prepStmt = connection.prepareStatement(editCommentQuery)) {
            prepStmt.setString(1, comment.getText());
            prepStmt.setTimestamp(2, new Timestamp(System.currentTimeMillis()), Calendar.getInstance());
            prepStmt.setString(3, comment.getCategory());
            prepStmt.setInt(4, id);
            prepStmt.setString(5, commentId);
            prepStmt.execute();
            connection.commit();
            return true;
        }
    } catch (SQLException e) {
        handleException("Error while editing comment " + commentId + " from the database", e);
    }
    return false;
}
Also used : APIIdentifier(org.wso2.carbon.apimgt.api.model.APIIdentifier) APIProductIdentifier(org.wso2.carbon.apimgt.api.model.APIProductIdentifier) Identifier(org.wso2.carbon.apimgt.api.model.Identifier) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) SQLException(java.sql.SQLException) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement) Timestamp(java.sql.Timestamp)

Example 74 with Comment

use of org.wso2.carbon.apimgt.api.model.Comment in project carbon-apimgt by wso2.

the class ApiMgtDAO method addComment.

/**
 * Adds a comment for an API
 *
 * @param identifier  API Identifier
 * @param commentText Commented Text
 * @param user        User who did the comment
 * @return Comment ID
 * @deprecated This method needs to be removed once the Jaggery web apps are removed.
 */
public int addComment(APIIdentifier identifier, String commentText, String user) throws APIManagementException {
    Connection connection = null;
    ResultSet resultSet = null;
    ResultSet insertSet = null;
    PreparedStatement getPrepStmt = null;
    PreparedStatement insertPrepStmt = null;
    int commentId = -1;
    int apiId = -1;
    try {
        connection = APIMgtDBUtil.getConnection();
        connection.setAutoCommit(false);
        String getApiQuery = SQLConstants.GET_API_ID_SQL;
        getPrepStmt = connection.prepareStatement(getApiQuery);
        getPrepStmt.setString(1, APIUtil.replaceEmailDomainBack(identifier.getProviderName()));
        getPrepStmt.setString(2, identifier.getApiName());
        getPrepStmt.setString(3, identifier.getVersion());
        resultSet = getPrepStmt.executeQuery();
        if (resultSet.next()) {
            apiId = resultSet.getInt("API_ID");
        }
        if (apiId == -1) {
            String msg = "Unable to get the API ID for: " + identifier;
            log.error(msg);
            throw new APIManagementException(msg);
        }
        /*This query to update the AM_API_COMMENTS table */
        String addCommentQuery = SQLConstants.ADD_COMMENT_SQL;
        /*Adding data to the AM_API_COMMENTS table*/
        String dbProductName = connection.getMetaData().getDatabaseProductName();
        insertPrepStmt = connection.prepareStatement(addCommentQuery, new String[] { DBUtils.getConvertedAutoGeneratedColumnName(dbProductName, "comment_id") });
        insertPrepStmt.setString(1, commentText);
        insertPrepStmt.setString(2, user);
        insertPrepStmt.setTimestamp(3, new Timestamp(System.currentTimeMillis()), Calendar.getInstance());
        insertPrepStmt.setInt(4, apiId);
        insertPrepStmt.executeUpdate();
        insertSet = insertPrepStmt.getGeneratedKeys();
        while (insertSet.next()) {
            commentId = Integer.parseInt(insertSet.getString(1));
        }
        connection.commit();
    } catch (SQLException e) {
        if (connection != null) {
            try {
                connection.rollback();
            } catch (SQLException e1) {
                log.error("Failed to rollback the add comment ", e1);
            }
        }
        handleException("Failed to add comment data, for  " + identifier.getApiName() + '-' + identifier.getVersion(), e);
    } finally {
        APIMgtDBUtil.closeAllConnections(getPrepStmt, connection, resultSet);
        APIMgtDBUtil.closeAllConnections(insertPrepStmt, null, insertSet);
    }
    return commentId;
}
Also used : APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) SQLException(java.sql.SQLException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) Timestamp(java.sql.Timestamp)

Example 75 with Comment

use of org.wso2.carbon.apimgt.api.model.Comment in project carbon-apimgt by wso2.

the class APIConsumerImplTest method testGetComments.

@Test
public void testGetComments() throws APIManagementException {
    Comment comment = new Comment();
    Comment[] comments = new Comment[] { comment };
    String uuid = UUID.randomUUID().toString();
    Mockito.when(apiMgtDAO.getComments(uuid, null)).thenReturn(comments);
    Assert.assertEquals(new APIConsumerImplWrapper(apiMgtDAO).getComments(uuid, null).length, 1);
    Mockito.verify(apiMgtDAO, Mockito.times(1)).getComments(uuid, null);
}
Also used : Comment(org.wso2.carbon.apimgt.api.model.Comment) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

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