org.camunda.bpm.engine.impl.persistence.entity.ResourceEntity Java Examples

The following examples show how to use org.camunda.bpm.engine.impl.persistence.entity.ResourceEntity. 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: 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 #2
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 #3
Source File: XlsxDeployer.java    From camunda-dmn-xlsx with Apache License 2.0 6 votes vote down vote up
public void deploy(DeploymentEntity deployment) {
  if (!deployment.isNew()) {
    // only generate dmn xml once when deploying for the first time
    return;
  }

  List<ResourceEntity> generatedResources = new ArrayList<ResourceEntity>();

  for (ResourceEntity resource : deployment.getResources().values()) {
    if (canHandle(resource)) {
      XlsxDeploymentMetaData metaData = loadMetaData(deployment, resource.getName() + ".yaml");
      DmnModelInstance dmnModel = generateDmnModel(resource, metaData);
      ResourceEntity dmnResource = generateDeploymentResource(deployment, dmnModel, generateDmnResourceName(resource));
      generatedResources.add(dmnResource);
    }
  }

  addToDeployment(generatedResources, deployment);
}
 
Example #4
Source File: XlsxDeployer.java    From camunda-dmn-xlsx with Apache License 2.0 6 votes vote down vote up
protected ResourceEntity generateDeploymentResource(DeploymentEntity deployment, DmnModelInstance dmnModel, String name) {
  ResourceEntity resource = new ResourceEntity();

  ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
  Dmn.writeModelToStream(byteStream, dmnModel);
  byte[] bytes = byteStream.toByteArray();

  resource.setName(name);
  resource.setBytes(bytes);
  resource.setDeploymentId(deployment.getId());

  // Mark the resource as 'generated'
  resource.setGenerated(true);

  return resource;
}
 
Example #5
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 #6
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 #7
Source File: DeployCmd.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
protected List<ResourceEntity> getResourcesByDeploymentId(Set<String> deploymentIds, CommandContext commandContext) {
  List<ResourceEntity> result = new ArrayList<>();

  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;
}
 
Example #8
Source File: DeployCmd.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
protected void checkDuplicateResourceName(List<ResourceEntity> resources) {
  Map<String, ResourceEntity> resourceMap = new HashMap<>();

  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);
  }
}
 
Example #9
Source File: CmmnTransformerTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example #10
Source File: DeployCmd.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
protected void ensureResourcesWithKeysExist(String deploymentId, Set<String> expectedKeys, Map<String, ResourceEntity> actual, String valueProperty) {
  List<String> missingResources = getMissingElements(expectedKeys, actual);

  if (!missingResources.isEmpty()) {
    StringBuilder builder = new StringBuilder();

    builder.append("The deployment with id '");
    builder.append(deploymentId);
    builder.append("' does not contain the following resources with ");
    builder.append(valueProperty);
    builder.append(": ");
    builder.append(StringUtil.join(missingResources.iterator()));

    throw new NotFoundException(builder.toString());
  }
}
 
Example #11
Source File: RepositoryByteArrayTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void testFormsBinaries() {
  Date fixedDate = new Date();
  ClockUtil.setCurrentTime(fixedDate);

  String deploymentId = testRule.deploy("org/camunda/bpm/engine/test/api/form/DeployedFormsProcess.bpmn20.xml",
      "org/camunda/bpm/engine/test/api/form/start.form",
      "org/camunda/bpm/engine/test/api/form/task.form",
      "org/camunda/bpm/engine/test/api/authorization/renderedFormProcess.bpmn20.xml",
      "org/camunda/bpm/engine/test/api/authorization/oneTaskCase.cmmn").getId();

  List<Resource> deploymentResources = repositoryService.getDeploymentResources(deploymentId);
  assertEquals(5, deploymentResources.size());
  for (Resource resource : deploymentResources) {
    ResourceEntity entity = (ResourceEntity) resource;
    checkEntity(fixedDate, entity);
  }
}
 
Example #12
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 #13
Source File: MockProvider.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public static Resource createMockDeploymentJsonResource() {
  Resource mockResource = mock(ResourceEntity.class);
  when(mockResource.getId()).thenReturn(EXAMPLE_DEPLOYMENT_JSON_RESOURCE_ID);
  when(mockResource.getName()).thenReturn(EXAMPLE_DEPLOYMENT_JSON_RESOURCE_NAME);
  when(mockResource.getDeploymentId()).thenReturn(EXAMPLE_DEPLOYMENT_ID);
  return mockResource;
}
 
Example #14
Source File: MockProvider.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public static Resource createMockDeploymentXmlResource() {
  Resource mockResource = mock(ResourceEntity.class);
  when(mockResource.getId()).thenReturn(EXAMPLE_DEPLOYMENT_XML_RESOURCE_ID);
  when(mockResource.getName()).thenReturn(EXAMPLE_DEPLOYMENT_XML_RESOURCE_NAME);
  when(mockResource.getDeploymentId()).thenReturn(EXAMPLE_DEPLOYMENT_ID);
  return mockResource;
}
 
Example #15
Source File: MockProvider.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public static Resource createMockDeploymentDmnXmlResource() {
  Resource mockResource = mock(ResourceEntity.class);
  when(mockResource.getId()).thenReturn(EXAMPLE_DEPLOYMENT_DMN_XML_RESOURCE_ID);
  when(mockResource.getName()).thenReturn(EXAMPLE_DEPLOYMENT_DMN_XML_RESOURCE_NAME);
  when(mockResource.getDeploymentId()).thenReturn(EXAMPLE_DEPLOYMENT_ID);
  return mockResource;
}
 
Example #16
Source File: MockProvider.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public static Resource createMockDeploymentDmnResource() {
  Resource mockResource = mock(ResourceEntity.class);
  when(mockResource.getId()).thenReturn(EXAMPLE_DEPLOYMENT_DMN_RESOURCE_ID);
  when(mockResource.getName()).thenReturn(EXAMPLE_DEPLOYMENT_DMN_RESOURCE_NAME);
  when(mockResource.getDeploymentId()).thenReturn(EXAMPLE_DEPLOYMENT_ID);
  return mockResource;
}
 
Example #17
Source File: MockProvider.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public static Resource createMockDeploymentJpegResource() {
  Resource mockResource = mock(ResourceEntity.class);
  when(mockResource.getId()).thenReturn(EXAMPLE_DEPLOYMENT_JPEG_RESOURCE_ID);
  when(mockResource.getName()).thenReturn(EXAMPLE_DEPLOYMENT_JPEG_RESOURCE_NAME);
  when(mockResource.getDeploymentId()).thenReturn(EXAMPLE_DEPLOYMENT_ID);
  return mockResource;
}
 
Example #18
Source File: MockProvider.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public static Resource createMockDeploymentPhpResource() {
  Resource mockResource = mock(ResourceEntity.class);
  when(mockResource.getId()).thenReturn(EXAMPLE_DEPLOYMENT_PHP_RESOURCE_ID);
  when(mockResource.getName()).thenReturn(EXAMPLE_DEPLOYMENT_PHP_RESOURCE_NAME);
  when(mockResource.getDeploymentId()).thenReturn(EXAMPLE_DEPLOYMENT_ID);
  return mockResource;
}
 
Example #19
Source File: MockProvider.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public static Resource createMockDeploymentJpgResource() {
  Resource mockResource = mock(ResourceEntity.class);
  when(mockResource.getId()).thenReturn(EXAMPLE_DEPLOYMENT_JPG_RESOURCE_ID);
  when(mockResource.getName()).thenReturn(EXAMPLE_DEPLOYMENT_JPG_RESOURCE_NAME);
  when(mockResource.getDeploymentId()).thenReturn(EXAMPLE_DEPLOYMENT_ID);
  return mockResource;
}
 
Example #20
Source File: MockProvider.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public static Resource createMockDeploymentPythonResource() {
  Resource mockResource = mock(ResourceEntity.class);
  when(mockResource.getId()).thenReturn(EXAMPLE_DEPLOYMENT_PYTHON_RESOURCE_ID);
  when(mockResource.getName()).thenReturn(EXAMPLE_DEPLOYMENT_PYTHON_RESOURCE_NAME);
  when(mockResource.getDeploymentId()).thenReturn(EXAMPLE_DEPLOYMENT_ID);
  return mockResource;
}
 
Example #21
Source File: MockProvider.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public static Resource createMockDeploymentPngResource() {
  Resource mockResource = mock(ResourceEntity.class);
  when(mockResource.getId()).thenReturn(EXAMPLE_DEPLOYMENT_PNG_RESOURCE_ID);
  when(mockResource.getName()).thenReturn(EXAMPLE_DEPLOYMENT_PNG_RESOURCE_NAME);
  when(mockResource.getDeploymentId()).thenReturn(EXAMPLE_DEPLOYMENT_ID);
  return mockResource;
}
 
Example #22
Source File: MockProvider.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public static Resource createMockDeploymentSvgResource() {
  Resource mockResource = mock(ResourceEntity.class);
  when(mockResource.getId()).thenReturn(EXAMPLE_DEPLOYMENT_SVG_RESOURCE_ID);
  when(mockResource.getName()).thenReturn(EXAMPLE_DEPLOYMENT_SVG_RESOURCE_NAME);
  when(mockResource.getDeploymentId()).thenReturn(EXAMPLE_DEPLOYMENT_ID);
  return mockResource;
}
 
Example #23
Source File: MockProvider.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public static Resource createMockDeploymentRubyResource() {
  Resource mockResource = mock(ResourceEntity.class);
  when(mockResource.getId()).thenReturn(EXAMPLE_DEPLOYMENT_RUBY_RESOURCE_ID);
  when(mockResource.getName()).thenReturn(EXAMPLE_DEPLOYMENT_RUBY_RESOURCE_NAME);
  when(mockResource.getDeploymentId()).thenReturn(EXAMPLE_DEPLOYMENT_ID);
  return mockResource;
}
 
Example #24
Source File: MockProvider.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public static Resource createMockDeploymentResource() {
  Resource mockResource = mock(ResourceEntity.class);
  when(mockResource.getId()).thenReturn(EXAMPLE_DEPLOYMENT_RESOURCE_ID);
  when(mockResource.getName()).thenReturn(EXAMPLE_DEPLOYMENT_RESOURCE_NAME);
  when(mockResource.getDeploymentId()).thenReturn(EXAMPLE_DEPLOYMENT_ID);

  return mockResource;
}
 
Example #25
Source File: MockProvider.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public static Resource createMockDeploymentHtmlResource() {
  Resource mockResource = mock(ResourceEntity.class);
  when(mockResource.getId()).thenReturn(EXAMPLE_DEPLOYMENT_HTML_RESOURCE_ID);
  when(mockResource.getName()).thenReturn(EXAMPLE_DEPLOYMENT_HTML_RESOURCE_NAME);
  when(mockResource.getDeploymentId()).thenReturn(EXAMPLE_DEPLOYMENT_ID);
  return mockResource;
}
 
Example #26
Source File: MockProvider.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public static Resource createMockDeploymentTxtResource() {
  Resource mockResource = mock(ResourceEntity.class);
  when(mockResource.getId()).thenReturn(EXAMPLE_DEPLOYMENT_TXT_RESOURCE_ID);
  when(mockResource.getName()).thenReturn(EXAMPLE_DEPLOYMENT_TXT_RESOURCE_NAME);
  when(mockResource.getDeploymentId()).thenReturn(EXAMPLE_DEPLOYMENT_ID);
  return mockResource;
}
 
Example #27
Source File: MockProvider.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public static Resource createMockDeploymentResourceFilename() {
  Resource mockResource = mock(ResourceEntity.class);
  when(mockResource.getId()).thenReturn(EXAMPLE_DEPLOYMENT_RESOURCE_FILENAME_ID);
  when(mockResource.getName()).thenReturn(EXAMPLE_DEPLOYMENT_RESOURCE_FILENAME_PATH + EXAMPLE_DEPLOYMENT_RESOURCE_FILENAME_NAME);
  when(mockResource.getDeploymentId()).thenReturn(EXAMPLE_DEPLOYMENT_ID);
  return mockResource;
}
 
Example #28
Source File: CompetingLicenseKeyAccessTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Override
public Long execute(CommandContext commandContext) {
  ResourceEntity licenseKey = commandContext.getResourceManager().findLicenseKeyResource();
  assertNotNull("license key is expected to be not null", licenseKey);

  monitor.sync();

  licenseKey.setBytes("updatedTestLicenseKeyBySecondThread".getBytes());
  new SetLicenseKeyCmd(new String(licenseKey.getBytes())).execute(commandContext);
  return null;
}
 
Example #29
Source File: MockProvider.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public static Resource createMockDeploymentResourceFilenameBackslash() {
  Resource mockResource = mock(ResourceEntity.class);
  when(mockResource.getId()).thenReturn(EXAMPLE_DEPLOYMENT_RESOURCE_FILENAME_ID);
  when(mockResource.getName()).thenReturn(EXAMPLE_DEPLOYMENT_RESOURCE_FILENAME_PATH_BACKSLASH + EXAMPLE_DEPLOYMENT_RESOURCE_FILENAME_NAME);
  when(mockResource.getDeploymentId()).thenReturn(EXAMPLE_DEPLOYMENT_ID);
  return mockResource;
}
 
Example #30
Source File: MockProvider.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public static Resource createMockDeploymentJpeResource() {
  Resource mockResource = mock(ResourceEntity.class);
  when(mockResource.getId()).thenReturn(EXAMPLE_DEPLOYMENT_JPE_RESOURCE_ID);
  when(mockResource.getName()).thenReturn(EXAMPLE_DEPLOYMENT_JPE_RESOURCE_NAME);
  when(mockResource.getDeploymentId()).thenReturn(EXAMPLE_DEPLOYMENT_ID);
  return mockResource;
}