cancel
Showing results for 
Search instead for 
Did you mean: 

Jsp page with ui action to start specific workflow

mohammed_amr
Champ in-the-making
Champ in-the-making
Dears,

This question is repeated and there is no help till now !

I'm trying to build a dashlet on the alfresco explorer 3.4.d contains button with an action to start a workflow; once workflow has been started the alfresco explorer must transfer the user interface to the first step in the workflow.

How can i achieve this task and if you don't how can any one give me a hint !!

Thanks

Mohammed Amr
Senior System Developer
Digital Series.

Notes: This is an old post in alfresco explorer development forum and i post it here cause i think that i post the problem in the wrong location.

This is url of old post: http://forums.alfresco.com/en/viewtopic.php?f=12&t=37665
1 REPLY 1

mohammed_amr
Champ in-the-making
Champ in-the-making
Dears,

I got the solution and is as follow:

- create a jsp page as dashelt (you can refer to how to write simple jsp as dashlet).
- use alfresco faces components such as (a:actionLink) which is exist in the alfresco.tld
- create a managed bean and register this bean in the faces-config-custom.xml and you can optionally point to another benefits managed bean such as NavigationBean using #{NavigationBean} tag.

This is a full example for my bean :

/**
*
*/
package com.someco.web.bean;

import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;

import org.alfresco.repo.domain.permissions.Authority;
import org.alfresco.repo.workflow.WorkflowModel;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.security.AuthorityType;
import org.alfresco.service.cmr.security.PersonService;
import org.alfresco.service.cmr.workflow.WorkflowDefinition;
import org.alfresco.service.cmr.workflow.WorkflowPath;
import org.alfresco.service.cmr.workflow.WorkflowService;
import org.alfresco.service.cmr.workflow.WorkflowTask;
import org.alfresco.service.namespace.QName;
import org.alfresco.web.app.Application;
import org.alfresco.web.bean.NavigationBean;
import org.alfresco.web.bean.repository.Repository;
import org.alfresco.web.bean.repository.TransientMapNode;
import org.alfresco.web.bean.workflow.WorkflowBean;
import org.alfresco.web.ui.common.component.UIActionLink;
import org.apache.log4j.Logger;
import org.springframework.extensions.surf.util.ParameterCheck;

/**
* @author Younis alomoush
* @updated Mohammed Amr
*/
public class CSWorkflowBean extends WorkflowBean {
   /**
    *
    */
   private static final long serialVersionUID = 1L;
   private WorkflowService workflowService;
   private PersonService personService;
   private ServiceRegistry serviceRegistry;
   private static Logger log = Logger.getLogger(CSWorkflowBean.class);

   private NavigationBean navigator;

   public NavigationBean getNavigator() {
      return navigator;
   }

   public void setNavigator(NavigationBean navigator) {
      this.navigator = navigator;
   }

   @Override
   public void setupTaskDialog(ActionEvent event) {
      UIActionLink link = (UIActionLink)event.getSource();
      Map<String,String> params = link.getParameterMap();
      // acquire the serviceRegistry
      this.serviceRegistry = Repository.getServiceRegistry(FacesContext.getCurrentInstance());
      
      // acquire workflowService from serviceRegistry
      this.workflowService = this.serviceRegistry.getWorkflowService();

      
      // acquire personService from serviceRegistry
      this.personService = this.serviceRegistry.getPersonService();
      
      Set<String> authorities = this.serviceRegistry.getAuthorityService().getAllAuthorities(AuthorityType.GROUP);
      Set<String> adminAuthorities = this.serviceRegistry.getAuthorityService().getAuthoritiesForUser(this.serviceRegistry.getAuthenticationService().getCurrentUserName());
      
      Iterator<String> authLoop = authorities.iterator();
      
      while(authLoop.hasNext()){
         String auth = (String)authLoop.next();
         System.out.println(auth);
      }
      
      System.out.println("User Name: "+ this.serviceRegistry.getAuthenticationService().getCurrentUserName());
      System.out.println(this.personService.getPerson(this.serviceRegistry.getAuthenticationService().getCurrentUserName())
      +   ","   + this.serviceRegistry.getAuthorityService().getName(AuthorityType.GROUP, this.serviceRegistry.getAuthenticationService().getCurrentUserName()));
      
      authLoop = adminAuthorities.iterator();
      
      while(authLoop.hasNext()){
         String auth = (String)authLoop.next();
         System.out.println(auth);
      }
      
      
      List<WorkflowDefinition> workflows = this.workflowService.getAllDefinitions();

      Iterator loop = workflows.iterator();

      String wid = "";
      while (loop.hasNext()) {
         Object obj = (Object) loop.next();
         WorkflowDefinition wd = (WorkflowDefinition) obj;
         System.out.println("WORKFLOW: " + wd.id + "," + wd.getName() + ","
               + wd.getTitle());
         if (wd.name.equals("jbpm$wf:adhoc")) {
            System.out.println("WORKFLOWID: " + wd.id);
            wid = wd.id;
         }
      }
      NodeRef person = personService.getPerson("admin");
      NodeRef workflowNodeRef = workflowService.createPackage(null);
      Map<QName, Serializable> parameters = new HashMap<QName, Serializable>();
      Date dueDate = new Date(System.currentTimeMillis());
      parameters.put(WorkflowModel.ASSOC_ASSIGNEE, personService
            .getPeopleContainer().getId());
      parameters.put(WorkflowModel.PROP_DUE_DATE, dueDate);
      parameters.put(WorkflowModel.PROP_DESCRIPTION,
            params.get("message"));
      parameters.put(WorkflowModel.PROP_WORKFLOW_DUE_DATE, dueDate);
      parameters.put(WorkflowModel.PROP_WORKFLOW_DESCRIPTION,
            params.get("message"));
      parameters.put(WorkflowModel.ASSOC_ASSIGNEE, personService
            .getPerson("admin"));
      parameters.put(WorkflowModel.ASSOC_GROUP_ASSIGNEE, "GROUP_ALFRESCO_ADMINISTRATORS");
      parameters.put(WorkflowModel.ASSOC_PACKAGE, workflowNodeRef);
      System.out.println("initiated successfully");

      WorkflowPath _path = workflowService.startWorkflow(wid, parameters);

      // Print
      System.out.println("WorkflowPath: " + _path.getId());

      String workflowId = _path.instance.id;
      String wfPathId = _path.id;
      List<WorkflowTask> _tasks = workflowService
            .getTasksForWorkflowPath(wfPathId);

      WorkflowTask workflowTask = _tasks.get(0);

      // Print
      System.out.println(workflowTask.getId() + "," + workflowTask.getName());

      TransientMapNode transientMapNode = createTask(workflowTask);

      // Print
      System.out.println("transientMapNode.getId()"
            + transientMapNode.getId());
      System.out.println("transientMapNode.getType().toString()"
            + transientMapNode.getType().toString());

      ParameterCheck.mandatoryString("Task ID", workflowTask.getId());
      ParameterCheck.mandatoryString("Task Type", transientMapNode.getType()
            .toString());

      // setup the dispatch context with the task we're opening a dialog for
      TransientMapNode node = new TransientMapNode(QName
            .createQName(transientMapNode.getType().toString()),
            workflowTask.getId(), null);
      System.out.println(node);
      System.out.println(this.navigator);
      this.navigator.setupDispatchContext(node);

      // pass on parameters for the dialog
      Map<String, String> _params = new HashMap<String, String>(2, 1.0f);
      _params.put("id", workflowTask.getId());
      _params.put("type", transientMapNode.getType().toString());
// Look At this
      Application.getDialogManager().setupParameters(_params);
      // setupTaskDialog(transientMapNode.getId(),transientMapNode.getType().toString());

   }

}

And Thanks for Alfresco Team.
Any question !! Smiley Happy

Mohammed Amr
Senior System Developer
Digital Series.