use of org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.CommentDTO 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) throws APIManagementException {
CommentDTO commentDTO = new CommentDTO();
commentDTO.setId(comment.getId());
commentDTO.setContent(comment.getText());
commentDTO.setCreatedBy(comment.getUser());
commentDTO.setCreatedTime(comment.getCreatedTime().toString());
if (comment.getUpdatedTime() != null) {
commentDTO.setUpdatedTime(comment.getUpdatedTime().toString());
}
commentDTO.setCategory(comment.getCategory());
commentDTO.setParentCommentId(comment.getParentCommentID());
if (APIConstants.CommentEntryPoint.DEVPORTAL.toString().equals(comment.getEntryPoint())) {
commentDTO.setEntryPoint(CommentDTO.EntryPointEnum.DEVPORTAL);
} else if (APIConstants.CommentEntryPoint.PUBLISHER.toString().equals(comment.getEntryPoint())) {
commentDTO.setEntryPoint(CommentDTO.EntryPointEnum.PUBLISHER);
}
commentDTO.setReplies(fromCommentListToDTO(comment.getReplies(), false));
return commentDTO;
}
use of org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.CommentDTO in project carbon-apimgt by wso2.
the class ApisApiServiceImpl method getAllCommentsOfAPI.
@Override
public Response getAllCommentsOfAPI(String apiId, String xWSO2Tenant, Integer limit, Integer offset, Boolean includeCommenterInfo, MessageContext messageContext) throws APIManagementException {
String organization = RestApiUtil.getValidatedOrganization(messageContext);
try {
APIConsumer apiConsumer = RestApiCommonUtil.getLoggedInUserConsumer();
ApiTypeWrapper apiTypeWrapper = apiConsumer.getAPIorAPIProductByUUID(apiId, organization);
String parentCommentID = null;
CommentList comments = apiConsumer.getComments(apiTypeWrapper, parentCommentID, limit, offset);
CommentListDTO commentDTO = CommentMappingUtil.fromCommentListToDTO(comments, includeCommenterInfo);
String uriString = RestApiConstants.RESOURCE_PATH_APIS + "/" + apiId + RestApiConstants.RESOURCE_PATH_COMMENTS;
URI uri = new URI(uriString);
return Response.ok(uri).entity(commentDTO).build();
} catch (APIManagementException e) {
if (RestApiUtil.isDueToResourceNotFound(e) || RestApiUtil.isDueToAuthorizationFailure(e)) {
RestApiUtil.handleResourceNotFoundError(RestApiConstants.RESOURCE_API, apiId, e, log);
} else {
RestApiUtil.handleInternalServerError("Failed to get comments of API " + apiId, e, log);
}
} catch (URISyntaxException e) {
String errorMessage = "Error while retrieving comments content location for API " + apiId;
RestApiUtil.handleInternalServerError(errorMessage, e, log);
}
return null;
}
use of org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.CommentDTO in project carbon-apimgt by wso2.
the class ApisApiServiceImpl method editCommentOfAPI.
@Override
public Response editCommentOfAPI(String commentId, String apiId, PatchRequestBodyDTO patchRequestBodyDTO, MessageContext messageContext) throws APIManagementException {
String username = RestApiCommonUtil.getLoggedInUsername();
String organization = RestApiUtil.getValidatedOrganization(messageContext);
try {
APIConsumer apiConsumer = RestApiCommonUtil.getLoggedInUserConsumer();
ApiTypeWrapper apiTypeWrapper = apiConsumer.getAPIorAPIProductByUUID(apiId, organization);
Comment comment = apiConsumer.getComment(apiTypeWrapper, commentId, 0, 0);
if (comment != null) {
if (comment.getUser().equals(username)) {
boolean commentEdited = false;
if (patchRequestBodyDTO.getCategory() != null && !(patchRequestBodyDTO.getCategory().equals(comment.getCategory()))) {
comment.setCategory(patchRequestBodyDTO.getCategory());
commentEdited = true;
}
if (patchRequestBodyDTO.getContent() != null && !(patchRequestBodyDTO.getContent().equals(comment.getText()))) {
comment.setText(patchRequestBodyDTO.getContent());
commentEdited = true;
}
if (commentEdited) {
if (apiConsumer.editComment(apiTypeWrapper, commentId, comment)) {
Comment editedComment = apiConsumer.getComment(apiTypeWrapper, commentId, 0, 0);
CommentDTO commentDTO = CommentMappingUtil.fromCommentToDTO(editedComment);
String uriString = RestApiConstants.RESOURCE_PATH_APIS + "/" + apiId + RestApiConstants.RESOURCE_PATH_COMMENTS + "/" + commentId;
URI uri = new URI(uriString);
return Response.ok(uri).entity(commentDTO).build();
}
} else {
return Response.ok().build();
}
} else {
RestApiUtil.handleAuthorizationFailure(RestApiConstants.RESOURCE_COMMENTS, String.valueOf(commentId), log);
}
} else {
RestApiUtil.handleResourceNotFoundError(RestApiConstants.RESOURCE_COMMENTS, String.valueOf(commentId), log);
}
} catch (URISyntaxException e) {
String errorMessage = "Error while retrieving comment content location for API " + apiId;
RestApiUtil.handleInternalServerError(errorMessage, e, log);
}
return null;
}
use of org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.CommentDTO in project ArachneCentralAPI by OHDSI.
the class CommentToCommentDTOConverter method convert.
@Override
public CommentDTO convert(Comment source) {
final CommentDTO commentDTO = new CommentDTO();
commentDTO.setId(source.getId());
commentDTO.setDate(source.getDate());
commentDTO.setComment(source.getComment());
commentDTO.setAuthor(conversionService.convert(source.getAuthor(), UserInfoDTO.class));
/*
final List<CommentDTO> commentDTOS = source.getComments()
.stream()
.map(c -> conversionService.convert(c, CommentDTO.class))
.collect(Collectors.toList());
commentDTO.setComments(commentDTOS);
*/
return commentDTO;
}
use of org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.CommentDTO in project ArachneCentralAPI by OHDSI.
the class CommentTopicToCommentTopicDTOConverter method convert.
@Override
public CommentTopicDTO convert(CommentTopic source) {
final CommentTopicDTO commentTopicDTO = new CommentTopicDTO();
final List<CommentDTO> commentDTOS = source.getComments().stream().map(c -> conversionService.convert(c, CommentDTO.class)).collect(Collectors.toList());
commentTopicDTO.setId(source.getId());
commentTopicDTO.setComments(commentDTOS);
return commentTopicDTO;
}
Aggregations