I have been trying to use Camunda’s Repository Service, but for some reason, it is behaving strangely. Here is my code:
groovy
Copier le code
import groovy.json.JsonSlurper
import org.camunda.bpm.engine.RepositoryService
RepositoryService repositoryService = execution.getProcessEngineServices().getRepositoryService()
String deploymentId = execution.getProcessDefinitionId()
String resourceName = 'default.json'
// InputStream resourceStream = repositoryService.getResourceAsStream(deploymentId, resourceName)
Set<String> resourceNames = repositoryService.getDeploymentResourceNames(deploymentId)
println "Resources in deployment: ${resourceNames.join(', ')}"
/*
println (namescontent)
if (resourceStream) {
def jsonContent = resourceStream.text
resourceStream.close()
def json = new JsonSlurper().parseText(jsonContent)
json.each { key, value ->
execution.setVariable(key, value)
}
} else {
throw new RuntimeException("Resource not found: " + resourceName)
}
In the code above, I am trying to get values from a JSON file and set values to some execution variables. However, it couldn’t find the resource ‘default.json’. To debug, I used repositoryService.getDeploymentResourceNames
and couldn’t find any resources in the deployment, although that was not the case.