Changes to Transformers configuration in Alfresco 4.2

cancel
Showing results for 
Search instead for 
Did you mean: 

Changes to Transformers configuration in Alfresco 4.2

wabson
Active Member II
0 2 2,933
If like me you have configured some custom transformers against the Alfresco repository in order to convert from one file type to another, you'll need to be aware of some changes that have been made in the 4.2 codeline currently available in the HEAD branch in SVN and in the latest nightly builds.



The major change is that the mimetype mappings which were previously defined via the Spring bean definitions have now moved to repository properties. This has the benefit that the Spring configuration is much simpler and sys admins can more easily change which transformers are used for specific transforms, as well as the priority assigned to them.



Today I added some default properties to the media-viewers add-on on Share Extras, which you may find useful as a guide to converting over any custom transformer configuration.



Previously in the project, the transformer mimetype mappings were defined on the transformers' Spring beans via the explicitTransformations property. Here is an extract.

<bean id='transformer.ffmpeg.flv'>

    ...

    <property name='explicitTransformations'>

        <list>

            <bean class='org.alfresco.repo.content.transform.ExplictTransformationDetails'>

                <property name='sourceMimetype'><value>video/mpeg</value></property>

                <property name='targetMimetype'><value>video/x-flv</value></property>

            </bean>

            ...

        </list>

    </property>

    ...

</bean>


This configuration configures this a transformer with the bean ID transformer.ffmpeg.flv, which is capable of converting an MPEG-2 file to Flash Video format (note that the transformation itself is performed by a separate worker bean since Alfresco 4.0, and that whilst not generally recommended, the explicitTransformation list can also be applied to that bean).



In 4.2.d onwards the explicitTransformation property is no longer used, so we must define the following repository properties in addition to the Spring configuration.

# Define a default priority for this transformer

content.transformer.ffmpeg.flv.priority=50

# List the transformations that are supported

content.transformer.ffmpeg.flv.extensions.mpg.flv.supported=true

content.transformer.ffmpeg.flv.extensions.mpg.flv.priority=50

...


It is important to get the format of the properties right, with a prefix of content. followed by the Spring bean ID of the transformer (transformer.ffmpeg.flv in this case), followed by the suffixes above. First we define a numerical priority for this transformer, then each supported transformation must be listed separately, one on each line, with the source and target mimetypes identified by their default file extensions, which can be obtained from the mimetypes web script, e.g. http://localhost:8080/alfresco/service/mimetypes.



As per Alan's advice on this related JIRA ticket, you can simply add the properties to your installation's alfresco-global.properties, and they will take effect immediately after a restart, but if your transformer config is packaged up in an add-on then you probably want to ship these properties with it, otherwise the transformer will be automatically configured to transform any mimetype into all others defined in the system (see this issue if you want to understand the consequences of this).



For the media-viewers project I utilised the ability of Alfresco Subsystems to pull in extended configuration properties placed on the classpath under alfresco/extension/subsystems. In this case I used the Transformers subsystem but perhaps thirdParty is also applicable for this, or you could even define your own custom subsystem!



I added the properties in a new file config/alfresco/extension/subsystems/Transformers/default/default/org_sharextras_media-viewers.properties in my project with the above contents (source). The config prefix is part of the standard project source layout and is removed from the classpath of the assets at build time, and the slightly obtuse file name ensures that different add-ons will not clash with each other if they both add additional properties (the file name can be anything, so long as it ends with the .properties extension.



Normally you would remove the explicitTransformations properties from the Spring configuration with these applied, in order to supress the warnings that are now output in the logs, but I made the decision to leave it in, in order to preserve backwards-compatibility with 4.0 and 4.1.



Thanks to the contributors davidyg and touchvignesh who reported these issues with the media-viewers add-on! The updated code is in the master branch on Github or you can grab a JAR file containing the latest code to try it out yourself.
2 Comments