I was looking at a way to tie the loading of a process to a ResourcePatternResolver and ran across a strange issue and I'm hoping someone can explain why it is this wayRespositoryService.createDeployment().addInputStream() takes two arguments (neither of which are documented BTW), a resourceName and an inputStream. The one that is strange is the resourceName. It appears that the addInputStream method takes the URL of the resource as the first argument. If you pass a logical name for that resource (i.e. "testProcess"), the Deployment you get back will be invalid (and no exception is thrown!!!!!!) and your processDefinition query will fail due to a NPE. InputStream inputStream = resource.getInputStream();
Deployment deployment = repositoryService.createDeployment().addInputStream( "testProcess", inputStream ).deploy();
ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().deploymentId(deployment.getId()).singleResult();
However if you pass in the URL for the first argument (which isn't clear since the argument isn't resourceURL), the approach will succeed. InputStream inputStream = resource.getInputStream();
Deployment deployment = repositoryService.createDeployment().addInputStream( resource.getURL().toString(), inputStream ).deploy();
ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().deploymentId(deployment.getId()).singleResult();
This is weird for three reasons: First architecturally it is not clear why you would need to pass the URL (as a string) to the method as opposed to just specifying the InputStream. You already have the InputStream so really what is the value of passing the URL? I may be passing in a URL to a file, class path, http resource, etc and it really shouldn't matter because you have the InputStream.Second it seems strange that there is no way to really pass the resource name to the system. While yes I do have a name for the process in the business process, it seems to be a bit weird that I cannot provide a logical name and refer to/query that process in that manner. It seems that it would have made more architectural "goodness" to be able to do:
public void loadProcess( String bpName )
{
InputStream inputStream = resource.getInputStream();
Deployment deployment = repositoryService.createDeployment().addInputStream( bpName, inputStream ).deploy();
ProcessDefinition processDefinition = repositoryService.getNamedResource(bpName);
…
Third, the use of resourceName is inconsistent across the API. For this method resourceName expects to be a URL. However for some of the other methods it is expecting it to get the id.I'm curious why the API is set up this way. I'm sure there is a reason, but it is unclear what that reason is.