AnsweredAssumed Answered

Null nodeRef when running action

Question asked by ardamose123 on Jul 18, 2013
Latest reply on Feb 4, 2015 by mluraschi
I've been developing some custom action proof of concepts. I've got to the point where I can implement an action, configure its bean, update the share-config-custom.xml file and make the action appear and show a form to collect input in Alfresco Share.

The action just returns (some day) the Levenshtein distance between two documents, with no validations about them being plain text files. However, when I run this action, I come across a problem: in my implementation of
executeImpl(Action, NodeRef)
method, the NodeRef is null, when it's supposed to be an actual NodeRef to the node being acted upon.

Can someone tell me if this is a mistake on my side or Alfresco's? I'm deploying the extension as a JAR. File contents follow.

<em>FormActionExecuter.java</em> (without Levenshtein distance code)

public class FormActionExecuter extends ActionExecuterAbstractBase {
   private ContentService contentService;
   private NodeService nodeService;
  
   public static final String PARAM_OTHER_DOC = "other-doc";
  
   public void setContentService(ContentService contentService) {
      this.contentService = contentService;
   }
  
   public void setNodeService(NodeService nodeService) {
      this.nodeService = nodeService;
   }

   @Override
   protected void addParameterDefinitions(List<ParameterDefinition> paramList) {
      paramList.add(new ParameterDefinitionImpl(PARAM_OTHER_DOC, DataTypeDefinition.NODE_REF, true, getParamDisplayLabel(PARAM_OTHER_DOC)));
   }

   @Override
   protected void executeImpl(Action action, NodeRef actionedUponNodeRef) {
      if (!nodeService.exists(actionedUponNodeRef)) // <– IllegalArgumentException HERE
         return;
     
      NodeRef other = (NodeRef) action.getParameterValue(PARAM_OTHER_DOC);
     
      String content1 = contentService.getReader(actionedUponNodeRef, ContentModel.PROP_CONTENT).getContentString();
      String content2 = contentService.getReader(other, ContentModel.PROP_CONTENT).getContentString();
     
      action.setParameterValue(PARAM_RESULT, Integer.valueOf(computeLevenshteinDistance(content1, content2)));
   }
}


<em>example-action-context.xml</em>

<beans>
   <bean id="org-form-bean" class="org.example.FormActionExecuter" parent="action-executer">
      <property name="contentService">
         <ref bean="ContentService" />
      </property>
      <property name="nodeService">
         <ref bean="NodeService" />
      </property>
   </bean>
</beans>


<em>share-config-custom.xml</em>

<alfresco-config>
   <config evaluator="string-compare" condition="org-form-bean">
      <forms>
         <form>
            <field-visibility>
               <show id="other-doc" />
            </field-visibility>
            <appearance>
               <field id="other-doc" label="Document to be compared"/>
            </appearance>
         </form>
      </forms>
   </config>
  
   <config evaluator="string-compare" condition="DocLibActions">
      <actions>
         <action id="org-form" type="javascript" label="Test form">
            <param name="function">onActionFormDialog</param>
            <param name="itemKind">action</param>
            <param name="itemId">org-form-bean</param>
            <param name="mode">edit</param>
            <param name="successMessage">Works!</param>
            <param name="failureMessage">Fail…</param>
         </action>
      </actions>
     
      <actionGroups>
         <actionGroup id="folder-browse">
            <action index="102" id="org-form" />
         </actionGroup>
         <actionGroup id="document-browse">
            <action index="102" id="org-form" />
         </actionGroup>        
      </actionGroups>
   </config>
</alfresco-config>

Outcomes