Search in sources :

Example 6 with ResourceEntity

use of org.activiti.engine.impl.persistence.entity.ResourceEntity in project Activiti by Activiti.

the class BpmnDeployer method createResource.

protected void createResource(String name, byte[] bytes, DeploymentEntity deploymentEntity) {
    ResourceEntity resource = new ResourceEntity();
    resource.setName(name);
    resource.setBytes(bytes);
    resource.setDeploymentId(deploymentEntity.getId());
    // Mark the resource as 'generated'
    resource.setGenerated(true);
    Context.getCommandContext().getDbSqlSession().insert(resource);
}
Also used : ResourceEntity(org.activiti.engine.impl.persistence.entity.ResourceEntity)

Example 7 with ResourceEntity

use of org.activiti.engine.impl.persistence.entity.ResourceEntity 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)

Example 8 with ResourceEntity

use of org.activiti.engine.impl.persistence.entity.ResourceEntity in project Activiti by Activiti.

the class DeploymentBuilderImpl method addString.

public DeploymentBuilder addString(String resourceName, String text) {
    if (text == null) {
        throw new ActivitiIllegalArgumentException("text is null");
    }
    ResourceEntity resource = new ResourceEntity();
    resource.setName(resourceName);
    try {
        resource.setBytes(text.getBytes(DEFAULT_ENCODING));
    } catch (UnsupportedEncodingException e) {
        throw new ActivitiException("Unable to get process bytes.", e);
    }
    deployment.addResource(resource);
    return this;
}
Also used : ActivitiException(org.activiti.engine.ActivitiException) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) ResourceEntity(org.activiti.engine.impl.persistence.entity.ResourceEntity) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 9 with ResourceEntity

use of org.activiti.engine.impl.persistence.entity.ResourceEntity in project Activiti by Activiti.

the class DeploymentBuilderImpl method addZipInputStream.

public DeploymentBuilder addZipInputStream(ZipInputStream zipInputStream) {
    try {
        ZipEntry entry = zipInputStream.getNextEntry();
        while (entry != null) {
            if (!entry.isDirectory()) {
                String entryName = entry.getName();
                byte[] bytes = IoUtil.readInputStream(zipInputStream, entryName);
                ResourceEntity resource = new ResourceEntity();
                resource.setName(entryName);
                resource.setBytes(bytes);
                deployment.addResource(resource);
            }
            entry = zipInputStream.getNextEntry();
        }
    } catch (Exception e) {
        throw new ActivitiException("problem reading zip input stream", e);
    }
    return this;
}
Also used : ActivitiException(org.activiti.engine.ActivitiException) ZipEntry(java.util.zip.ZipEntry) ResourceEntity(org.activiti.engine.impl.persistence.entity.ResourceEntity) ActivitiException(org.activiti.engine.ActivitiException) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 10 with ResourceEntity

use of org.activiti.engine.impl.persistence.entity.ResourceEntity in project Activiti by Activiti.

the class RulesDeployer method deploy.

public void deploy(DeploymentEntity deployment, Map<String, Object> deploymentSettings) {
    log.debug("Processing deployment {}", deployment.getName());
    KnowledgeBuilder knowledgeBuilder = null;
    DeploymentManager deploymentManager = Context.getProcessEngineConfiguration().getDeploymentManager();
    Map<String, ResourceEntity> resources = deployment.getResources();
    for (String resourceName : resources.keySet()) {
        log.info("Processing resource {}", resourceName);
        if (resourceName.endsWith(".drl")) {
            // is only parsing .drls sufficient? what about other rule dsl's? (@see ResourceType)
            if (knowledgeBuilder == null) {
                knowledgeBuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
            }
            ResourceEntity resourceEntity = resources.get(resourceName);
            byte[] resourceBytes = resourceEntity.getBytes();
            Resource droolsResource = ResourceFactory.newByteArrayResource(resourceBytes);
            knowledgeBuilder.add(droolsResource, ResourceType.DRL);
        }
    }
    if (knowledgeBuilder != null) {
        KnowledgeBase knowledgeBase = knowledgeBuilder.newKnowledgeBase();
        deploymentManager.getKnowledgeBaseCache().add(deployment.getId(), knowledgeBase);
    }
}
Also used : KnowledgeBuilder(org.drools.builder.KnowledgeBuilder) KnowledgeBase(org.drools.KnowledgeBase) DeploymentManager(org.activiti.engine.impl.persistence.deploy.DeploymentManager) ResourceEntity(org.activiti.engine.impl.persistence.entity.ResourceEntity) Resource(org.drools.io.Resource)

Aggregations

ResourceEntity (org.activiti.engine.impl.persistence.entity.ResourceEntity)10 ActivitiException (org.activiti.engine.ActivitiException)4 ActivitiIllegalArgumentException (org.activiti.engine.ActivitiIllegalArgumentException)4 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ArrayList (java.util.ArrayList)2 BpmnModel (org.activiti.bpmn.model.BpmnModel)2 ActivitiObjectNotFoundException (org.activiti.engine.ActivitiObjectNotFoundException)2 DeploymentManager (org.activiti.engine.impl.persistence.deploy.DeploymentManager)2 ProcessDefinitionEntity (org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity)2 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ZipEntry (java.util.zip.ZipEntry)1 BpmnXMLConverter (org.activiti.bpmn.converter.BpmnXMLConverter)1 BpmnParse (org.activiti.engine.impl.bpmn.parser.BpmnParse)1 ProcessEngineConfigurationImpl (org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl)1 DbSqlSession (org.activiti.engine.impl.db.DbSqlSession)1 CommandContext (org.activiti.engine.impl.interceptor.CommandContext)1