cancel
Showing results for 
Search instead for 
Did you mean: 

Creating an actionlink

ishachadha
Champ in-the-making
Champ in-the-making
Hi,

I have a requirement where when from a list of listed action icons inside 'My Pooled Tasks' on 'My Alfresco' page, one of the actions (Take Ownership) is clicked then that task should move to 'My Tasks To Do' list. Any pointers how to do this?

I have read and tried using the dialog framework, and thus creating a new dialog bean but hoping to escape the opening of a new dialog.
But no luck as of now…

Now, thinking of making an ajax call from the action and calling a webscript to handle this…

Thanks,
Isha
1 REPLY 1

ishachadha
Champ in-the-making
Champ in-the-making
OK, here is what I did to resolve this:

In your customised services-context.xml file:
1) <bean class="org.alfresco.web.app.ResourceBundleBootstrap">
      <property name="resourceBundles">
         <list>
            <value>alfresco.extension.workflow-messages</value>
         </list>
      </property>
   </bean>
2) In workflow-messages.properties
    abort_task=Abort Task
3) In web-client-config-custom.xml
a) <action id="abort_task">
            <label-id>abort_task</label-id>
            <image>/images/icons/cancel_checkout.gif</image>
            <action-listener>#{WorkflowCustomisedIconsAction.abortTask}</action-listener>
            <params>
               <param name="id">#{actionContext.id}</param>
               <param name="type">#{actionContext.type}</param>
            </params>
         </action>
b) <action-group id="dashlet_todo_actions">
                  <action idref="manage_task" />
                  <action idref="reassign_task" />
                  <action idref="abort_task" />
           </action-group>
c) <action-group id="dashlet_pooled_actions">
               <action idref="manage_task" />
               <action idref="take_ownership_task" />
           </action-group>
d) <action id="take_ownership_task">
              <permissions>
                 <permission allow="true">TakeOwnership</permission>
              </permissions>
              <label-id>take_ownership</label-id>
              <image>/images/icons/take_ownership.gif</image>
              <action>dialog:manageTask</action>
              <action-listener>#{WorkflowCustomisedIconsAction.takeOwnership}</action-listener>
              <params>
               <param name="id">#{actionContext.id}</param>
                <param name="type">#{actionContext.type}</param>
             </params>  
         </action>
4) In faces-config-custom.xml
   <managed-bean>
      <description>
         Backing bean used by the document details dialog
      </description>
      <managed-bean-name>WorkflowCustomisedIconsAction</managed-bean-name>
      <managed-bean-class>com.company.alfresco.actions.WorkflowCustomisedIconsAction</managed-bean-class>
      <managed-bean-scope>session</managed-bean-scope>
      <managed-property>
         <property-name>nodeService</property-name>
         <value>#{NodeService}</value>
      </managed-property>
      <managed-property>
         <property-name>workflowService</property-name>
         <value>#{WorkflowService}</value>
      </managed-property>
      <managed-property>
         <property-name>navigationBean</property-name>
         <value>#{NavigationBean}</value>
      </managed-property>
   </managed-bean>
5) In WorkflowCustomisedIconsAction.java
public void takeOwnership(final ActionEvent event) {

        UIActionLink link = (UIActionLink)event.getComponent();
        Map<String, String> parameters = link.getParameterMap();
        String id = parameters.get("id");

        // pass on parameters for the dialog
        Application.getDialogManager().setupParameters(event);
        UIContextService.getInstance(FacesContext.getCurrentInstance()).notifyBeans();

        final FacesContext context = FacesContext.getCurrentInstance();

        // before taking ownership check the task still exists and is not
        // completed
        final WorkflowTask checkTask = workflowService.getTaskById(id);
        if (checkTask == null || checkTask.state == WorkflowTaskState.COMPLETED) {
            Utils.addErrorMessage(Application.getMessage(context, "invalid_task"));
            return;
        }

        UserTransaction tx = null;

        try {
            tx = Repository.getUserTransaction(context);
            tx.begin();

            // prepare the edited parameters for saving
            final User user = Application.getCurrentUser(context);
            final String userName = user.getUserName();
            final Map<QName, Serializable> params = new HashMap<QName, Serializable>();
            params.put(ContentModel.PROP_OWNER, userName);

            // update the task with the updated parameters and resources
            workflowService.updateTask(id, params, null, null);

            // commit the changes
            tx.commit();
        } catch (final Throwable e) {
            // rollback the transaction
            try {
                if (tx != null) {
                    tx.rollback();
                }
            } catch (final Exception ex) {
                s_logger.info(ex);
            }

        }

    }

    public void abortTask(final ActionEvent event) {
        UIActionLink link = (UIActionLink)event.getComponent();
        Map<String, String> parameters = link.getParameterMap();
        String id = parameters.get("id");

        // pass on parameters for the dialog
        Application.getDialogManager().setupParameters(event);

        // before taking ownership check the task still exists and is not
        // completed
        final WorkflowTask checkTask = workflowService.getTaskById(id);
       
        checkTask.state = WorkflowTaskState.COMPLETED;

        String transition = "Abort Task";
        if (transition != null) {
            WorkflowTransition[] transitions = checkTask.definition.node.transitions;
            for (WorkflowTransition trans : transitions) {
                if (trans.id.equals(transition)) {
                    workflowService.endTask(id, transition);
                    break;
                }
            }
        }

    }