use of org.alfresco.service.cmr.thumbnail.ThumbnailException in project alfresco-repository by Alfresco.
the class ThumbnailServiceImpl method updateThumbnail.
/**
* @see org.alfresco.service.cmr.thumbnail.ThumbnailService#updateThumbnail(org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.cmr.repository.TransformationOptions)
*/
public void updateThumbnail(final NodeRef thumbnail, final TransformationOptions transformationOptions) {
if (logger.isDebugEnabled() == true) {
logger.debug("Updating thumbnail (thumbnail=" + thumbnail.toString() + ")");
}
// First check that we are dealing with a rendition object
if (renditionService.isRendition(thumbnail)) {
// Get the node that is the source of the thumbnail
ChildAssociationRef parentAssoc = renditionService.getSourceNode(thumbnail);
if (parentAssoc == null) {
if (logger.isDebugEnabled() == true) {
logger.debug("Updating thumbnail: The thumbnails parent cannot be found (thumbnail=" + thumbnail.toString() + ")");
}
throw new ThumbnailException(ERR_NO_PARENT);
}
final QName renditionAssociationName = parentAssoc.getQName();
NodeRef sourceNode = parentAssoc.getParentRef();
// Get the content property
QName contentProperty = (QName) nodeService.getProperty(thumbnail, ContentModel.PROP_CONTENT_PROPERTY_NAME);
// Set the basic detail of the transformation options
transformationOptions.setSourceNodeRef(sourceNode);
transformationOptions.setSourceContentProperty(contentProperty);
transformationOptions.setTargetContentProperty(ContentModel.PROP_CONTENT);
// Do the thumbnail transformation. Rendition Definitions are persisted underneath the Data Dictionary for which Group ALL
// has Consumer access by default. However, we cannot assume that that access level applies for all deployments. See ALF-7334.
RenditionDefinition rendDefn = AuthenticationUtil.runAs(new AuthenticationUtil.RunAsWork<RenditionDefinition>() {
@Override
public RenditionDefinition doWork() throws Exception {
return renditionService.loadRenditionDefinition(renditionAssociationName);
}
}, AuthenticationUtil.getSystemUserName());
if (rendDefn == null) {
String renderingEngineName = getRenderingEngineNameFor(transformationOptions);
rendDefn = renditionService.createRenditionDefinition(parentAssoc.getQName(), renderingEngineName);
}
Map<String, Serializable> params = thumbnailRegistry.getThumbnailRenditionConvertor().convert(transformationOptions, null);
for (String key : params.keySet()) {
rendDefn.setParameterValue(key, params.get(key));
}
renditionService.render(sourceNode, rendDefn);
} else {
if (logger.isDebugEnabled() == true) {
logger.debug("Updating thumbnail: cannot update a thumbnail node that isn't the correct thumbnail type (thumbnail=" + thumbnail.toString() + ")");
}
}
}
use of org.alfresco.service.cmr.thumbnail.ThumbnailException in project alfresco-repository by Alfresco.
the class ThumbnailServiceImpl method createThumbnailNode.
private NodeRef createThumbnailNode(final NodeRef node, final QName contentProperty, final String mimetype, final TransformationOptions transformationOptions, final String thumbnailName, final ThumbnailParentAssociationDetails assocDetails) {
// Get the name of the thumbnail and add to properties map
QName thumbnailQName = getThumbnailQName(thumbnailName);
RenditionDefinition definition = createRenditionDefinition(contentProperty, mimetype, transformationOptions, thumbnailQName, assocDetails);
try {
ChildAssociationRef thumbnailAssoc = renditionService.render(node, definition);
NodeRef thumbnail = getThumbnailNode(thumbnailAssoc);
setThumbnailNameProperty(thumbnail, thumbnailName);
return thumbnail;
} catch (RenditionServiceException rsx) {
throw new ThumbnailException(rsx.getMessage(), rsx);
}
}
Aggregations