use of org.alfresco.repo.thumbnail.script.ScriptThumbnail in project alfresco-repository by Alfresco.
the class ScriptNode method createThumbnail.
/**
* Creates a thumbnail for the content property of the node.
*
* The thumbnail name corresponds to pre-set thumbnail details stored in the
* repository.
*
* If the thumbnail is created asynchronously then the result will be null and creation
* of the thumbnail will occure at some point in the background.
*
* If foce param specified system.thumbnail.generate is ignoring. Could be used for preview creation
*
* @param thumbnailName the name of the thumbnail
* @param async indicates whether the thumbnail is create asynchronously or not
* @param force ignore system.thumbnail.generate=false
* @return ScriptThumbnail the newly create thumbnail node or null if async creation occures
*
* @deprecated The async flag in the method signature will not be applicable as all of
* the future transformations will be asynchronous
*/
@Deprecated
public ScriptThumbnail createThumbnail(String thumbnailName, boolean async, boolean force) {
final ThumbnailService thumbnailService = services.getThumbnailService();
ScriptThumbnail result = null;
// We need to create preview for node even if system.thumbnail.generate=false
if (force || thumbnailService.getThumbnailsEnabled()) {
// Use the thumbnail registy to get the details of the thumbail
ThumbnailRegistry registry = thumbnailService.getThumbnailRegistry();
ThumbnailDefinition details = registry.getThumbnailDefinition(thumbnailName);
if (details == null) {
// Throw exception
throw new ScriptException("The thumbnail name '" + thumbnailName + "' is not registered");
}
// If there's nothing currently registered to generate thumbnails for the
// specified mimetype, then log a message and bail out
String nodeMimeType = getMimetype();
Serializable value = this.nodeService.getProperty(nodeRef, ContentModel.PROP_CONTENT);
ContentData contentData = DefaultTypeConverter.INSTANCE.convert(ContentData.class, value);
if (!ContentData.hasContent(contentData)) {
if (logger.isDebugEnabled())
logger.debug("Unable to create thumbnail '" + details.getName() + "' as there is no content");
return null;
}
if (!registry.isThumbnailDefinitionAvailable(contentData.getContentUrl(), nodeMimeType, getSize(), nodeRef, details)) {
logger.info("Unable to create thumbnail '" + details.getName() + "' for " + nodeMimeType + " as no transformer is currently available.");
return null;
}
// Have the thumbnail created
if (async == false) {
try {
// Create the thumbnail
NodeRef thumbnailNodeRef = thumbnailService.createThumbnail(this.nodeRef, ContentModel.PROP_CONTENT, details.getMimetype(), details.getTransformationOptions(), details.getName());
// Create the thumbnail script object
result = new ScriptThumbnail(thumbnailNodeRef, this.services, this.scope);
} catch (AlfrescoRuntimeException e) {
Throwable rootCause = e.getRootCause();
if (rootCause instanceof UnimportantTransformException) {
logger.debug("Unable to create thumbnail '" + details.getName() + "' as " + rootCause.getMessage());
return null;
}
throw e;
}
} else {
RenditionDefinition2 renditionDefinition = renditionDefinitionRegistry2.getRenditionDefinition(thumbnailName);
if (renditionDefinition != null) {
renditionService2.render(nodeRef, thumbnailName);
} else {
Action action = ThumbnailHelper.createCreateThumbnailAction(details, services);
// Queue async creation of thumbnail
this.services.getActionService().executeAction(action, this.nodeRef, true, true);
}
}
}
return result;
}
use of org.alfresco.repo.thumbnail.script.ScriptThumbnail in project alfresco-repository by Alfresco.
the class ScriptNode method getThumbnail.
/**
* Get the given thumbnail for the content property
*
* @param thumbnailName the thumbnail name
* @return ScriptThumbnail the thumbnail
*/
public ScriptThumbnail getThumbnail(String thumbnailName) {
ScriptThumbnail result = null;
NodeRef thumbnailNodeRef = this.services.getThumbnailService().getThumbnailByName(this.nodeRef, ContentModel.PROP_CONTENT, thumbnailName);
if (thumbnailNodeRef != null) {
result = new ScriptThumbnail(thumbnailNodeRef, this.services, this.scope);
}
return result;
}
use of org.alfresco.repo.thumbnail.script.ScriptThumbnail in project alfresco-repository by Alfresco.
the class ScriptNode method getThumbnails.
/**
* Get the all the thumbnails for a given node's content property.
*
* @return Scriptable list of thumbnails, empty if none available
*/
public ScriptThumbnail[] getThumbnails() {
List<NodeRef> thumbnails = this.services.getThumbnailService().getThumbnails(this.nodeRef, ContentModel.PROP_CONTENT, null, null);
List<ScriptThumbnail> result = new ArrayList<ScriptThumbnail>(thumbnails.size());
for (NodeRef thumbnail : thumbnails) {
ScriptThumbnail scriptThumbnail = new ScriptThumbnail(thumbnail, this.services, this.scope);
result.add(scriptThumbnail);
}
return (ScriptThumbnail[]) result.toArray(new ScriptThumbnail[result.size()]);
}
Aggregations