using scripting execution
variable:
I want to get IDs of the resources. Preference to getting a keyValue pair of resource Names and Record IDs.
execution.getProcessEngineServices().getRepositoryService().getDeploymentResources(deploymentId)
and also looked at using:
execution.getProcessEngineServices().getRepositoryService(). getDeploymentResourceNames(deploymentId)
-
getDeploymentResources: This provides me with the ID and Name of the resource but it also returns the “bytes” field.(https://docs.camunda.org/javadoc/camunda-bpm-platform/7.5/org/camunda/bpm/engine/impl/persistence/entity/ResourceEntity.html#bytes). I see this being a problem if you start dealing with large number of resources in a single deployment and the files are quite large. You end with a getDeploymentResources method call that uses up a huge amount of memory.
-
getDeploymentResourceNames: this only returns the file Names/resource names of the resources. I additionally need the IDs. So preference is to use: getDeploymentResources.
Is there a way to filter out the fields in the methods? Or is there another method from another service that can be used? The core of the problem seems to be that getDeploymentResources returns the bytes. If we can restrict the method from returning that information that would be great!
(I know we can filter out the bytes field after it is received from the method. But then we still have to process all of that data in memory. Please correct me if i am wrong about this)
Current workaround is to be build a new resource object:
var obj = new Object();
obj.process = {};
obj.deployment = {};
obj.deployment.resources = [];
obj.process.processDefinitionId = execution.getProcessDefinitionId();
obj.process.processInstanceId = execution.getProcessInstanceId();
obj.deployment.deploymentId = execution.getProcessEngineServices().getRepositoryService().getProcessDefinition(obj.process.processDefinitionId).getDeploymentId();
obj.deployment.deploymentVersionTag = execution.getProcessEngineServices().getRepositoryService().getProcessDefinition(obj.process.processDefinitionId).getVersionTag();
obj.deployment.deploymentVersion = execution.getProcessEngineServices().getRepositoryService().getProcessDefinition(obj.process.processDefinitionId).getVersion();
var resources = execution.getProcessEngineServices().getRepositoryService().getDeploymentResources(obj.deployment.deploymentId);
for each (var resource in resources){
var resourceObj = new Object();
resourceObj.id = resource.getId()
resourceObj.name = resource.getName();
obj.deployment.resources.push(resourceObj);
}
JSON.stringify(obj);
Thanks!