How to get already Deployed Process Definition

cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Member II

How to get already Deployed Process Definition

I want to get already Deployed Process Definition. I have created process in which there are 2 group and each group contains some user.

once a user logged in , one process is started by a user of first group and then he logged out.

After that second user logged in and claim the task which was started by first user so that he can complete that task.

My code is working fine till first user is starting a job. but then I am getting below error while I am trying to claim the task belong to second group.

org.activiti.bpmn.exceptions.XMLException: Error reading XML
at org.activiti.bpmn.converter.BpmnXMLConverter.convertToBpmnModel(BpmnXMLConverter.java:312)
at org.activiti.bpmn.converter.BpmnXMLConverter.convertToBpmnModel(BpmnXMLConverter.java:284)
at org.activiti.engine.impl.bpmn.parser.BpmnParse.execute(BpmnParse.java:148)
at org.activiti.engine.impl.bpmn.deployer.ParsedDeploymentBuilder.createBpmnParseFromResource(ParsedDeploymentBuilder.java:96)
at org.activiti.engine.impl.bpmn.deployer.ParsedDeploymentBuilder.build(ParsedDeploymentBuilder.java:55)
at org.activiti.engine.impl.bpmn.deployer.BpmnDeployer.deploy(BpmnDeployer.java:69)
at org.activiti.engine.impl.persistence.deploy.DeploymentManager.deploy(DeploymentManager.java:60)
at org.activiti.engine.impl.persistence.deploy.DeploymentManager.resolveProcessDefinition(DeploymentManager.java:131)
at org.activiti.engine.impl.persistence.deploy.DeploymentManager.findDeployedProcessDefinitionById(DeploymentManager.java:78)
at org.activiti.engine.impl.util.ProcessDefinitionUtil.getProcessDefinition(ProcessDefinitionUtil.java:49)
Caused by: javax.xml.stream.XMLStreamException: ParseError at [row,col]:[1,1]
Message: Content is not allowed in prolog.
at com.sun.org.apache.xerces.internal.impl.XMLStreamReaderImpl.next(XMLStreamReaderImpl.java:604)
at org.activiti.bpmn.converter.BpmnXMLConverter.convertToBpmnModel(BpmnXMLConverter.java:309)
at org.activiti.bpmn.converter.BpmnXMLConverter.convertToBpmnModel(BpmnXMLConverter.java:284)
at org.activiti.engine.impl.bpmn.parser.BpmnParse.execute(BpmnParse.java:148)
at org.activiti.engine.impl.bpmn.deployer.ParsedDeploymentBuilder.createBpmnParseFromResource(ParsedDeploymentBuilder.java:96)
at org.activiti.engine.impl.bpmn.deployer.ParsedDeploymentBuilder.build(ParsedDeploymentBuilder.java:55)
at org.activiti.engine.impl.bpmn.deployer.BpmnDeployer.deploy(BpmnDeployer.java:69)
at org.activiti.engine.impl.persistence.deploy.DeploymentManager.deploy(DeploymentManager.java:60)
at org.activiti.engine.impl.persistence.deploy.DeploymentManager.resolveProcessDefinition(DeploymentManager.java:131)
at org.activiti.engine.impl.persistence.deploy.DeploymentManager.findDeployedProcessDefinitionById(DeploymentManager.java:78)

I think my program is not able to get process definition which was deployed in previous step.

Please let me know how can I get already deployed process definition, So that I can claim the task.

Below is the code I am using at the time second logged in user to claim the task.

ProcessEngineConfiguration processEngineConfiguration = ProcessEngineConfiguration
.createStandaloneProcessEngineConfiguration().setDatabaseType("postgres")
.setJdbcDriver("org.postgresql.Driver").setJdbcUsername("abcd").setJdbcPassword("abc@123")
.setJdbcUrl("jdbcSmiley Tongueostgresql://127.0.0.1:5432/WorkFlowDB");

// Create Process Engine that connect to DB
this.processEngine = processEngineConfiguration.buildProcessEngine();
this.taskService = processEngine.getTaskService();
this.historyService = processEngine.getHistoryService();

List<Task> verifytasks =  taskService.createTaskQuery().taskTenantId("orgId").taskCandidateGroup("SecondGroup").list();


for (Task verifytask : verifytasks) {
taskService.claim(verifytask.getId(), userId);

}

Please help to find the reason of above error.

12 Replies
Highlighted
Alfresco Employee

Re: How to get already Deployed Process Definition

The error you are seeing is 'Content is not allowed in prolog' so maybe you're hitting the same issue as New process definition deployment 

Highlighted
Member II

Re: How to get already Deployed Process Definition

Sorry but i didn't get you. What do you mean by same issue. ? Can plz provide or suggest solution to resolve this error. This error occur only at the time of claiming or completing the task. If i get list of pending task then it work fine. 

Highlighted
Alfresco Employee

Re: How to get already Deployed Process Definition

I'm suggesting that the process definition's xml may contain a non-standard character which can't be read like in the example referenced in the other thread.

Highlighted
Member II

Re: How to get already Deployed Process Definition

I have already checked the xml and it seem fine. And also the same code is working properly if i execute it in one go. Means once i deploy process definition and at the same time claiming the task then it is working fine.  But it is not working when i deployed process definition and trying to claim it after getting the already deployed definition which is stored in database. So as you can see in error logs , xml parsing failed. So I'm thinking that it is possible that my code is not able to get the parsed xml which is already deployed in previous step. 

That's why my question was : how can i get already deployed and parsed process definition at any time. Because there may be chance that i have deployed more than 1 process definition. And next time i want to get create repositoryservice object which refer to one of the process definition which is already deployed by me having some id.

I hope now you got my point. Plz help me out of this problem. You can see my code provided above. I know that there is something missing in my code because of which repositoryservice is not able to find parsed xml.

Thanks in advance. 

Highlighted
Alfresco Employee

Re: How to get already Deployed Process Definition

It's also possible that the code being used to retrieve the process definition at runtime isn't the same as the code that reads it when it is first deployed so it might be that it is parsed ok at deployment but not at runtime. If that were the case it might be possible for it to be a stray character/encoding problem. You seem to be suggesting that you're making the call to retrieve the process definition incorrectly. I presume you've got code being invoked from the process that does that and that's where the stacktrace is from. I see that the error ends with findDeployedProcessDefinitionById and that seems correct to me (see  ). I'm afraid I'm not sure if I'm understanding the distinction between the cases in which it is working and not working for you? Do you mean that there is a condition under which you are able to read the process definition at runtime?

Highlighted
Member II

Re: How to get already Deployed Process Definition

Yes. You got my point. The problem is with findDeployedProcessDefinitionById. And I already found the link provided you Getting 'deployed' process from Repository/RuntimeService  but I am not able to understand the solution.

Below is my code and process definition xml.

When First user logged In below code runs fines.

STEP 1 : ( This code is working fine)

String userId = "xyz";

// Configure Process Engine by Database connection
ProcessEngineConfiguration processEngineConfiguration = ProcessEngineConfiguration
.createStandaloneProcessEngineConfiguration().setDatabaseType("postgres")
.setJdbcDriver("org.postgresql.Driver").setJdbcUsername("abcd").setJdbcPassword("abcd@123")
.setJdbcUrl("jdbcSmiley Tongueostgresql://127.0.0.1:5432/xyz");

// Create Process Engine that connect to DB
ProcessEngine processEngine = processEngineConfiguration.buildProcessEngine();

// Create repository service and deploy with process xml.
RepositoryService repositoryService = processEngine.getRepositoryService();

try {
repositoryService.createDeployment().tenantId(orgId)
.addInputStream("abcd.bpmn20.xml",
new FileInputStream(new File(
"/home/gladiris/Project/workspace/abcd/resource/abcd.bpmn20.xml")))
.deploy();
} catch (FileNotFoundException e) {
System.out.println("Error");
e.printStackTrace();
}

// Everything related to the runtime state of processes can be found in
// the RuntimeService.
RuntimeService runtimeService = processEngine.getRuntimeService();


ProcessInstance processInstance = runtimeService.startProcessInstanceByKeyAndTenantId("ABCD", "tenantId");

String processIntanceId = processInstance.getId();
TaskService taskService = processEngine.getTaskService();

// Fetch all tasks for the logged in user
Task task = taskService.createTaskQuery().taskTenantId("tenantId").taskCandidateUser("firstUser")
.processInstanceId(processIntanceId).singleResult();


taskService.claim(task.getId(), userId);
taskService.complete(task.getId());

Now first user is logged out and second user logged In and trying to get process definition deployed in STEP 1 and continue to work which was now in task list of second user. 

Below is the code which is giving error because it is not able to get process definition which is deployed in STEP 1.

STEP 2 : ( Below is the  Giving error)

ProcessEngineConfiguration processEngineConfiguration = ProcessEngineConfiguration
.createStandaloneProcessEngineConfiguration().setDatabaseType("postgres")
.setJdbcDriver("org.postgresql.Driver").setJdbcUsername("abcd").setJdbcPassword("abcd@123")
.setJdbcUrl("jdbcSmiley Tongueostgresql://127.0.0.1:5432/xyz");

// Create Process Engine that connect to DB
ProcessEngine processEngine = processEngineConfiguration.buildProcessEngine();

// I'll getprocessIntanceId from DB. 

String processIntanceId = "1";

// I think some code need to be insert here through which I can get Process definition having same process instance Id and tenant Id which was deployed in // STEP 1. ( Something like the link you have provided Getting 'deployed' process from Repository/RuntimeService ) .

// If possible can you provide the code which need to be put here.


TaskService taskService = processEngine.getTaskService();

Task task =taskService.createTaskQuery().taskTenantId("tenantId").taskCandidateUser("secondUser").processInstanceId(processIntanceId).singleResult();

// At the time of claiming the task. Above mentioned error occured

taskService.claim(task.getId(), userId);

// Below is the Process Definition I am using. ( I have made some changes in name and Id so if something mismatch , Ignore it)

<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:activiti="http://activiti.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlnsSmiley Surprisedmgdc="http://www.omg.org/spec/DD/20100524/DC" xmlnsSmiley Surprisedmgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.activiti.org/processdef">
<process id="ABCD" name="ABCD" isExecutable="true">


<startEvent id="uploadStart" name="uploading"></startEvent>
<userTask id="uploadGroup" name="UploadGroup" activiti:candidateGroups="uploadGroup">
<extensionElements>
<activiti:taskListener event="create" class="bpmManager.PdfUpload">
</activiti:taskListener>
</extensionElements>
</userTask>
<userTask id="verifyGroup" name="VerifyGroup" activiti:candidateGroups="verifyGroup">
<extensionElements>
<activiti:taskListener event="create" class="bpmManager.VerifyPdf">
</activiti:taskListener>
</extensionElements>
</userTask>
<sequenceFlow id="assignToUploadGroup" name="AssignToUpload" sourceRef="uploadStart" targetRef="uploadGroup"></sequenceFlow>
<sequenceFlow id="assignToVerifyGroup" name="AssignToVerifyGroup" sourceRef="uploadGroup" targetRef="verifyGroup"></sequenceFlow>
<userTask id="managementGroup" name="ManagementGroup" activiti:candidateGroups="managementGroup">
<extensionElements>
<activiti:taskListener event="create" class="bpmManager.VerifiedDataManager">
</activiti:taskListener>
</extensionElements>
</userTask>
<sequenceFlow id="assignToManagement" name="AssignToManagement" sourceRef="verifyGroup" targetRef="managementGroup"></sequenceFlow>
<endEvent id="end" name="End"></endEvent>
<sequenceFlow id="goingToEnd" name="GoingToEnd" sourceRef="managementGroup" targetRef="end"></sequenceFlow>
</process>

</definitions>

Highlighted
Alfresco Employee

Re: How to get already Deployed Process Definition

Ok I think I had misunderstood. I thought maybe you had a service task that was reading the process definition but you don't have that.

It seems that what you are doing is running step 2 from a separate application and want to retrieve tasks for that same process definition.

I would think that you could just restrict the query by the task name instead of the process instance. See Activiti/TaskQueryTest.java at 5.22.0-release · Activiti/Activiti · GitHub 

If you wanted to find a process definition you could to it by process definition name (Activiti/ProcessDefinitionQueryTest.java at 5.22.0-release · Activiti/Activiti · GitHub ) but I am not sure if you need to do that.

Highlighted
Alfresco Employee

Re: How to get already Deployed Process Definition

Am I right in thinking that steps 1 and 2 are taking place in two different java applications? Presumably if you follow step 1 immediately with a taskQuery and claim the task (possibly setting authenticated user through identityService in between to change user) then that doesn't error?

Member II

Re: How to get already Deployed Process Definition

Yes you are right. Step 1 and 2 are two different java applications. And it works fine if both Step 1 and 2 are executed in same application. And as you said to "restrict the query by the task name instead of the process instance. " will it help me to perform claiming the task , completing the task , get other pending task list for second user ( in another java application) which was started by first user ( of another java application).

 

My goal is to get all task list with was started by first user and then resume by second user. And it is web application,

So both the user are different and they having logging to account to get task list , then claim it and at last complete it.

 

Hope you got my Point.  Please help me to get its solution. As I am new to it. And not able to get the solution.