Search in sources :

Example 66 with Comment

use of org.wso2.carbon.apimgt.core.models.Comment in project carbon-apimgt by wso2.

the class ApisApiServiceImpl method apisApiIdCommentsPost.

/**
 * Update a comment
 *
 * @param apiId   API ID
 * @param body    comment body
 * @param request msf4j request object
 * @return comment update response
 * @throws NotFoundException if this method is not defined in ApisApiServiceImpl
 */
@Override
public Response apisApiIdCommentsPost(String apiId, CommentDTO body, Request request) throws NotFoundException {
    String username = RestApiUtil.getLoggedInUsername(request);
    try {
        APIStore apiStore = RestApiUtil.getConsumer(username);
        Comment comment = CommentMappingUtil.fromDTOToComment(body, username);
        String createdCommentId = apiStore.addComment(comment, apiId);
        Comment createdComment = apiStore.getCommentByUUID(createdCommentId, apiId);
        CommentDTO createdCommentDTO = CommentMappingUtil.fromCommentToDTO(createdComment);
        URI location = new URI(RestApiConstants.RESOURCE_PATH_APIS + "/" + apiId + RestApiConstants.SUBRESOURCE_PATH_COMMENTS + "/" + createdCommentId);
        String fingerprint = getEtag(comment.getUuid(), request.getProperty("LOGGED_IN_USER").toString());
        return Response.status(Response.Status.CREATED).header(RestApiConstants.LOCATION_HEADER, location).header(HttpHeaders.ETAG, "\"" + fingerprint + "\"").entity(createdCommentDTO).build();
    } catch (APIManagementException e) {
        String errorMessage = "Error while adding comment to api : " + apiId;
        Map<String, String> paramList = new HashMap<String, String>();
        paramList.put(APIMgtConstants.ExceptionsConstants.API_ID, body.getApiId());
        ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler(), paramList);
        log.error(errorMessage, e);
        return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
    } catch (URISyntaxException e) {
        String errorMessage = "Error while adding location header in response for comment";
        ErrorHandler errorHandler = ExceptionCodes.LOCATION_HEADER_INCORRECT;
        ErrorDTO errorDTO = RestApiUtil.getErrorDTO(errorHandler);
        log.error(errorMessage, e);
        return Response.status(errorHandler.getHttpStatusCode()).entity(errorDTO).build();
    }
}
Also used : Comment(org.wso2.carbon.apimgt.core.models.Comment) ErrorHandler(org.wso2.carbon.apimgt.core.exception.ErrorHandler) APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) ErrorDTO(org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO) CommentDTO(org.wso2.carbon.apimgt.rest.api.store.dto.CommentDTO) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) HashMap(java.util.HashMap) Map(java.util.Map) APIStore(org.wso2.carbon.apimgt.core.api.APIStore)

Example 67 with Comment

use of org.wso2.carbon.apimgt.core.models.Comment 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();
    }
}
Also used : Comment(org.wso2.carbon.apimgt.core.models.Comment) APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) ErrorDTO(org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO) CommentListDTO(org.wso2.carbon.apimgt.rest.api.store.dto.CommentListDTO) HashMap(java.util.HashMap) Map(java.util.Map) APIStore(org.wso2.carbon.apimgt.core.api.APIStore)

Example 68 with Comment

use of org.wso2.carbon.apimgt.core.models.Comment in project carbon-apimgt by wso2.

the class ApisApiServiceImpl method apisApiIdCommentsCommentIdGet.

/**
 * Retrives comments for a given API ID and comment ID
 *
 * @param commentId       Comment ID
 * @param apiId           API ID
 * @param ifNoneMatch     If-None-Match header value
 * @param ifModifiedSince If-Modified-Since header value
 * @param request         msf4j request object
 * @return CommentDTO object
 * @throws NotFoundException if this method is not defined in ApisApiServiceImpl
 */
@Override
public Response apisApiIdCommentsCommentIdGet(String commentId, String apiId, String ifNoneMatch, String ifModifiedSince, Request request) throws NotFoundException {
    String username = RestApiUtil.getLoggedInUsername(request);
    try {
        APIStore apiStore = RestApiUtil.getConsumer(username);
        String existingFingerprint = apisApiIdCommentsCommentIdGetFingerprint(commentId, apiId, ifNoneMatch, ifModifiedSince, request);
        if (!StringUtils.isEmpty(ifNoneMatch) && !StringUtils.isEmpty(existingFingerprint) && ifNoneMatch.contains(existingFingerprint)) {
            return Response.notModified().build();
        }
        Comment comment = apiStore.getCommentByUUID(commentId, apiId);
        CommentDTO commentDTO = CommentMappingUtil.fromCommentToDTO(comment);
        return Response.ok().header(HttpHeaders.ETAG, "\"" + existingFingerprint + "\"").entity(commentDTO).build();
    } catch (APIManagementException e) {
        String errorMessage = "Error while retrieving comment with commentId: " + commentId + " of apiID :" + apiId;
        Map<String, String> paramList = new HashMap<String, String>();
        paramList.put(APIMgtConstants.ExceptionsConstants.API_ID, apiId);
        paramList.put(APIMgtConstants.ExceptionsConstants.COMMENT_ID, commentId);
        ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler(), paramList);
        log.error(errorMessage, e);
        return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
    }
}
Also used : Comment(org.wso2.carbon.apimgt.core.models.Comment) APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) ErrorDTO(org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO) CommentDTO(org.wso2.carbon.apimgt.rest.api.store.dto.CommentDTO) HashMap(java.util.HashMap) Map(java.util.Map) APIStore(org.wso2.carbon.apimgt.core.api.APIStore)

Example 69 with Comment

use of org.wso2.carbon.apimgt.core.models.Comment in project carbon-business-process by wso2.

the class HistoricProcessInstanceService method createComment.

@POST
@Path("/{processInstanceId}/comments")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response createComment(@PathParam("processInstanceId") String processInstanceId, CommentResponse comment) {
    HistoricProcessInstance instance = getHistoricProcessInstanceFromRequest(processInstanceId);
    if (comment.getMessage() == null) {
        throw new ActivitiIllegalArgumentException("Comment text is required.");
    }
    TaskService taskService = BPMNOSGIService.getTaskService();
    Comment createdComment = taskService.addComment(null, instance.getId(), comment.getMessage());
    CommentResponse commentResponse = new RestResponseFactory().createRestComment(createdComment, uriInfo.getBaseUri().toString());
    return Response.ok().status(Response.Status.CREATED).entity(commentResponse).build();
}
Also used : Comment(org.activiti.engine.task.Comment) CommentResponse(org.wso2.carbon.bpmn.rest.model.runtime.CommentResponse) RestResponseFactory(org.wso2.carbon.bpmn.rest.common.RestResponseFactory) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance)

Example 70 with Comment

use of org.wso2.carbon.apimgt.core.models.Comment in project carbon-business-process by wso2.

the class InstanceManagementServiceSkeleton method fillScopeInfoWithEvents.

private void fillScopeInfoWithEvents(ScopeInfoWithEventsType scopeInfoWithEvents, ScopeDAO scope) {
    scopeInfoWithEvents.setSiid(scope.getScopeInstanceId().toString());
    scopeInfoWithEvents.setName(scope.getName());
    scopeInfoWithEvents.setStatus(odeScopeStatusToManagementAPIStatus(scope.getState()));
    ChildrenWithEvents_type0 childScopesWithEvents = new ChildrenWithEvents_type0();
    for (ScopeDAO childScope : scope.getChildScopes()) {
        ScopeInfoWithEventsType childScopeInfoWithEvents = new ScopeInfoWithEventsType();
        fillScopeInfoWithEvents(childScopeInfoWithEvents, childScope);
        childScopesWithEvents.addChildWithEventsRef(childScopeInfoWithEvents);
    }
    scopeInfoWithEvents.setChildrenWithEvents(childScopesWithEvents);
    // scopeInfoWithEvents.setVariablesWithEvents(getVariablesWithEvents(scope));         //TODO:
    // TODO: Just need to change the schema s.t. avoid CorrelationSets_type1 and remove the comment
    // if (!scope.getCorrelationSets().isEmpty()) {
    // //            scopeInfoWithEvents.setCorrelationSets(getCorrelationPropertires(scope));
    // }
    scopeInfoWithEvents.setActivitiesWithEvents(getActivitiesWithEvents(scope));
}
Also used : ScopeInfoWithEventsType(org.wso2.carbon.bpel.skeleton.ode.integration.mgt.services.types.ScopeInfoWithEventsType) ChildrenWithEvents_type0(org.wso2.carbon.bpel.skeleton.ode.integration.mgt.services.types.ChildrenWithEvents_type0) ScopeDAO(org.apache.ode.bpel.dao.ScopeDAO)

Aggregations

Comment (org.wso2.carbon.apimgt.core.models.Comment)36 APIStore (org.wso2.carbon.apimgt.core.api.APIStore)28 ApiDAO (org.wso2.carbon.apimgt.core.dao.ApiDAO)23 Test (org.testng.annotations.Test)22 SQLException (java.sql.SQLException)18 BeforeTest (org.testng.annotations.BeforeTest)18 API (org.wso2.carbon.apimgt.core.models.API)17 CompositeAPI (org.wso2.carbon.apimgt.core.models.CompositeAPI)17 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)16 Comment (org.wso2.carbon.apimgt.api.model.Comment)16 APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)15 PreparedStatement (java.sql.PreparedStatement)13 Connection (java.sql.Connection)12 HashMap (java.util.HashMap)12 Map (java.util.Map)12 ArrayList (java.util.ArrayList)10 CommentDTO (org.wso2.carbon.apimgt.rest.api.store.dto.CommentDTO)9 URI (java.net.URI)8 URISyntaxException (java.net.URISyntaxException)8 Test (org.junit.Test)8