Search in sources :

Example 1 with RenditionServiceException

use of org.alfresco.service.cmr.rendition.RenditionServiceException in project alfresco-repository by Alfresco.

the class StandardRenditionLocationResolverImpl method findOrCreateTemplatedPath.

private RenditionLocationImpl findOrCreateTemplatedPath(NodeRef sourceNode, String path, NodeRef companyHome) {
    if (log.isDebugEnabled()) {
        StringBuilder msg = new StringBuilder();
        msg.append("FindOrCreateTemplatedPath for ").append(sourceNode).append(", ").append(path);
        log.debug(msg.toString());
    }
    NodeService nodeService = serviceRegistry.getNodeService();
    List<String> pathElements = Arrays.asList(path.split("/"));
    LinkedList<String> folderElements = new LinkedList<String>(pathElements);
    // We need to strip out any empty strings within the path elements.
    // prior to passing this path to the fileFolderService for creation.
    // e.g. "//foo//bar///item.txt" would cause an exception.
    folderElements.removeAll(Arrays.asList(new String[] { "" }));
    // Remove 'Company Home' if it is at the start of the path.
    Serializable companyHomeName = nodeService.getProperty(companyHome, ContentModel.PROP_NAME);
    if (folderElements.getFirst().equals(companyHomeName)) {
        folderElements.removeFirst();
    }
    String fileName = folderElements.removeLast();
    if (fileName == null || fileName.length() == 0) {
        StringBuilder msg = new StringBuilder();
        msg.append("The path must include a valid filename! Path: ").append(path);
        if (log.isDebugEnabled()) {
            log.debug(msg.toString());
        }
        throw new RenditionServiceException(msg.toString());
    }
    FileFolderService fileFolderService = serviceRegistry.getFileFolderService();
    NodeRef parent = companyHome;
    if (!folderElements.isEmpty()) {
        FileInfo parentInfo = FileFolderUtil.makeFolders(fileFolderService, companyHome, folderElements, ContentModel.TYPE_FOLDER);
        parent = parentInfo.getNodeRef();
    }
    if (log.isDebugEnabled()) {
        log.debug("folderElements: " + folderElements);
        log.debug("parent: " + parent);
        log.debug("   " + nodeService.getType(parent) + " " + nodeService.getPath(parent));
        log.debug("fileName: " + fileName);
    }
    NodeRef child = fileFolderService.searchSimple(parent, fileName);
    if (log.isDebugEnabled()) {
        StringBuilder msg = new StringBuilder();
        msg.append("RenditionLocation parent=").append(parent).append(", child=").append(child).append(", fileName=").append(fileName);
        log.debug(msg.toString());
        if (child != null) {
            log.debug("child path = " + nodeService.getPath(child));
        }
    }
    return new RenditionLocationImpl(parent, child, fileName);
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) Serializable(java.io.Serializable) FileInfo(org.alfresco.service.cmr.model.FileInfo) NodeService(org.alfresco.service.cmr.repository.NodeService) FileFolderService(org.alfresco.service.cmr.model.FileFolderService) RenditionServiceException(org.alfresco.service.cmr.rendition.RenditionServiceException) LinkedList(java.util.LinkedList)

Example 2 with RenditionServiceException

use of org.alfresco.service.cmr.rendition.RenditionServiceException in project alfresco-repository by Alfresco.

the class StandardRenditionLocationResolverImpl method createNodeLocation.

/**
 * This method creates a {@link RenditionLocation} object from the specified destination node.
 * This is formed from the specified destination NodeRef, its cm:name and its primary parent.
 *
 * @param destination NodeRef
 * @return RenditionLocationImpl
 * @throws RenditionServiceException if the destination node does not exist.
 */
private RenditionLocationImpl createNodeLocation(NodeRef destination) {
    NodeService nodeService = serviceRegistry.getNodeService();
    if (nodeService.exists(destination) == false)
        throw new RenditionServiceException("The rendition destination node does not exist! NodeRef: " + destination);
    NodeRef parentRef = nodeService.getPrimaryParent(destination).getParentRef();
    String destinationCmName = (String) nodeService.getProperty(destination, ContentModel.PROP_NAME);
    RenditionLocationImpl location = new RenditionLocationImpl(parentRef, destination, destinationCmName);
    return location;
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) NodeService(org.alfresco.service.cmr.repository.NodeService) RenditionServiceException(org.alfresco.service.cmr.rendition.RenditionServiceException)

Example 3 with RenditionServiceException

use of org.alfresco.service.cmr.rendition.RenditionServiceException in project alfresco-repository by Alfresco.

the class AbstractTransformationRenderingEngine method render.

/*
     * (non-Javadoc)
     * @see org.alfresco.repo.rendition.executer.AbstractRenderingEngine#render(org.alfresco.repo.rendition.executer.AbstractRenderingEngine.RenderingContext)
     */
@Override
protected void render(RenderingContext context) {
    ContentReader contentReader = context.makeContentReader();
    // There will have been an exception if there is no content data so contentReader is not null.
    String contentUrl = contentReader.getContentUrl();
    String sourceMimeType = contentReader.getMimetype();
    String targetMimeType = getTargetMimeType(context);
    // The child NodeRef gets created here
    TransformationOptions transformationOptions = getTransformOptions(context);
    long sourceSizeInBytes = contentReader.getSize();
    Map<String, String> options = converter.getOptions(transformationOptions, sourceMimeType, targetMimeType);
    NodeRef sourceNodeRef = transformationOptions.getSourceNodeRef();
    if (!synchronousTransformClient.isSupported(sourceMimeType, sourceSizeInBytes, contentUrl, targetMimeType, options, null, sourceNodeRef)) {
        String optionsString = TransformerDebug.toString(options);
        throw new RenditionServiceException(String.format(NOT_TRANSFORMABLE_MESSAGE_PATTERN, sourceMimeType, targetMimeType, optionsString));
    }
    long startTime = new Date().getTime();
    boolean actionCancelled = false;
    boolean actionCompleted = false;
    // Cache the execution summary to get details later
    ExecutionSummary executionSummary = null;
    try {
        executionSummary = getExecutionSummary(context);
    } catch (ActionServiceException e) {
        if (logger.isInfoEnabled()) {
            logger.info("Cancelling of multiple concurrent action instances " + "currently unsupported, this action can't be cancelled");
        }
    }
    // Call the transform in a different thread so we can move on if cancelled
    FutureTask<ContentWriter> transformTask = new FutureTask<ContentWriter>(new TransformationCallable(contentReader, targetMimeType, transformationOptions, context, AuthenticationUtil.getFullyAuthenticatedUser()));
    getExecutorService().execute(transformTask);
    // Start checking for cancellation or timeout
    while (true) {
        try {
            Thread.sleep(CANCELLED_ACTION_POLLING_INTERVAL);
            if (transformTask.isDone()) {
                actionCompleted = true;
                break;
            }
            // Check timeout in case transformer doesn't obey it
            if (transformationOptions.getTimeoutMs() > 0 && new Date().getTime() - startTime > (transformationOptions.getTimeoutMs() + CANCELLED_ACTION_POLLING_INTERVAL)) {
                // We hit a timeout, let the transform thread continue but results will be ignored
                if (logger.isDebugEnabled()) {
                    logger.debug("Transformation did not obey timeout limit, " + "rendition action is moving on");
                }
                break;
            }
            if (executionSummary != null) {
                ExecutionDetails executionDetails = actionTrackingService.getExecutionDetails(executionSummary);
                if (executionDetails != null) {
                    actionCancelled = executionDetails.isCancelRequested();
                    if (actionCancelled) {
                        if (logger.isDebugEnabled()) {
                            logger.debug("Cancelling transformation");
                        }
                        transformTask.cancel(true);
                        break;
                    }
                }
            }
        } catch (InterruptedException e) {
            // entire thread was asked to stop
            actionCancelled = true;
            transformTask.cancel(true);
            break;
        }
    }
    if (actionCancelled) {
        throw new RenditionCancelledException("Rendition action cancelled");
    }
    if (!actionCompleted && !actionCancelled) {
        throw new RenditionServiceException("Transformation failed to obey timeout limit");
    }
    if (actionCompleted) {
        // Copy content from temp writer to real writer
        ContentWriter writer = context.makeContentWriter();
        try {
            // We should not need another timeout here, things should be ready for us
            ContentWriter tempTarget = transformTask.get();
            if (tempTarget == null) {
                // We should never be in this state, but just in case
                throw new RenditionServiceException("Target of transformation not present");
            }
            writer.putContent(tempTarget.getReader().getContentInputStream());
        } catch (ExecutionException e) {
            // Unwrap our cause and throw that
            Throwable transformException = e.getCause();
            if (transformException instanceof RuntimeException) {
                throw (RuntimeException) e.getCause();
            }
            throw new RenditionServiceException(TRANSFORMING_ERROR_MESSAGE + e.getCause().getMessage(), e.getCause());
        } catch (InterruptedException e) {
            // We were asked to stop
            transformTask.cancel(true);
        }
    }
}
Also used : ContentReader(org.alfresco.service.cmr.repository.ContentReader) RenditionCancelledException(org.alfresco.service.cmr.rendition.RenditionCancelledException) ExecutionDetails(org.alfresco.service.cmr.action.ExecutionDetails) RenditionServiceException(org.alfresco.service.cmr.rendition.RenditionServiceException) Date(java.util.Date) TransformationOptions(org.alfresco.service.cmr.repository.TransformationOptions) ActionServiceException(org.alfresco.service.cmr.action.ActionServiceException) NodeRef(org.alfresco.service.cmr.repository.NodeRef) ContentWriter(org.alfresco.service.cmr.repository.ContentWriter) FutureTask(java.util.concurrent.FutureTask) ExecutionSummary(org.alfresco.service.cmr.action.ExecutionSummary) ExecutionException(java.util.concurrent.ExecutionException)

Example 4 with RenditionServiceException

use of org.alfresco.service.cmr.rendition.RenditionServiceException in project alfresco-repository by Alfresco.

the class RenditionNodeManager method orphanOldRendition.

/**
 * This method performs the 'orphaning' of the oldRendition. It removes the rendition aspect(s) and removes
 * the child-association linking the old rendition to its source node. The old rendition node is not deleted.
 *
 * @param renditionName the name of the rendition.
 * @throws RenditionServiceException if there was not exactly one parent assoc from the oldRendition having the specified renditionName
 *                                   or if the matching parent assoc was not to the correct source node.
 */
private void orphanOldRendition(QNamePattern renditionName) {
    // Get all parent assocs from the old rendition of the specified renditionName.
    List<ChildAssociationRef> parents = nodeService.getParentAssocs(existingLinkedRendition, RenditionModel.ASSOC_RENDITION, renditionName);
    // There should only be one matching assoc.
    if (parents.size() == 1) {
        ChildAssociationRef parentAssoc = parents.get(0);
        if (parentAssoc.getParentRef().equals(sourceNode)) {
            if (logger.isDebugEnabled()) {
                logger.debug("Orphaning old rendition node " + existingLinkedRendition);
            }
            behaviourFilter.disableBehaviour(existingLinkedRendition, ContentModel.ASPECT_AUDITABLE);
            behaviourFilter.disableBehaviour(sourceNode, ContentModel.ASPECT_AUDITABLE);
            try {
                nodeService.removeAspect(existingLinkedRendition, RenditionModel.ASPECT_HIDDEN_RENDITION);
                nodeService.removeAspect(existingLinkedRendition, RenditionModel.ASPECT_VISIBLE_RENDITION);
                nodeService.removeChildAssociation(parentAssoc);
            } finally {
                behaviourFilter.enableBehaviour(existingLinkedRendition, ContentModel.ASPECT_AUDITABLE);
                behaviourFilter.enableBehaviour(sourceNode, ContentModel.ASPECT_AUDITABLE);
            }
            return;
        }
    }
    String msg = "Node: " + existingLinkedRendition + " is not a rendition of type: " + renditionName + " for source node: " + sourceNode;
    if (logger.isDebugEnabled()) {
        logger.debug(msg);
    }
    throw new RenditionServiceException(msg);
}
Also used : ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) RenditionServiceException(org.alfresco.service.cmr.rendition.RenditionServiceException)

Example 5 with RenditionServiceException

use of org.alfresco.service.cmr.rendition.RenditionServiceException 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);
}
Also used : AuthenticationUtil(org.alfresco.repo.security.authentication.AuthenticationUtil) RenditionDefinition(org.alfresco.service.cmr.rendition.RenditionDefinition) CompositeRenditionDefinition(org.alfresco.service.cmr.rendition.CompositeRenditionDefinition) RenditionServiceException(org.alfresco.service.cmr.rendition.RenditionServiceException) RenditionServiceException(org.alfresco.service.cmr.rendition.RenditionServiceException) RenditionPreventedException(org.alfresco.service.cmr.rendition.RenditionPreventedException)

Aggregations

RenditionServiceException (org.alfresco.service.cmr.rendition.RenditionServiceException)20 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)8 NodeRef (org.alfresco.service.cmr.repository.NodeRef)8 RenditionDefinition (org.alfresco.service.cmr.rendition.RenditionDefinition)7 CompositeRenditionDefinition (org.alfresco.service.cmr.rendition.CompositeRenditionDefinition)5 QName (org.alfresco.service.namespace.QName)5 ContentReader (org.alfresco.service.cmr.repository.ContentReader)3 IOException (java.io.IOException)2 Serializable (java.io.Serializable)2 Date (java.util.Date)2 TransformerConfigurationException (javax.xml.transform.TransformerConfigurationException)2 AbstractContentTransformerTest (org.alfresco.repo.content.transform.AbstractContentTransformerTest)2 RenderingContext (org.alfresco.repo.rendition.executer.AbstractRenderingEngine.RenderingContext)2 AuthenticationUtil (org.alfresco.repo.security.authentication.AuthenticationUtil)2 RenditionPreventedException (org.alfresco.service.cmr.rendition.RenditionPreventedException)2 ContentWriter (org.alfresco.service.cmr.repository.ContentWriter)2 NodeService (org.alfresco.service.cmr.repository.NodeService)2 BaseAlfrescoSpringTest (org.alfresco.util.BaseAlfrescoSpringTest)2 BodyContentHandler (org.apache.tika.sax.BodyContentHandler)2 Test (org.junit.Test)2