JBoss Community

Re: NodeInstanceLog and Human Tasks relationship

created by Rahul Agrawal in jBPM - View the full discussion

I tried to implement it in the following way.

 

It works fine.

 

List<NodeInstanceLog> nodeInstancesList = dbLog.findNodeInstances(processInstanceId);

 

                    List<HistoryRecord> objLstHistoryList =  new ArrayList<HistoryRecord>();

 

                    Map<String, NodeInstanceLog> nodeInstances = new HashMap<String, NodeInstanceLog>();

 

                    for (NodeInstanceLog nodeInstance : nodeInstancesList) {

                              if (nodeInstance.getType() == NodeInstanceLog.TYPE_ENTER) {

                                        nodeInstances.put(nodeInstance.getNodeInstanceId(),

                                                            nodeInstance);

                              } else {

                                        NodeInstanceLog enterLog = nodeInstances.get(nodeInstance.getNodeInstanceId());

 

                                        HistoryRecord objHistoryRecord = null;

                                        objHistoryRecord = new HistoryRecord();

                                        objHistoryRecord.setId(enterLog.getId());

                                        objHistoryRecord.setStrNodeName(enterLog.getNodeName());

                                        objHistoryRecord.setStrActedTime(nodeInstance.getDate().toString());

                                        objHistoryRecord.setStrComment("Approved");

 

                                        long lOrgDiff = nodeInstance.getDate().getTime() - enterLog.getDate().getTime() ;

                                         long lDiff = 0;

                                         lDiff = lOrgDiff / (60*60*1000);

                                         if(lDiff == 0)

                                         {

                                                   lDiff = lOrgDiff / (60*1000);

                                                   if (lDiff ==0 )

                                                   {

                                                             lDiff = lOrgDiff / 1000;

                                                             if(lDiff == 0)

                                                             {

                                                                       objHistoryRecord.setStrDuration (lOrgDiff + " milisec.");

                                                             }

                                                             else

                                                                       objHistoryRecord.setStrDuration (lDiff + " sec.");

                                                   }

                                                   else

                                                   {

                                                             objHistoryRecord.setStrDuration (lDiff + " min.");

                                                   }

                                         } else if(lDiff >= 24)

                                         {

                                                   lDiff = lOrgDiff / (24*60*60*1000);

                                                   objHistoryRecord.setStrDuration ( lDiff + " days.");

                                         }

                                         else

                                         {

                                                   objHistoryRecord.setStrDuration (lDiff + " hrs.");          

                                         }

                                        //Use the enterLog and nodeInstance object to get the duration field

                                        objLstHistoryList.add(objHistoryRecord);

                                        nodeInstances.remove(nodeInstance.getNodeInstanceId());

 

                              }

                    }

 

                    EntityManagerFactory emf = getEntityManagerFactory(processName);

                    EntityManager em = emf.createEntityManager();

 

 

                    Query resultQuery = em.createQuery("SELECT t.taskData.actualOwner FROM NodeInstanceLog n ,org.jbpm.task.Task t left join t.names as i "+

                                        "WHERE n.id = :nodeinstanceid AND " +

                                        " n.nodeName = i.text AND " +

                                        "n.processInstanceId = t.taskData.processInstanceId AND " +

                                        "t.taskData.status = 'Completed'");

 

                    java.util.Iterator<HistoryRecord> lstIterator = objLstHistoryList.iterator();

 

                    while(lstIterator.hasNext())

                    {

                              try{

                                        HistoryRecord hstryObj = lstIterator.next();

                                        User user = (User)resultQuery.setParameter("nodeinstanceid", hstryObj.getId()).getSingleResult();

                                        hstryObj.setStrActedBy(user.getId());

                              }

                              catch (Exception e) {

                                                  // TODO: handle exception

                              }

                    }

                    return objLstHistoryList;

Reply to this message by going to Community

Start a new discussion in jBPM at Community