use of org.wso2.carbon.apimgt.api.model.Comment 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.apimgt.api.model.Comment in project carbon-apimgt by wso2.
the class ApiDAOImpl method updateComment.
@Override
public void updateComment(Comment comment, String commentId, String apiId) throws APIMgtDAOException {
final String updateCommentQuery = "UPDATE AM_API_COMMENTS SET COMMENT_TEXT = ? " + ", UPDATED_BY = ? , LAST_UPDATED_TIME = ?" + " WHERE UUID = ? AND API_ID = ?";
try (Connection connection = DAOUtil.getConnection();
PreparedStatement statement = connection.prepareStatement(updateCommentQuery)) {
try {
connection.setAutoCommit(false);
statement.setString(1, comment.getCommentText());
statement.setString(2, comment.getUpdatedUser());
statement.setTimestamp(3, Timestamp.valueOf(LocalDateTime.now()));
statement.setString(4, commentId);
statement.setString(5, apiId);
statement.execute();
connection.commit();
} catch (SQLException e) {
connection.rollback();
String errorMessage = "updating 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 = "updating comment for API " + apiId + ", Comment " + commentId;
throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + errorMessage, e);
}
}
use of org.wso2.carbon.apimgt.api.model.Comment in project carbon-apimgt by wso2.
the class ApiDAOImplIT method testUpdateComment.
@Test
public void testUpdateComment() throws Exception {
String newCommentText = "updated comment";
ApiDAO apiDAO = DAOFactory.getApiDAO();
API.APIBuilder builder = SampleTestObjectCreator.createDefaultAPI().apiDefinition(SampleTestObjectCreator.apiDefinition);
API api = builder.build();
testAddGetEndpoint();
apiDAO.addAPI(api);
Comment comment1 = SampleTestObjectCreator.createDefaultComment(api.getId());
apiDAO.addComment(comment1, api.getId());
String lastUpdatedTime1 = apiDAO.getLastUpdatedTimeOfComment(comment1.getUuid());
// Keep at least millisecond difference between the two timestamps
Thread.sleep(1);
Comment comment2 = SampleTestObjectCreator.createDefaultComment(api.getId());
comment2.setCommentText(newCommentText);
apiDAO.updateComment(comment2, comment1.getUuid(), api.getId());
Comment commentFromDB = apiDAO.getCommentByUUID(comment1.getUuid(), api.getId());
String lastUpdatedTimeAfterUpdating = apiDAO.getLastUpdatedTimeOfComment(comment1.getUuid());
Assert.assertNotNull(commentFromDB);
Assert.assertNotNull(lastUpdatedTime1);
Assert.assertNotNull(lastUpdatedTimeAfterUpdating);
Assert.assertNotEquals(lastUpdatedTime1, lastUpdatedTimeAfterUpdating);
Assert.assertEquals(newCommentText, commentFromDB.getCommentText());
}
use of org.wso2.carbon.apimgt.api.model.Comment in project carbon-apimgt by wso2.
the class ApiDAOImplIT method testDeleteComment.
@Test
public void testDeleteComment() throws Exception {
ApiDAO apiDAO = DAOFactory.getApiDAO();
API.APIBuilder builder = SampleTestObjectCreator.createDefaultAPI().apiDefinition(SampleTestObjectCreator.apiDefinition);
API api = builder.build();
testAddGetEndpoint();
apiDAO.addAPI(api);
Comment comment = SampleTestObjectCreator.createDefaultComment(api.getId());
apiDAO.addComment(comment, api.getId());
apiDAO.deleteComment(comment.getUuid(), api.getId());
Comment commentFromDB = apiDAO.getCommentByUUID(comment.getUuid(), api.getId());
Assert.assertNull(commentFromDB);
}
use of org.wso2.carbon.apimgt.api.model.Comment in project carbon-apimgt by wso2.
the class ApiDAOImplIT method testAddGetComment.
@Test
public void testAddGetComment() throws Exception {
ApiDAO apiDAO = DAOFactory.getApiDAO();
API.APIBuilder builder = SampleTestObjectCreator.createDefaultAPI().apiDefinition(SampleTestObjectCreator.apiDefinition);
API api = builder.build();
testAddGetEndpoint();
apiDAO.addAPI(api);
Comment comment = SampleTestObjectCreator.createDefaultComment(api.getId());
apiDAO.addComment(comment, api.getId());
Comment commentFromDB = apiDAO.getCommentByUUID(comment.getUuid(), api.getId());
Assert.assertNotNull(commentFromDB);
}
Aggregations