cancel
Showing results for 
Search instead for 
Did you mean: 

Current method for adding a rendition definition for the thumbnail service?

oofdachile
Champ in-the-making
Champ in-the-making
Hi, folks –

  I would like to add an ImageMagick thumbnail rendition definition for use by the 4.2e Community thumbnail service.  Jeff wrote a <a href="http://ecmarchitect.com/archives/2009/03/03/913" target="_blank">thorough article</a> on the subject (thanks, Jeff!).  He observed that adding a new thumbnail rendition definition in a slick fashion takes some work.

The out-of-the-box thumbnails are registered in the thumbnail-service-context.xml file. I don’t see a clean way to extend that without repeating the definitions, so in my example, I wrote a bean that calls the Thumbnail Registry and registers the custom thumbnail definitions provided in the Spring context file

… and later in the comments to his post, Umut Utkan observed that one could call the Thumbnail Registry's methods without writing Java code.

Instead of creating a custom bean to register your custom thumbnail definitions, you could have just used MethodInvokingFactory bean to register them directly to the default thumbnailRegistry bean.

… and he provides a substantial bean-within-a-bean approach.  Being the lazy sort, I tried Umut's technique by placing his code in a *-context.xml file in my alfresco/extensions folder & restarting, but calling a script containing …


document.createThumbnail("scImageThumbnail", true);


… from a space-rule didn't produce this rendition, even overnight, though the standard renditions were created successfully this way.  This probably means that I did something wrong.

Jeff's article was written a while ago (2009).  How would you add a new rendition definition to the 4.2e thumbnail service today?  Have you gotten the MethodInvokingFactory to work for adding renditions or for other Alfresco-related purposes?

Thanks for your time.

Don
6 REPLIES 6

arnoldschrijve1
Champ on-the-rise
Champ on-the-rise
Hi,

I don't know about the script part, but the trick with the MethodInvokingFactory bean worked quite well….registered a new thumbnail this way, then afterwards triggering the rendition in Java code, something more or less like this:

<java>
        QName thumbnailRenditionName = QName.createQName(
                NamespaceService.CONTENT_MODEL_1_0_URI, "assetThumbnail");
       
        // Trigger the renditionService to create Thumbnail image.
        RenditionDefinition assetThumbnailRendition =
                serviceRegistry.getRenditionService().loadRenditionDefinition(
                        thumbnailRenditionName);

            serviceRegistry.getRenditionService().render(
                    getNodeRef(), assetThumbnailRendition , new RenderCallback()
            {
                public void handleFailedRendition(Throwable t)
                {
                    // In the event of a failed (re-)rendition, delete the rendition node
                    if (logger.isDebugEnabled())
                    {
                        logger.debug("Stuff went wrong", t);
                    }
                }

                public void handleSuccessfulRendition(
                        ChildAssociationRef primaryParentOfNewRendition)
                {
                    // Stuff went right
                }
            });
</java>

Thanks for taking the time to reply, Arnold.

I'm glad this technique worked for you, though I still wonder what I'm doing wrong.  This is my context file that tries to use this MethodInvokingFactory technique to define Jeff's thumbnail rendition in 4.2.e:


<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE beans PUBLIC '-//SPRING//DTD BEAN//EN' 'http://www.springframework.org/dtd/spring-beans.dtd'>

<beans>

   <bean class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
      <property name="targetObject" ref="thumbnailRegistry"/>
      <property name="targetMethod" value="addThumbnailDefinition"/>
      <property name="arguments">
         <list>
            <bean class="org.alfresco.repo.thumbnail.ThumbnailDefinition">
               <property name="name" value="scImageThumbnail"/>
               <property name="mimetype" value="image/png"/>
               <property name="transformationOptions">
                  <bean class="org.alfresco.repo.content.transform.magick.ImageTransformationOptions">
                     <property name="resizeOptions">
                        <bean class="org.alfresco.repo.content.transform.magick.ImageResizeOptions">
                           <property name="height" value="100"/>
                           <property name="maintainAspectRatio" value="true"/>
                           <property name="resizeToThumbnail" value="true"/>
                        </bean>
                     </property>
                  </bean>
               </property>
               <property name="placeHolderResourcePath" value="alfresco/thumbnail/thumbnail_placeholder_medium.jpg"/>
            </bean>
         </list>
      </property>
   </bean>

</beans>


Do you, or does anyone else who has a minute to look) see anything wrong with my context file, or using a context file for this purpose?  Would you share your context file & let us know which Alfresco Community version you're running, please?

I dug into the system's context file that defines the OOTB renditions, and found an enticing comment in front of all of the renditions there.  Here's the one for the 64x64 Avatar rendition:


<!– User avatar 64x64 image thumbnail options –>
<!– Note that this will auto-register with parent="baseThumbnailDefinition" in the future –>


Has anyone heard about this technique?  Does anyone know when it will be implemented (or, I guess, whether it has already been implemented, as I haven't tried it yet)?

Thanks!

Don

Hi,

Looking at your context, it looks pretty good. Except in my definition I have an additional RunAs property and some failure options.
I am using Enterprise Edition at version 4.1.1.3, not Community Edition, but I don't think there are differences in thumbnailing codes between EE and CE.

Here's my bean declaration:


    <bean id="assetPreview" class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
        <property name="targetObject" ref="thumbnailRegistry" />
        <property name="targetMethod" value="addThumbnailDefinition" />
        <property name="arguments">
            <list>
                 <!– Asset Preview - thumbnail options –>
                 <bean class="org.alfresco.repo.thumbnail.ThumbnailDefinition">
                    <property name="name" value="assetPreview" />
                    <property name="mimetype" value="image/png"/>
                    <property name="transformationOptions">
                       <bean class="org.alfresco.repo.content.transform.magick.ImageTransformationOptions">
                          <property name="resizeOptions">
                             <bean class="org.alfresco.repo.content.transform.magick.ImageResizeOptions">
                                <property name="width" value="600"/>
                                <property name="height" value="600"/>
                                <property name="maintainAspectRatio" value="true"/>
                                <property name="resizeToThumbnail" value="true" />
                                <property name="allowEnlargement" value="false" />
                             </bean>
                          </property>
                       </bean>
                    </property>
                    <property name="placeHolderResourcePath" value="alfresco/thumbnail/thumbnail_placeholder_imgpreview.png" />
                    <property name="runAs" value="System"/>
                    <property name="failureHandlingOptions" ref="standardFailureOptions"/>
                </bean>
            </list>
        </property>
    </bean>

oofdachile
Champ in-the-making
Champ in-the-making
Arnold, THANKS for sending your configuration.  Along the way, I tried outright redefining the Thumbnail registry in an alfresco extension context, but couldn't make it work until I added a "width" property.  I hoped that by providing both a "height" and a "preserve aspect ratio" property, the rendition would hold to a fixed height but variable width.  But server startup errors complained about missing an "X" parameter.  After a bit of digging, I confirmed that the X parameter in question is set by the "width" property.  Sigh.

So I added the properties that your configuration had which mine did not, including a width, and now my MethodInvokingFactory configuration works just fine.  Hooray!

Thanks again for your help!

Don

Cool, glad that it worked!!

midouvich
Champ in-the-making
Champ in-the-making
je ne trouve pas les trois fichier :
mt-context.xml.sample
mt-admin-context.xml.sample
mt-contentstore-context.xml.sample

bien que je ne trouve pas le répertoire /opt/alfresco/tomcat/shared/classes/alfresco/extension/mt.

que je dois faire pour continuer l'activation de alfresco multi tenant ?

Merci d'avance