Search in sources :

Example 1 with DeploymentBuilder

use of org.activiti.engine.repository.DeploymentBuilder in project Activiti by Activiti.

the class DeploymentCollectionResource method uploadDeployment.

@RequestMapping(value = "/repository/deployments", method = RequestMethod.POST, produces = "application/json")
public DeploymentResponse uploadDeployment(@RequestParam(value = "tenantId", required = false) String tenantId, HttpServletRequest request, HttpServletResponse response) {
    if (request instanceof MultipartHttpServletRequest == false) {
        throw new ActivitiIllegalArgumentException("Multipart request is required");
    }
    MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
    if (multipartRequest.getFileMap().size() == 0) {
        throw new ActivitiIllegalArgumentException("Multipart request with file content is required");
    }
    MultipartFile file = multipartRequest.getFileMap().values().iterator().next();
    try {
        DeploymentBuilder deploymentBuilder = repositoryService.createDeployment();
        String fileName = file.getOriginalFilename();
        if (StringUtils.isEmpty(fileName) || !(fileName.endsWith(".bpmn20.xml") || fileName.endsWith(".bpmn") || fileName.toLowerCase().endsWith(".bar") || fileName.toLowerCase().endsWith(".zip"))) {
            fileName = file.getName();
        }
        if (fileName.endsWith(".bpmn20.xml") || fileName.endsWith(".bpmn")) {
            deploymentBuilder.addInputStream(fileName, file.getInputStream());
        } else if (fileName.toLowerCase().endsWith(".bar") || fileName.toLowerCase().endsWith(".zip")) {
            deploymentBuilder.addZipInputStream(new ZipInputStream(file.getInputStream()));
        } else {
            throw new ActivitiIllegalArgumentException("File must be of type .bpmn20.xml, .bpmn, .bar or .zip");
        }
        deploymentBuilder.name(fileName);
        if (tenantId != null) {
            deploymentBuilder.tenantId(tenantId);
        }
        Deployment deployment = deploymentBuilder.deploy();
        response.setStatus(HttpStatus.CREATED.value());
        return restResponseFactory.createDeploymentResponse(deployment);
    } catch (Exception e) {
        if (e instanceof ActivitiException) {
            throw (ActivitiException) e;
        }
        throw new ActivitiException(e.getMessage(), e);
    }
}
Also used : MultipartFile(org.springframework.web.multipart.MultipartFile) ZipInputStream(java.util.zip.ZipInputStream) ActivitiException(org.activiti.engine.ActivitiException) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) Deployment(org.activiti.engine.repository.Deployment) DeploymentBuilder(org.activiti.engine.repository.DeploymentBuilder) ActivitiException(org.activiti.engine.ActivitiException) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) MultipartHttpServletRequest(org.springframework.web.multipart.MultipartHttpServletRequest) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with DeploymentBuilder

use of org.activiti.engine.repository.DeploymentBuilder in project Activiti by Activiti.

the class DeploymentUploadReceiver method deployUploadedFile.

protected void deployUploadedFile() {
    DeploymentBuilder deploymentBuilder = repositoryService.createDeployment().name(fileName);
    DeploymentFilter deploymentFilter = ExplorerApp.get().getComponentFactory(DeploymentFilterFactory.class).create();
    try {
        try {
            if (fileName.endsWith(".bpmn20.xml") || fileName.endsWith(".bpmn")) {
                validFile = true;
                deploymentBuilder.addInputStream(fileName, new ByteArrayInputStream(outputStream.toByteArray()));
            } else if (fileName.endsWith(".bar") || fileName.endsWith(".zip")) {
                validFile = true;
                deploymentBuilder.addZipInputStream(new ZipInputStream(new ByteArrayInputStream(outputStream.toByteArray())));
            } else {
                notificationManager.showErrorNotification(Messages.DEPLOYMENT_UPLOAD_INVALID_FILE, i18nManager.getMessage(Messages.DEPLOYMENT_UPLOAD_INVALID_FILE_EXPLANATION));
            }
            // If the deployment is valid, run it through the beforeDeploy and actually deploy it in Activiti
            if (validFile) {
                deploymentFilter.beforeDeploy(deploymentBuilder);
                deployment = deploymentBuilder.deploy();
            }
        } catch (ActivitiException e) {
            String errorMsg = e.getMessage().replace(System.getProperty("line.separator"), "<br/>");
            notificationManager.showErrorNotification(Messages.DEPLOYMENT_UPLOAD_FAILED, errorMsg);
            throw e;
        }
    } finally {
        if (outputStream != null) {
            try {
                outputStream.close();
            } catch (IOException e) {
                notificationManager.showErrorNotification("Server-side error", e.getMessage());
            }
        }
    }
}
Also used : ZipInputStream(java.util.zip.ZipInputStream) ActivitiException(org.activiti.engine.ActivitiException) ByteArrayInputStream(java.io.ByteArrayInputStream) IOException(java.io.IOException) DeploymentBuilder(org.activiti.engine.repository.DeploymentBuilder)

Example 3 with DeploymentBuilder

use of org.activiti.engine.repository.DeploymentBuilder in project Activiti by Activiti.

the class DefaultAutoDeploymentStrategy method deployResources.

@Override
public void deployResources(final String deploymentNameHint, final Resource[] resources, final RepositoryService repositoryService) {
    // Create a single deployment for all resources using the name hint as the
    // literal name
    final DeploymentBuilder deploymentBuilder = repositoryService.createDeployment().enableDuplicateFiltering().name(deploymentNameHint);
    for (final Resource resource : resources) {
        final String resourceName = determineResourceName(resource);
        try {
            if (resourceName.endsWith(".bar") || resourceName.endsWith(".zip") || resourceName.endsWith(".jar")) {
                deploymentBuilder.addZipInputStream(new ZipInputStream(resource.getInputStream()));
            } else {
                deploymentBuilder.addInputStream(resourceName, resource.getInputStream());
            }
        } catch (IOException e) {
            throw new ActivitiException("couldn't auto deploy resource '" + resource + "': " + e.getMessage(), e);
        }
    }
    deploymentBuilder.deploy();
}
Also used : ZipInputStream(java.util.zip.ZipInputStream) ActivitiException(org.activiti.engine.ActivitiException) Resource(org.springframework.core.io.Resource) IOException(java.io.IOException) DeploymentBuilder(org.activiti.engine.repository.DeploymentBuilder)

Example 4 with DeploymentBuilder

use of org.activiti.engine.repository.DeploymentBuilder in project Activiti by Activiti.

the class ResourceParentFolderAutoDeploymentStrategy method deployResources.

@Override
public void deployResources(final String deploymentNameHint, final Resource[] resources, final RepositoryService repositoryService) {
    // Create a deployment for each distinct parent folder using the name hint
    // as a prefix
    final Map<String, Set<Resource>> resourcesMap = createMap(resources);
    for (final Entry<String, Set<Resource>> group : resourcesMap.entrySet()) {
        final String deploymentName = determineDeploymentName(deploymentNameHint, group.getKey());
        final DeploymentBuilder deploymentBuilder = repositoryService.createDeployment().enableDuplicateFiltering().name(deploymentName);
        for (final Resource resource : group.getValue()) {
            final String resourceName = determineResourceName(resource);
            try {
                if (resourceName.endsWith(".bar") || resourceName.endsWith(".zip") || resourceName.endsWith(".jar")) {
                    deploymentBuilder.addZipInputStream(new ZipInputStream(resource.getInputStream()));
                } else {
                    deploymentBuilder.addInputStream(resourceName, resource.getInputStream());
                }
            } catch (IOException e) {
                throw new ActivitiException("couldn't auto deploy resource '" + resource + "': " + e.getMessage(), e);
            }
        }
        deploymentBuilder.deploy();
    }
}
Also used : ZipInputStream(java.util.zip.ZipInputStream) ActivitiException(org.activiti.engine.ActivitiException) HashSet(java.util.HashSet) Set(java.util.Set) Resource(org.springframework.core.io.Resource) IOException(java.io.IOException) DeploymentBuilder(org.activiti.engine.repository.DeploymentBuilder)

Example 5 with DeploymentBuilder

use of org.activiti.engine.repository.DeploymentBuilder in project Activiti by Activiti.

the class SingleResourceAutoDeploymentStrategy method deployResources.

@Override
public void deployResources(final String deploymentNameHint, final Resource[] resources, final RepositoryService repositoryService) {
    for (final Resource resource : resources) {
        final String resourceName = determineResourceName(resource);
        final DeploymentBuilder deploymentBuilder = repositoryService.createDeployment().enableDuplicateFiltering().name(resourceName);
        try {
            if (resourceName.endsWith(".bar") || resourceName.endsWith(".zip") || resourceName.endsWith(".jar")) {
                deploymentBuilder.addZipInputStream(new ZipInputStream(resource.getInputStream()));
            } else {
                deploymentBuilder.addInputStream(resourceName, resource.getInputStream());
            }
        } catch (IOException e) {
            throw new ActivitiException("couldn't auto deploy resource '" + resource + "': " + e.getMessage(), e);
        }
        deploymentBuilder.deploy();
    }
}
Also used : ZipInputStream(java.util.zip.ZipInputStream) ActivitiException(org.activiti.engine.ActivitiException) Resource(org.springframework.core.io.Resource) IOException(java.io.IOException) DeploymentBuilder(org.activiti.engine.repository.DeploymentBuilder)

Aggregations

DeploymentBuilder (org.activiti.engine.repository.DeploymentBuilder)12 IOException (java.io.IOException)6 ZipInputStream (java.util.zip.ZipInputStream)5 ActivitiException (org.activiti.engine.ActivitiException)5 Deployment (org.activiti.engine.repository.Deployment)3 Resource (org.springframework.core.io.Resource)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 InputStream (java.io.InputStream)2 ArrayList (java.util.ArrayList)2 FileInputStream (java.io.FileInputStream)1 Method (java.lang.reflect.Method)1 URL (java.net.URL)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 ActivitiIllegalArgumentException (org.activiti.engine.ActivitiIllegalArgumentException)1 ActivitiObjectNotFoundException (org.activiti.engine.ActivitiObjectNotFoundException)1 ProcessEngine (org.activiti.engine.ProcessEngine)1 RepositoryService (org.activiti.engine.RepositoryService)1