Search in sources :

Example 1 with DeploymentResourceDto

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.");
    }
}
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 2 with DeploymentResourceDto

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

DeploymentResourceDto (org.camunda.bpm.engine.rest.dto.repository.DeploymentResourceDto)2 InvalidRequestException (org.camunda.bpm.engine.rest.exception.InvalidRequestException)2 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 RepositoryService (org.camunda.bpm.engine.RepositoryService)1 Resource (org.camunda.bpm.engine.repository.Resource)1 DeploymentResourcesResource (org.camunda.bpm.engine.rest.sub.repository.DeploymentResourcesResource)1