use of org.wso2.carbon.apimgt.core.models.Comment in project carbon-apimgt by wso2.
the class ApisApiServiceImplTestCase method testApisApiIdCommentsCommentIdPut.
@Test
public void testApisApiIdCommentsCommentIdPut() 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.doNothing().doThrow(new IllegalArgumentException()).when(apiStore).updateComment(comment, commentId, apiId, USER);
Mockito.when(apiStore.getCommentByUUID(commentId, apiId)).thenReturn(comment);
Response response = apisApiService.apisApiIdCommentsCommentIdPut(commentId, apiId, commentDTO, null, null, request);
Assert.assertEquals(200, response.getStatus());
}
use of org.wso2.carbon.apimgt.core.models.Comment in project carbon-apimgt by wso2.
the class RatingMappingUtil method fromRatingToDTO.
/**
* Converts an Rating object into corresponding REST API RatingDTO object
*
* @param rating Comment object
* @return a new RatingDTO object corresponding to given Rating object
*/
public static RatingDTO fromRatingToDTO(Rating rating) {
RatingDTO ratingDTO = new RatingDTO();
ratingDTO.setRatingId(rating.getUuid());
ratingDTO.setRating(rating.getRating());
ratingDTO.setUsername(rating.getUsername());
return ratingDTO;
}
use of org.wso2.carbon.apimgt.core.models.Comment in project carbon-apimgt by wso2.
the class CommentMappingUtil method fromDTOToComment.
/**
* Converts a CommentDTO to a Comment object
*
* @param body commentDTO body
* @param username username of the consumer
* @return Comment object
*/
public static Comment fromDTOToComment(CommentDTO body, String username) {
Comment comment = new Comment();
comment.setCommentText(body.getCommentText());
comment.setCommentedUser(username);
comment.setApiId(body.getApiId());
comment.setCreatedUser(username);
comment.setUpdatedUser(username);
return comment;
}
use of org.wso2.carbon.apimgt.core.models.Comment in project carbon-apimgt by wso2.
the class CommentMappingUtil method fromCommentListToDTO.
/**
* Wraps a List of Comments to a CommentListDTO
*
* @param commentList list of comments
* @param limit maximum comments to return
* @param offset starting position of the pagination
* @return CommentListDTO
*/
public static CommentListDTO fromCommentListToDTO(List<Comment> commentList, int limit, int offset) {
CommentListDTO commentListDTO = new CommentListDTO();
List<CommentDTO> listOfCommentDTOs = new ArrayList<>();
commentListDTO.setCount(commentList.size());
int start = offset < commentList.size() && offset >= 0 ? offset : Integer.MAX_VALUE;
int end = offset + limit - 1 <= commentList.size() - 1 ? offset + limit - 1 : commentList.size() - 1;
for (int i = start; i <= end; i++) {
listOfCommentDTOs.add(fromCommentToDTO(commentList.get(i)));
}
commentListDTO.setList(listOfCommentDTOs);
return commentListDTO;
}
use of org.wso2.carbon.apimgt.core.models.Comment in project carbon-apimgt by wso2.
the class APIStoreImpl method updateComment.
@Override
public void updateComment(Comment comment, String commentId, String apiId, String username) throws APICommentException, APIMgtResourceNotFoundException {
validateCommentMaxCharacterLength(comment.getCommentText());
try {
failIfApiNotExists(apiId);
Comment oldComment = getApiDAO().getCommentByUUID(commentId, apiId);
if (oldComment != null) {
// if the update operation is done by a user who isn't the owner of the comment
if (!oldComment.getCommentedUser().equals(username)) {
checkIfUserIsCommentModerator(username);
}
getApiDAO().updateComment(comment, commentId, apiId);
} else {
String errorMsg = "Couldn't find comment with comment_id : " + commentId + "and api_id : " + apiId;
log.error(errorMsg);
throw new APIMgtResourceNotFoundException(errorMsg, ExceptionCodes.COMMENT_NOT_FOUND);
}
} catch (APIMgtDAOException e) {
String errorMsg = "Error occurred while updating comment " + commentId;
log.error(errorMsg, e);
throw new APICommentException(errorMsg, e, e.getErrorHandler());
}
}
Aggregations