AnsweredAssumed Answered

My custom action is null

Question asked by darkling235 on Jul 18, 2007
Hi. I'm working on making a custom action for my alfresco. It's being made purely for proof of principal at the moment. All it is supposed to do is register the node print a brief message to a log file and then exit.

The problem is it won't seem to fire.

This is my action

package org.csm.alfresco.action.executer;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.action.executer.ActionExecuterAbstractBase;
import org.alfresco.service.cmr.model.FileFolderService;

import org.alfresco.service.cmr.action.Action;
import org.alfresco.repo.action.ParameterDefinitionImpl;
import org.alfresco.service.cmr.action.ParameterDefinition;
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
import org.alfresco.service.cmr.repository.InvalidNodeRefException;
import org.alfresco.service.cmr.repository.ContentReader;
import org.alfresco.service.cmr.repository.ContentService;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.repository.ContentIOException;
import org.alfresco.service.namespace.QName;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import java.util.List;

public class AlfescoCacheImpl extends ActionExecuterAbstractBase
{

   public static final String NAME = "add-aspect";
   public static final String PARAM_ASPECT_NAME = "aspect-name";


      /**
       * the node service
       */
      private NodeService nodeService;

      /**
       * Set the node service
       *
       * @param nodeService  the node service
       */
      public void setNodeService(NodeService nodeService)
      {
         this.nodeService = nodeService;
      }

      /**
       * Get the node service
       *
       *
       */

      public NodeService getNodeService()
      {
         return nodeService;
      }

      /**
       * @see org.alfresco.repo.action.executer.ActionExecuter#execute(org.alfresco.service.cmr.repository.NodeRef, NodeRef)
       */
      public void executeImpl(Action action, NodeRef actionedUponNodeRef)
      {
        System.out.println("Executing action");
         // Check that the node still exists
              if (this.nodeService.exists(actionedUponNodeRef) == true)
              {
                 // Get the qname of the aspect to apply, we know it must have been set since it is mandatory parameter
                 QName aspectQName = (QName)action.getParameterValue(PARAM_ASPECT_NAME);

                 // Use the node service to apply the aspect to the node
                 this.nodeService.addAspect(actionedUponNodeRef, aspectQName, null);
                 System.out.println("Aspect applied");
              }
      }

      /**
       * @see org.alfresco.repo.action.ParameterizedItemAbstractBase#addParameterDefinitions(java.util.List)
       */
      @Override
      protected void addParameterDefinitions(List<ParameterDefinition> paramList)
      {
         // Add definitions for action parameters
              paramList.add(new ParameterDefinitionImpl(             // Create a new parameter defintion to add to the list
                    PARAM_ASPECT_NAME,                              // The name used to identify the parameter
                    DataTypeDefinition.QNAME,                       // The parameter value type
                    true,                                           // Indicates whether the parameter is mandatory
                    getParamDisplayLabel(PARAM_ASPECT_NAME)));      // The parameters display label

       }
}

This code was all borrowed from a tutorial except for the print statements.

I then added these lines to my action-services-context.xml

<bean id="Flush" class="org.csm.alfresco.action.executer.AlfescoCacheImpl" parent="action-executer">
          <property name="nodeService">
             <ref bean="nodeService" />
          </property>
          <property name="publicAction">
             <value>true</value>
          </property>
       </bean>
   
    <bean id="actionFlushResourceBundles" parent="actionResourceBundles">
    <property name="resourceBundles">
    <list>
    <value>alfresco.messages.CacheFlushActionMessages</value>
    </list>
    </property>
</bean>

The action-services-context.xml is located in
Tomcat\webapps\alfresco\WEB-INF\classes\alfresco
and my
CacheFlushActionMessages is located in
Tomcat\webapps\alfresco\WEB-INF\classes\alfresco\messages

The message file is pretty simple

# Custom action messages
add-aspect.title=Flush Alfresco Cache
add-aspect.description=Flush Alfresco Cache
add-aspect.aspect-name.display-label=Flush Alfresco Cache

Alfresco starts without trouble but when I try to create a new rule, the action is called Flush which is the name of the bean but not the name in the resource file (which i think is wrong) and on the create rule summary page the action is listed as null. I'm not sure what's wrong can anyone tell me what I am doing wrong? I have not altered any files but these.

Outcomes