Search in sources :

Example 6 with DeploymentBuilder

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

the class DeployClasspathResourcesEventHandler method handle.

@SuppressWarnings("unchecked")
@Override
public void handle(SimulationEvent event) {
    List<String> resources = (List<String>) event.getProperty(resourcesKey);
    DeploymentBuilder deploymentBuilder = SimulationRunContext.getRepositoryService().createDeployment();
    for (String resource : resources) {
        log.debug("adding resource [{}] to repository", resource, SimulationRunContext.getRepositoryService());
        deploymentBuilder.addClasspathResource(resource);
    }
    deploymentBuilder.deploy();
}
Also used : List(java.util.List) DeploymentBuilder(org.activiti.engine.repository.DeploymentBuilder)

Example 7 with DeploymentBuilder

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

the class Extender method checkBundle.

private void checkBundle(Bundle bundle) {
    LOGGER.debug("Scanning bundle {} for activiti process", bundle.getSymbolicName());
    try {
        List<URL> pathList = new ArrayList<URL>();
        String activitiHeader = (String) bundle.getHeaders().get(BUNDLE_ACTIVITI_HEADER);
        if (activitiHeader == null) {
            activitiHeader = "OSGI-INF/activiti/";
        }
        List<PathElement> paths = HeaderParser.parseHeader(activitiHeader);
        for (PathElement path : paths) {
            String name = path.getName();
            if (name.endsWith("/")) {
                addEntries(bundle, name, "*.*", pathList);
            } else {
                String baseName;
                String filePattern;
                int pos = name.lastIndexOf('/');
                if (pos < 0) {
                    baseName = "/";
                    filePattern = name;
                } else {
                    baseName = name.substring(0, pos + 1);
                    filePattern = name.substring(pos + 1);
                }
                if (hasWildcards(filePattern)) {
                    addEntries(bundle, baseName, filePattern, pathList);
                } else {
                    addEntry(bundle, name, pathList);
                }
            }
        }
        if (!pathList.isEmpty()) {
            LOGGER.debug("Found activiti process in bundle {} with paths: {}", bundle.getSymbolicName(), pathList);
            ProcessEngine engine = (ProcessEngine) engineServiceTracker.waitForService(timeout);
            if (engine == null) {
                throw new IllegalStateException("Unable to find a ProcessEngine service");
            }
            RepositoryService service = engine.getRepositoryService();
            DeploymentBuilder builder = service.createDeployment();
            builder.name(bundle.getSymbolicName());
            for (URL url : pathList) {
                InputStream is = url.openStream();
                if (is == null) {
                    throw new IOException("Error opening url: " + url);
                }
                try {
                    builder.addInputStream(getPath(url), is);
                } finally {
                    is.close();
                }
            }
            builder.enableDuplicateFiltering();
            builder.deploy();
        } else {
            LOGGER.debug("No activiti process found in bundle {}", bundle.getSymbolicName());
        }
    } catch (Throwable t) {
        LOGGER.error("Unable to deploy activiti bundle", t);
    }
}
Also used : InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) IOException(java.io.IOException) URL(java.net.URL) PathElement(org.activiti.osgi.HeaderParser.PathElement) DeploymentBuilder(org.activiti.engine.repository.DeploymentBuilder) ProcessEngine(org.activiti.engine.ProcessEngine) RepositoryService(org.activiti.engine.RepositoryService)

Example 8 with DeploymentBuilder

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

the class ProcessDeployer method deployProcess.

/**
   * Deploys a single process
   * 
   * @return the processDefinitionId of the deployed process as returned by
   *         {@link ProcessDefinition#getId()}
   */
public String deployProcess(String resourceName) {
    logger.debug("Start deploying single process.");
    // deploy processes as one deployment
    DeploymentBuilder deploymentBuilder = processEngine.getRepositoryService().createDeployment();
    deploymentBuilder.addClasspathResource(resourceName);
    // deploy the processes
    Deployment deployment = deploymentBuilder.deploy();
    logger.debug("Process deployed");
    // retreive the processDefinitionId for this process
    return processEngine.getRepositoryService().createProcessDefinitionQuery().deploymentId(deployment.getId()).singleResult().getId();
}
Also used : Deployment(org.activiti.engine.repository.Deployment) DeploymentBuilder(org.activiti.engine.repository.DeploymentBuilder)

Example 9 with DeploymentBuilder

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

the class ProcessDeployer method deployProcesses.

/**
   * Deploys all processes listed in the {@link #PROCESSES_FILE_NAME}-file.
   */
public void deployProcesses() {
    // build a single deployment containing all discovered processes
    Set<String> resourceNames = getResourceNames();
    if (resourceNames.isEmpty()) {
        logger.debug("Not creating a deployment");
        return;
    }
    logger.debug("Start deploying processes.");
    DeploymentBuilder deploymentBuilder = processEngine.getRepositoryService().createDeployment();
    for (String string : resourceNames) {
        logger.info("Adding '" + string + "' to deployment.");
        deploymentBuilder.addClasspathResource(string);
    }
    // deploy the processes
    deploymentBuilder.deploy();
    logger.debug("Done deploying processes.");
}
Also used : DeploymentBuilder(org.activiti.engine.repository.DeploymentBuilder)

Example 10 with DeploymentBuilder

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

the class DeployResourcesEventHandler method handle.

@Override
public void handle(SimulationEvent event) {
    @SuppressWarnings("unchecked") Map<String, ResourceEntity> resources = (Map<String, ResourceEntity>) event.getProperty(resourcesKey);
    List<InputStream> inputStreams = new ArrayList<InputStream>();
    try {
        DeploymentBuilder deploymentBuilder = SimulationRunContext.getRepositoryService().createDeployment();
        for (ResourceEntity resource : resources.values()) {
            log.debug("adding resource [{}] to deploymnet", resource.getName());
            InputStream is = new ByteArrayInputStream(resource.getBytes());
            deploymentBuilder.addInputStream(resource.getName(), is);
            inputStreams.add(is);
        }
        deploymentBuilder.deploy();
    } finally {
        for (InputStream is : inputStreams) {
            try {
                is.close();
            } catch (IOException e) {
                log.error("Unable to close resource input stream {}", is);
            }
        }
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ResourceEntity(org.activiti.engine.impl.persistence.entity.ResourceEntity) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Map(java.util.Map) 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