cancel
Showing results for 
Search instead for 
Did you mean: 

Workflow task history

igor_shaldev
Champ in-the-making
Champ in-the-making
Hello,

Is there a way to follow the assignment of the advanced AdHoc workflow even after re-assignment? So even if the workflow task is reassigned from person to person, several times, and the starter of the task to know in any time where the process is assigned

Thanks in advance

Best Regards,
Igor Shaldev
12 REPLIES 12

igor_shaldev
Champ in-the-making
Champ in-the-making
I found a way to list all started workflow's by the logged in user. I created new dashlet that lists the workflow description, current owner of the process (even if it is reassigned), creation date, and status. I can send the code if someone is interested.

riogrande
Champ in-the-making
Champ in-the-making
Yes I'm interested in your code Smiley Happy I need something similar

giorgio
Champ in-the-making
Champ in-the-making
Hi igor I'm having trouble getting the property owner of workflows pooled, but I am trying to access from review_pooled_proccessdefinition.xml, you will know if you are not able to help me. greetings

igor_shaldev
Champ in-the-making
Champ in-the-making
Here is my code, it's still in the test phase so if anyone has some ideas, please share. Smiley Very Happy

WorkflowTest.java
package com.someco.web.bean;

import java.io.Serializable;
import java.util.ArrayList;

import java.util.List;
import java.util.Map;
import java.util.Set;

import javax.faces.context.FacesContext;
import javax.transaction.UserTransaction;

import org.alfresco.model.ContentModel;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.security.AuthorityService;
import org.alfresco.service.cmr.security.AuthorityType;
import org.alfresco.service.cmr.workflow.WorkflowDefinition;
import org.alfresco.service.cmr.workflow.WorkflowInstance;
import org.alfresco.service.cmr.workflow.WorkflowService;
import org.alfresco.service.cmr.workflow.WorkflowTask;
import org.alfresco.service.cmr.workflow.WorkflowTaskDefinition;
import org.alfresco.service.cmr.workflow.WorkflowTaskState;
import org.alfresco.service.namespace.QName;
import org.alfresco.web.app.Application;
import org.alfresco.web.bean.NavigationBean;
import org.alfresco.web.bean.repository.Node;
import org.alfresco.web.bean.repository.Repository;
import org.alfresco.web.bean.repository.TransientMapNode;
import org.alfresco.web.bean.repository.User;
import org.alfresco.web.ui.common.Utils;

public class WorkflowTest implements Serializable {
   
   private static final long serialVersionUID = 1L;
   
   protected NavigationBean navigationBean;
   
   transient private NodeService nodeService;
   transient private WorkflowService workflowService;
   transient private AuthorityService authorityService;
   
   protected List<Node> taskList;
   
   public static final String BEAN_NAME = "WorkflowTest";
   
   public List<Node> getTaskList()
   {
      // get the current username
           FacesContext context = FacesContext.getCurrentInstance();
           User user = Application.getCurrentUser(context);
           String currentUser = user.getUserName();
           
           UserTransaction tx = null;
                try
                {
                    tx = Repository.getUserTransaction(context, true);
                        tx.begin();
               
              WorkflowDefinition workflowDef = null;
         List<WorkflowDefinition> workflowDefs = getWorkflowService().getDefinitions();
         for(WorkflowDefinition def : workflowDefs)
                        {
            if(def.name.equals("jbpm$wf:adhoc"))
                                {
               workflowDef = def;
               break;
            }
         }
            
         List<NodeRef> wfPackages = new ArrayList<NodeRef>();
         List<WorkflowInstance> wis = getWorkflowService().getActiveWorkflows(workflowDef.id);
         for(WorkflowInstance wi : wis)
                        {      
            String wfInitiator = (String) getNodeService().getProperty(wi.initiator, QName.createQName("http://www.alfresco.org/model/content/1.0", "userName"));
            if(currentUser.equalsIgnoreCase(wfInitiator))
                                {
               wfPackages.add(wi.workflowPackage);
            }
         }
            
         this.taskList = new ArrayList<Node>();
         Set<String> people = getAuthorityService().getAllAuthorities(AuthorityType.USER);
         for(String person : people)
                        {
            List<WorkflowTask> tasks = getWorkflowService().getAssignedTasks(person, WorkflowTaskState.IN_PROGRESS);
            for(WorkflowTask task : tasks)
                                {
                    Map<QName, Serializable> props = task.properties;
               for(NodeRef wfPackage : wfPackages)
                  if(wfPackage.equals(props.get(QName.createQName("http://www.alfresco.org/model/bpm/1.0", "package"))))
                                                {
                     Node node = createTask(task);
                     this.taskList.add(node);
                  }
            }
         }
         tx.commit();
            
            }
           catch (Throwable e)
           {
                // rollback the transaction
                try { if (tx != null) {tx.rollback();} } catch (Exception ex) {}
                Utils.addErrorMessage("Failed to get all active tasks: " + e.toString(), e);
           }

      return this.taskList;
}
   
   protected TransientMapNode createTask(WorkflowTask task) {
      // get the type of the task
       WorkflowTaskDefinition taskDef = task.definition;
        
       // create the basic transient node
       TransientMapNode node = new TransientMapNode(taskDef.metadata.getName(), task.title, task.properties);
        
       // add properties for the other useful metadata
       node.getProperties().put(ContentModel.PROP_NAME.toString(), task.title);
       node.getProperties().put("type", node.getType().toString());
       node.getProperties().put("id", task.id);
       node.getProperties().put("owner", task.properties.get(QName.createQName("http://www.alfresco.org/model/content/1.0", "owner")));
     
       return node;
   }
   

   public void setNavigationBean(NavigationBean navigationBean) {
      this.navigationBean = navigationBean;
   }
  
   public void setWorkflowService(WorkflowService workflowService) {
      this.workflowService = workflowService;
   }
  
   protected WorkflowService getWorkflowService() {
      if (this.workflowService == null) {
         this.workflowService = Repository.getServiceRegistry(FacesContext.getCurrentInstance()).getWorkflowService();
      }
      return this.workflowService;
   }
  
   public void setNodeService(NodeService nodeService) {
      this.nodeService = nodeService;
   }
  
   protected NodeService getNodeService() {
      if (this.nodeService == null) {
         this.nodeService = Repository.getServiceRegistry(FacesContext.getCurrentInstance()).getNodeService();
      }
      return this.nodeService;
   }
  
   protected AuthorityService getAuthorityService() {
      if(this.authorityService == null) {
         this.authorityService = Repository.getServiceRegistry(FacesContext.getCurrentInstance()).getAuthorityService();
      }
      return this.authorityService;
   }
  
   public void setAuthorityService(AuthorityService authorityService) {
      this.authorityService = authorityService;
   }    
}

web-client-config-custom.xml
<config evaluator="string-compare" condition="Dashboards">
<dashboards>
<dashlets>
<dashlet id="workflow-task-search" label-id="wf_dash_label" description-id="wf_dash_desc" jsp="/jsp/extension/customDashlet/workflow-task-search.jsp" allow-narrow="false" />
</dashlets>
</dashboards>
</config>

workflow-task-search.jsp
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<%@ taglib uri="/WEB-INF/alfresco.tld" prefix="a" %>
<%@ taglib uri="/WEB-INF/repo.tld" prefix="r" %>

<a:richList id="task-list" value="#{WorkflowTest.taskList}" var="r" rendered="#{not empty WorkflowTest.taskList}"
viewMode="details" styleClass="recordSet" headerStyleClass="recordSetHeader" rowStyleClass="recordSetRow"
initialSortColumn="created" initialSortDescending="true"
altRowStyleClass="recordSetRowAlt" width="100%" pageSize="10" refreshOnBind="true" >

<a:column id="col1" primary="true" width="400" style="padding:2px;text-align:left">
<f:facet name="header">
<a:sortLink label="#{msg.description}" value="bpm:description" mode="case-insensitive" styleClass="header" />
</f:facet>
<h:outputText id="desc-coll" value="#{r['bpm:description']}" />
</a:column>

<%– Task owner column –%>
<a:column id="col2a" style="padding:2px;text-align:left">
<f:facet name="header">
<a:sortLink id="col2a-sort" label="#{msg.owner}" value="cm:owner" styleClass="header"/>
</f:facet>
<h:outputText id="col2a-txt" value="#{r['cm:owner']}" />
</a:column>

<%– Created Date column –%>
<a:column id="col4" style="padding:2px;text-align:left">
<f:facet name="header">
<a:sortLink id="col4-sort" label="#{msg.created}" value="created" styleClass="header"/>
</f:facet>
<h:outputText id="col4-txt" value="#{r.created}">
<a:convertXMLDate type="both" pattern="#{msg.date_time_pattern}" />
</h:outputText>
</a:column>

<%– Status column –%>
<a:column id="col6" style="padding:2px;text-align:left">
<f:facet name="header">
<a:sortLink id="col6-sort" label="#{msg.status}" value="bpm:status" styleClass="header"/>
</f:facet>
<h:outputText id="col6-txt" value="#{r['bpm:status']}" />
</a:column>

<a:dataPager styleClass="pager" />
</a:richList>

faces-config-custom.xml
   <managed-bean>
       <description>Workflow Test</description>
         <managed-bean-name>WorkflowTest</managed-bean-name>
         <managed-bean-class>com.someco.web.bean.WorkflowTest</managed-bean-class>
         <managed-bean-scope>session</managed-bean-scope>
         <managed-property>
          <property-name>navigationBean</property-name>
          <value>#{NavigationBean}</value>
        </managed-property>
        <managed-property>
          <property-name>workflowService</property-name>
          <value>#{WorkflowService}</value>
        </managed-property>
        <managed-property>
         <property-name>authorityService</property-name>
         <value>#{AuthorityService}</value>
      </managed-property>
      <managed-property>
          <property-name>nodeService</property-name>
          <value>#{NodeService}</value>
        </managed-property>
      </managed-bean>

A little explanation for the getTaskList() method. It gets all the active workflow tasks initiated from the current user, and adds them to a workflow package (list of nodeRef's). Then, it iterates thru all users on the system (I don't know how well will this work if there is a lot of users) who have the workflow task assigned to them, and adds it to taskList.

I put a system.out.print, that calculates the execution time, it's fast with 5 users, but there is a problem that I cannot see, it executes the method several times. I don't know why is this happening.

I hope the code helps.
Regards

riogrande
Champ in-the-making
Champ in-the-making
Perhaps I did something wrong, but I put exactly your code in a someco project (from the book Smiley Tongue) but I have nothing in the dashlet.

igor_shaldev
Champ in-the-making
Champ in-the-making
Did you add the dashlet to your dashboard? My Alfresco > Configure > Add started workflow tracker

regards

riogrande
Champ in-the-making
Champ in-the-making
I know I'm a noob but nevertheless I managed that Smiley Very Happy

[img]http://www.digitalmindstudio.ch/~magicrio/alfresco/no_history_workflow.png[/img]

End I have no error in the log  :?

igor_shaldev
Champ in-the-making
Champ in-the-making
Sorry for that, but I had to check. Try adding the following line at the end of the catch statement:
e.printStackTrace();

I don't know if it will return anything but it's worth a try

riogrande
Champ in-the-making
Champ in-the-making
still nothing,
Perhaps he didn't find WorkflowTest.java, but I have no error so it doesn't help me.

Edit: when I introduce a syntax error in WorkflowTest.java I have an error on the "My Alfresco" page, so he use correctly the file  :mrgreen:.

Witch version of Alfresco have you ? (probably not the root of the problem…)