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 have a new update for the workflow bean, I think it works faster… and it's smaller Smiley Happy

package com.someco.web.bean;

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

import java.util.List;

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

import org.alfresco.model.ContentModel;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.security.AuthorityService;
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.WorkflowTaskQuery;
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()
   {
      this.taskList = new ArrayList<Node>();
      
      // 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 = getWorkflowService().getDefinitionByName("jbpm$wf:adhoc");
         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))
            {
               WorkflowTaskQuery wtq = new WorkflowTaskQuery();
               
               wtq.setActive(true);
               wtq.setTaskState(WorkflowTaskState.IN_PROGRESS);
               wtq.setProcessId(wi.id);
               
               List<WorkflowTask> tasks = workflowService.queryTasks(wtq);
               for(WorkflowTask task : tasks){
                     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;
   }    
}

riogrande
Champ in-the-making
Champ in-the-making
Ok, in fact it works, I haven't understood for what it was really for.
So you can "just" see adhoc task actually in progress (from any user), it's not really a History as I need. I would like to see any workflow and also the completed one (from anybody).

igor_shaldev
Champ in-the-making
Champ in-the-making
I need the same thing, I will make something like that soon. Also I found a similar thing that lists all workflow history for a file.
http://www.wowww.nl/wordpress/?p=69