Skip to content
Browse files

-added services for edit variable and display variable history

  • Loading branch information...
1 parent 7cb41f2 commit 0e4f7fbc305691559e777a3a6b5e1d4d1a99d71e @mswiderski mswiderski committed
View
2 ...pm-knowledge-services/src/main/java/org/droolsjbpm/services/api/KnowledgeDataService.java
@@ -50,6 +50,6 @@
Collection<VariableStateDesc> getVariablesCurrentState(long processInstanceId);
-
+ Collection<VariableStateDesc> getVariableHistory(long processInstanceId, String variableId);
}
View
11 ...owledge-services/src/main/java/org/droolsjbpm/services/impl/KnowledgeDataServiceImpl.java
@@ -91,7 +91,7 @@ public ProcessInstanceDesc getProcessInstanceById(int sessionId, long processId)
}
public Collection<VariableStateDesc> getVariablesCurrentState(long processInstanceId) {
- List<VariableStateDesc> variablesState = em.createQuery("select vs FROM VariableStateDesc vs where vs.processInstanceId =:processInstanceId AND vs.pk = (select max(vss.pk) FROM VariableStateDesc vss WHERE vss.id = vs.id ) ")
+ List<VariableStateDesc> variablesState = em.createQuery("select vs FROM VariableStateDesc vs where vs.processInstanceId =:processInstanceId AND vs.pk in (select max(vss.pk) FROM VariableStateDesc vss WHERE vss.processInstanceId =:processInstanceId group by vss.variableId ) order by vs.pk")
.setParameter("processInstanceId", processInstanceId)
.getResultList();
@@ -147,4 +147,13 @@ public ProcessInstanceDesc getProcessInstanceById(int sessionId, long processId)
return uncompletedNodeInstances;
}
+
+ public Collection<VariableStateDesc> getVariableHistory(long processInstanceId, String variableId) {
+ List<VariableStateDesc> variablesState = em.createQuery("select vs FROM VariableStateDesc vs where vs.processInstanceId =:processInstanceId AND vs.variableId =:variableId order by vs.pk DESC")
+ .setParameter("processInstanceId", processInstanceId)
+ .setParameter("variableId", variableId)
+ .getResultList();
+
+ return variablesState;
+ }
}
View
19 ...e-services/src/test/java/org/droolsjbpm/services/test/DomainKnowledgeServiceBaseTest.java
@@ -34,6 +34,7 @@
import org.droolsjbpm.services.impl.model.VariableStateDesc;
import org.jbpm.task.api.TaskServiceEntryPoint;
import org.jbpm.task.query.TaskSummary;
+import org.jbpm.workflow.instance.WorkflowProcessInstance;
import org.junit.Test;
import static org.junit.Assert.*;
@@ -157,6 +158,13 @@ public void testSimpleProcess() throws Exception {
assertEquals("Initial Document", variableIterator.next().getNewValue());
assertEquals("Reviewed Document", variableIterator.next().getNewValue());
+
+ ProcessInstance pi = ksession.getProcessInstance(processInstance.getId());
+ ((WorkflowProcessInstance) pi).setVariable("approval_document", "Initial Document(updated)");
+
+ variablesCurrentState = dataService.getVariablesCurrentState(processInstance.getId());
+ assertEquals(2, variablesCurrentState.size());
+
translatorTasks = taskService.getTasksAssignedAsPotentialOwner("translator", "en-UK");
assertEquals(1, translatorTasks.size());
@@ -183,16 +191,21 @@ public void testSimpleProcess() throws Exception {
variablesCurrentState = dataService.getVariablesCurrentState(processInstance.getId());
assertEquals(3, variablesCurrentState.size());
variableIterator = variablesCurrentState.iterator();
- assertEquals("Initial Document", variableIterator.next().getNewValue());
+
assertEquals("Reviewed Document", variableIterator.next().getNewValue());
+ assertEquals("Initial Document(updated)", variableIterator.next().getNewValue());
assertEquals("Translated Document", variableIterator.next().getNewValue());
processInstanceHistory = dataService.getProcessInstanceFullHistory(0, processInstance.getId());
assertEquals(18, processInstanceHistory.size());
-
-
+ variablesCurrentState = dataService.getVariableHistory(processInstance.getId(), "approval_document");
+ assertEquals(2, variablesCurrentState.size());
+ variableIterator = variablesCurrentState.iterator();
+ assertEquals("Initial Document(updated)", variableIterator.next().getNewValue());
+ assertEquals("Initial Document", variableIterator.next().getNewValue());
+
}
@Test

0 comments on commit 0e4f7fb

Please sign in to comment.
Something went wrong with that request. Please try again.