[jboss-user] [jBPM] - Re: NodeInstanceLog and Human Tasks relationship

Rahul Agrawal do-not-reply at jboss.com
Wed Feb 27 04:58:34 EST 2013


Rahul Agrawal [https://community.jboss.org/people/rahulamt] created the discussion

"Re: NodeInstanceLog and Human Tasks relationship"

To view the discussion, visit: https://community.jboss.org/message/799833#799833

--------------------------------------------------------------
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
[https://community.jboss.org/message/799833#799833]

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/jboss-user/attachments/20130227/5b291bdb/attachment-0001.html 


More information about the jboss-user mailing list