Exemplo n.º 1
0
        public virtual void modifyVariables(PatchVariablesDto patch)
        {
            VariableMap variableModifications = null;

            try
            {
                variableModifications = VariableValueDto.toMap(patch.Modifications, engine, objectMapper);
            }
            catch (RestException e)
            {
                string errorMessage = string.Format("Cannot modify variables for {0}: {1}", ResourceTypeName, e.Message);
                throw new InvalidRequestException(e.Status, e, errorMessage);
            }

            IList <string> variableDeletions = patch.Deletions;

            try
            {
                updateVariableEntities(variableModifications, variableDeletions);
            }
            catch (AuthorizationException e)
            {
                throw e;
            }
            catch (ProcessEngineException e)
            {
                string errorMessage = string.Format("Cannot modify variables for {0} {1}: {2}", ResourceTypeName, resourceId, e.Message);
                throw new RestException(Response.Status.INTERNAL_SERVER_ERROR, e, errorMessage);
            }
        }
Exemplo n.º 2
0
        public virtual void resolve(CompleteTaskDto dto)
        {
            TaskService taskService = engine.TaskService;

            try
            {
                VariableMap variables = VariableValueDto.toMap(dto.Variables, engine, objectMapper);
                taskService.resolveTask(taskId, variables);
            }
            catch (RestException e)
            {
                string errorMessage = string.Format("Cannot resolve task {0}: {1}", taskId, e.Message);
                throw new InvalidRequestException(e.Status, e, errorMessage);
            }
        }
Exemplo n.º 3
0
        public virtual CaseInstanceDto createCaseInstance(UriInfo context, CreateCaseInstanceDto parameters)
        {
            CaseService caseService = engine.CaseService;

            CaseInstance instance = null;

            try
            {
                string      businessKey = parameters.BusinessKey;
                VariableMap variables   = VariableValueDto.toMap(parameters.Variables, engine, objectMapper);

                instance = caseService.withCaseDefinition(caseDefinitionId).businessKey(businessKey).setVariables(variables).create();
            }
            catch (RestException e)
            {
                string errorMessage = string.Format("Cannot instantiate case definition {0}: {1}", caseDefinitionId, e.Message);
                throw new InvalidRequestException(e.Status, e, errorMessage);
            }
            catch (NotFoundException e)
            {
                string errorMessage = string.Format("Cannot instantiate case definition {0}: {1}", caseDefinitionId, e.Message);
                throw new InvalidRequestException(Response.Status.NOT_FOUND, e, errorMessage);
            }
            catch (NotValidException e)
            {
                string errorMessage = string.Format("Cannot instantiate case definition {0}: {1}", caseDefinitionId, e.Message);
                throw new InvalidRequestException(Response.Status.BAD_REQUEST, e, errorMessage);
            }
            catch (NotAllowedException e)
            {
                string errorMessage = string.Format("Cannot instantiate case definition {0}: {1}", caseDefinitionId, e.Message);
                throw new InvalidRequestException(Response.Status.FORBIDDEN, e, errorMessage);
            }
            catch (ProcessEngineException e)
            {
                string errorMessage = string.Format("Cannot instantiate case definition {0}: {1}", caseDefinitionId, e.Message);
                throw new RestException(Response.Status.INTERNAL_SERVER_ERROR, e, errorMessage);
            }

            CaseInstanceDto result = CaseInstanceDto.fromCaseInstance(instance);

            URI uri = context.BaseUriBuilder.path(rootResourcePath).path(org.camunda.bpm.engine.rest.CaseInstanceRestService_Fields.PATH).path(instance.Id).build();

            result.addReflexiveLink(uri, HttpMethod.GET, "self");

            return(result);
        }
Exemplo n.º 4
0
        public virtual ProcessInstanceDto submitForm(UriInfo context, StartProcessInstanceDto parameters)
        {
            FormService formService = engine.FormService;

            ProcessInstance instance = null;

            try
            {
                IDictionary <string, object> variables = VariableValueDto.toMap(parameters.Variables, engine, objectMapper);
                string businessKey = parameters.BusinessKey;
                if (!string.ReferenceEquals(businessKey, null))
                {
                    instance = formService.submitStartForm(processDefinitionId, businessKey, variables);
                }
                else
                {
                    instance = formService.submitStartForm(processDefinitionId, variables);
                }
            }
            catch (AuthorizationException e)
            {
                throw e;
            }
            catch (FormFieldValidationException e)
            {
                string errorMessage = string.Format("Cannot instantiate process definition {0}: {1}", processDefinitionId, e.Message);
                throw new RestException(Response.Status.BAD_REQUEST, e, errorMessage);
            }
            catch (ProcessEngineException e)
            {
                string errorMessage = string.Format("Cannot instantiate process definition {0}: {1}", processDefinitionId, e.Message);
                throw new RestException(Response.Status.INTERNAL_SERVER_ERROR, e, errorMessage);
            }
            catch (RestException e)
            {
                string errorMessage = string.Format("Cannot instantiate process definition {0}: {1}", processDefinitionId, e.Message);
                throw new InvalidRequestException(e.Status, e, errorMessage);
            }

            ProcessInstanceDto result = ProcessInstanceDto.fromProcessInstance(instance);

            URI uri = context.BaseUriBuilder.path(rootResourcePath).path(org.camunda.bpm.engine.rest.ProcessInstanceRestService_Fields.PATH).path(instance.Id).build();

            result.addReflexiveLink(uri, HttpMethod.GET, "self");

            return(result);
        }
Exemplo n.º 5
0
        protected internal virtual ProcessInstanceWithVariables startProcessInstanceAtActivities(StartProcessInstanceDto dto)
        {
            IDictionary <string, object> processInstanceVariables = VariableValueDto.toMap(dto.Variables, engine, objectMapper);
            string businessKey    = dto.BusinessKey;
            string caseInstanceId = dto.CaseInstanceId;

            ProcessInstantiationBuilder instantiationBuilder = engine.RuntimeService.createProcessInstanceById(processDefinitionId).businessKey(businessKey).caseInstanceId(caseInstanceId).setVariables(processInstanceVariables);

            if (dto.StartInstructions != null && dto.StartInstructions.Count > 0)
            {
                foreach (ProcessInstanceModificationInstructionDto instruction in dto.StartInstructions)
                {
                    instruction.applyTo(instantiationBuilder, engine, objectMapper);
                }
            }

            return(instantiationBuilder.executeWithVariablesInReturn(dto.SkipCustomListeners, dto.SkipIoMappings));
        }
Exemplo n.º 6
0
        public virtual Response complete(CompleteTaskDto dto)
        {
            TaskService taskService = engine.TaskService;

            try
            {
                VariableMap variables = VariableValueDto.toMap(dto.Variables, engine, objectMapper);
                if (dto.WithVariablesInReturn)
                {
                    VariableMap taskVariables = taskService.completeWithVariablesInReturn(taskId, variables, false);

                    IDictionary <string, VariableValueDto> body = VariableValueDto.fromMap(taskVariables, true);

                    return(Response.ok(body).type(MediaType.APPLICATION_JSON).build());
                }
                else
                {
                    taskService.complete(taskId, variables);
                    return(Response.noContent().build());
                }
            }
            catch (RestException e)
            {
                string errorMessage = string.Format("Cannot complete task {0}: {1}", taskId, e.Message);
                throw new InvalidRequestException(e.Status, e, errorMessage);
            }
            catch (AuthorizationException e)
            {
                throw e;
            }
            catch (FormFieldValidationException e)
            {
                string errorMessage = string.Format("Cannot complete task {0}: {1}", taskId, e.Message);
                throw new RestException(Response.Status.BAD_REQUEST, e, errorMessage);
            }
            catch (ProcessEngineException e)
            {
                string errorMessage = string.Format("Cannot complete task {0}: {1}", taskId, e.Message);
                throw new RestException(Response.Status.INTERNAL_SERVER_ERROR, e, errorMessage);
            }
        }
Exemplo n.º 7
0
        protected internal virtual SignalEventReceivedBuilder createSignalEventReceivedBuilder(SignalDto dto)
        {
            RuntimeService             runtimeService = processEngine.RuntimeService;
            string                     name           = dto.Name;
            SignalEventReceivedBuilder signalEvent    = runtimeService.createSignalEvent(name);

            string executionId = dto.ExecutionId;

            if (!string.ReferenceEquals(executionId, null))
            {
                signalEvent.executionId(executionId);
            }

            IDictionary <string, VariableValueDto> variablesDto = dto.Variables;

            if (variablesDto != null)
            {
                IDictionary <string, object> variables = VariableValueDto.toMap(variablesDto, processEngine, objectMapper);
                signalEvent.Variables = variables;
            }

            string tenantId = dto.TenantId;

            if (!string.ReferenceEquals(tenantId, null))
            {
                signalEvent.tenantId(tenantId);
            }

            bool isWithoutTenantId = dto.WithoutTenantId;

            if (isWithoutTenantId)
            {
                signalEvent.withoutTenantId();
            }

            return(signalEvent);
        }
Exemplo n.º 8
0
        public virtual IList <IDictionary <string, VariableValueDto> > evaluateDecision(UriInfo context, EvaluateDecisionDto parameters)
        {
            DecisionService decisionService = engine.DecisionService;

            IDictionary <string, object> variables = VariableValueDto.toMap(parameters.Variables, engine, objectMapper);

            try
            {
                DmnDecisionResult decisionResult = decisionService.evaluateDecisionById(decisionDefinitionId).variables(variables).evaluate();

                return(createDecisionResultDto(decisionResult));
            }
            catch (AuthorizationException e)
            {
                throw e;
            }
            catch (NotFoundException e)
            {
                string errorMessage = string.Format("Cannot evaluate decision {0}: {1}", decisionDefinitionId, e.Message);
                throw new InvalidRequestException(Response.Status.NOT_FOUND, e, errorMessage);
            }
            catch (NotValidException e)
            {
                string errorMessage = string.Format("Cannot evaluate decision {0}: {1}", decisionDefinitionId, e.Message);
                throw new InvalidRequestException(Response.Status.BAD_REQUEST, e, errorMessage);
            }
            catch (ProcessEngineException e)
            {
                string errorMessage = string.Format("Cannot evaluate decision {0}: {1}", decisionDefinitionId, e.Message);
                throw new RestException(Response.Status.INTERNAL_SERVER_ERROR, e, errorMessage);
            }
            catch (DmnEngineException e)
            {
                string errorMessage = string.Format("Cannot evaluate decision {0}: {1}", decisionDefinitionId, e.Message);
                throw new RestException(Response.Status.INTERNAL_SERVER_ERROR, e, errorMessage);
            }
        }
Exemplo n.º 9
0
        protected internal virtual ConditionEvaluationBuilder createConditionEvaluationBuilder(EvaluationConditionDto conditionDto)
        {
            RuntimeService runtimeService = processEngine.RuntimeService;

            ObjectMapper objectMapper = ObjectMapper;

            VariableMap variables = VariableValueDto.toMap(conditionDto.Variables, processEngine, objectMapper);

            ConditionEvaluationBuilder builder = runtimeService.createConditionEvaluation();

            if (variables != null && !variables.Empty)
            {
                builder.Variables = variables;
            }

            if (!string.ReferenceEquals(conditionDto.BusinessKey, null))
            {
                builder.processInstanceBusinessKey(conditionDto.BusinessKey);
            }

            if (!string.ReferenceEquals(conditionDto.ProcessDefinitionId, null))
            {
                builder.processDefinitionId(conditionDto.ProcessDefinitionId);
            }

            if (!string.ReferenceEquals(conditionDto.TenantId, null))
            {
                builder.tenantId(conditionDto.TenantId);
            }
            else if (conditionDto.WithoutTenantId)
            {
                builder.withoutTenantId();
            }

            return(builder);
        }
Exemplo n.º 10
0
        protected internal virtual MessageCorrelationBuilder createMessageCorrelationBuilder(CorrelationMessageDto messageDto)
        {
            RuntimeService runtimeService = processEngine.RuntimeService;

            ObjectMapper objectMapper = ObjectMapper;
            IDictionary <string, object> correlationKeys       = VariableValueDto.toMap(messageDto.CorrelationKeys, processEngine, objectMapper);
            IDictionary <string, object> localCorrelationKeys  = VariableValueDto.toMap(messageDto.LocalCorrelationKeys, processEngine, objectMapper);
            IDictionary <string, object> processVariables      = VariableValueDto.toMap(messageDto.ProcessVariables, processEngine, objectMapper);
            IDictionary <string, object> processVariablesLocal = VariableValueDto.toMap(messageDto.ProcessVariablesLocal, processEngine, objectMapper);

            MessageCorrelationBuilder builder = runtimeService.createMessageCorrelation(messageDto.MessageName);

            if (processVariables != null)
            {
                builder.Variables = processVariables;
            }
            if (processVariablesLocal != null)
            {
                builder.VariablesLocal = processVariablesLocal;
            }
            if (!string.ReferenceEquals(messageDto.BusinessKey, null))
            {
                builder.processInstanceBusinessKey(messageDto.BusinessKey);
            }

            if (correlationKeys != null && correlationKeys.Count > 0)
            {
                foreach (KeyValuePair <string, object> correlationKey in correlationKeys.SetOfKeyValuePairs())
                {
                    string name  = correlationKey.Key;
                    object value = correlationKey.Value;
                    builder.processInstanceVariableEquals(name, value);
                }
            }

            if (localCorrelationKeys != null && localCorrelationKeys.Count > 0)
            {
                foreach (KeyValuePair <string, object> correlationKey in localCorrelationKeys.SetOfKeyValuePairs())
                {
                    string name  = correlationKey.Key;
                    object value = correlationKey.Value;
                    builder.localVariableEquals(name, value);
                }
            }

            if (!string.ReferenceEquals(messageDto.TenantId, null))
            {
                builder.tenantId(messageDto.TenantId);
            }
            else if (messageDto.WithoutTenantId)
            {
                builder.withoutTenantId();
            }

            string processInstanceId = messageDto.ProcessInstanceId;

            if (!string.ReferenceEquals(processInstanceId, null))
            {
                builder.processInstanceId(processInstanceId);
            }

            return(builder);
        }