Search in sources :

Example 1 with DeploymentNotActiveException

use of org.jbpm.services.api.DeploymentNotActiveException 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 2 with DeploymentNotActiveException

use of org.jbpm.services.api.DeploymentNotActiveException 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 3 with DeploymentNotActiveException

use of org.jbpm.services.api.DeploymentNotActiveException 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 4 with DeploymentNotActiveException

use of org.jbpm.services.api.DeploymentNotActiveException in project jbpm by kiegroup.

the class AdHocProcessServiceImpl method startProcess.

@Override
public Long startProcess(String deploymentId, String processId, CorrelationKey correlationKey, Map<String, Object> params, Long parentProcessInstanceId) {
    DeployedUnit deployedUnit = deploymentService.getDeployedUnit(deploymentId);
    if (deployedUnit == null) {
        throw new DeploymentNotFoundException("No deployments available for " + deploymentId);
    }
    if (!deployedUnit.isActive()) {
        throw new DeploymentNotActiveException("Deployment " + deploymentId + " is not active");
    }
    RuntimeManager manager = deployedUnit.getRuntimeManager();
    params = process(params, ((InternalRuntimeManager) manager).getEnvironment().getClassLoader());
    RuntimeEngine engine = manager.getRuntimeEngine(ProcessInstanceIdContext.get());
    KieSession ksession = engine.getKieSession();
    ProcessInstance pi = null;
    try {
        pi = ((CorrelationAwareProcessRuntime) ksession).createProcessInstance(processId, correlationKey, params);
        pi = ksession.execute(new StartProcessInstanceWithParentCommand(pi.getId(), parentProcessInstanceId));
        return pi.getId();
    } finally {
        disposeRuntimeEngine(manager, engine);
    }
}
Also used : DeploymentNotActiveException(org.jbpm.services.api.DeploymentNotActiveException) DeploymentNotFoundException(org.jbpm.services.api.DeploymentNotFoundException) RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) DeployedUnit(org.jbpm.services.api.model.DeployedUnit) RuntimeManager(org.kie.api.runtime.manager.RuntimeManager) InternalRuntimeManager(org.kie.internal.runtime.manager.InternalRuntimeManager) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) StartProcessInstanceWithParentCommand(org.jbpm.kie.services.impl.cmd.StartProcessInstanceWithParentCommand)

Example 5 with DeploymentNotActiveException

use of org.jbpm.services.api.DeploymentNotActiveException in project jbpm by kiegroup.

the class ProcessServiceImpl method startProcess.

@Override
public Long startProcess(String deploymentId, String processId, Map<String, Object> params) {
    DeployedUnit deployedUnit = deploymentService.getDeployedUnit(deploymentId);
    if (deployedUnit == null) {
        throw new DeploymentNotFoundException("No deployments available for " + deploymentId);
    }
    if (!deployedUnit.isActive()) {
        throw new DeploymentNotActiveException("Deployment " + deploymentId + " is not active");
    }
    RuntimeManager manager = deployedUnit.getRuntimeManager();
    params = process(params, ((InternalRuntimeManager) manager).getEnvironment().getClassLoader());
    RuntimeEngine engine = manager.getRuntimeEngine(getContext(params));
    KieSession ksession = engine.getKieSession();
    ProcessInstance pi;
    try {
        pi = ksession.startProcess(processId, params);
        return pi.getId();
    } finally {
        disposeRuntimeEngine(manager, engine);
    }
}
Also used : DeploymentNotActiveException(org.jbpm.services.api.DeploymentNotActiveException) DeploymentNotFoundException(org.jbpm.services.api.DeploymentNotFoundException) RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) DeployedUnit(org.jbpm.services.api.model.DeployedUnit) RuntimeManager(org.kie.api.runtime.manager.RuntimeManager) InternalRuntimeManager(org.kie.internal.runtime.manager.InternalRuntimeManager) KieSession(org.kie.api.runtime.KieSession) RuleFlowProcessInstance(org.jbpm.ruleflow.instance.RuleFlowProcessInstance) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) WorkflowProcessInstance(org.kie.api.runtime.process.WorkflowProcessInstance)

Aggregations

DeploymentNotActiveException (org.jbpm.services.api.DeploymentNotActiveException)10 DeploymentNotFoundException (org.jbpm.services.api.DeploymentNotFoundException)10 ApiOperation (io.swagger.annotations.ApiOperation)5 ApiResponses (io.swagger.annotations.ApiResponses)5 Consumes (javax.ws.rs.Consumes)5 POST (javax.ws.rs.POST)5 Path (javax.ws.rs.Path)5 Produces (javax.ws.rs.Produces)5 Variant (javax.ws.rs.core.Variant)5 ProcessDefinitionNotFoundException (org.jbpm.services.api.ProcessDefinitionNotFoundException)5 ProcessInstanceNotFoundException (org.jbpm.services.api.ProcessInstanceNotFoundException)5 WorkItemNotFoundException (org.jbpm.services.api.WorkItemNotFoundException)5 DeployedUnit (org.jbpm.services.api.model.DeployedUnit)5 KieSession (org.kie.api.runtime.KieSession)5 RuntimeEngine (org.kie.api.runtime.manager.RuntimeEngine)5 RuntimeManager (org.kie.api.runtime.manager.RuntimeManager)5 InternalRuntimeManager (org.kie.internal.runtime.manager.InternalRuntimeManager)5 Header (org.kie.server.remote.rest.common.Header)5 RestUtils.buildConversationIdHeader (org.kie.server.remote.rest.common.util.RestUtils.buildConversationIdHeader)5 RestUtils.createCorrectVariant (org.kie.server.remote.rest.common.util.RestUtils.createCorrectVariant)5