use of org.wso2.carbon.humantask.core.engine.commands.DeleteComment in project carbon-apimgt by wso2.
the class ApiDAOImpl method deleteComment.
@Override
public void deleteComment(String commentId, String apiId) throws APIMgtDAOException {
final String deleteCommentQuery = "DELETE FROM AM_API_COMMENTS WHERE UUID = ? AND API_ID = ?";
try (Connection connection = DAOUtil.getConnection();
PreparedStatement statement = connection.prepareStatement(deleteCommentQuery)) {
try {
connection.setAutoCommit(false);
statement.setString(1, commentId);
statement.setString(2, apiId);
statement.execute();
connection.commit();
} catch (SQLException e) {
connection.rollback();
String errorMessage = "deleting comment for API " + apiId + ", Comment " + commentId;
throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + errorMessage, e);
} finally {
connection.setAutoCommit(DAOUtil.isAutoCommit());
}
} catch (SQLException e) {
String errorMessage = "deleting comment for API " + apiId + ", Comment " + commentId;
throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + errorMessage, e);
}
}
use of org.wso2.carbon.humantask.core.engine.commands.DeleteComment in project carbon-apimgt by wso2.
the class ApisApiServiceImplTestCase method testApisApiIdCommentsCommentIdDeleteNotFound.
@Test
public void testApisApiIdCommentsCommentIdDeleteNotFound() throws APIManagementException, NotFoundException {
printTestMethodName();
String apiId = UUID.randomUUID().toString();
String commentId = UUID.randomUUID().toString();
ApisApiServiceImpl apisApiService = new ApisApiServiceImpl();
APIStore apiStore = Mockito.mock(APIStoreImpl.class);
PowerMockito.mockStatic(RestApiUtil.class);
PowerMockito.when(RestApiUtil.getConsumer(USER)).thenReturn(apiStore);
Request request = getRequest();
PowerMockito.when(RestApiUtil.getLoggedInUsername(request)).thenReturn(USER);
Mockito.doThrow(new APICommentException("Error occurred", ExceptionCodes.COMMENT_NOT_FOUND)).when(apiStore).deleteComment(commentId, apiId, USER);
Response response = apisApiService.apisApiIdCommentsCommentIdDelete(commentId, apiId, IF_MATCH, IF_UNMODIFIED_SINCE, request);
assertEquals(response.getStatus(), 404);
}
use of org.wso2.carbon.humantask.core.engine.commands.DeleteComment in project carbon-apimgt by wso2.
the class ApisApiServiceImplTestCase method testApisApiIdCommentsCommentIdDeleteIfMatchStringExistingFingerprintCheck.
@Test
public void testApisApiIdCommentsCommentIdDeleteIfMatchStringExistingFingerprintCheck() throws APIManagementException, NotFoundException {
printTestMethodName();
String apiId = UUID.randomUUID().toString();
String commentId = UUID.randomUUID().toString();
ApisApiServiceImpl apisApiService = new ApisApiServiceImpl();
APIStore apiStore = Mockito.mock(APIStoreImpl.class);
PowerMockito.mockStatic(RestApiUtil.class);
PowerMockito.when(RestApiUtil.getConsumer(USER)).thenReturn(apiStore);
Request request = getRequest();
PowerMockito.when(RestApiUtil.getLoggedInUsername(request)).thenReturn(USER);
String existingFingerprint = "existingFingerprint";
Mockito.when(apisApiService.apisApiIdCommentsCommentIdDeleteFingerprint(commentId, apiId, "test", "test", request)).thenReturn(existingFingerprint);
Mockito.doNothing().doThrow(new IllegalArgumentException()).when(apiStore).deleteComment(commentId, apiId, USER);
Response response = apisApiService.apisApiIdCommentsCommentIdDelete(commentId, apiId, "test", "test", request);
assertEquals(response.getStatus(), 412);
}
use of org.wso2.carbon.humantask.core.engine.commands.DeleteComment in project carbon-apimgt by wso2.
the class APIStoreImpl method deleteComment.
@Override
public void deleteComment(String commentId, String apiId, String username) throws APICommentException, APIMgtResourceNotFoundException {
try {
ApiDAO apiDAO = getApiDAO();
failIfApiNotExists(apiId);
Comment comment = apiDAO.getCommentByUUID(commentId, apiId);
if (comment != null) {
// if the delete operation is done by a user who isn't the owner of the comment
if (!comment.getCommentedUser().equals(username)) {
checkIfUserIsCommentModerator(username);
}
apiDAO.deleteComment(commentId, apiId);
} else {
String errorMsg = "Couldn't find comment with comment_id : " + commentId;
log.error(errorMsg);
throw new APIMgtResourceNotFoundException(errorMsg, ExceptionCodes.COMMENT_NOT_FOUND);
}
} catch (APIMgtDAOException e) {
String errorMsg = "Error occurred while deleting comment " + commentId;
log.error(errorMsg, e);
throw new APICommentException(errorMsg, e, e.getErrorHandler());
}
}
use of org.wso2.carbon.humantask.core.engine.commands.DeleteComment in project carbon-apimgt by wso2.
the class APIStoreImplTestCase method testDeleteCommentDaoException.
@Test(description = "Exception in dao when deleting a specific comment", expectedExceptions = APIMgtResourceNotFoundException.class)
public void testDeleteCommentDaoException() 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.when(apiDAO.getCommentByUUID(comment.getUuid(), api.getId())).thenReturn(comment);
Mockito.doThrow(new APIMgtDAOException("Error occurred while deleting comment " + comment.getUuid(), new SQLException())).when(apiDAO).deleteComment(comment.getUuid(), api.getId());
apiStore.deleteComment(comment.getUuid(), api.getId(), "admin");
}
Aggregations