I am using the Java web services in Alfresco Community 4.0.d and currently looking to add thumbnail functionality to my site. I noticed the thumbnails are not available immediately after posting a new image; I was wondering if someone can recommend a good approach to have the generation triggered manually?
-
Do you really mean manually (via human intervention), or do you just mean programatically (so your code explicitly triggers it)? – Gagravarr May 08 '12 at 11:33
-
thanks, I mean manually in code :). using Java web service hopefully (if not, what would be a good way?), maybe I can trigger Alfresco to create the thumbnail as soon as the file is posted. – user1380431 May 08 '12 at 15:10
1 Answers
Answered your question in the forums as well. Using the JavaScript API you can ask a document to generate its thumbnail, like this:
document.createThumbnail("doclib");
In this case, "doclib" is the name of the thumbnail configuration for the document library thumbnails in Share, but this could be any thumbnail definition you've created.
Docs live at http://docs.alfresco.com/4.0/topic/com.alfresco.enterprise.doc/references/API-JS-Thumbnail-createThumbnail.html
For Java, look at the org.alfresco.repo.thumbnail.CreateThumbnailActionExecuter class source. In your own class you could do something similar. Or, better yet, use the actionService to invoke the create-thumbnail action.
To use the Action Service, all you need is the name of the action and the parameters it expects. For example, here's what it looks like when you use the mail action:
ActionService actionService = getServiceRegistry().getActionService();
Action mailAction = actionService.createAction(MailActionExecuter.NAME);
mailAction.setParameterValue(MailActionExecuter.PARAM_SUBJECT, ExternalReviewNotification.SUBJECT);
mailAction.setParameterValue(MailActionExecuter.PARAM_TO, recipient);
mailAction.setParameterValue(MailActionExecuter.PARAM_FROM, ExternalReviewNotification.FROM_ADDRESS);
mailAction.setParameterValue(MailActionExecuter.PARAM_TEXT, sb.toString());
actionService.executeAction(mailAction, null);
To do this for thumbnails, you'll use "create-thumbnail" for the name (or CreateThumbnailActionExecuter.NAME). Looking at the source for that class I see that it takes two parameters, PARAM_CONTENT_PROPERTY, which would be "cm:content", and PARAM_THUMBNAIL_NAME which would be "doclib" for the normal document library thumbnail or your thumbnail name if you've defined your own.
One thing to note, in the executeAction call, that second argument is the "actioned upon noderef". In your case, you'll want that to be the node you are generating the thumbnail for.

- 10,468
- 17
- 40
-
Thank you very much Jeff! could please elaborate a bit on using the actionService to invoke a thumbnail action? or perhaps link to an example? I assume I'll be calling: actionService.executeAction(Predicate, Action) but how do you construct a 'create thumbnail' Action object? many thanks! :) – user1380431 May 08 '12 at 17:16