use of org.alfresco.service.cmr.rendition.RenditionDefinition 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);
}
}
use of org.alfresco.service.cmr.rendition.RenditionDefinition in project alfresco-repository by Alfresco.
the class ThumbnailRegistry method initThumbnailDefinitionsTransaction.
private void initThumbnailDefinitionsTransaction() {
RetryingTransactionHelper transactionHelper = transactionService.getRetryingTransactionHelper();
transactionHelper.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<Void>() {
@Override
public Void execute() throws Throwable {
for (String thumbnailDefName : thumbnailDefinitions.keySet()) {
final ThumbnailDefinition thumbnailDefinition = thumbnailDefinitions.get(thumbnailDefName);
// Built-in thumbnailDefinitions do not provide any non-standard values
// for the ThumbnailParentAssociationDetails object. Hence the null
RenditionDefinition renditionDef = thumbnailRenditionConvertor.convert(thumbnailDefinition, null);
// Thumbnail definitions are saved into the repository as actions
renditionService.saveRenditionDefinition(renditionDef);
}
return null;
}
});
}
use of org.alfresco.service.cmr.rendition.RenditionDefinition in project alfresco-repository by Alfresco.
the class ThumbnailServiceImpl method createRenditionDefinition.
/**
* Creates a fully parameterized {@link RenditionDefinition}.
* @param contentProperty QName
* @param mimetype String
* @param transformationOptions TransformationOptions
* @param thumbnailQName QName
* @param assocDetails ThumbnailParentAssociationDetails
* @return RenditionDefinition
*/
private RenditionDefinition createRenditionDefinition(final QName contentProperty, final String mimetype, final TransformationOptions transformationOptions, final QName thumbnailQName, final ThumbnailParentAssociationDetails assocDetails) {
RenditionDefinition definition = createRawRenditionDefinition(thumbnailQName, transformationOptions);
// Convert the TransformationOptions and ThumbnailParentAssocDetails to
// rendition-style parameters
Map<String, Serializable> params = thumbnailRegistry.getThumbnailRenditionConvertor().convert(transformationOptions, assocDetails);
// Add the other parameters given in this method signature.
params.put(AbstractRenderingEngine.PARAM_SOURCE_CONTENT_PROPERTY, contentProperty);
params.put(AbstractRenderingEngine.PARAM_MIME_TYPE, mimetype);
// Set the parameters on the rendition definition.
definition.addParameterValues(params);
return definition;
}
use of org.alfresco.service.cmr.rendition.RenditionDefinition in project alfresco-repository by Alfresco.
the class RenditionedAspect method onUpdateProperties.
/**
* @see org.alfresco.repo.node.NodeServicePolicies.OnUpdatePropertiesPolicy#onUpdateProperties(org.alfresco.service.cmr.repository.NodeRef, java.util.Map, java.util.Map)
*/
public void onUpdateProperties(NodeRef nodeRef, Map<QName, Serializable> before, Map<QName, Serializable> after) {
if (this.nodeService.exists(nodeRef)) {
// Find the changed properties
List<QName> changedProperties = getChangedProperties(before, after);
// There may be a different policy for different rendition kinds.
List<ChildAssociationRef> renditions = getRenditionChildAssociations(nodeRef);
for (ChildAssociationRef chAssRef : renditions) {
final QName renditionAssocName = chAssRef.getQName();
// 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(renditionAssocName);
}
}, AuthenticationUtil.getSystemUserName());
if (rendDefn == null) {
if (logger.isDebugEnabled()) {
// We will see this debug if a new RenditionService2 definition exists.
StringBuilder msg = new StringBuilder();
msg.append("Cannot update rendition ").append(renditionAssocName).append(" on node ").append(nodeRef).append(" as the renditionDefinition could not be loaded.");
logger.debug(msg.toString());
}
continue;
}
Serializable updateRenditionsPolicy = rendDefn.getParameterValue(AbstractRenderingEngine.PARAM_UPDATE_RENDITIONS_ON_ANY_PROPERTY_CHANGE);
boolean updateRenditionsAlways = updateRenditionsPolicy == null ? false : (Boolean) updateRenditionsPolicy;
boolean renditionUpdateRequired = false;
for (QName qname : changedProperties) {
try {
PropertyDefinition propertyDef = dictionaryService.getProperty(qname);
if (propertyDef == null) {
// the property is not recognised
continue;
} else if (!propertyDef.getDataType().getName().equals(DataTypeDefinition.CONTENT)) {
// not a content type
if (updateRenditionsAlways) {
renditionUpdateRequired = true;
}
continue;
} else {
// it is a content property. We always update renditions for changes to content.
renditionUpdateRequired = true;
}
} catch (ClassCastException ccx) {
// the property does not confirm to the model
continue;
}
}
if (renditionUpdateRequired) {
this.queueUpdate(nodeRef, rendDefn, chAssRef);
}
}
}
}
use of org.alfresco.service.cmr.rendition.RenditionDefinition in project alfresco-repository by Alfresco.
the class AbstractRenderingEngine method executeRenditionImpl.
protected void executeRenditionImpl(Action action, NodeRef sourceNode) {
if (logger.isDebugEnabled()) {
StringBuilder msg = new StringBuilder();
msg.append("Executing rendering engine; name:").append(this.name).append(", class:").append(this.getClass().getName());
logger.debug(msg.toString());
}
checkParameterValues(action);
RenditionDefinition renditionDefinition = checkActionIsRenditionDefinition(action);
checkSourceNodeExists(sourceNode);
QName targetContentProp = getRenditionContentProperty(renditionDefinition);
RenderingContext context = new RenderingContext(sourceNode, renditionDefinition, targetContentProp);
render(context);
// This is a workaround for the fact that actions don't have return
// values.
action.getParameterValues().put(PARAM_RESULT, context.getChildAssociationRef());
}
Aggregations