Search in sources :

Example 1 with AddComment

use of org.wso2.carbon.humantask.core.engine.commands.AddComment in project carbon-apimgt by wso2.

the class APIStoreImpl method addComment.

@Override
public String addComment(Comment comment, String apiId) throws APICommentException, APIMgtResourceNotFoundException {
    validateCommentMaxCharacterLength(comment.getCommentText());
    String generatedUuid = UUID.randomUUID().toString();
    comment.setUuid(generatedUuid);
    try {
        failIfApiNotExists(apiId);
        getApiDAO().addComment(comment, apiId);
    } catch (APIMgtDAOException e) {
        String errorMsg = "Error occurred while adding comment for api - " + apiId;
        log.error(errorMsg, e);
        throw new APICommentException(errorMsg, e, e.getErrorHandler());
    }
    return comment.getUuid();
}
Also used : APIMgtDAOException(org.wso2.carbon.apimgt.core.exception.APIMgtDAOException) APICommentException(org.wso2.carbon.apimgt.core.exception.APICommentException)

Example 2 with AddComment

use of org.wso2.carbon.humantask.core.engine.commands.AddComment in project carbon-apimgt by wso2.

the class APIStoreImplTestCase method testAddComment.

@Test(description = "Add comment")
public void testAddComment() throws APIManagementException {
    ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
    APIStore apiStore = getApiStoreImpl(apiDAO);
    API api = SampleTestObjectCreator.createDefaultAPI().build();
    Mockito.when(apiDAO.isAPIExists(api.getId())).thenReturn(true);
    Comment comment = SampleTestObjectCreator.createDefaultComment(api.getId());
    apiStore.addComment(comment, api.getId());
    Mockito.verify(apiDAO, Mockito.times(1)).isAPIExists(api.getId());
    Mockito.verify(apiDAO, Mockito.times(1)).addComment(comment, api.getId());
}
Also used : Comment(org.wso2.carbon.apimgt.core.models.Comment) CompositeAPI(org.wso2.carbon.apimgt.core.models.CompositeAPI) API(org.wso2.carbon.apimgt.core.models.API) ApiDAO(org.wso2.carbon.apimgt.core.dao.ApiDAO) APIStore(org.wso2.carbon.apimgt.core.api.APIStore) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 3 with AddComment

use of org.wso2.carbon.humantask.core.engine.commands.AddComment in project carbon-apimgt by wso2.

the class APIStoreImplTestCase method testAddCommentException.

@Test(description = "Exception in dao when adding a comment", expectedExceptions = APIManagementException.class)
public void testAddCommentException() throws APIManagementException {
    ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
    APIStore apiStore = getApiStoreImpl(apiDAO);
    API api = SampleTestObjectCreator.createDefaultAPI().build();
    Mockito.when(apiDAO.getAPI(api.getId())).thenReturn(api);
    Comment comment = SampleTestObjectCreator.createDefaultComment(api.getId());
    Mockito.doThrow(new APIMgtDAOException("Error occurred while adding comment for api id " + api.getId(), new SQLException())).when(apiDAO).addComment(comment, api.getId());
    apiStore.addComment(comment, api.getId());
}
Also used : Comment(org.wso2.carbon.apimgt.core.models.Comment) APIMgtDAOException(org.wso2.carbon.apimgt.core.exception.APIMgtDAOException) SQLException(java.sql.SQLException) CompositeAPI(org.wso2.carbon.apimgt.core.models.CompositeAPI) API(org.wso2.carbon.apimgt.core.models.API) ApiDAO(org.wso2.carbon.apimgt.core.dao.ApiDAO) APIStore(org.wso2.carbon.apimgt.core.api.APIStore) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 4 with AddComment

use of org.wso2.carbon.humantask.core.engine.commands.AddComment in project carbon-apimgt by wso2.

the class ApiDAOImpl method addComment.

@Override
public void addComment(Comment comment, String apiId) throws APIMgtDAOException {
    final String addCommentQuery = "INSERT INTO AM_API_COMMENTS (UUID, COMMENT_TEXT, USER_IDENTIFIER, API_ID, " + "CREATED_BY, CREATED_TIME, UPDATED_BY, LAST_UPDATED_TIME" + ") VALUES (?,?,?,?,?,?,?,?)";
    try (Connection connection = DAOUtil.getConnection();
        PreparedStatement statement = connection.prepareStatement(addCommentQuery)) {
        try {
            connection.setAutoCommit(false);
            statement.setString(1, comment.getUuid());
            statement.setString(2, comment.getCommentText());
            statement.setString(3, comment.getCommentedUser());
            statement.setString(4, apiId);
            statement.setString(5, comment.getCreatedUser());
            statement.setTimestamp(6, Timestamp.valueOf(LocalDateTime.now()));
            statement.setString(7, comment.getUpdatedUser());
            statement.setTimestamp(8, Timestamp.valueOf(LocalDateTime.now()));
            statement.execute();
            connection.commit();
        } catch (SQLException e) {
            connection.rollback();
            String errorMessage = "adding comment for API " + apiId;
            throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + errorMessage, e);
        } finally {
            connection.setAutoCommit(DAOUtil.isAutoCommit());
        }
    } catch (SQLException e) {
        String errorMessage = "adding comment for API " + apiId;
        throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + errorMessage, e);
    }
}
Also used : APIMgtDAOException(org.wso2.carbon.apimgt.core.exception.APIMgtDAOException) SQLException(java.sql.SQLException) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement)

Example 5 with AddComment

use of org.wso2.carbon.humantask.core.engine.commands.AddComment 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)

Aggregations

APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)3 SQLException (java.sql.SQLException)2 BeforeTest (org.testng.annotations.BeforeTest)2 Test (org.testng.annotations.Test)2 APIStore (org.wso2.carbon.apimgt.core.api.APIStore)2 ApiDAO (org.wso2.carbon.apimgt.core.dao.ApiDAO)2 API (org.wso2.carbon.apimgt.core.models.API)2 Comment (org.wso2.carbon.apimgt.core.models.Comment)2 CompositeAPI (org.wso2.carbon.apimgt.core.models.CompositeAPI)2 Connection (java.sql.Connection)1 PreparedStatement (java.sql.PreparedStatement)1 URI (org.apache.axis2.databinding.types.URI)1 ScriptException (org.jaggeryjs.scriptengine.exceptions.ScriptException)1 APICommentException (org.wso2.carbon.apimgt.core.exception.APICommentException)1 CommentDAO (org.wso2.carbon.humantask.core.dao.CommentDAO)1 HumanTaskException (org.wso2.carbon.humantask.core.engine.HumanTaskException)1 AddComment (org.wso2.carbon.humantask.core.engine.commands.AddComment)1 HumanTaskIllegalAccessException (org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskIllegalAccessException)1 HumanTaskIllegalArgumentException (org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskIllegalArgumentException)1 HumanTaskIllegalOperationException (org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskIllegalOperationException)1