Search in sources :

Example 26 with CommentDTO

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;
}
Also used : CommentDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.CommentDTO)

Example 27 with 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;
}
Also used : APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) ApiTypeWrapper(org.wso2.carbon.apimgt.api.model.ApiTypeWrapper) CommentList(org.wso2.carbon.apimgt.api.model.CommentList) APIConsumer(org.wso2.carbon.apimgt.api.APIConsumer) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI)

Example 28 with CommentDTO

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;
}
Also used : Comment(org.wso2.carbon.apimgt.api.model.Comment) ApiTypeWrapper(org.wso2.carbon.apimgt.api.model.ApiTypeWrapper) APIConsumer(org.wso2.carbon.apimgt.api.APIConsumer) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI)

Example 29 with CommentDTO

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;
}
Also used : CommentDTO(com.odysseusinc.arachne.portal.api.v1.dto.CommentDTO) UserInfoDTO(com.odysseusinc.arachne.portal.api.v1.dto.UserInfoDTO)

Example 30 with 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;
}
Also used : List(java.util.List) Component(org.springframework.stereotype.Component) CommentTopic(com.odysseusinc.arachne.portal.model.CommentTopic) CommentTopicDTO(com.odysseusinc.arachne.portal.api.v1.dto.CommentTopicDTO) Autowired(org.springframework.beans.factory.annotation.Autowired) BaseConversionServiceAwareConverter(com.odysseusinc.arachne.portal.api.v1.dto.converters.BaseConversionServiceAwareConverter) GenericConversionService(org.springframework.core.convert.support.GenericConversionService) CommentDTO(com.odysseusinc.arachne.portal.api.v1.dto.CommentDTO) Collectors(java.util.stream.Collectors) CommentTopicDTO(com.odysseusinc.arachne.portal.api.v1.dto.CommentTopicDTO) CommentDTO(com.odysseusinc.arachne.portal.api.v1.dto.CommentDTO)

Aggregations

URI (java.net.URI)11 URISyntaxException (java.net.URISyntaxException)11 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)10 ApiTypeWrapper (org.wso2.carbon.apimgt.api.model.ApiTypeWrapper)10 Comment (org.wso2.carbon.apimgt.api.model.Comment)10 HashMap (java.util.HashMap)9 Map (java.util.Map)9 CommentDTO (org.wso2.carbon.apimgt.rest.api.store.dto.CommentDTO)9 Comment (org.wso2.carbon.apimgt.core.models.Comment)8 CommentDTO (org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.CommentDTO)6 APIConsumer (org.wso2.carbon.apimgt.api.APIConsumer)5 APIProvider (org.wso2.carbon.apimgt.api.APIProvider)5 APIStore (org.wso2.carbon.apimgt.core.api.APIStore)5 Test (org.junit.Test)4 CommentList (org.wso2.carbon.apimgt.api.model.CommentList)4 CommentDTO (com.odysseusinc.arachne.portal.api.v1.dto.CommentDTO)3 ArrayList (java.util.ArrayList)3 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)3 ErrorDTO (org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO)3 CommentListDTO (org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.CommentListDTO)3