Java Code Examples for org.camunda.bpm.engine.impl.persistence.entity.ResourceEntity#getBytes()

The following examples show how to use org.camunda.bpm.engine.impl.persistence.entity.ResourceEntity#getBytes() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JuelFormEngine.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example 2
Source File: GetLicenseKeyCmd.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Override
public String execute(CommandContext commandContext) {
  AuthorizationManager authorizationManager = commandContext.getAuthorizationManager();
  authorizationManager.checkCamundaAdmin();

  // case I: license is stored as BLOB
  ResourceEntity licenseResource = commandContext.getResourceManager().findLicenseKeyResource();
  if (licenseResource != null) {
    return new String(licenseResource.getBytes(), StandardCharsets.UTF_8);
  }

  // case II: license is stored in properties
  PropertyEntity licenseProperty = commandContext.getPropertyManager().findPropertyById(LICENSE_KEY_PROPERTY_NAME);
  if (licenseProperty != null) {
    return licenseProperty.getValue();
  }

  return null;
}
 
Example 3
Source File: DeployCmd.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
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);
  }
}
 
Example 4
Source File: BpmnDeployer.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Override
protected List<ProcessDefinitionEntity> transformDefinitions(DeploymentEntity deployment, ResourceEntity resource, Properties properties) {
  byte[] bytes = resource.getBytes();
  ByteArrayInputStream inputStream = new ByteArrayInputStream(bytes);

  BpmnParse bpmnParse = bpmnParser
      .createParse()
      .sourceInputStream(inputStream)
      .deployment(deployment)
      .name(resource.getName());

  if (!deployment.isValidatingSchema()) {
    bpmnParse.setSchemaResource(null);
  }

  bpmnParse.execute();

  if (!properties.contains(JOB_DECLARATIONS_PROPERTY)) {
    properties.set(JOB_DECLARATIONS_PROPERTY, new HashMap<String, List<JobDeclaration<?, ?>>>());
  }
  properties.get(JOB_DECLARATIONS_PROPERTY).putAll(bpmnParse.getJobDeclarations());

  return bpmnParse.getProcessDefinitions();
}
 
Example 5
Source File: DecisionRequirementsDefinitionDeployer.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Override
protected List<DecisionRequirementsDefinitionEntity> transformDefinitions(DeploymentEntity deployment, ResourceEntity resource, Properties properties) {
  byte[] bytes = resource.getBytes();
  ByteArrayInputStream inputStream = new ByteArrayInputStream(bytes);

  try {
    DecisionRequirementsDefinitionEntity drd = transformer
        .createTransform()
        .modelInstance(inputStream)
        .transformDecisionRequirementsGraph();

    return Collections.singletonList(drd);

  } catch (Exception e) {
    throw LOG.exceptionParseDmnResource(resource.getName(), e);
  }
}
 
Example 6
Source File: XlsxDeployer.java    From camunda-dmn-xlsx with Apache License 2.0 5 votes vote down vote up
protected DmnModelInstance generateDmnModel(ResourceEntity xlsxResource, XlsxDeploymentMetaData metaData) {
  byte[] bytes = xlsxResource.getBytes();
  ByteArrayInputStream inputStream = new ByteArrayInputStream(bytes);

  XlsxConverter converter = new XlsxConverter();
  if (metaData != null) {
    metaData.applyTo(converter);
  }
  return converter.convert(inputStream);
}
 
Example 7
Source File: XlsxDeployer.java    From camunda-dmn-xlsx with Apache License 2.0 5 votes vote down vote up
protected XlsxDeploymentMetaData loadMetaData(DeploymentEntity deployment, String metaDataResource) {

    ResourceEntity resource = deployment.getResource(metaDataResource);

    if (resource != null) {
      ByteArrayInputStream inputStream = new ByteArrayInputStream(resource.getBytes());

      Yaml yaml = new Yaml();
      return yaml.loadAs(inputStream, XlsxDeploymentMetaData.class);
    }
    else {
      return null;
    }
  }
 
Example 8
Source File: ResourceUtil.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
/**
 * 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);
  }
}
 
Example 9
Source File: GetDeploymentResourceCmd.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public InputStream execute(CommandContext commandContext) {
  ensureNotNull("deploymentId", deploymentId);
  ensureNotNull("resourceName", resourceName);

  for(CommandChecker checker : commandContext.getProcessEngineConfiguration().getCommandCheckers()) {
    checker.checkReadDeployment(deploymentId);
  }

  ResourceEntity resource = commandContext
    .getResourceManager()
    .findResourceByDeploymentIdAndResourceName(deploymentId, resourceName);
  ensureNotNull(DeploymentResourceNotFoundException.class, "no resource found with name '" + resourceName + "' in deployment '" + deploymentId + "'", "resource", resource);
  return new ByteArrayInputStream(resource.getBytes());
}
 
Example 10
Source File: GetDeploymentResourceForIdCmd.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public InputStream execute(CommandContext commandContext) {
  ensureNotNull("deploymentId", deploymentId);
  ensureNotNull("resourceId", resourceId);

  for(CommandChecker checker : commandContext.getProcessEngineConfiguration().getCommandCheckers()) {
    checker.checkReadDeployment(deploymentId);
  }

  ResourceEntity resource = commandContext
    .getResourceManager()
    .findResourceByDeploymentIdAndResourceId(deploymentId, resourceId);
  ensureNotNull("no resource found with id '" + resourceId + "' in deployment '" + deploymentId + "'", "resource", resource);
  return new ByteArrayInputStream(resource.getBytes());
}