}
@Override
public List<GraphElement> getProcessHistory(final ProcessInstance pi) {
ProcessEngine processEngine = getProcessEngine(ProcessToolContext.Util.getThreadProcessToolContext());
HistoryService service = processEngine.getHistoryService();
HistoryActivityInstanceQuery createHistoryActivityInstanceQuery = service.createHistoryActivityInstanceQuery();
HistoryActivityInstanceQuery activityInstanceQuery = createHistoryActivityInstanceQuery.processInstanceId(pi.getInternalId());
List<HistoryActivityInstance> list = activityInstanceQuery.list();
Map<String,GraphElement> processGraphElements = parseProcessDefinition(pi);
List<GraphElement> transitionaArcsList = new ArrayList<GraphElement>();
Collection<GraphElement> pge = processGraphElements.values() ;
for (GraphElement ge : pge) {
if( ge instanceof TransitionArc){
TransitionArc ta = (TransitionArc)ge;
transitionaArcsList.add(ta);
}
}
ArrayList<GraphElement> res = new ArrayList<GraphElement>();
for (HistoryActivityInstance hpi : list) {
loger.fine("Handling: " + hpi.getActivityName());
if (hpi instanceof HistoryActivityInstanceImpl) {
HistoryActivityInstanceImpl activity = (HistoryActivityInstanceImpl) hpi;
String activityName = activity.getActivityName();
if (res.isEmpty()) { //initialize start node and its transition
GraphElement startNode = processGraphElements.get("__AWF__start_node");
if (startNode != null) {
res.add(startNode);
}
GraphElement firstTransition = processGraphElements.get("__AWF__start_transition_to_" + activityName);
if (firstTransition != null) {
res.add(firstTransition);
}
}
StateNode sn = (StateNode) processGraphElements.get(activityName);
ArrayList<StateNode> arrayList = new ArrayList<StateNode>();
Collection<GraphElement> values = processGraphElements.values();
for (GraphElement graphElement : values) {
if(graphElement instanceof StateNode){
arrayList.add((StateNode) graphElement);
}
}
if (sn == null) continue;
sn = sn.cloneNode();
sn.setUnfinished(activity.getEndTime() == null);
sn.setLabel(activityName + ": " + hpi.getDuration() + "ms");
res.add(sn);
//look for transition
TransitionArc ta = (TransitionArc) processGraphElements.get(activityName + "_" + activity.getTransitionName());
if (ta == null) { //look for default!
ta = (TransitionArc) processGraphElements.get("__AWF__default_transition_" + activityName);
}
if (ta == null) {
continue;
}
res.add(ta.cloneNode());
} else {
loger.severe("Unsupported entry: " + hpi);
}
}
addJoinAndForkElements(res,processGraphElements);
HistoryProcessInstanceQuery historyProcessInstanceQuery = processEngine.getHistoryService()
.createHistoryProcessInstanceQuery().processInstanceId(pi.getInternalId());
HistoryProcessInstance historyProcessInstance = historyProcessInstanceQuery.uniqueResult();
if (historyProcessInstance != null && historyProcessInstance.getEndActivityName() != null) {
StateNode sn = (StateNode) processGraphElements.get(historyProcessInstance.getEndActivityName());
if (sn != null) {