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();
}
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());
}
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());
}
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);
}
}
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;
}
Aggregations