Search in sources :

Example 41 with Header

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

the class ProcessResource method startProcessWithCorrelationKeyFromNodeIds.

@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"), @ApiResponse(code = 409, message = "Duplicate correlation key") })
@POST
@Path(START_PROCESS_FROM_NODES_WITH_CORRELATION_KEY_POST_URI)
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response startProcessWithCorrelationKeyFromNodeIds(@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 = "correlation key that should be used for creating the process", required = true, example = "evaluation") @PathParam(CORRELATION_KEY) String correlationKey, @ApiParam(value = "start process specifications", required = false) @DefaultValue("") String payload) {
    Variant v = getVariant(headers);
    String type = getContentType(headers);
    Header conversationIdHeader = buildConversationIdHeader(containerId, context, headers);
    try {
        String response = processServiceBase.startProcessWithCorrelationKeyFromNodeIds(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 42 with Header

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

the class ProcessResource method signalProcessInstances.

@ApiOperation(value = "Signals multiple process instances with a specified signal name.", response = Void.class, code = 200)
@ApiResponses(value = { @ApiResponse(code = 500, message = "Unexpected error"), @ApiResponse(code = 404, message = "Process instance or Container Id not found"), @ApiResponse(code = 403, message = "User does not have permission to access this asset") })
@POST
@Path(SIGNAL_PROCESS_INSTANCES_PORT_URI)
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response signalProcessInstances(@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 = "list of identifiers of the process instances to be signaled", required = false) @QueryParam("instanceId") List<Long> processInstanceIds, @ApiParam(value = "list of correlationKeys of the process instances to be signaled", required = false) @QueryParam("correlationKey") List<String> correlationKeys, @ApiParam(value = "signal name to be send to process instance", required = true, example = "EventReceived") @PathParam(SIGNAL_NAME) String signalName, @ApiParam(value = "optional event data - any type can be provided", required = false, examples = @Example(value = { @ExampleProperty(mediaType = JSON, value = VAR_JSON), @ExampleProperty(mediaType = XML, value = VAR_XML) })) String eventPayload) {
    Variant v = getVariant(headers);
    String type = getContentType(headers);
    Header conversationIdHeader = buildConversationIdHeader(containerId, context, headers);
    try {
        if (processInstanceIds != null && !processInstanceIds.isEmpty()) {
            logger.debug("Signaling given process instances - {}", processInstanceIds);
            processServiceBase.signalProcessInstances(containerId, processInstanceIds, signalName, eventPayload, type);
        } else if (correlationKeys != null && !correlationKeys.isEmpty()) {
            logger.debug("Signaling given process instances by correlation key - {}", correlationKeys);
            processServiceBase.signalProcessInstancesByCorrelationKey(containerId, correlationKeys, signalName, eventPayload, type);
        } else {
            logger.debug("No process instances given, signal container..");
            processServiceBase.signal(containerId, signalName, eventPayload, type);
        }
        return createResponse("", v, Response.Status.OK, conversationIdHeader);
    } catch (ProcessInstanceNotFoundException e) {
        return notFound(MessageFormat.format(PROCESS_INSTANCE_NOT_FOUND, processInstanceIds), v, conversationIdHeader);
    } catch (DeploymentNotFoundException e) {
        return notFound(MessageFormat.format(CONTAINER_NOT_FOUND, containerId), 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) 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) 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 43 with Header

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

the class FormResource method getProcessForm.

@ApiOperation(value = "Returns the form information for a specified process definition.")
@ApiResponses(value = { @ApiResponse(code = 500, message = "Unexpected error"), @ApiResponse(code = 404, message = "Process definition, form or Container Id not found"), @ApiResponse(code = 200, response = String.class, message = "Successful response", examples = @Example(value = { @ExampleProperty(mediaType = JSON, value = PROCESS_FORM_DEF_JSON) })) })
@GET
@Path(PROCESS_FORM_GET_URI)
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response getProcessForm(@javax.ws.rs.core.Context HttpHeaders headers, @ApiParam(value = "container id that process definition belongs to", required = true, example = "evaluation_1.0.0-SNAPSHOT") @PathParam(CONTAINER_ID) String containerId, @ApiParam(value = "identifier of process definition that form should be fetched for", required = true, example = "evaluation") @PathParam(PROCESS_ID) String processId, @ApiParam(value = "optional language that the form should be found for", required = false) @QueryParam("lang") @DefaultValue("en") String language, @ApiParam(value = "optional filter flag if form should be filtered or returned as is", required = false) @QueryParam("filter") boolean filter, @ApiParam(value = "optional type of the form, defaults to ANY so system will find the most current one", required = false) @QueryParam("type") @DefaultValue("ANY") String formType, @ApiParam(value = "optional marshall content flag if the content should be transformed or not, defaults to true", required = false) @QueryParam("marshallContent") @DefaultValue("true") boolean marshallContent) {
    Variant variant = getVariant(headers);
    Header conversationIdHeader = buildConversationIdHeader(containerId, context, headers);
    try {
        String response = formServiceBase.getFormDisplayProcess(containerId, processId, language, filter, formType);
        if (marshallContent) {
            response = marshallFormContent(response, formType, variant);
        }
        logger.debug("Returning OK response with content '{}'", response);
        return createResponse(response, variant, Response.Status.OK, conversationIdHeader);
    } catch (DeploymentNotFoundException e) {
        return notFound(MessageFormat.format(CONTAINER_NOT_FOUND, containerId), variant, conversationIdHeader);
    } catch (ProcessDefinitionNotFoundException e) {
        return notFound(MessageFormat.format(PROCESS_DEFINITION_NOT_FOUND, processId, containerId), variant, conversationIdHeader);
    } catch (IllegalStateException e) {
        return notFound("Form for process id " + processId + " not found", variant, conversationIdHeader);
    } catch (Exception e) {
        logger.error("Unexpected error during processing {}", e.getMessage(), e);
        return internalServerError(errorMessage(e), variant, conversationIdHeader);
    }
}
Also used : 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) ProcessDefinitionNotFoundException(org.jbpm.services.api.ProcessDefinitionNotFoundException) JSONException(org.json.JSONException) PermissionDeniedException(org.jbpm.services.task.exception.PermissionDeniedException) ProcessDefinitionNotFoundException(org.jbpm.services.api.ProcessDefinitionNotFoundException) DeploymentNotFoundException(org.jbpm.services.api.DeploymentNotFoundException) TaskNotFoundException(org.jbpm.services.api.TaskNotFoundException) 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 44 with Header

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

the class FormResource method getProcessRenderedForm.

@ApiOperation(value = "Returns the rendered form for a specified process definition", response = String.class, code = 200)
@ApiResponses(value = { @ApiResponse(code = 500, message = "Unexpected error"), @ApiResponse(code = 404, message = "Process, form or Container Id not found") })
@GET
@Path(PROCESS_FORM_CONTENT_GET_URI)
@Produces({ MediaType.TEXT_HTML })
public Response getProcessRenderedForm(@javax.ws.rs.core.Context HttpHeaders headers, @ApiParam(value = "container id that process definition belongs to", required = true, example = "evaluation_1.0.0-SNAPSHOT") @PathParam(CONTAINER_ID) String containerId, @ApiParam(value = "identifier of process definition that form should be fetched for", required = true, example = "evaluation") @PathParam(PROCESS_ID) String processId, @ApiParam(value = "optional renderer name that the form should be rendered with", required = false) @QueryParam("renderer") @DefaultValue("patternfly") String renderer) {
    Variant variant = getVariant(headers);
    Header conversationIdHeader = buildConversationIdHeader(containerId, context, headers);
    try {
        String renderedForm = formRendererBase.getProcessRenderedForm(renderer, containerId, processId);
        if (renderedForm == null) {
            return Response.status(Status.NOT_FOUND).build();
        }
        return Response.ok().entity(renderedForm).build();
    } catch (DeploymentNotFoundException e) {
        return notFound(MessageFormat.format(CONTAINER_NOT_FOUND, containerId), variant, conversationIdHeader);
    } catch (ProcessDefinitionNotFoundException e) {
        return notFound(MessageFormat.format(PROCESS_DEFINITION_NOT_FOUND, processId, containerId), variant, conversationIdHeader);
    } catch (IllegalArgumentException e) {
        return notFound(e.getMessage(), variant, conversationIdHeader);
    } catch (Exception e) {
        logger.error("Unexpected error during processing {}", e.getMessage(), e);
        return internalServerError(errorMessage(e), variant, conversationIdHeader);
    }
}
Also used : 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) ProcessDefinitionNotFoundException(org.jbpm.services.api.ProcessDefinitionNotFoundException) JSONException(org.json.JSONException) PermissionDeniedException(org.jbpm.services.task.exception.PermissionDeniedException) ProcessDefinitionNotFoundException(org.jbpm.services.api.ProcessDefinitionNotFoundException) DeploymentNotFoundException(org.jbpm.services.api.DeploymentNotFoundException) TaskNotFoundException(org.jbpm.services.api.TaskNotFoundException) 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 45 with Header

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

the class ImageResource method getProcessImage.

@ApiOperation(value = "Returns an SVG image file of a specified process definition diagram.", response = String.class, code = 200)
@ApiResponses(value = { @ApiResponse(code = 500, message = "Unexpected error"), @ApiResponse(code = 404, message = "Process definition, image or Container Id not found") })
@GET
@Path(PROCESS_IMG_GET_URI)
@Produces({ MediaType.APPLICATION_SVG_XML })
public Response getProcessImage(@javax.ws.rs.core.Context HttpHeaders headers, @ApiParam(value = "container id that process definition belongs to", required = true, example = "evaluation_1.0.0-SNAPSHOT") @PathParam(CONTAINER_ID) String containerId, @ApiParam(value = "identifier of the process definition that image should be loaded for", required = true, example = "evaluation") @PathParam(PROCESS_ID) String processId) {
    Variant v = getVariant(headers);
    Header conversationIdHeader = buildConversationIdHeader(containerId, context, headers);
    try {
        String svgString = imageServiceBase.getProcessImage(containerId, processId);
        logger.debug("Returning OK response with content '{}'", svgString);
        return createResponse(svgString, v, Response.Status.OK, conversationIdHeader);
    } catch (IllegalArgumentException e) {
        return notFound("Image for process id " + processId + " not found", v, conversationIdHeader);
    } catch (Exception e) {
        logger.error("Unexpected error during processing {}", e.getMessage(), e);
        return internalServerError(errorMessage(e), v, conversationIdHeader);
    }
}
Also used : Variant(javax.ws.rs.core.Variant) Header(org.kie.server.remote.rest.common.Header) ProcessInstanceNotFoundException(org.jbpm.services.api.ProcessInstanceNotFoundException) 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)

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