use of org.camunda.bpm.engine.rest.dto.repository.DeploymentResourceDto 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.dto.repository.DeploymentResourceDto 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