use of org.alfresco.service.cmr.rendition.RenditionDefinition in project alfresco-repository by Alfresco.
the class ThumbnailServiceImpl method createRawRenditionDefinition.
/**
* Creates a {@link RenditionDefinition} with no parameters set.
* @param thumbnailQName QName
* @param transformationOptions TransformationOptions
* @return RenditionDefinition
*/
private RenditionDefinition createRawRenditionDefinition(QName thumbnailQName, final TransformationOptions transformationOptions) {
// Create the renditionDefinition
String renderingEngineName = getRenderingEngineNameFor(transformationOptions);
RenditionDefinition definition = renditionService.createRenditionDefinition(thumbnailQName, renderingEngineName);
// Track thumbnail rendition actions so cancellation can be requested
definition.setTrackStatus(true);
return definition;
}
use of org.alfresco.service.cmr.rendition.RenditionDefinition 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.rendition.RenditionDefinition in project alfresco-repository by Alfresco.
the class ThumbnailRenditionConvertor method convert.
/**
* Given the specified {@link ThumbnailDefinition thumbnailDefinition} and
* {@link ThumbnailParentAssociationDetails assocDetails},
* create and return an equivalent {@link RenditionDefinition} object.
*
* @param thumbnailDefinition ThumbnailDefinition
* @param assocDetails ThumbnailParentAssociationDetails
* @return RenditionDefinitions
*/
public RenditionDefinition convert(ThumbnailDefinition thumbnailDefinition, ThumbnailParentAssociationDetails assocDetails) {
// We must always have a valid name for a thumbnail definition
if (thumbnailDefinition == null || thumbnailDefinition.getName() == null || thumbnailDefinition.getName().trim().length() == 0) {
throw new IllegalArgumentException("Thumbnail Definition and Name must be non-null and non-empty.");
}
TransformationOptions transformationOptions = thumbnailDefinition.getTransformationOptions();
Map<String, Serializable> parameters = this.convert(transformationOptions, assocDetails);
// Extract parameters defined directly within the ThumbnailDefinition object.
putParameterIfNotNull(AbstractRenderingEngine.PARAM_MIME_TYPE, thumbnailDefinition.getMimetype(), parameters);
putParameterIfNotNull(AbstractRenderingEngine.PARAM_PLACEHOLDER_RESOURCE_PATH, thumbnailDefinition.getPlaceHolderResourcePath(), parameters);
putParameterIfNotNull(AbstractRenderingEngine.PARAM_RUN_AS, thumbnailDefinition.getRunAs(), parameters);
QName namespacedRenditionName = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, thumbnailDefinition.getName());
// The built-in RenditionDefinitions are all non-composites.
// They are either "imageRenderingEngine" or "reformat"
boolean isImageThumbnail = isImageBasedRendition(thumbnailDefinition);
String renderingEngineName = isImageThumbnail ? ImageRenderingEngine.NAME : ReformatRenderingEngine.NAME;
RenditionDefinition renditionDef = renditionService.createRenditionDefinition(namespacedRenditionName, renderingEngineName);
for (String paramName : parameters.keySet()) {
renditionDef.setParameterValue(paramName, parameters.get(paramName));
}
return renditionDef;
}
use of org.alfresco.service.cmr.rendition.RenditionDefinition in project alfresco-repository by Alfresco.
the class RenditionServiceImpl method render.
/*
* (non-Javadoc)
* @see org.alfresco.service.cmr.rendition.RenditionService#render(org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.namespace.QName)
*/
public ChildAssociationRef render(NodeRef sourceNode, final QName renditionDefinitionQName) {
checkSourceNodeForPreventionClass(sourceNode);
RenditionDefinition rendDefn = AuthenticationUtil.runAs(new AuthenticationUtil.RunAsWork<RenditionDefinition>() {
public RenditionDefinition doWork() throws Exception {
return loadRenditionDefinition(renditionDefinitionQName);
}
}, AuthenticationUtil.getSystemUserName());
if (rendDefn == null) {
throw new RenditionServiceException("Rendition Definition " + renditionDefinitionQName + " was not found.");
}
return this.render(sourceNode, rendDefn);
}
use of org.alfresco.service.cmr.rendition.RenditionDefinition in project alfresco-repository by Alfresco.
the class RenditionServiceImpl method render.
/*
* (non-Javadoc)
* @see org.alfresco.service.cmr.rendition.RenditionService#render(org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.namespace.QName, org.alfresco.service.cmr.rendition.RenderCallback)
*/
public void render(NodeRef sourceNode, final QName renditionDefinitionQName, RenderCallback callback) {
checkSourceNodeForPreventionClass(sourceNode);
RenditionDefinition rendDefn = AuthenticationUtil.runAs(new AuthenticationUtil.RunAsWork<RenditionDefinition>() {
public RenditionDefinition doWork() throws Exception {
return loadRenditionDefinition(renditionDefinitionQName);
}
}, AuthenticationUtil.getSystemUserName());
if (rendDefn == null) {
throw new RenditionServiceException("Rendition Definition " + renditionDefinitionQName + " was not found.");
}
this.render(sourceNode, rendDefn, callback);
}
Aggregations