use of org.wso2.carbon.apimgt.core.models.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);
}
}
use of org.wso2.carbon.apimgt.core.models.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;
}
use of org.wso2.carbon.apimgt.core.models.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;
}
use of org.wso2.carbon.apimgt.core.models.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;
}
use of org.wso2.carbon.apimgt.core.models.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);
}
Aggregations