Search in sources :

Example 6 with ResourceEntity

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

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);
    getDbEntityManager().insert(resource);
}
Also used : ResourceEntity(org.camunda.bpm.engine.impl.persistence.entity.ResourceEntity)

Example 7 with ResourceEntity

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

the class ResourceUtil method loadResourceContent.

/**
 * Parse a camunda:resource attribute and loads the resource depending on the url scheme.
 * Supported URL schemes are <code>classpath://</code> and <code>deployment://</code>.
 * If the scheme is omitted <code>classpath://</code> is assumed.
 *
 * @param resourcePath the path to the resource to load
 * @param deployment the deployment to load resources from
 * @return the resource content as {@link String}
 */
public static String loadResourceContent(String resourcePath, DeploymentEntity deployment) {
    String[] pathSplit = resourcePath.split("://", 2);
    String resourceType;
    if (pathSplit.length == 1) {
        resourceType = "classpath";
    } else {
        resourceType = pathSplit[0];
    }
    String resourceLocation = pathSplit[pathSplit.length - 1];
    byte[] resourceBytes = null;
    if (resourceType.equals("classpath")) {
        InputStream resourceAsStream = null;
        try {
            resourceAsStream = ReflectUtil.getResourceAsStream(resourceLocation);
            if (resourceAsStream != null) {
                resourceBytes = IoUtil.readInputStream(resourceAsStream, resourcePath);
            }
        } finally {
            IoUtil.closeSilently(resourceAsStream);
        }
    } else if (resourceType.equals("deployment")) {
        ResourceEntity resourceEntity = deployment.getResource(resourceLocation);
        if (resourceEntity != null) {
            resourceBytes = resourceEntity.getBytes();
        }
    }
    if (resourceBytes != null) {
        return new String(resourceBytes, Charset.forName("UTF-8"));
    } else {
        throw LOG.cannotFindResource(resourcePath);
    }
}
Also used : InputStream(java.io.InputStream) ResourceEntity(org.camunda.bpm.engine.impl.persistence.entity.ResourceEntity)

Example 8 with ResourceEntity

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

the class DeploymentBuilderImpl method addBytes.

protected DeploymentBuilder addBytes(String resourceName, byte[] bytes) {
    ResourceEntity resource = new ResourceEntity();
    resource.setBytes(bytes);
    resource.setName(resourceName);
    deployment.addResource(resource);
    return this;
}
Also used : ResourceEntity(org.camunda.bpm.engine.impl.persistence.entity.ResourceEntity)

Example 9 with ResourceEntity

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

the class JuelFormEngine method getFormTemplateString.

protected String getFormTemplateString(FormData formInstance, String formKey) {
    String deploymentId = formInstance.getDeploymentId();
    ResourceEntity resourceStream = Context.getCommandContext().getResourceManager().findResourceByDeploymentIdAndResourceName(deploymentId, formKey);
    ensureNotNull("Form with formKey '" + formKey + "' does not exist", "resourceStream", resourceStream);
    byte[] resourceBytes = resourceStream.getBytes();
    String encoding = "UTF-8";
    String formTemplateString = "";
    try {
        formTemplateString = new String(resourceBytes, encoding);
    } catch (UnsupportedEncodingException e) {
        throw new ProcessEngineException("Unsupported encoding of :" + encoding, e);
    }
    return formTemplateString;
}
Also used : ResourceEntity(org.camunda.bpm.engine.impl.persistence.entity.ResourceEntity) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException)

Example 10 with ResourceEntity

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

the class RedeploymentTest method testRedeployDeploymentResource.

public void testRedeployDeploymentResource() {
    // given
    // first deployment
    BpmnModelInstance model = createProcessWithServiceTask(PROCESS_KEY);
    Deployment deployment1 = repositoryService.createDeployment().name(DEPLOYMENT_NAME).addModelInstance(RESOURCE_NAME, model).deploy();
    Resource resource1 = getResourceByName(deployment1.getId(), RESOURCE_NAME);
    // second deployment
    model = createProcessWithUserTask(PROCESS_KEY);
    Deployment deployment2 = repositoryService.createDeployment().name(DEPLOYMENT_NAME).addModelInstance(RESOURCE_NAME, model).deploy();
    Resource resource2 = getResourceByName(deployment2.getId(), RESOURCE_NAME);
    // when
    Deployment deployment3 = repositoryService.createDeployment().name(DEPLOYMENT_NAME).addDeploymentResources(deployment1.getId()).deploy();
    // then
    Resource resource3 = getResourceByName(deployment3.getId(), RESOURCE_NAME);
    assertNotNull(resource3);
    // id
    assertNotNull(resource3.getId());
    assertFalse(resource1.getId().equals(resource3.getId()));
    // deployment id
    assertEquals(deployment3.getId(), resource3.getDeploymentId());
    // name
    assertEquals(resource1.getName(), resource3.getName());
    // bytes
    byte[] bytes1 = ((ResourceEntity) resource1).getBytes();
    byte[] bytes2 = ((ResourceEntity) resource2).getBytes();
    byte[] bytes3 = ((ResourceEntity) resource3).getBytes();
    assertTrue(Arrays.equals(bytes1, bytes3));
    assertFalse(Arrays.equals(bytes2, bytes3));
    deleteDeployments(deployment1, deployment2, deployment3);
}
Also used : Resource(org.camunda.bpm.engine.repository.Resource) ResourceEntity(org.camunda.bpm.engine.impl.persistence.entity.ResourceEntity) ProcessApplicationDeployment(org.camunda.bpm.engine.repository.ProcessApplicationDeployment) Deployment(org.camunda.bpm.engine.repository.Deployment) BpmnModelInstance(org.camunda.bpm.model.bpmn.BpmnModelInstance)

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