cancel
Showing results for 
Search instead for 
Did you mean: 

Creating new rule for document transformation

swithun
Champ in-the-making
Champ in-the-making
I want to be able to use FITS - a technical metadata extractor, on documents that I've ingested into Alfresco. I managed to get this working as a 'Transform and copy content' action. This used a custom class which wrapped a call to the FITS library. It works fine, but I had to create a dummy mimetype of text/fits, and do a transform from whatever mimetype the original was to this dummy text/fits (actually XML).

I wasn't very happy with this, and I found this topic, which describes another way to get something similar to what I want. I created a class which extends TransformActionExecuter, and then calls my transform class. The trouble is that Alfresco complains that I haven't set the mandatory mime-type parameter:

Failed to run Actions due to error: 04250001 A value for the mandatory parameter mime-type has not been set on the rule item fits-transform

My class has a method doTransform, which is given an Action object. This Action object should have a mime-type property set before it gets passed to doTransform. In org.alfresco.repo.action.executer.execute(), the Action object is checked for mandatory properties, so setting the mime-type property has to be done before that.

How would I set the mimetype property (to text/xml)? Is it in an XML document or in my Java class?
1 REPLY 1

swithun
Champ in-the-making
Champ in-the-making
To answer my question, the solution is to use Javascript.

var action_name = "fits-transform";
var act = actions.create(action_name);

act.parameters["mime-type"] = "text/xml";
act.parameters["destination-folder"] = userhome;
act.parameters["assoc-type"] = "cm:contains";
act.parameters["assoc-name"] = "cm:copy";

act.execute(document);

This gets all the mandatory parameters declared without having to create a wizard to get the values from the user, or using XML which may necessitate a server restart, or in Java which would require a recompilation. Eventually I found this page in the wiki, which had a good example making things clearer.

I think the action name should match the @id of the bean declared in action-services-context.xml:

<bean id="fits-transform" class="uk.ac.st_andrews.repo.action.executer.FITSTransformActionExecuter" parent="transform">
  <property name="fitsContentTransformer">
    <ref bean="transformer.FitsWrapper" />
  </property>
</bean>

and the NAME member of the class:

public class FITSTransformActionExecuter extends TransformActionExecuter
{
   public static final String NAME = "fits-transform";
   private ContentTransformer fitsContentTransformer;

   public void setFitsContentTransformer(ContentTransformer trans)
     {
        this.fitsContentTransformer = trans;
     }

   @Override
   protected void addParameterDefinitions(List<ParameterDefinition> paramList)
     {
        super.addParameterDefinitions(paramList);
     }

   protected void doTransform( Action ruleAction, NodeRef sourceNodeRef, ContentReader contentReader, NodeRef destinationNodeRef, ContentWriter contentWriter)
     {
        ruleAction.getParameterValue(PARAM_CONVERT_COMMAND);
        TransformationOptions options = new TransformationOptions();

        if (!this.fitsContentTransformer.isTransformable(contentReader.getMimetype(), contentWriter.getMimetype(), options))
          {
             throw new NoTransformerException(contentReader.getMimetype(), contentWriter.getMimetype());
          }
        this.fitsContentTransformer.transform(contentReader, contentWriter, options);
     }
}

The bean says which class should be used for the transformation done by this action class. In the doTransform method, this class has its transform method called. Hopefully this will help anyone else trying something similar.
Getting started

Tags


Find what you came for

We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.