use of org.wso2.carbon.apimgt.rest.api.store.v1.dto.CommentListDTO in project carbon-apimgt by wso2.
the class ApisApiServiceImpl method getRepliesOfComment.
@Override
public Response getRepliesOfComment(String commentId, String apiId, String xWSO2Tenant, Integer limit, Integer offset, String ifNoneMatch, Boolean includeCommenterInfo, MessageContext messageContext) throws APIManagementException {
String organization = RestApiUtil.getValidatedOrganization(messageContext);
try {
APIConsumer apiConsumer = RestApiCommonUtil.getLoggedInUserConsumer();
ApiTypeWrapper apiTypeWrapper = apiConsumer.getAPIorAPIProductByUUID(apiId, organization);
CommentList comments = apiConsumer.getComments(apiTypeWrapper, commentId, 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.store.v1.dto.CommentListDTO in project carbon-apimgt by wso2.
the class ApisApiServiceImpl method apisApiIdCommentsGet.
/**
* Retrives A list of comments for a given API ID
*
* @param apiId API ID
* @param limit Max number of comments to return
* @param offset Starting point of pagination
* @param request msf4j request object
* @return CommentListDTO object
* @throws NotFoundException if this method is not defined in ApisApiServiceImpl
*/
@Override
public Response apisApiIdCommentsGet(String apiId, Integer limit, Integer offset, Request request) throws NotFoundException {
String username = RestApiUtil.getLoggedInUsername(request);
try {
APIStore apiStore = RestApiUtil.getConsumer(username);
List<Comment> commentList = apiStore.getCommentsForApi(apiId);
CommentListDTO commentListDTO = CommentMappingUtil.fromCommentListToDTO(commentList, limit, offset);
return Response.ok().entity(commentListDTO).build();
} catch (APIManagementException e) {
String errorMessage = "Error while retrieving comments for api : " + apiId;
Map<String, String> paramList = new HashMap<String, String>();
paramList.put(APIMgtConstants.ExceptionsConstants.API_ID, apiId);
ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler(), paramList);
log.error(errorMessage, e);
return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
}
}
use of org.wso2.carbon.apimgt.rest.api.store.v1.dto.CommentListDTO in project carbon-apimgt by wso2.
the class CommentMappingUtil method fromCommentListToDTO.
/**
* Wraps a List of Comments to a CommentListDTO
*
* @param commentList list of comments
* @return CommentListDTO
*/
public static CommentListDTO fromCommentListToDTO(CommentList commentList, boolean includeCommenterInfo) {
CommentListDTO commentListDTO = new CommentListDTO();
List<CommentDTO> listOfCommentDTOs = new ArrayList<>();
commentListDTO.setCount(commentList.getCount());
PaginationDTO paginationDTO = new PaginationDTO();
paginationDTO.setLimit(commentList.getPagination().getLimit());
paginationDTO.setOffset(commentList.getPagination().getOffset());
paginationDTO.setTotal(commentList.getPagination().getTotal());
paginationDTO.setNext(commentList.getPagination().getNext());
paginationDTO.setPrevious(commentList.getPagination().getPrevious());
commentListDTO.setPagination(paginationDTO);
Map<String, Map<String, String>> userClaimsMap = new HashMap<>();
for (Comment comment : commentList.getList()) {
try {
if (includeCommenterInfo) {
userClaimsMap = retrieveUserClaims(comment.getUser(), userClaimsMap);
listOfCommentDTOs.add(fromCommentToDTOWithUserInfo(comment, userClaimsMap));
} else {
listOfCommentDTOs.add(fromCommentToDTO(comment));
}
} catch (APIManagementException e) {
log.error("Error while creating comments list", e);
}
}
commentListDTO.setList(listOfCommentDTOs);
return commentListDTO;
}
use of org.wso2.carbon.apimgt.rest.api.store.v1.dto.CommentListDTO 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;
}
Aggregations