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);
}
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);
}
}
}
}
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;
}
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;
}
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);
}
}
Aggregations