Search in sources :

Example 86 with ProcessEngineException

use of org.camunda.bpm.engine.ProcessEngineException in project camunda-bpm-platform by camunda.

the class ProcessDefinitionResourceImpl method startProcessInstance.

@Override
public ProcessInstanceDto startProcessInstance(UriInfo context, StartProcessInstanceDto parameters) {
    ProcessInstanceWithVariables instance = null;
    try {
        instance = startProcessInstanceAtActivities(parameters);
    } catch (AuthorizationException e) {
        throw e;
    } catch (ProcessEngineException e) {
        String errorMessage = String.format("Cannot instantiate process definition %s: %s", processDefinitionId, e.getMessage());
        throw new RestException(Status.INTERNAL_SERVER_ERROR, e, errorMessage);
    } catch (RestException e) {
        String errorMessage = String.format("Cannot instantiate process definition %s: %s", processDefinitionId, e.getMessage());
        throw new InvalidRequestException(e.getStatus(), e, errorMessage);
    }
    ProcessInstanceDto result;
    if (parameters.isWithVariablesInReturn()) {
        result = ProcessInstanceWithVariablesDto.fromProcessInstance(instance);
    } else {
        result = ProcessInstanceDto.fromProcessInstance(instance);
    }
    URI uri = context.getBaseUriBuilder().path(rootResourcePath).path(ProcessInstanceRestService.PATH).path(instance.getId()).build();
    result.addReflexiveLink(uri, HttpMethod.GET, "self");
    return result;
}
Also used : AuthorizationException(org.camunda.bpm.engine.AuthorizationException) RestartProcessInstanceDto(org.camunda.bpm.engine.rest.dto.runtime.RestartProcessInstanceDto) ProcessInstanceDto(org.camunda.bpm.engine.rest.dto.runtime.ProcessInstanceDto) StartProcessInstanceDto(org.camunda.bpm.engine.rest.dto.runtime.StartProcessInstanceDto) RestException(org.camunda.bpm.engine.rest.exception.RestException) InvalidRequestException(org.camunda.bpm.engine.rest.exception.InvalidRequestException) ProcessInstanceWithVariables(org.camunda.bpm.engine.runtime.ProcessInstanceWithVariables) URI(java.net.URI) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException)

Example 87 with ProcessEngineException

use of org.camunda.bpm.engine.ProcessEngineException in project camunda-bpm-platform by camunda.

the class DecisionDefinitionResourceImpl method getDecisionDefinitionDmnXml.

@Override
public DecisionDefinitionDiagramDto getDecisionDefinitionDmnXml() {
    InputStream decisionModelInputStream = null;
    try {
        decisionModelInputStream = engine.getRepositoryService().getDecisionModel(decisionDefinitionId);
        byte[] decisionModel = IoUtil.readInputStream(decisionModelInputStream, "decisionModelDmnXml");
        return DecisionDefinitionDiagramDto.create(decisionDefinitionId, new String(decisionModel, "UTF-8"));
    } catch (NotFoundException e) {
        throw new InvalidRequestException(Status.NOT_FOUND, e, e.getMessage());
    } catch (NotValidException e) {
        throw new InvalidRequestException(Status.BAD_REQUEST, e, e.getMessage());
    } catch (ProcessEngineException e) {
        throw new RestException(Status.INTERNAL_SERVER_ERROR, e);
    } catch (UnsupportedEncodingException e) {
        throw new RestException(Status.INTERNAL_SERVER_ERROR, e);
    } finally {
        IoUtil.closeSilently(decisionModelInputStream);
    }
}
Also used : NotValidException(org.camunda.bpm.engine.exception.NotValidException) InputStream(java.io.InputStream) RestException(org.camunda.bpm.engine.rest.exception.RestException) NotFoundException(org.camunda.bpm.engine.exception.NotFoundException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) InvalidRequestException(org.camunda.bpm.engine.rest.exception.InvalidRequestException) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException)

Example 88 with ProcessEngineException

use of org.camunda.bpm.engine.ProcessEngineException in project camunda-bpm-platform by camunda.

the class TaskResourceImpl method getForm.

@Override
public FormDto getForm() {
    FormService formService = engine.getFormService();
    Task task = getTaskById(taskId);
    FormData formData;
    try {
        formData = formService.getTaskFormData(taskId);
    } catch (AuthorizationException e) {
        throw e;
    } catch (ProcessEngineException e) {
        throw new RestException(Status.BAD_REQUEST, e, "Cannot get form for task " + taskId);
    }
    FormDto dto = FormDto.fromFormData(formData);
    if (dto.getKey() == null || dto.getKey().isEmpty()) {
        if (formData != null && formData.getFormFields() != null && !formData.getFormFields().isEmpty()) {
            dto.setKey("embedded:engine://engine/:engine/task/" + taskId + "/rendered-form");
        }
    }
    // to get the application context path it is necessary to
    // execute it without authentication (tries to fetch the
    // process definition), because:
    // - user 'demo' has READ permission on a specific task resource
    // - user 'demo' does not have a READ permission on the corresponding
    // process definition
    // -> running the following lines with authorization would lead
    // to an AuthorizationException because the user 'demo' does not
    // have READ permission on the corresponding process definition
    IdentityService identityService = engine.getIdentityService();
    Authentication currentAuthentication = identityService.getCurrentAuthentication();
    try {
        identityService.clearAuthentication();
        String processDefinitionId = task.getProcessDefinitionId();
        String caseDefinitionId = task.getCaseDefinitionId();
        if (processDefinitionId != null) {
            dto.setContextPath(ApplicationContextPathUtil.getApplicationPathByProcessDefinitionId(engine, processDefinitionId));
        } else if (caseDefinitionId != null) {
            dto.setContextPath(ApplicationContextPathUtil.getApplicationPathByCaseDefinitionId(engine, caseDefinitionId));
        }
    } finally {
        identityService.setAuthentication(currentAuthentication);
    }
    return dto;
}
Also used : FormData(org.camunda.bpm.engine.form.FormData) IdentityService(org.camunda.bpm.engine.IdentityService) Task(org.camunda.bpm.engine.task.Task) HalTask(org.camunda.bpm.engine.rest.hal.task.HalTask) AuthorizationException(org.camunda.bpm.engine.AuthorizationException) Authentication(org.camunda.bpm.engine.impl.identity.Authentication) FormService(org.camunda.bpm.engine.FormService) RestException(org.camunda.bpm.engine.rest.exception.RestException) FormDto(org.camunda.bpm.engine.rest.dto.task.FormDto) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException)

Example 89 with ProcessEngineException

use of org.camunda.bpm.engine.ProcessEngineException in project camunda-bpm-platform by camunda.

the class CaseExecutionResourceImpl method reenable.

public void reenable(CaseExecutionTriggerDto triggerDto) {
    try {
        CaseService caseService = engine.getCaseService();
        CaseExecutionCommandBuilder commandBuilder = caseService.withCaseExecution(caseExecutionId);
        initializeCommand(commandBuilder, triggerDto, "reenable");
        commandBuilder.reenable();
    } catch (NotFoundException e) {
        throw createInvalidRequestException("reenable", Status.NOT_FOUND, e);
    } catch (NotValidException e) {
        throw createInvalidRequestException("reenable", Status.BAD_REQUEST, e);
    } catch (NotAllowedException e) {
        throw createInvalidRequestException("reenable", Status.FORBIDDEN, e);
    } catch (ProcessEngineException e) {
        throw createRestException("reenable", Status.INTERNAL_SERVER_ERROR, e);
    }
}
Also used : NotValidException(org.camunda.bpm.engine.exception.NotValidException) NotAllowedException(org.camunda.bpm.engine.exception.NotAllowedException) NotFoundException(org.camunda.bpm.engine.exception.NotFoundException) CaseService(org.camunda.bpm.engine.CaseService) CaseExecutionCommandBuilder(org.camunda.bpm.engine.runtime.CaseExecutionCommandBuilder) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException)

Example 90 with ProcessEngineException

use of org.camunda.bpm.engine.ProcessEngineException in project camunda-bpm-platform by camunda.

the class CaseExecutionResourceImpl method disable.

public void disable(CaseExecutionTriggerDto triggerDto) {
    try {
        CaseService caseService = engine.getCaseService();
        CaseExecutionCommandBuilder commandBuilder = caseService.withCaseExecution(caseExecutionId);
        initializeCommand(commandBuilder, triggerDto, "disable");
        commandBuilder.disable();
    } catch (NotFoundException e) {
        throw createInvalidRequestException("disable", Status.NOT_FOUND, e);
    } catch (NotValidException e) {
        throw createInvalidRequestException("disable", Status.BAD_REQUEST, e);
    } catch (NotAllowedException e) {
        throw createInvalidRequestException("disable", Status.FORBIDDEN, e);
    } catch (ProcessEngineException e) {
        throw createRestException("disable", Status.INTERNAL_SERVER_ERROR, e);
    }
}
Also used : NotValidException(org.camunda.bpm.engine.exception.NotValidException) NotAllowedException(org.camunda.bpm.engine.exception.NotAllowedException) NotFoundException(org.camunda.bpm.engine.exception.NotFoundException) CaseService(org.camunda.bpm.engine.CaseService) CaseExecutionCommandBuilder(org.camunda.bpm.engine.runtime.CaseExecutionCommandBuilder) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException)

Aggregations

ProcessEngineException (org.camunda.bpm.engine.ProcessEngineException)611 Test (org.junit.Test)185 Deployment (org.camunda.bpm.engine.test.Deployment)138 ProcessInstance (org.camunda.bpm.engine.runtime.ProcessInstance)79 HashMap (java.util.HashMap)62 RestException (org.camunda.bpm.engine.rest.exception.RestException)62 Matchers.anyString (org.mockito.Matchers.anyString)60 TaskQuery (org.camunda.bpm.engine.task.TaskQuery)57 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)47 InvalidRequestException (org.camunda.bpm.engine.rest.exception.InvalidRequestException)41 Task (org.camunda.bpm.engine.task.Task)40 ArrayList (java.util.ArrayList)39 ProcessDefinition (org.camunda.bpm.engine.repository.ProcessDefinition)36 Matchers.containsString (org.hamcrest.Matchers.containsString)35 CaseExecutionQuery (org.camunda.bpm.engine.runtime.CaseExecutionQuery)24 MigrationPlan (org.camunda.bpm.engine.migration.MigrationPlan)22 AuthorizationException (org.camunda.bpm.engine.AuthorizationException)21 CaseInstanceQuery (org.camunda.bpm.engine.runtime.CaseInstanceQuery)21 NotValidException (org.camunda.bpm.engine.exception.NotValidException)19 NotFoundException (org.camunda.bpm.engine.exception.NotFoundException)18