Search in sources :

Example 11 with ResourceEntity

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;
}
Also used : InputStream(java.io.InputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) CaseDefinitionEntity(org.camunda.bpm.engine.impl.cmmn.entity.repository.CaseDefinitionEntity) ResourceEntity(org.camunda.bpm.engine.impl.persistence.entity.ResourceEntity) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 12 with ResourceEntity

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;
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ResourceEntity(org.camunda.bpm.engine.impl.persistence.entity.ResourceEntity) Process(org.camunda.bpm.model.bpmn.instance.Process) BpmnModelInstance(org.camunda.bpm.model.bpmn.BpmnModelInstance) CmmnModelInstance(org.camunda.bpm.model.cmmn.CmmnModelInstance) HashSet(java.util.HashSet) Case(org.camunda.bpm.model.cmmn.instance.Case)

Example 13 with ResourceEntity

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");
}
Also used : HashMap(java.util.HashMap) ResourceEntity(org.camunda.bpm.engine.impl.persistence.entity.ResourceEntity)

Example 14 with ResourceEntity

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;
}
Also used : ProcessApplicationRegistration(org.camunda.bpm.application.ProcessApplicationRegistration) NotValidException(org.camunda.bpm.engine.exception.NotValidException) Set(java.util.Set) HashSet(java.util.HashSet) DeploymentManager(org.camunda.bpm.engine.impl.persistence.entity.DeploymentManager) NotValidException(org.camunda.bpm.engine.exception.NotValidException) NotFoundException(org.camunda.bpm.engine.exception.NotFoundException) DeploymentEntity(org.camunda.bpm.engine.impl.persistence.entity.DeploymentEntity) ProcessApplicationDeploymentImpl(org.camunda.bpm.engine.impl.persistence.entity.ProcessApplicationDeploymentImpl) ResourceEntity(org.camunda.bpm.engine.impl.persistence.entity.ResourceEntity) Map(java.util.Map) HashMap(java.util.HashMap)

Example 15 with ResourceEntity

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);
    }
}
Also used : NotValidException(org.camunda.bpm.engine.exception.NotValidException) HashMap(java.util.HashMap) ResourceEntity(org.camunda.bpm.engine.impl.persistence.entity.ResourceEntity)

Aggregations

ResourceEntity (org.camunda.bpm.engine.impl.persistence.entity.ResourceEntity)19 HashMap (java.util.HashMap)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 ArrayList (java.util.ArrayList)3 NotValidException (org.camunda.bpm.engine.exception.NotValidException)3 DeploymentEntity (org.camunda.bpm.engine.impl.persistence.entity.DeploymentEntity)3 InputStream (java.io.InputStream)2 HashSet (java.util.HashSet)2 CommandChecker (org.camunda.bpm.engine.impl.cfg.CommandChecker)2 DeploymentManager (org.camunda.bpm.engine.impl.persistence.entity.DeploymentManager)2 ResourceManager (org.camunda.bpm.engine.impl.persistence.entity.ResourceManager)2 BpmnModelInstance (org.camunda.bpm.model.bpmn.BpmnModelInstance)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 OutputStream (java.io.OutputStream)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 Map (java.util.Map)1 Set (java.util.Set)1 ProcessApplicationRegistration (org.camunda.bpm.application.ProcessApplicationRegistration)1 ProcessEngineException (org.camunda.bpm.engine.ProcessEngineException)1 NotFoundException (org.camunda.bpm.engine.exception.NotFoundException)1