use of org.camunda.bpm.engine.impl.persistence.entity.ResourceEntity in project camunda-bpm-platform by camunda.
the class CmmnTransformerTest method transform.
protected List<CaseDefinitionEntity> transform() {
// convert the model to the XML string representation
OutputStream outputStream = new ByteArrayOutputStream();
Cmmn.writeModelToStream(outputStream, modelInstance);
InputStream inputStream = IoUtil.convertOutputStreamToInputStream(outputStream);
byte[] model = org.camunda.bpm.engine.impl.util.IoUtil.readInputStream(inputStream, "model");
ResourceEntity resource = new ResourceEntity();
resource.setBytes(model);
resource.setName("test");
transformer.setResource(resource);
List<CaseDefinitionEntity> definitions = transformer.transform();
IoUtil.closeSilently(outputStream);
IoUtil.closeSilently(inputStream);
return definitions;
}
use of org.camunda.bpm.engine.impl.persistence.entity.ResourceEntity in project camunda-bpm-platform by camunda.
the class DeployCmd method retrieveProcessKeysFromResources.
protected Set<String> retrieveProcessKeysFromResources(Map<String, ResourceEntity> resources) {
Set<String> keys = new HashSet<String>();
for (ResourceEntity resource : resources.values()) {
if (isBpmnResource(resource)) {
ByteArrayInputStream byteStream = new ByteArrayInputStream(resource.getBytes());
BpmnModelInstance model = Bpmn.readModelFromStream(byteStream);
for (Process process : model.getDefinitions().getChildElementsByType(Process.class)) {
keys.add(process.getId());
}
} else if (isCmmnResource(resource)) {
ByteArrayInputStream byteStream = new ByteArrayInputStream(resource.getBytes());
CmmnModelInstance model = Cmmn.readModelFromStream(byteStream);
for (Case cmmnCase : model.getDefinitions().getCases()) {
keys.add(cmmnCase.getId());
}
}
}
return keys;
}
use of org.camunda.bpm.engine.impl.persistence.entity.ResourceEntity in project camunda-bpm-platform by camunda.
the class DeployCmd method ensureResourcesWithNamesExist.
protected void ensureResourcesWithNamesExist(String deploymentId, Set<String> expectedNames, List<ResourceEntity> actual) {
Map<String, ResourceEntity> resources = new HashMap<String, ResourceEntity>();
for (ResourceEntity resource : actual) {
resources.put(resource.getName(), resource);
}
ensureResourcesWithKeysExist(deploymentId, expectedNames, resources, "name");
}
use of org.camunda.bpm.engine.impl.persistence.entity.ResourceEntity in project camunda-bpm-platform by camunda.
the class DeployCmd method doExecute.
protected DeploymentWithDefinitions doExecute(final CommandContext commandContext) {
DeploymentManager deploymentManager = commandContext.getDeploymentManager();
Set<String> deploymentIds = getAllDeploymentIds(deploymentBuilder);
if (!deploymentIds.isEmpty()) {
String[] deploymentIdArray = deploymentIds.toArray(new String[deploymentIds.size()]);
List<DeploymentEntity> deployments = deploymentManager.findDeploymentsByIds(deploymentIdArray);
ensureDeploymentsWithIdsExists(deploymentIds, deployments);
}
checkCreateAndReadDeployments(commandContext, deploymentIds);
// set deployment name if it should retrieved from an existing deployment
String nameFromDeployment = deploymentBuilder.getNameFromDeployment();
setDeploymentName(nameFromDeployment, deploymentBuilder, commandContext);
// get resources to re-deploy
List<ResourceEntity> resources = getResources(deploymentBuilder, commandContext);
// .. and add them the builder
addResources(resources, deploymentBuilder);
Collection<String> resourceNames = deploymentBuilder.getResourceNames();
if (resourceNames == null || resourceNames.isEmpty()) {
throw new NotValidException("No deployment resources contained to deploy.");
}
// perform deployment
DeploymentWithDefinitions deployment = commandContext.runWithoutAuthorization(new Callable<DeploymentWithDefinitions>() {
@Override
public DeploymentWithDefinitions call() throws Exception {
acquireExclusiveLock(commandContext);
DeploymentEntity deployment = initDeployment();
Map<String, ResourceEntity> resourcesToDeploy = resolveResourcesToDeploy(commandContext, deployment);
Map<String, ResourceEntity> resourcesToIgnore = new HashMap<String, ResourceEntity>(deployment.getResources());
resourcesToIgnore.keySet().removeAll(resourcesToDeploy.keySet());
if (!resourcesToDeploy.isEmpty()) {
LOG.debugCreatingNewDeployment();
deployment.setResources(resourcesToDeploy);
deploy(deployment);
} else {
LOG.usingExistingDeployment();
deployment = getExistingDeployment(commandContext, deployment.getName());
}
scheduleProcessDefinitionActivation(commandContext, deployment);
if (deploymentBuilder instanceof ProcessApplicationDeploymentBuilder) {
// for process application deployments, job executor registration is managed by
// process application manager
Set<String> processesToRegisterFor = retrieveProcessKeysFromResources(resourcesToIgnore);
ProcessApplicationRegistration registration = registerProcessApplication(commandContext, deployment, processesToRegisterFor);
return new ProcessApplicationDeploymentImpl(deployment, registration);
} else {
registerWithJobExecutor(commandContext, deployment);
}
return deployment;
}
});
createUserOperationLog(deploymentBuilder, deployment, commandContext);
return deployment;
}
use of org.camunda.bpm.engine.impl.persistence.entity.ResourceEntity in project camunda-bpm-platform by camunda.
the class DeployCmd method checkDuplicateResourceName.
protected void checkDuplicateResourceName(List<ResourceEntity> resources) {
Map<String, ResourceEntity> resourceMap = new HashMap<String, ResourceEntity>();
for (ResourceEntity resource : resources) {
String name = resource.getName();
ResourceEntity duplicate = resourceMap.get(name);
if (duplicate != null) {
String deploymentId = resource.getDeploymentId();
if (!deploymentId.equals(duplicate.getDeploymentId())) {
String message = String.format("The deployments with id '%s' and '%s' contain a resource with same name '%s'.", deploymentId, duplicate.getDeploymentId(), name);
throw new NotValidException(message);
}
}
resourceMap.put(name, resource);
}
}
Aggregations