User Tools

Site Tools


forum:alfresco:custom-action

This is an old revision of the document!


alfresco

Custom Action

References

Alfresco Custom Action

Alfresco Custom Action UI Integration

Howto for creating a custom action

Howto for creating a task history

Also it's a good idea to have installed the Alfresco SDK project in your Eclipse and have unzipped some parts of the Alfresco sources and API docs to understand the functionality.

Alfresco SDK

Goal

This article describes the steps to go for creating a simple action. The action - Quick Checkout - will replace the standard checkout action. Instead of offering all the checkout options quick checkout of a document will be a straight forward process without user interaction. QuickCheckout should:

  • checkout the document into a dedicated space inside the users home folder
  • create this space if it doesn't exist
  • after finishing the checkout open this space or the details view of the working copy

Additionall changes in the user interface:

  • the check out action button is replaced by the quick checkout button
  • the edit action button is removed from all documents which have the quick checkout action
  • in the details view the edit action is available as a button

If that's possible, the quick checkout should be available as an aspect and/or a rule and/or mandatory for special custom content models.

Implementation

The action class

The QuickCheckout class is the actual implementation of the QuickCheckout action. It extends ActionExecuterAbstractBase and overrides executeImpl().

Making the action available to the web client

To make the QuickCheckout available to the web client the following steps have to be done:

  1. Create a backing bean for the action.
  2. Make the backing bean managed.
  3. Customize the web client configuration to include the action.

For the rest of this example some Java Server Faces (JSF) knowledge is presumed.

The backing bean

This is the code of the backing bean:

package de.hmedia.alfresco.web.actions;

import java.util.Map;

import javax.faces.event.ActionEvent;

import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.service.cmr.coci.CheckOutCheckInService;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.security.PersonService;
import org.alfresco.web.bean.NavigationBean;
import org.alfresco.web.ui.common.component.UIActionLink;

/**
 * The backing bean needed to make the QuickCheckout action available in the web ui. 
 * 
 * @author Sebastian Lorenz
 * @author Andreas Hartmann
 *
 */

public class QuickCheckoutBean {    
    /**
     * the node service
     */
    private NodeService nodeService;
    /**
     * the coci service
     */
    private CheckOutCheckInService cociService;
    /**
     * the person service
     */
    private PersonService personService;
    /**
     * the navigation bean
     */
    protected NavigationBean navigator;
    /**
     * the QuickCheckout action
     */
    de.hmedia.alfresco.actions.QuickCheckout quickCheckout;
    
    /**
     * This method will be called as an action listener from within the jsf context.
     * It does the quick checkout and navigates to the checkout target folder.
     *  
     * @param e ActionEvent given by the jsf context.
     */
    public void doQuickCheckout(ActionEvent e) {
        UIActionLink link = (UIActionLink)e.getComponent();
        Map<String, String> params = link.getParameterMap();
        String ref = params.get("ref");
        NodeRef n = new NodeRef(ref);
        
        de.hmedia.alfresco.actions.QuickCheckout qco = getQuickCheckout();
        qco.setPersonService(personService);
        qco.setCociService(cociService);
        qco.setNodeService(nodeService);
        
        qco.setTargetSubFolder("In Arbeit");
        
        qco.execute(null, n);
        
        if (qco.getWorkingCopy() != null) {
            NodeRef person = personService.getPerson(AuthenticationUtil.getCurrentUserName());
            String targetSubFolder = qco.getTargetSubFolder();
            NodeRef targetSpace = qco.getTargetSpace(person, targetSubFolder);
            navigator.setCurrentNodeId(targetSpace.getId());
        }
    }

    /**
     * @return the nodeService
     */
    public NodeService getNodeService() {
        return nodeService;
    }

    /**
     * @param nodeService the nodeService to set
     */
    public void setNodeService(NodeService nodeService) {
        this.nodeService = nodeService;
    }

    /**
     * @return the cociService
     */
    public CheckOutCheckInService getCociService() {
        return cociService;
    }

    /**
     * @param cociService the cociService to set
     */
    public void setCociService(CheckOutCheckInService cociService) {
        this.cociService = cociService;
    }

    /**
     * @return the personService
     */
    public PersonService getPersonService() {
        return personService;
    }

    /**
     * @param personService the personService to set
     */
    public void setPersonService(PersonService personService) {
        this.personService = personService;
    }

    /**
     * @return the navigator
     */
    public NavigationBean getNavigator() {
        return navigator;
    }

    /**
     * @param navigator the navigator to set
     */
    public void setNavigator(NavigationBean navigator) {
        this.navigator = navigator;
    }
    
    /**
     * @return the QuickCheckout action.
     */
    public de.hmedia.alfresco.actions.QuickCheckout getQuickCheckout() {
        if (quickCheckout == null)
            quickCheckout = new de.hmedia.alfresco.actions.QuickCheckout();
        return quickCheckout;
    }

    /**
     * @param qco the QuickCheckout action to set.
     */
    public void setQuickCheckout(de.hmedia.alfresco.actions.QuickCheckout quickCheckout) {
        this.quickCheckout = quickCheckout;
    }
}

Making the backing bean managed

Include the action in the web client

To make the action available to Alfresco the web-client-config-custom.xml file has to be altered. This file resides in the /conf/alfresco/extension/ directory. The following lines have to be added:

<config>
    <actions>
        <!-- Quick Checkout document -->
	<action id="quick_checkout_doc">
	    <evaluator>
		org.alfresco.web.action.evaluator.CheckoutDocEvaluator
	    </evaluator>
            <label-id>quickcheckout</label-id>
            <image>/images/extension/QuickCheckOut_icon.gif</image>
            <action-listener>
	        #{QuickCheckout.doQuickCheckout}
            </action-listener>
	    <action>browse</action>
            <params>
                <param name="ref">#{actionContext.nodeRef}</param>
            </params>
        </action>
        <!-- Actions for a document in the Browse screen -->
        <action-group id="document_browse">
            <action idref="quick_checkout_doc" />
        </action-group>
        <!-- Actions Menu for Document Details screen -->
        <action-group id="doc_details_actions">
            <action idref="quitck_checkout_doc" />
        </action-group>
    </actions>
</config>

TODO

  • The beans shouldn't reside directly in the alfresco.war deploy dir.
  • The doQuickCheckout method of QuickCheckoutBean contains the name of the target subfolder. This should be given as a parameter.

Discussion

Enter your comment. Wiki syntax is allowed:
T Q᠎ N᠎ S C
 
forum/alfresco/custom-action.1211542093.txt.gz · Last modified: 2023/11/19 22:45 (external edit)