Search in sources :

Example 31 with InvalidRequestException

use of org.camunda.bpm.engine.rest.exception.InvalidRequestException in project camunda-bpm-platform by camunda.

the class CaseDefinitionResourceImpl method getCaseDefinition.

@Override
public CaseDefinitionDto getCaseDefinition() {
    RepositoryService repositoryService = engine.getRepositoryService();
    CaseDefinition definition = null;
    try {
        definition = repositoryService.getCaseDefinition(caseDefinitionId);
    } 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);
    }
    return CaseDefinitionDto.fromCaseDefinition(definition);
}
Also used : NotValidException(org.camunda.bpm.engine.exception.NotValidException) CaseDefinition(org.camunda.bpm.engine.repository.CaseDefinition) RestException(org.camunda.bpm.engine.rest.exception.RestException) NotFoundException(org.camunda.bpm.engine.exception.NotFoundException) InvalidRequestException(org.camunda.bpm.engine.rest.exception.InvalidRequestException) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException) RepositoryService(org.camunda.bpm.engine.RepositoryService)

Example 32 with InvalidRequestException

use of org.camunda.bpm.engine.rest.exception.InvalidRequestException in project camunda-bpm-platform by camunda.

the class DecisionRequirementsDefinitionResourceImpl method getDecisionRequirementsDefinition.

@Override
public DecisionRequirementsDefinitionDto getDecisionRequirementsDefinition() {
    RepositoryService repositoryService = engine.getRepositoryService();
    DecisionRequirementsDefinition definition = null;
    try {
        definition = repositoryService.getDecisionRequirementsDefinition(decisionRequirementsDefinitionId);
    } 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);
    }
    return DecisionRequirementsDefinitionDto.fromDecisionRequirementsDefinition(definition);
}
Also used : NotValidException(org.camunda.bpm.engine.exception.NotValidException) DecisionRequirementsDefinition(org.camunda.bpm.engine.repository.DecisionRequirementsDefinition) RestException(org.camunda.bpm.engine.rest.exception.RestException) NotFoundException(org.camunda.bpm.engine.exception.NotFoundException) InvalidRequestException(org.camunda.bpm.engine.rest.exception.InvalidRequestException) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException) RepositoryService(org.camunda.bpm.engine.RepositoryService)

Example 33 with InvalidRequestException

use of org.camunda.bpm.engine.rest.exception.InvalidRequestException in project camunda-bpm-platform by camunda.

the class DecisionRequirementsDefinitionResourceImpl method getDecisionRequirementsDefinitionDmnXml.

@Override
public DecisionRequirementsDefinitionXmlDto getDecisionRequirementsDefinitionDmnXml() {
    InputStream decisionRequirementsModelInputStream = null;
    try {
        decisionRequirementsModelInputStream = engine.getRepositoryService().getDecisionRequirementsModel(decisionRequirementsDefinitionId);
        byte[] decisionRequirementsModel = IoUtil.readInputStream(decisionRequirementsModelInputStream, "decisionRequirementsModelDmnXml");
        return DecisionRequirementsDefinitionXmlDto.create(decisionRequirementsDefinitionId, new String(decisionRequirementsModel, "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(decisionRequirementsModelInputStream);
    }
}
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 34 with InvalidRequestException

use of org.camunda.bpm.engine.rest.exception.InvalidRequestException in project camunda-bpm-platform by camunda.

the class DeploymentResourcesResourceImpl method getDeploymentResources.

public List<DeploymentResourceDto> getDeploymentResources() {
    List<Resource> resources = engine.getRepositoryService().getDeploymentResources(deploymentId);
    List<DeploymentResourceDto> deploymentResources = new ArrayList<DeploymentResourceDto>();
    for (Resource resource : resources) {
        deploymentResources.add(DeploymentResourceDto.fromResources(resource));
    }
    if (!deploymentResources.isEmpty()) {
        return deploymentResources;
    } else {
        throw new InvalidRequestException(Status.NOT_FOUND, "Deployment resources for deployment id '" + deploymentId + "' do not exist.");
    }
}
Also used : Resource(org.camunda.bpm.engine.repository.Resource) DeploymentResourcesResource(org.camunda.bpm.engine.rest.sub.repository.DeploymentResourcesResource) ArrayList(java.util.ArrayList) InvalidRequestException(org.camunda.bpm.engine.rest.exception.InvalidRequestException) DeploymentResourceDto(org.camunda.bpm.engine.rest.dto.repository.DeploymentResourceDto)

Example 35 with InvalidRequestException

use of org.camunda.bpm.engine.rest.exception.InvalidRequestException in project camunda-bpm-platform by camunda.

the class DeploymentResourcesResourceImpl method getDeploymentResourceData.

public Response getDeploymentResourceData(String resourceId) {
    RepositoryService repositoryService = engine.getRepositoryService();
    InputStream resourceAsStream = repositoryService.getResourceAsStreamById(deploymentId, resourceId);
    if (resourceAsStream != null) {
        DeploymentResourceDto resource = getDeploymentResource(resourceId);
        String name = resource.getName();
        String filename = null;
        String mediaType = null;
        if (name != null) {
            name = name.replace("\\", "/");
            String[] filenameParts = name.split("/");
            if (filenameParts.length > 0) {
                int idx = filenameParts.length - 1;
                filename = filenameParts[idx];
            }
            String[] extensionParts = name.split("\\.");
            if (extensionParts.length > 0) {
                int idx = extensionParts.length - 1;
                String extension = extensionParts[idx];
                if (extension != null) {
                    mediaType = MEDIA_TYPE_MAPPING.get(extension);
                }
            }
        }
        if (filename == null) {
            filename = "data";
        }
        if (mediaType == null) {
            mediaType = MediaType.APPLICATION_OCTET_STREAM;
        }
        return Response.ok(resourceAsStream, mediaType).header("Content-Disposition", "attachment; filename=" + filename).build();
    } else {
        throw new InvalidRequestException(Status.NOT_FOUND, "Deployment resource '" + resourceId + "' for deployment id '" + deploymentId + "' does not exist.");
    }
}
Also used : InputStream(java.io.InputStream) InvalidRequestException(org.camunda.bpm.engine.rest.exception.InvalidRequestException) DeploymentResourceDto(org.camunda.bpm.engine.rest.dto.repository.DeploymentResourceDto) RepositoryService(org.camunda.bpm.engine.RepositoryService)

Aggregations

InvalidRequestException (org.camunda.bpm.engine.rest.exception.InvalidRequestException)116 ProcessEngineException (org.camunda.bpm.engine.ProcessEngineException)30 RestException (org.camunda.bpm.engine.rest.exception.RestException)25 AuthorizationException (org.camunda.bpm.engine.AuthorizationException)20 NotValidException (org.camunda.bpm.engine.exception.NotValidException)12 ArrayList (java.util.ArrayList)11 BadUserRequestException (org.camunda.bpm.engine.BadUserRequestException)11 ManagementService (org.camunda.bpm.engine.ManagementService)11 NotFoundException (org.camunda.bpm.engine.exception.NotFoundException)11 VariableQueryParameterDto (org.camunda.bpm.engine.rest.dto.VariableQueryParameterDto)10 HistoryService (org.camunda.bpm.engine.HistoryService)9 RuntimeService (org.camunda.bpm.engine.RuntimeService)9 InputStream (java.io.InputStream)8 RepositoryService (org.camunda.bpm.engine.RepositoryService)8 Batch (org.camunda.bpm.engine.batch.Batch)8 URI (java.net.URI)6 VariableMap (org.camunda.bpm.engine.variable.VariableMap)6 ByteArrayInputStream (java.io.ByteArrayInputStream)5 FormService (org.camunda.bpm.engine.FormService)5 HistoricProcessInstanceQuery (org.camunda.bpm.engine.history.HistoricProcessInstanceQuery)5