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