Search in sources :

Example 1 with ThumbnailException

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() + ")");
        }
    }
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) Serializable(java.io.Serializable) AuthenticationUtil(org.alfresco.repo.security.authentication.AuthenticationUtil) ThumbnailException(org.alfresco.service.cmr.thumbnail.ThumbnailException) QName(org.alfresco.service.namespace.QName) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) RenditionDefinition(org.alfresco.service.cmr.rendition.RenditionDefinition) RenditionServiceException(org.alfresco.service.cmr.rendition.RenditionServiceException) ThumbnailException(org.alfresco.service.cmr.thumbnail.ThumbnailException)

Example 2 with ThumbnailException

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);
    }
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) QName(org.alfresco.service.namespace.QName) ThumbnailException(org.alfresco.service.cmr.thumbnail.ThumbnailException) RenditionDefinition(org.alfresco.service.cmr.rendition.RenditionDefinition) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) RenditionServiceException(org.alfresco.service.cmr.rendition.RenditionServiceException)

Aggregations

RenditionDefinition (org.alfresco.service.cmr.rendition.RenditionDefinition)2 RenditionServiceException (org.alfresco.service.cmr.rendition.RenditionServiceException)2 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)2 NodeRef (org.alfresco.service.cmr.repository.NodeRef)2 ThumbnailException (org.alfresco.service.cmr.thumbnail.ThumbnailException)2 QName (org.alfresco.service.namespace.QName)2 Serializable (java.io.Serializable)1 AuthenticationUtil (org.alfresco.repo.security.authentication.AuthenticationUtil)1