Search in sources :

Example 66 with ActivitiException

use of org.activiti.engine.ActivitiException in project carbon-business-process by wso2.

the class HistoricDetailService method getVariableData.

@GET
@Path("/{detailId}/data")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response getVariableData(@PathParam("detailId") String detailId) {
    try {
        byte[] result = null;
        RestVariable variable = getVariableFromRequest(true, detailId);
        Response.ResponseBuilder response = Response.ok();
        if (RestResponseFactory.BYTE_ARRAY_VARIABLE_TYPE.equals(variable.getType())) {
            result = (byte[]) variable.getValue();
            response.type("application/octet-stream");
        } else if (RestResponseFactory.SERIALIZABLE_VARIABLE_TYPE.equals(variable.getType())) {
            ByteArrayOutputStream buffer = new ByteArrayOutputStream();
            ObjectOutputStream outputStream = new ObjectOutputStream(buffer);
            outputStream.writeObject(variable.getValue());
            outputStream.close();
            result = buffer.toByteArray();
            response.type("application/x-java-serialized-object");
        } else {
            throw new ActivitiObjectNotFoundException("The variable does not have a binary data stream.", null);
        }
        return response.entity(result).build();
    } catch (IOException ioe) {
        // Re-throw IOException
        throw new ActivitiException("Unexpected exception getting variable data", ioe);
    }
}
Also used : RestVariable(org.wso2.carbon.bpmn.rest.engine.variable.RestVariable) DataResponse(org.wso2.carbon.bpmn.rest.model.common.DataResponse) Response(javax.ws.rs.core.Response) ActivitiException(org.activiti.engine.ActivitiException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) ObjectOutputStream(java.io.ObjectOutputStream) ActivitiObjectNotFoundException(org.activiti.engine.ActivitiObjectNotFoundException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 67 with ActivitiException

use of org.activiti.engine.ActivitiException in project carbon-business-process by wso2.

the class FormDataService method submitForm.

@POST
@Path("/")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response submitForm(SubmitFormRequest submitRequest) {
    if (submitRequest == null) {
        throw new ActivitiException("A request body was expected when executing the form submit.");
    }
    if (submitRequest.getTaskId() == null && submitRequest.getProcessDefinitionId() == null) {
        throw new ActivitiIllegalArgumentException("The taskId or processDefinitionId property has to be provided");
    }
    Map<String, String> propertyMap = new HashMap<String, String>();
    if (submitRequest.getProperties() != null) {
        for (RestFormProperty formProperty : submitRequest.getProperties()) {
            propertyMap.put(formProperty.getId(), formProperty.getValue());
        }
    }
    FormService formService = BPMNOSGIService.getFormService();
    Response.ResponseBuilder response = Response.ok();
    if (submitRequest.getTaskId() != null) {
        formService.submitTaskFormData(submitRequest.getTaskId(), propertyMap);
        response.status(Response.Status.NO_CONTENT);
        return response.build();
    } else {
        ProcessInstance processInstance = null;
        if (submitRequest.getBusinessKey() != null) {
            processInstance = formService.submitStartFormData(submitRequest.getProcessDefinitionId(), submitRequest.getBusinessKey(), propertyMap);
        } else {
            processInstance = formService.submitStartFormData(submitRequest.getProcessDefinitionId(), propertyMap);
        }
        ProcessInstanceResponse processInstanceResponse = new RestResponseFactory().createProcessInstanceResponse(processInstance, uriInfo.getBaseUri().toString());
        return response.entity(processInstanceResponse).build();
    }
}
Also used : ProcessInstanceResponse(org.wso2.carbon.bpmn.rest.model.runtime.ProcessInstanceResponse) Response(javax.ws.rs.core.Response) ActivitiException(org.activiti.engine.ActivitiException) RestResponseFactory(org.wso2.carbon.bpmn.rest.common.RestResponseFactory) HashMap(java.util.HashMap) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) FormService(org.activiti.engine.FormService) ProcessInstanceResponse(org.wso2.carbon.bpmn.rest.model.runtime.ProcessInstanceResponse) RestFormProperty(org.wso2.carbon.bpmn.rest.model.form.RestFormProperty) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces)

Example 68 with ActivitiException

use of org.activiti.engine.ActivitiException in project tutorials-java by Artister.

the class ModelSaveRestResource method saveModel.

@RequestMapping(value = "/model/{modelId}/save", method = RequestMethod.PUT)
@ResponseStatus(value = HttpStatus.OK)
public void saveModel(@PathVariable String modelId, @RequestParam("name") String name, @RequestParam("json_xml") String json_xml, @RequestParam("svg_xml") String svg_xml, @RequestParam("description") String description) {
    // 对接收参数进行了修改
    try {
        Model model = repositoryService.getModel(modelId);
        ObjectNode modelJson = (ObjectNode) objectMapper.readTree(model.getMetaInfo());
        modelJson.put(MODEL_NAME, name);
        modelJson.put(MODEL_DESCRIPTION, description);
        model.setMetaInfo(modelJson.toString());
        model.setName(name);
        repositoryService.saveModel(model);
        repositoryService.addModelEditorSource(model.getId(), json_xml.getBytes("utf-8"));
        InputStream svgStream = new ByteArrayInputStream(svg_xml.getBytes("utf-8"));
        TranscoderInput input = new TranscoderInput(svgStream);
        PNGTranscoder transcoder = new PNGTranscoder();
        // Setup output
        ByteArrayOutputStream outStream = new ByteArrayOutputStream();
        TranscoderOutput output = new TranscoderOutput(outStream);
        // Do the transformation
        transcoder.transcode(input, output);
        final byte[] result = outStream.toByteArray();
        repositoryService.addModelEditorSourceExtra(model.getId(), result);
        outStream.close();
    } catch (Exception e) {
        LOGGER.error("Error saving model", e);
        throw new ActivitiException("Error saving model", e);
    }
}
Also used : PNGTranscoder(org.apache.batik.transcoder.image.PNGTranscoder) ActivitiException(org.activiti.engine.ActivitiException) TranscoderOutput(org.apache.batik.transcoder.TranscoderOutput) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ByteArrayInputStream(java.io.ByteArrayInputStream) TranscoderInput(org.apache.batik.transcoder.TranscoderInput) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Model(org.activiti.engine.repository.Model) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ActivitiException(org.activiti.engine.ActivitiException)

Example 69 with ActivitiException

use of org.activiti.engine.ActivitiException in project Activiti by Activiti.

the class DefaultActivityBehaviorFactory method createMuleActivityBehavior.

protected ActivityBehavior createMuleActivityBehavior(TaskWithFieldExtensions task, List<FieldExtension> fieldExtensions) {
    try {
        Class<?> theClass = Class.forName("org.activiti.mule.MuleSendActivitiBehavior");
        List<FieldDeclaration> fieldDeclarations = createFieldDeclarations(fieldExtensions);
        return (ActivityBehavior) ClassDelegate.defaultInstantiateDelegate(theClass, fieldDeclarations);
    } catch (ClassNotFoundException e) {
        throw new ActivitiException("Could not find org.activiti.mule.MuleSendActivitiBehavior: ", e);
    }
}
Also used : ActivitiException(org.activiti.engine.ActivitiException) BoundaryTimerEventActivityBehavior(org.activiti.engine.impl.bpmn.behavior.BoundaryTimerEventActivityBehavior) IntermediateCatchSignalEventActivityBehavior(org.activiti.engine.impl.bpmn.behavior.IntermediateCatchSignalEventActivityBehavior) BoundaryMessageEventActivityBehavior(org.activiti.engine.impl.bpmn.behavior.BoundaryMessageEventActivityBehavior) UserTaskActivityBehavior(org.activiti.engine.impl.bpmn.behavior.UserTaskActivityBehavior) ActivityBehavior(org.activiti.engine.impl.delegate.ActivityBehavior) MailActivityBehavior(org.activiti.engine.impl.bpmn.behavior.MailActivityBehavior) IntermediateThrowNoneEventActivityBehavior(org.activiti.engine.impl.bpmn.behavior.IntermediateThrowNoneEventActivityBehavior) BoundarySignalEventActivityBehavior(org.activiti.engine.impl.bpmn.behavior.BoundarySignalEventActivityBehavior) ManualTaskActivityBehavior(org.activiti.engine.impl.bpmn.behavior.ManualTaskActivityBehavior) IntermediateCatchEventActivityBehavior(org.activiti.engine.impl.bpmn.behavior.IntermediateCatchEventActivityBehavior) EventSubProcessErrorStartEventActivityBehavior(org.activiti.engine.impl.bpmn.behavior.EventSubProcessErrorStartEventActivityBehavior) EventBasedGatewayActivityBehavior(org.activiti.engine.impl.bpmn.behavior.EventBasedGatewayActivityBehavior) CancelEndEventActivityBehavior(org.activiti.engine.impl.bpmn.behavior.CancelEndEventActivityBehavior) AbstractBpmnActivityBehavior(org.activiti.engine.impl.bpmn.behavior.AbstractBpmnActivityBehavior) EventSubProcessMessageStartEventActivityBehavior(org.activiti.engine.impl.bpmn.behavior.EventSubProcessMessageStartEventActivityBehavior) ParallelGatewayActivityBehavior(org.activiti.engine.impl.bpmn.behavior.ParallelGatewayActivityBehavior) IntermediateThrowMessageEventActivityBehavior(org.activiti.engine.impl.bpmn.behavior.IntermediateThrowMessageEventActivityBehavior) BoundaryEventActivityBehavior(org.activiti.engine.impl.bpmn.behavior.BoundaryEventActivityBehavior) ScriptTaskActivityBehavior(org.activiti.engine.impl.bpmn.behavior.ScriptTaskActivityBehavior) ErrorEndEventActivityBehavior(org.activiti.engine.impl.bpmn.behavior.ErrorEndEventActivityBehavior) InclusiveGatewayActivityBehavior(org.activiti.engine.impl.bpmn.behavior.InclusiveGatewayActivityBehavior) AdhocSubProcessActivityBehavior(org.activiti.engine.impl.bpmn.behavior.AdhocSubProcessActivityBehavior) ServiceTaskDelegateExpressionActivityBehavior(org.activiti.engine.impl.bpmn.behavior.ServiceTaskDelegateExpressionActivityBehavior) ServiceTaskExpressionActivityBehavior(org.activiti.engine.impl.bpmn.behavior.ServiceTaskExpressionActivityBehavior) BoundaryCompensateEventActivityBehavior(org.activiti.engine.impl.bpmn.behavior.BoundaryCompensateEventActivityBehavior) ReceiveTaskActivityBehavior(org.activiti.engine.impl.bpmn.behavior.ReceiveTaskActivityBehavior) CallActivityBehavior(org.activiti.engine.impl.bpmn.behavior.CallActivityBehavior) ExclusiveGatewayActivityBehavior(org.activiti.engine.impl.bpmn.behavior.ExclusiveGatewayActivityBehavior) TransactionActivityBehavior(org.activiti.engine.impl.bpmn.behavior.TransactionActivityBehavior) NoneStartEventActivityBehavior(org.activiti.engine.impl.bpmn.behavior.NoneStartEventActivityBehavior) ShellActivityBehavior(org.activiti.engine.impl.bpmn.behavior.ShellActivityBehavior) TerminateEndEventActivityBehavior(org.activiti.engine.impl.bpmn.behavior.TerminateEndEventActivityBehavior) IntermediateThrowCompensationEventActivityBehavior(org.activiti.engine.impl.bpmn.behavior.IntermediateThrowCompensationEventActivityBehavior) IntermediateThrowSignalEventActivityBehavior(org.activiti.engine.impl.bpmn.behavior.IntermediateThrowSignalEventActivityBehavior) WebServiceActivityBehavior(org.activiti.engine.impl.bpmn.behavior.WebServiceActivityBehavior) NoneEndEventActivityBehavior(org.activiti.engine.impl.bpmn.behavior.NoneEndEventActivityBehavior) IntermediateCatchTimerEventActivityBehavior(org.activiti.engine.impl.bpmn.behavior.IntermediateCatchTimerEventActivityBehavior) ThrowMessageEndEventActivityBehavior(org.activiti.engine.impl.bpmn.behavior.ThrowMessageEndEventActivityBehavior) IntermediateCatchMessageEventActivityBehavior(org.activiti.engine.impl.bpmn.behavior.IntermediateCatchMessageEventActivityBehavior) BoundaryCancelEventActivityBehavior(org.activiti.engine.impl.bpmn.behavior.BoundaryCancelEventActivityBehavior) SubProcessActivityBehavior(org.activiti.engine.impl.bpmn.behavior.SubProcessActivityBehavior) TaskActivityBehavior(org.activiti.engine.impl.bpmn.behavior.TaskActivityBehavior) FieldDeclaration(org.activiti.engine.impl.bpmn.parser.FieldDeclaration)

Example 70 with ActivitiException

use of org.activiti.engine.ActivitiException in project Activiti by Activiti.

the class DefaultActivityBehaviorFactory method createBusinessRuleTaskActivityBehavior.

public ActivityBehavior createBusinessRuleTaskActivityBehavior(BusinessRuleTask businessRuleTask) {
    BusinessRuleTaskDelegate ruleActivity = null;
    if (StringUtils.isNotEmpty(businessRuleTask.getClassName())) {
        try {
            Class<?> clazz = Class.forName(businessRuleTask.getClassName());
            ruleActivity = (BusinessRuleTaskDelegate) clazz.newInstance();
        } catch (Exception e) {
            throw new ActivitiException("Could not instantiate businessRuleTask (id:" + businessRuleTask.getId() + ") class: " + businessRuleTask.getClassName(), e);
        }
    } else {
    // no default behavior
    }
    for (String ruleVariableInputObject : businessRuleTask.getInputVariables()) {
        ruleActivity.addRuleVariableInputIdExpression(expressionManager.createExpression(ruleVariableInputObject.trim()));
    }
    for (String rule : businessRuleTask.getRuleNames()) {
        ruleActivity.addRuleIdExpression(expressionManager.createExpression(rule.trim()));
    }
    ruleActivity.setExclude(businessRuleTask.isExclude());
    if (businessRuleTask.getResultVariableName() != null && businessRuleTask.getResultVariableName().length() > 0) {
        ruleActivity.setResultVariable(businessRuleTask.getResultVariableName());
    } else {
        ruleActivity.setResultVariable("org.activiti.engine.rules.OUTPUT");
    }
    return ruleActivity;
}
Also used : ActivitiException(org.activiti.engine.ActivitiException) ActivitiException(org.activiti.engine.ActivitiException) BusinessRuleTaskDelegate(org.activiti.engine.delegate.BusinessRuleTaskDelegate)

Aggregations

ActivitiException (org.activiti.engine.ActivitiException)289 ActivitiIllegalArgumentException (org.activiti.engine.ActivitiIllegalArgumentException)45 ActivitiObjectNotFoundException (org.activiti.engine.ActivitiObjectNotFoundException)44 ExecutionEntity (org.activiti.engine.impl.persistence.entity.ExecutionEntity)38 IOException (java.io.IOException)35 ArrayList (java.util.ArrayList)25 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)22 ByteArrayOutputStream (java.io.ByteArrayOutputStream)20 FlowElement (org.activiti.bpmn.model.FlowElement)19 CommandContext (org.activiti.engine.impl.interceptor.CommandContext)18 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)17 Expression (org.activiti.engine.delegate.Expression)17 ProcessDefinition (org.activiti.engine.repository.ProcessDefinition)17 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)17 ObjectOutputStream (java.io.ObjectOutputStream)15 WorkflowException (org.alfresco.service.cmr.workflow.WorkflowException)15 HashMap (java.util.HashMap)12 ExecutionEntityManager (org.activiti.engine.impl.persistence.entity.ExecutionEntityManager)11 ProcessDefinitionEntity (org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity)11 InputStream (java.io.InputStream)10