use of org.wso2.carbon.apimgt.api.model.Comment in project carbon-apimgt by wso2.
the class ApiDAOImpl method getCommentsForApi.
@Override
public List<Comment> getCommentsForApi(String apiId) throws APIMgtDAOException {
List<Comment> commentList = new ArrayList<>();
final String getCommentsQuery = "SELECT UUID, COMMENT_TEXT, USER_IDENTIFIER, API_ID, " + "CREATED_BY, CREATED_TIME, UPDATED_BY, LAST_UPDATED_TIME " + "FROM AM_API_COMMENTS WHERE API_ID = ?";
try (Connection connection = DAOUtil.getConnection();
PreparedStatement statement = connection.prepareStatement(getCommentsQuery)) {
try {
statement.setString(1, apiId);
statement.execute();
try (ResultSet rs = statement.getResultSet()) {
while (rs.next()) {
commentList.add(constructCommentFromResultSet(rs));
}
}
} catch (SQLException e) {
connection.rollback();
String errorMessage = "getting all comments for API " + apiId;
throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + errorMessage, e);
}
} catch (SQLException e) {
String errorMessage = "getting all comments for API " + apiId;
throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + errorMessage, e);
}
return commentList;
}
use of org.wso2.carbon.apimgt.api.model.Comment 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.apimgt.api.model.Comment in project carbon-apimgt by wso2.
the class ApisApiServiceImplTestCase method testApisApiIdCommentsCommentIdPutErrorCase.
@Test
public void testApisApiIdCommentsCommentIdPutErrorCase() 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);
CommentDTO commentDTO = new CommentDTO();
commentDTO.setApiId(apiId);
commentDTO.setCommentText("comment text");
commentDTO.setCreatedBy("creater");
commentDTO.setLastUpdatedBy("updater");
Comment comment = new Comment();
comment.setCommentedUser("commentedUser");
comment.setCommentText("this is a comment");
comment.setCreatedUser("createdUser");
comment.setUpdatedUser("updatedUser");
comment.setCreatedTime(LocalDateTime.now().minusHours(1));
comment.setUpdatedTime(LocalDateTime.now());
Mockito.doThrow(new APICommentException("Error occurred", ExceptionCodes.INTERNAL_ERROR)).when(apiStore).updateComment(comment, commentId, apiId, USER);
Mockito.doThrow(new APICommentException("Error occurred", ExceptionCodes.INTERNAL_ERROR)).when(apiStore).getCommentByUUID(commentId, apiId);
Response response = apisApiService.apisApiIdCommentsCommentIdPut(commentId, apiId, commentDTO, IF_MATCH, IF_UNMODIFIED_SINCE, request);
Assert.assertEquals(ExceptionCodes.INTERNAL_ERROR.getHttpStatusCode(), response.getStatus());
}
use of org.wso2.carbon.apimgt.api.model.Comment in project carbon-apimgt by wso2.
the class CommentMappingUtil method fromCommentToDTO.
/**
* Converts a Comment object into corresponding REST API CommentDTO object
*
* @param comment comment object
* @return CommentDTO
*/
public static CommentDTO fromCommentToDTO(Comment comment) {
CommentDTO commentDTO = new CommentDTO();
commentDTO.setCommentId(comment.getUuid());
commentDTO.setUsername(comment.getCommentedUser());
commentDTO.setCommentText(comment.getCommentText());
commentDTO.setCreatedBy(comment.getCreatedUser());
commentDTO.setLastUpdatedBy(comment.getUpdatedUser());
commentDTO.setCreatedTime(comment.getCreatedTime().toString());
commentDTO.setLastUpdatedTime(comment.getUpdatedTime().toString());
return commentDTO;
}
use of org.wso2.carbon.apimgt.api.model.Comment in project carbon-apimgt by wso2.
the class SampleTestObjectCreator method createDefaultComment.
public static Comment createDefaultComment(String apiId) {
Comment comment = new Comment();
comment.setUuid(UUID.randomUUID().toString());
comment.setApiId(apiId);
comment.setCommentText("this is a sample comment");
comment.setCommentedUser("admin");
comment.setUpdatedUser("admin");
comment.setCreatedTime(LocalDateTime.now());
comment.setUpdatedTime(LocalDateTime.now());
return comment;
}
Aggregations