cancel
Showing results for 
Search instead for 
Did you mean: 

Adding a custom menu item to start an advanced workflow

erangaj
Champ in-the-making
Champ in-the-making
Hello,

Is it possible to add a custom menu item to the document_browse_menu to start a custom advanced workflow, instead of navigating through Start Advanced Workflow menu item?

Thanks & Regards,
Eranga
3 REPLIES 3

jzulu2000
Champ in-the-making
Champ in-the-making
I think this should work. The idea is to create a new Bean called Start333WorkflowWizard who takes the workflow id as a parameter and override some StartWorkflowWizard functionality just to have 2 steps, and in the "init" method configure what was configured originally on the "next" method.

Create a new action, called.. let's say start_333_workflow pointing to a new wizard; thw-workflow-id should point to the workflow you want to init
         

         <action id="start_333_workflow">
            <label-id>start_333_workflow</label-id>
            <image>/images/icons/new_workflow.gif</image>
            <evaluator>org.alfresco.web.action.evaluator.StartWorkflowEvaluator</evaluator>
            <action>wizard:start333Workflow</action>
            <action-listener>#{WizardManager.setupParameters}</action-listener>
            <params>
               <param name="item-to-workflow">#{actionContext.id}</param>
               <param name="the-workflow-id">jbpm$33343</param>
            </params>
         </action>
  
Add this new action to the desired action-group

Create a new wizard, start333Workflow, the same as startWorkflow but without chooseWorkflow step.
         

         <wizard name="start333Workflow" managed-bean="Start333WorkflowWizard"
                 description-id="start_workflow_desc" icon="/images/icons/new_workflow_large.gif">
            <step name="options" title-id="step_workflow_options"
                  description-id="start_workflow_options_desc">
               <page path="/jsp/workflow/start-workflow-wizard/workflow-options.jsp"
                     title-id="start_workflow_options_title"
                     description-id="start_workflow_options_desc"
                     instruction-id="default_instruction" />
            </step>
            <step name="summary" title-id="summary" description-id="summary_step_description">
               <page path="/jsp/wizard/summary.jsp"
                     title-id="summary"
                     description-id="summary_desc"
                     instruction-id="start_workflow_finish_instruction" />
            </step>
         </wizard>
  
Create a bean Start333WorkflowWizard extends original StartWorkflowWizard, add it to the managed beans with the Start333WorkflowWizard name, override init and next methods to do something like

   public void init(Map<String, String> parameters)
   {
      super.init(parameters);
      //take the-workflow-id parameter to start
         this.selectedWorkflow = this.parameters.get("the-workflow-id");

     //populate the workflows list in memory…
   getHasStartableWorkflows();

      //next code was taken from original next() method
         WorkflowDefinition flowDef = this.workflows.get(this.selectedWorkflow);

         if (logger.isDebugEnabled())
            logger.debug("Selected workflow: "+ flowDef);

         WorkflowTaskDefinition taskDef = flowDef.startTaskDefinition;
         if (taskDef != null)
         {
            if (logger.isDebugEnabled())
               logger.debug("Start task definition: " + taskDef);

            // create an instance of a task from the data dictionary
            this.startTaskNode = TransientNode.createNew(dictionaryService, taskDef.metadata,
                  "task_" + System.currentTimeMillis(), null);
         }

         // we also need to reset the resources list so that the actions get re-evaluated
         resetRichList();

   }
   public String next()
   {
      return null;
   }

  

I haven't tested this, buy it should work, maybe with modifications, but that's the idea.

erangaj
Champ in-the-making
Champ in-the-making
Thanks a lot jzulu2000

lnoto
Champ in-the-making
Champ in-the-making
Hi everyone,

I'm getting an authentication error, but I really don't know why!

This following code is taken from the wizard manager's bean which should start a workfow from a wizard.

public class PublishSpaceWizard extends StartWorkflowWizard {

   @Override
   public void init(Map<String, String> arg0) {
      // TODO Auto-generated method stub      
      super.init(arg0);      

      getHasStartableWorkflows();
      String workflow = this.parameters.get("workflow-name");
      WorkflowDefinition flowDef = null;
      Collection<WorkflowDefinition> flowDefs = this.workflows.values();
      for (WorkflowDefinition current : flowDefs) {
         if (current.name.equals(workflow)) {
            flowDef = current;
            this.selectedWorkflow = current.id;
            break;
         }
      }
      if (logger.isDebugEnabled())
         logger.debug("Selected workflow: " + flowDef);
      WorkflowTaskDefinition taskDef = flowDef.startTaskDefinition;
      if (taskDef != null) {
         if (logger.isDebugEnabled())
            logger.debug("Start task definition: " + taskDef);
         this.startTaskNode = TransientNode.createNew(dictionaryService,
               taskDef.metadata, "task_" + System.currentTimeMillis(),   null);
      }
      resetRichList();
   }
   …
}
   
Here are the definitions of the wizard and the action.

   <config>
      <actions>
         <action id="publish_space">
           <permissions>
             <permission allow="true">Write</permission>
           </permissions>
           <evaluator>com.integration.cms.extension.wizard.PublishSpaceEvaluator</evaluator>
           <label-id>publish_space</label-id>
           <image>/images/icons/PublishFile_Icon.gif</image>
           <show-link>true</show-link>
           <action>wizard:publishSpace</action>
         <action-listener>#{WizardManager.setupParameters}</action-listener>
         <params>
            <param name="item-to-workflow">#{actionContext.id}</param>
            <param name="workflow-name">jbpm$wfl:publish-space</param>
         </params>
      </action>
      <action-group id="browse_actions_menu">
         <action idref="publish_space" />
       </action-group>
      <action-group id="space_browse_menu">
         <action idref="publish_space" />
      </action-group>
      </actions>
   <wizards>
     <wizard name="publishSpace"
            managed-bean="PublishSpaceWizard" title-id="publish_space_title"
            description-id="publish_space_desc"
            icon="/images/icons/PublishFile_Icon.gif">            
            <step name="options" title-id="step_workflow_options"
                  description-id="start_workflow_options_desc">
               <page path="/jsp/workflow/start-workflow-wizard/workflow-options.jsp"
                     title-id="start_workflow_options_title"
                     description-id="start_workflow_options_desc"
                     instruction-id="default_instruction" />
            </step>
            <step name="summary" title-id="summary" description-id="summary_step_description">
               <page path="/jsp/wizard/summary.jsp"
                     title-id="summary"
                     description-id="summary_desc"
                     instruction-id="start_workflow_finish_instruction" />
            </step>
     </wizard>
   </wizards>

   </config>

The bean can find the workflow but then we get the following error invoking the super.init() method.
Looking at the code inside the StartWorkflowWizard bean, It seems to me that I have not the permission to invoke the nodeService.getType(itemToWorkflow) method.

Any ideas of what happened?

Thanks in advance,
Luigi

PS: Here is the stacktrace.

16:39:04,062 ERROR [[Faces Servlet]] Servlet.service() for servlet Faces Servlet threw exception
net.sf.acegisecurity.BadCredentialsException: Bad credentials presented
        at net.sf.acegisecurity.providers.dao.DaoAuthenticationProvider.authenticate(DaoAuthenticationProvider.java:290)
        at net.sf.acegisecurity.providers.ProviderManager.doAuthentication(ProviderManager.java:159)
        at net.sf.acegisecurity.AbstractAuthenticationManager.authenticate(AbstractAuthenticationManager.java:49)
        at net.sf.acegisecurity.intercept.AbstractSecurityInterceptor.beforeInvocation(AbstractSecurityInterceptor.java:372)
        at net.sf.acegisecurity.intercept.method.aopalliance.MethodSecurityInterceptor.invoke(MethodSecurityInterceptor.java:77)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:176)
        at org.alfresco.repo.security.permissions.impl.ExceptionTranslatorMethodInterceptor.invoke(ExceptionTranslatorMethodInterceptor.java:49)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:176)
        at org.alfresco.repo.audit.AuditComponentImpl.auditImpl(AuditComponentImpl.java:256)
        at org.alfresco.repo.audit.AuditComponentImpl.audit(AuditComponentImpl.java:191)
        at org.alfresco.repo.audit.AuditMethodInterceptor.invoke(AuditMethodInterceptor.java:69)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:176)
        at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:107)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:176)
        at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:210)
        at $Proxy47.getType(Unknown Source)
        at org.alfresco.web.bean.workflow.StartWorkflowWizard.init(StartWorkflowWizard.java:123)
        at com.integration.cms.extension.wizard.PublishSpaceWizard.init(PublishSpaceWizard.java:22)
        at org.alfresco.web.bean.wizard.WizardManager.setCurrentWizard(WizardManager.java:123)
        at org.alfresco.web.app.AlfrescoNavigationHandler.handleWizardOpen(AlfrescoNavigationHandler.java:636)
        at org.alfresco.web.app.AlfrescoNavigationHandler.handleNavigation(AlfrescoNavigationHandler.java:118)
        at org.apache.myfaces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:82)
        at javax.faces.component.UICommand.broadcast(UICommand.java:109)
        at javax.faces.component.UIViewRoot._broadcastForPhase(UIViewRoot.java:97)
        at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:171)
        at org.apache.myfaces.lifecycle.InvokeApplicationExecutor.execute(InvokeApplicationExecutor.java:32)
        at org.apache.myfaces.lifecycle.LifecycleImpl.executePhase(LifecycleImpl.java:95)
        at org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:70)
        at javax.faces.webapp.FacesServlet.service(FacesServlet.java:139)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
        at org.alfresco.web.app.servlet.AuthenticationFilter.doFilter(AuthenticationFilter.java:81)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
        at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:81)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
        at org.jboss.web.tomcat.security.CustomPrincipalValve.invoke(CustomPrincipalValve.java:39)
        at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:159)
        at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:59)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
        at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:856)
        at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:744)
        at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
        at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112)
        at java.lang.Thread.run(Thread.java:619)