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);
}
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);
}
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);
}
}
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.");
}
}
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.");
}
}
Aggregations