Search in sources :

Example 66 with Header

use of org.kie.server.remote.rest.common.Header in project droolsjbpm-integration by kiegroup.

the class ProcessResource method startProcessWithCorrelation.

@ApiOperation(value = "Starts a new process instance of a specified process and assigns a new correlation key to the process instance.")
@ApiResponses(value = { @ApiResponse(code = 201, response = Long.class, message = "Process instance started", examples = @Example(value = { @ExampleProperty(mediaType = JSON, value = LONG_RESPONSE_JSON), @ExampleProperty(mediaType = XML, value = LONG_RESPONSE_XML) })), @ApiResponse(code = 500, message = "Unexpected error"), @ApiResponse(code = 404, message = "Process ID or Container Id not found"), @ApiResponse(code = 403, message = "User does not have permission to access this asset"), @ApiResponse(code = 409, message = "Duplicate correlation key") })
@POST
@Path(START_PROCESS_WITH_CORRELATION_KEY_POST_URI)
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response startProcessWithCorrelation(@javax.ws.rs.core.Context HttpHeaders headers, @ApiParam(value = "container id where the process definition resides", required = true, example = "evaluation_1.0.0-SNAPSHOT") @PathParam(CONTAINER_ID) String containerId, @ApiParam(value = "process id that new instance should be created from", required = true, example = "evaluation") @PathParam(PROCESS_ID) String processId, @ApiParam(value = "correlation key to be assigned to process instance", required = true, example = "john-evaluation-2019") @PathParam("correlationKey") String correlationKey, @ApiParam(value = "optional map of process variables", required = false, examples = @Example(value = { @ExampleProperty(mediaType = JSON, value = VAR_MAP_JSON), @ExampleProperty(mediaType = XML, value = VAR_MAP_XML) })) @DefaultValue("") String payload) {
    Variant v = getVariant(headers);
    String type = getContentType(headers);
    Header conversationIdHeader = buildConversationIdHeader(containerId, context, headers);
    try {
        String response = processServiceBase.startProcessWithCorrelation(containerId, processId, correlationKey, payload, type);
        logger.debug("Returning CREATED response with content '{}'", response);
        return createResponse(response, v, Response.Status.CREATED, conversationIdHeader);
    } catch (DeploymentNotActiveException e) {
        return badRequest(e.getMessage(), v);
    } catch (DeploymentNotFoundException e) {
        return notFound(MessageFormat.format(CONTAINER_NOT_FOUND, containerId), v);
    } catch (ProcessDefinitionNotFoundException e) {
        return notFound(MessageFormat.format(PROCESS_DEFINITION_NOT_FOUND, processId, containerId), v);
    } catch (SecurityException e) {
        return forbidden(errorMessage(e, e.getMessage()), v, conversationIdHeader);
    } catch (Exception e) {
        if (isCorrelationKeyAlreadyExists(e)) {
            return conflict(errorMessage(e, e.getMessage()), v, conversationIdHeader);
        }
        logger.error("Unexpected error during processing {}", e.getMessage(), e);
        return internalServerError(MessageFormat.format(CREATE_RESPONSE_ERROR, e.getMessage()), v);
    }
}
Also used : RestUtils.createCorrectVariant(org.kie.server.remote.rest.common.util.RestUtils.createCorrectVariant) RestUtils.getVariant(org.kie.server.remote.rest.common.util.RestUtils.getVariant) Variant(javax.ws.rs.core.Variant) DeploymentNotActiveException(org.jbpm.services.api.DeploymentNotActiveException) DeploymentNotFoundException(org.jbpm.services.api.DeploymentNotFoundException) Header(org.kie.server.remote.rest.common.Header) RestUtils.buildConversationIdHeader(org.kie.server.remote.rest.common.util.RestUtils.buildConversationIdHeader) ProcessDefinitionNotFoundException(org.jbpm.services.api.ProcessDefinitionNotFoundException) ProcessInstanceNotFoundException(org.jbpm.services.api.ProcessInstanceNotFoundException) DeploymentNotFoundException(org.jbpm.services.api.DeploymentNotFoundException) WorkItemNotFoundException(org.jbpm.services.api.WorkItemNotFoundException) DeploymentNotActiveException(org.jbpm.services.api.DeploymentNotActiveException) ProcessDefinitionNotFoundException(org.jbpm.services.api.ProcessDefinitionNotFoundException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 67 with Header

use of org.kie.server.remote.rest.common.Header in project droolsjbpm-integration by kiegroup.

the class ProcessResource method startProcessFromNodeIds.

@ApiOperation(value = "Starts a new process instance from the specific nodes")
@ApiResponses(value = { @ApiResponse(code = 201, response = Long.class, message = "Process instance created", examples = @Example(value = { @ExampleProperty(mediaType = JSON, value = LONG_RESPONSE_JSON), @ExampleProperty(mediaType = XML, value = LONG_RESPONSE_XML) })), @ApiResponse(code = 500, message = "Unexpected error"), @ApiResponse(code = 404, message = "Process ID or Container Id not found"), @ApiResponse(code = 403, message = "User does not have permission to access this asset") })
@POST
@Path(START_PROCESS_FROM_NODES_POST_URI)
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response startProcessFromNodeIds(@javax.ws.rs.core.Context HttpHeaders headers, @ApiParam(value = "container id where the process definition resides", required = true, example = "evaluation_1.0.0-SNAPSHOT") @PathParam(CONTAINER_ID) String containerId, @ApiParam(value = "process instance id that new instance should be created from", required = true, example = "evaluation") @PathParam(PROCESS_ID) String processId, @ApiParam(value = "optional map of process variables", required = false) @DefaultValue("") String payload) {
    Variant v = getVariant(headers);
    String type = getContentType(headers);
    Header conversationIdHeader = buildConversationIdHeader(containerId, context, headers);
    try {
        String response = processServiceBase.startProcessFromNodeIds(containerId, processId, payload, type);
        logger.debug("Returning CREATED response with content '{}'", response);
        return createResponse(response, v, Response.Status.CREATED, conversationIdHeader);
    } catch (DeploymentNotActiveException e) {
        return badRequest(e.getMessage(), v);
    } catch (DeploymentNotFoundException e) {
        return notFound(MessageFormat.format(CONTAINER_NOT_FOUND, containerId), v);
    } catch (ProcessDefinitionNotFoundException e) {
        return notFound(MessageFormat.format(PROCESS_DEFINITION_NOT_FOUND, processId, containerId), v);
    } catch (SecurityException e) {
        return forbidden(errorMessage(e, e.getMessage()), v, conversationIdHeader);
    } catch (Exception e) {
        logger.error("Unexpected error during processing {}", e.getMessage(), e);
        return internalServerError(MessageFormat.format(CREATE_RESPONSE_ERROR, e.getMessage()), v);
    }
}
Also used : RestUtils.createCorrectVariant(org.kie.server.remote.rest.common.util.RestUtils.createCorrectVariant) RestUtils.getVariant(org.kie.server.remote.rest.common.util.RestUtils.getVariant) Variant(javax.ws.rs.core.Variant) DeploymentNotActiveException(org.jbpm.services.api.DeploymentNotActiveException) DeploymentNotFoundException(org.jbpm.services.api.DeploymentNotFoundException) Header(org.kie.server.remote.rest.common.Header) RestUtils.buildConversationIdHeader(org.kie.server.remote.rest.common.util.RestUtils.buildConversationIdHeader) ProcessDefinitionNotFoundException(org.jbpm.services.api.ProcessDefinitionNotFoundException) ProcessInstanceNotFoundException(org.jbpm.services.api.ProcessInstanceNotFoundException) DeploymentNotFoundException(org.jbpm.services.api.DeploymentNotFoundException) WorkItemNotFoundException(org.jbpm.services.api.WorkItemNotFoundException) DeploymentNotActiveException(org.jbpm.services.api.DeploymentNotActiveException) ProcessDefinitionNotFoundException(org.jbpm.services.api.ProcessDefinitionNotFoundException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 68 with Header

use of org.kie.server.remote.rest.common.Header in project droolsjbpm-integration by kiegroup.

the class ProcessResource method getWorkItem.

@ApiOperation(value = "Returns information about a specified work item for a specified process instance.")
@ApiResponses(value = { @ApiResponse(code = 500, message = "Unexpected error"), @ApiResponse(code = 404, message = "Process instance, Work Item or Container Id not found"), @ApiResponse(code = 403, message = "User does not have permission to access this asset"), @ApiResponse(code = 200, response = WorkItemInstance.class, message = "Successful response", examples = @Example(value = { @ExampleProperty(mediaType = JSON, value = GET_PROCESS_INSTANCE_WORK_ITEM_RESPONSE_JSON) })) })
@GET
@Path(PROCESS_INSTANCE_WORK_ITEM_BY_ID_GET_URI)
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response getWorkItem(@javax.ws.rs.core.Context HttpHeaders headers, @ApiParam(value = "container id that process instance belongs to", required = true, example = "evaluation_1.0.0-SNAPSHOT") @PathParam(CONTAINER_ID) String containerId, @ApiParam(value = "identifier of the process instance that work item belongs to", required = true, example = "123") @PathParam(PROCESS_INST_ID) Long processInstanceId, @ApiParam(value = "identifier of the work item to retrieve", required = true, example = "567") @PathParam("workItemId") Long workItemId) {
    Variant v = getVariant(headers);
    String type = getContentType(headers);
    Header conversationIdHeader = buildConversationIdHeader(containerId, context, headers);
    try {
        String response = processServiceBase.getWorkItem(containerId, processInstanceId, workItemId, type);
        logger.debug("Returning OK response with content '{}'", response);
        return createResponse(response, v, Response.Status.OK, conversationIdHeader);
    } catch (ProcessInstanceNotFoundException e) {
        return notFound(MessageFormat.format(PROCESS_INSTANCE_NOT_FOUND, processInstanceId), v, conversationIdHeader);
    } catch (DeploymentNotFoundException e) {
        return notFound(MessageFormat.format(CONTAINER_NOT_FOUND, containerId), v, conversationIdHeader);
    } catch (WorkItemNotFoundException e) {
        return notFound(MessageFormat.format(WORK_ITEM_NOT_FOUND, workItemId), v, conversationIdHeader);
    } catch (SecurityException e) {
        return forbidden(errorMessage(e, e.getMessage()), v, conversationIdHeader);
    } catch (Exception e) {
        logger.error("Unexpected error during processing {}", e.getMessage(), e);
        return internalServerError(errorMessage(e), v, conversationIdHeader);
    }
}
Also used : RestUtils.createCorrectVariant(org.kie.server.remote.rest.common.util.RestUtils.createCorrectVariant) RestUtils.getVariant(org.kie.server.remote.rest.common.util.RestUtils.getVariant) Variant(javax.ws.rs.core.Variant) DeploymentNotFoundException(org.jbpm.services.api.DeploymentNotFoundException) Header(org.kie.server.remote.rest.common.Header) RestUtils.buildConversationIdHeader(org.kie.server.remote.rest.common.util.RestUtils.buildConversationIdHeader) WorkItemNotFoundException(org.jbpm.services.api.WorkItemNotFoundException) ProcessInstanceNotFoundException(org.jbpm.services.api.ProcessInstanceNotFoundException) ProcessInstanceNotFoundException(org.jbpm.services.api.ProcessInstanceNotFoundException) DeploymentNotFoundException(org.jbpm.services.api.DeploymentNotFoundException) WorkItemNotFoundException(org.jbpm.services.api.WorkItemNotFoundException) DeploymentNotActiveException(org.jbpm.services.api.DeploymentNotActiveException) ProcessDefinitionNotFoundException(org.jbpm.services.api.ProcessDefinitionNotFoundException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 69 with Header

use of org.kie.server.remote.rest.common.Header in project droolsjbpm-integration by kiegroup.

the class QueryDataResource method runQuery.

@ApiOperation(value = "Returns the results of a specified custom query.")
@ApiResponses(value = { @ApiResponse(code = 500, message = "Unexpected error"), @ApiResponse(code = 404, message = "Query definition with given name not found"), @ApiResponse(code = 200, response = Object.class, responseContainer = "List", message = "Successful response", examples = @Example(value = { @ExampleProperty(mediaType = JSON, value = GET_PROCESS_INSTANCES_RESPONSE_JSON) })) })
@GET
@Path(RUN_QUERY_DEF_GET_URI)
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response runQuery(@Context HttpHeaders headers, @ApiParam(value = "identifier of the query definition to be used for query", required = true, example = "customQuery") @PathParam("queryName") String queryName, @ApiParam(value = "identifier of the query mapper to be used when transforming results", required = true) @QueryParam("mapper") String mapper, @ApiParam(value = "optional sort order", required = false) @QueryParam("orderBy") String orderBy, @ApiParam(value = "optional pagination - at which page to start, defaults to 0 (meaning first)", required = false) @QueryParam("page") @DefaultValue("0") Integer page, @ApiParam(value = "optional pagination - size of the result, defaults to 10", required = false) @QueryParam("pageSize") @DefaultValue("10") Integer pageSize) {
    // no container id available so only used to transfer conversation id if
    // given by client
    Header conversationIdHeader = buildConversationIdHeader("", context, headers);
    Object result = queryDataServiceBase.query(queryName, mapper, orderBy, page, pageSize);
    logger.debug("Returning result of process instance search: {}", result);
    return createCorrectVariant(result, headers, Response.Status.OK, conversationIdHeader);
}
Also used : Header(org.kie.server.remote.rest.common.Header) RestUtils.buildConversationIdHeader(org.kie.server.remote.rest.common.util.RestUtils.buildConversationIdHeader) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 70 with Header

use of org.kie.server.remote.rest.common.Header in project droolsjbpm-integration by kiegroup.

the class QueryDataResource method dropQueryDefinition.

@ApiOperation(value = "Deletes a specified custom query.", response = Void.class, code = 204)
@ApiResponses(value = { @ApiResponse(code = 500, message = "Unexpected error"), @ApiResponse(code = 404, message = "Query definition with given name not found") })
@DELETE
@Path(DROP_QUERY_DEF_DELETE_URI)
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response dropQueryDefinition(@javax.ws.rs.core.Context HttpHeaders headers, @ApiParam(value = "identifier of the query definition to be deleted", required = true, example = "customQuery") @PathParam("queryName") String queryName) {
    Variant v = getVariant(headers);
    // no container id available so only used to transfer conversation id if
    // given by client
    Header conversationIdHeader = buildConversationIdHeader("", context, headers);
    try {
        queryDataServiceBase.unregisterQuery(queryName);
        // produce 204 NO_CONTENT response code
        return noContent(v, conversationIdHeader);
    } catch (QueryNotFoundException e) {
        return notFound(MessageFormat.format(QUERY_NOT_FOUND, queryName), v, conversationIdHeader);
    } catch (Exception e) {
        logger.error("Unexpected error during processing {}", e.getMessage(), e);
        return internalServerError(errorMessage(e), v, conversationIdHeader);
    }
}
Also used : RestUtils.getVariant(org.kie.server.remote.rest.common.util.RestUtils.getVariant) RestUtils.createCorrectVariant(org.kie.server.remote.rest.common.util.RestUtils.createCorrectVariant) Variant(javax.ws.rs.core.Variant) Header(org.kie.server.remote.rest.common.Header) RestUtils.buildConversationIdHeader(org.kie.server.remote.rest.common.util.RestUtils.buildConversationIdHeader) QueryNotFoundException(org.jbpm.services.api.query.QueryNotFoundException) HttpStatusCodeException(org.kie.server.common.rest.HttpStatusCodeException) QueryAlreadyRegisteredException(org.jbpm.services.api.query.QueryAlreadyRegisteredException) DataSetLookupException(org.dashbuilder.dataset.exception.DataSetLookupException) QueryNotFoundException(org.jbpm.services.api.query.QueryNotFoundException) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Aggregations

Header (org.kie.server.remote.rest.common.Header)212 ApiOperation (io.swagger.annotations.ApiOperation)203 Produces (javax.ws.rs.Produces)203 ApiResponses (io.swagger.annotations.ApiResponses)197 Path (javax.ws.rs.Path)191 RestUtils.buildConversationIdHeader (org.kie.server.remote.rest.common.util.RestUtils.buildConversationIdHeader)190 Variant (javax.ws.rs.core.Variant)184 RestUtils.createCorrectVariant (org.kie.server.remote.rest.common.util.RestUtils.createCorrectVariant)175 RestUtils.getVariant (org.kie.server.remote.rest.common.util.RestUtils.getVariant)168 GET (javax.ws.rs.GET)110 DeploymentNotFoundException (org.jbpm.services.api.DeploymentNotFoundException)75 ProcessInstanceNotFoundException (org.jbpm.services.api.ProcessInstanceNotFoundException)72 TaskNotFoundException (org.jbpm.services.api.TaskNotFoundException)70 Consumes (javax.ws.rs.Consumes)54 PUT (javax.ws.rs.PUT)42 PermissionDeniedException (org.jbpm.services.task.exception.PermissionDeniedException)41 POST (javax.ws.rs.POST)35 ProcessDefinitionNotFoundException (org.jbpm.services.api.ProcessDefinitionNotFoundException)31 ExecutionErrorNotFoundException (org.jbpm.services.api.admin.ExecutionErrorNotFoundException)31 DeploymentNotActiveException (org.jbpm.services.api.DeploymentNotActiveException)25