Search in sources :

Example 1 with ResourceEntity

use of org.camunda.bpm.engine.impl.persistence.entity.ResourceEntity in project camunda-bpm-platform by camunda.

the class DeployCmd method addResources.

protected void addResources(List<ResourceEntity> resources, DeploymentBuilderImpl deploymentBuilder) {
    DeploymentEntity deployment = deploymentBuilder.getDeployment();
    Map<String, ResourceEntity> existingResources = deployment.getResources();
    for (ResourceEntity resource : resources) {
        String resourceName = resource.getName();
        if (existingResources != null && existingResources.containsKey(resourceName)) {
            String message = String.format("Cannot add resource with id '%s' and name '%s' from " + "deployment with id '%s' to new deployment because the new deployment contains " + "already a resource with same name.", resource.getId(), resourceName, resource.getDeploymentId());
            throw new NotValidException(message);
        }
        ByteArrayInputStream inputStream = new ByteArrayInputStream(resource.getBytes());
        deploymentBuilder.addInputStream(resourceName, inputStream);
    }
}
Also used : DeploymentEntity(org.camunda.bpm.engine.impl.persistence.entity.DeploymentEntity) NotValidException(org.camunda.bpm.engine.exception.NotValidException) ByteArrayInputStream(java.io.ByteArrayInputStream) ResourceEntity(org.camunda.bpm.engine.impl.persistence.entity.ResourceEntity)

Example 2 with ResourceEntity

use of org.camunda.bpm.engine.impl.persistence.entity.ResourceEntity in project camunda-bpm-platform by camunda.

the class DeployCmd method getResourcesByName.

protected List<ResourceEntity> getResourcesByName(Map<String, Set<String>> resourcesByName, CommandContext commandContext) {
    List<ResourceEntity> result = new ArrayList<ResourceEntity>();
    ResourceManager resourceManager = commandContext.getResourceManager();
    for (String deploymentId : resourcesByName.keySet()) {
        Set<String> resourceNames = resourcesByName.get(deploymentId);
        String[] resourceNameArray = resourceNames.toArray(new String[resourceNames.size()]);
        List<ResourceEntity> resources = resourceManager.findResourceByDeploymentIdAndResourceNames(deploymentId, resourceNameArray);
        ensureResourcesWithNamesExist(deploymentId, resourceNames, resources);
        result.addAll(resources);
    }
    return result;
}
Also used : ResourceEntity(org.camunda.bpm.engine.impl.persistence.entity.ResourceEntity) ArrayList(java.util.ArrayList) ResourceManager(org.camunda.bpm.engine.impl.persistence.entity.ResourceManager)

Example 3 with ResourceEntity

use of org.camunda.bpm.engine.impl.persistence.entity.ResourceEntity in project camunda-bpm-platform by camunda.

the class DeployCmd method resolveResourcesToDeploy.

protected Map<String, ResourceEntity> resolveResourcesToDeploy(CommandContext commandContext, DeploymentEntity deployment) {
    Map<String, ResourceEntity> resourcesToDeploy = new HashMap<String, ResourceEntity>();
    Map<String, ResourceEntity> containedResources = deployment.getResources();
    if (deploymentBuilder.isDuplicateFilterEnabled()) {
        String source = deployment.getSource();
        if (source == null || source.isEmpty()) {
            source = ProcessApplicationDeployment.PROCESS_APPLICATION_DEPLOYMENT_SOURCE;
        }
        Map<String, ResourceEntity> existingResources = commandContext.getResourceManager().findLatestResourcesByDeploymentName(deployment.getName(), containedResources.keySet(), source, deployment.getTenantId());
        for (ResourceEntity deployedResource : containedResources.values()) {
            String resourceName = deployedResource.getName();
            ResourceEntity existingResource = existingResources.get(resourceName);
            if (existingResource == null || existingResource.isGenerated() || resourcesDiffer(deployedResource, existingResource)) {
                if (deploymentBuilder.isDeployChangedOnly()) {
                    resourcesToDeploy.put(resourceName, deployedResource);
                } else {
                    // all resources should be deployed
                    resourcesToDeploy = containedResources;
                    break;
                }
            }
        }
    } else {
        resourcesToDeploy = containedResources;
    }
    return resourcesToDeploy;
}
Also used : HashMap(java.util.HashMap) ResourceEntity(org.camunda.bpm.engine.impl.persistence.entity.ResourceEntity)

Example 4 with ResourceEntity

use of org.camunda.bpm.engine.impl.persistence.entity.ResourceEntity in project camunda-bpm-platform by camunda.

the class DeployCmd method getResourcesByDeploymentId.

protected List<ResourceEntity> getResourcesByDeploymentId(Set<String> deploymentIds, CommandContext commandContext) {
    List<ResourceEntity> result = new ArrayList<ResourceEntity>();
    if (!deploymentIds.isEmpty()) {
        DeploymentManager deploymentManager = commandContext.getDeploymentManager();
        for (String deploymentId : deploymentIds) {
            DeploymentEntity deployment = deploymentManager.findDeploymentById(deploymentId);
            Map<String, ResourceEntity> resources = deployment.getResources();
            Collection<ResourceEntity> values = resources.values();
            result.addAll(values);
        }
    }
    return result;
}
Also used : DeploymentEntity(org.camunda.bpm.engine.impl.persistence.entity.DeploymentEntity) DeploymentManager(org.camunda.bpm.engine.impl.persistence.entity.DeploymentManager) ResourceEntity(org.camunda.bpm.engine.impl.persistence.entity.ResourceEntity) ArrayList(java.util.ArrayList)

Example 5 with ResourceEntity

use of org.camunda.bpm.engine.impl.persistence.entity.ResourceEntity in project camunda-bpm-platform by camunda.

the class DeployCmd method getResourcesById.

protected List<ResourceEntity> getResourcesById(Map<String, Set<String>> resourcesById, CommandContext commandContext) {
    List<ResourceEntity> result = new ArrayList<ResourceEntity>();
    ResourceManager resourceManager = commandContext.getResourceManager();
    for (String deploymentId : resourcesById.keySet()) {
        Set<String> resourceIds = resourcesById.get(deploymentId);
        String[] resourceIdArray = resourceIds.toArray(new String[resourceIds.size()]);
        List<ResourceEntity> resources = resourceManager.findResourceByDeploymentIdAndResourceIds(deploymentId, resourceIdArray);
        ensureResourcesWithIdsExist(deploymentId, resourceIds, resources);
        result.addAll(resources);
    }
    return result;
}
Also used : ResourceEntity(org.camunda.bpm.engine.impl.persistence.entity.ResourceEntity) ArrayList(java.util.ArrayList) ResourceManager(org.camunda.bpm.engine.impl.persistence.entity.ResourceManager)

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