Search in sources :

Example 1 with RenditionDefinitionRegistry2

use of org.alfresco.repo.rendition2.RenditionDefinitionRegistry2 in project alfresco-remote-api by Alfresco.

the class RenditionsImpl method createRenditions.

@Override
public void createRenditions(NodeRef nodeRef, String versionLabelId, List<Rendition> renditions, Parameters parameters) throws NotFoundException, ConstraintViolatedException {
    if (renditions.isEmpty()) {
        return;
    }
    if (!renditionService2.isEnabled()) {
        throw new DisabledServiceException("Rendition generation has been disabled.");
    }
    final NodeRef sourceNodeRef = validateNode(nodeRef.getStoreRef(), nodeRef.getId(), versionLabelId, parameters);
    RenditionDefinitionRegistry2 renditionDefinitionRegistry2 = renditionService2.getRenditionDefinitionRegistry2();
    // So that POST /nodes/{nodeId}/renditions can specify rendition names as a comma separated list just like
    // POST /nodes/{nodId}/children can specify a comma separated list, the following code checks to see if the
    // supplied Rendition names are actually comma separated lists. The following example shows it is possible to
    // use both approaches.
    // [
    // { "id": "doclib" },
    // { "id": "avatar,avatar32" }
    // ]
    Set<String> renditionNames = new HashSet<>();
    for (Rendition rendition : renditions) {
        String name = getName(rendition);
        Set<String> requestedRenditions = NodesImpl.getRequestedRenditions(name);
        if (requestedRenditions == null) {
            renditionNames.add(null);
        } else {
            renditionNames.addAll(requestedRenditions);
        }
    }
    StringJoiner renditionNamesAlreadyExist = new StringJoiner(",");
    StringJoiner renditionNamesNotRegistered = new StringJoiner(",");
    List<String> renditionNamesToCreate = new ArrayList<>();
    for (String renditionName : renditionNames) {
        if (renditionName == null) {
            // 400
            throw new IllegalArgumentException(("Null rendition name supplied"));
        }
        RenditionDefinition2 renditionDefinition = renditionDefinitionRegistry2.getRenditionDefinition(renditionName);
        if (renditionDefinition == null) {
            renditionNamesNotRegistered.add(renditionName);
        }
        final NodeRef renditionNodeRef = getRenditionByName(sourceNodeRef, renditionName, parameters);
        if (renditionNodeRef == null) {
            renditionNamesToCreate.add(renditionName);
        } else {
            renditionNamesAlreadyExist.add(renditionName);
        }
    }
    if (renditionNamesNotRegistered.length() != 0) {
        // 404
        throw new NotFoundException("Renditions not registered: " + renditionNamesNotRegistered);
    }
    if (renditionNamesToCreate.size() == 0) {
        // 409
        throw new ConstraintViolatedException("All renditions requested already exist: " + renditionNamesAlreadyExist);
    }
    for (String renditionName : renditionNamesToCreate) {
        try {
            renditionService2.render(sourceNodeRef, renditionName);
        } catch (UnsupportedOperationException e) {
            // 400
            throw new IllegalArgumentException((e.getMessage()));
        } catch (IllegalStateException e) {
            // 409
            throw new StaleEntityException(e.getMessage());
        }
    }
}
Also used : DisabledServiceException(org.alfresco.rest.framework.core.exceptions.DisabledServiceException) Rendition(org.alfresco.rest.api.model.Rendition) ArrayList(java.util.ArrayList) NotFoundException(org.alfresco.rest.framework.core.exceptions.NotFoundException) RenditionDefinitionRegistry2(org.alfresco.repo.rendition2.RenditionDefinitionRegistry2) ConstraintViolatedException(org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException) NodeRef(org.alfresco.service.cmr.repository.NodeRef) RenditionDefinition2(org.alfresco.repo.rendition2.RenditionDefinition2) StaleEntityException(org.alfresco.rest.framework.core.exceptions.StaleEntityException) StringJoiner(java.util.StringJoiner) HashSet(java.util.HashSet)

Example 2 with RenditionDefinitionRegistry2

use of org.alfresco.repo.rendition2.RenditionDefinitionRegistry2 in project alfresco-remote-api by Alfresco.

the class RenditionsImpl method toApiRendition.

protected Rendition toApiRendition(String renditionName) {
    RenditionDefinitionRegistry2 renditionDefinitionRegistry2 = renditionService2.getRenditionDefinitionRegistry2();
    RenditionDefinition2 renditionDefinition = renditionDefinitionRegistry2.getRenditionDefinition(renditionName);
    ContentInfo contentInfo = new ContentInfo(renditionDefinition.getTargetMimetype(), getMimeTypeDisplayName(renditionDefinition.getTargetMimetype()), null, null);
    Rendition apiRendition = new Rendition();
    apiRendition.setId(renditionName);
    apiRendition.setContent(contentInfo);
    apiRendition.setStatus(RenditionStatus.NOT_CREATED);
    return apiRendition;
}
Also used : ContentInfo(org.alfresco.rest.api.model.ContentInfo) Rendition(org.alfresco.rest.api.model.Rendition) RenditionDefinition2(org.alfresco.repo.rendition2.RenditionDefinition2) RenditionDefinitionRegistry2(org.alfresco.repo.rendition2.RenditionDefinitionRegistry2)

Example 3 with RenditionDefinitionRegistry2

use of org.alfresco.repo.rendition2.RenditionDefinitionRegistry2 in project alfresco-remote-api by Alfresco.

the class RenditionsImpl method getRendition.

@Override
public Rendition getRendition(NodeRef nodeRef, String versionLabelId, String renditionId, Parameters parameters) {
    final NodeRef validatedNodeRef = validateNode(nodeRef.getStoreRef(), nodeRef.getId(), versionLabelId, parameters);
    NodeRef renditionNodeRef = getRenditionByName(validatedNodeRef, renditionId, parameters);
    boolean includeNotCreated = true;
    String status = getStatus(parameters);
    if (status != null) {
        includeNotCreated = !RenditionStatus.CREATED.equals(RenditionStatus.valueOf(status));
    }
    // if there is no rendition, then try to find the available/registered rendition (yet to be created).
    if (renditionNodeRef == null && includeNotCreated) {
        ContentData contentData = getContentData(validatedNodeRef, true);
        String sourceMimetype = contentData.getMimetype();
        long size = contentData.getSize();
        RenditionDefinitionRegistry2 renditionDefinitionRegistry2 = renditionService2.getRenditionDefinitionRegistry2();
        RenditionDefinition2 renditionDefinition = renditionDefinitionRegistry2.getRenditionDefinition(renditionId);
        if (renditionDefinition == null) {
            throw new NotFoundException(renditionId + " is not registered.");
        } else {
            Set<String> renditionNames = renditionDefinitionRegistry2.getRenditionNamesFrom(sourceMimetype, size);
            boolean found = false;
            for (String renditionName : renditionNames) {
                // Check the registered renditionId is applicable for the node's mimeType
                if (renditionId.equals(renditionName)) {
                    found = true;
                    break;
                }
            }
            if (!found) {
                throw new NotFoundException(renditionId + " is not applicable for the node's mimeType " + sourceMimetype);
            }
        }
        return toApiRendition(renditionId);
    }
    if (renditionNodeRef == null) {
        throw new NotFoundException("The rendition with id: " + renditionId + " was not found.");
    }
    return toApiRendition(renditionNodeRef);
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) ContentData(org.alfresco.service.cmr.repository.ContentData) RenditionDefinition2(org.alfresco.repo.rendition2.RenditionDefinition2) NotFoundException(org.alfresco.rest.framework.core.exceptions.NotFoundException) RenditionDefinitionRegistry2(org.alfresco.repo.rendition2.RenditionDefinitionRegistry2)

Example 4 with RenditionDefinitionRegistry2

use of org.alfresco.repo.rendition2.RenditionDefinitionRegistry2 in project alfresco-remote-api by Alfresco.

the class RenditionsImpl method getRenditions.

@Override
public CollectionWithPagingInfo<Rendition> getRenditions(NodeRef nodeRef, String versionLabelId, Parameters parameters) {
    final NodeRef validatedNodeRef = validateNode(nodeRef.getStoreRef(), nodeRef.getId(), versionLabelId, parameters);
    ContentData contentData = getContentData(validatedNodeRef, true);
    String sourceMimetype = contentData.getMimetype();
    boolean includeCreated = true;
    boolean includeNotCreated = true;
    String status = getStatus(parameters);
    if (status != null) {
        includeCreated = RenditionStatus.CREATED.equals(RenditionStatus.valueOf(status));
        includeNotCreated = !includeCreated;
    }
    // List all available rendition definitions
    long size = contentData.getSize();
    RenditionDefinitionRegistry2 renditionDefinitionRegistry2 = renditionService2.getRenditionDefinitionRegistry2();
    Set<String> renditionNames = renditionDefinitionRegistry2.getRenditionNamesFrom(sourceMimetype, size);
    Map<String, Rendition> apiRenditions = new TreeMap<>();
    if (includeNotCreated) {
        for (String renditionName : renditionNames) {
            apiRenditions.put(renditionName, toApiRendition(renditionName));
        }
    }
    List<ChildAssociationRef> nodeRefRenditions = renditionService2.getRenditions(validatedNodeRef);
    if (!nodeRefRenditions.isEmpty()) {
        for (ChildAssociationRef childAssociationRef : nodeRefRenditions) {
            NodeRef renditionNodeRef = childAssociationRef.getChildRef();
            Rendition apiRendition = toApiRendition(renditionNodeRef);
            String renditionName = apiRendition.getId();
            if (renditionNames.contains(renditionName)) {
                if (includeCreated) {
                    // Replace/append any thumbnail definitions with created rendition info
                    apiRenditions.put(renditionName, apiRendition);
                } else {
                    // Remove any thumbnail definitions that has been created from the list,
                    // as the filter requires only the Not_Created renditions
                    apiRenditions.remove(renditionName);
                }
            } else {
                if (logger.isTraceEnabled()) {
                    logger.trace("Skip unknown rendition [" + renditionName + ", " + renditionNodeRef + "]");
                }
            }
        }
    }
    // Wrap paging info, as the core service doesn't support paging
    Paging paging = parameters.getPaging();
    PagingResults<Rendition> results = Util.wrapPagingResults(paging, apiRenditions.values());
    return CollectionWithPagingInfo.asPaged(paging, results.getPage(), results.hasMoreItems(), results.getTotalResultCount().getFirst());
}
Also used : Rendition(org.alfresco.rest.api.model.Rendition) Paging(org.alfresco.rest.framework.resource.parameters.Paging) RenditionDefinitionRegistry2(org.alfresco.repo.rendition2.RenditionDefinitionRegistry2) TreeMap(java.util.TreeMap) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) NodeRef(org.alfresco.service.cmr.repository.NodeRef) ContentData(org.alfresco.service.cmr.repository.ContentData)

Example 5 with RenditionDefinitionRegistry2

use of org.alfresco.repo.rendition2.RenditionDefinitionRegistry2 in project alfresco-remote-api by Alfresco.

the class NodesImpl method requestRenditions.

private void requestRenditions(Set<String> renditionNames, Node fileNode) {
    if (renditionNames != null) {
        NodeRef sourceNodeRef = fileNode.getNodeRef();
        String mimeType = fileNode.getContent().getMimeType();
        long size = fileNode.getContent().getSizeInBytes();
        RenditionDefinitionRegistry2 renditionDefinitionRegistry2 = renditionService2.getRenditionDefinitionRegistry2();
        Set<String> availableRenditions = renditionDefinitionRegistry2.getRenditionNamesFrom(mimeType, size);
        for (String renditionName : renditionNames) {
            // RA-1052 (REPO-47)
            try {
                // File may be to big
                if (!availableRenditions.contains(renditionName)) {
                    throw new InvalidArgumentException("Unable to create thumbnail '" + renditionName + "' for " + mimeType + " as no transformer is currently available.");
                }
                renditionService2.render(sourceNodeRef, renditionName);
            } catch (Exception ex) {
                // Note: The log level is not 'error' as it could easily fill out the log file.
                if (logger.isDebugEnabled()) {
                    // Don't throw the exception as we don't want the the upload to fail, just log it.
                    logger.debug("Asynchronous request to create a rendition upon upload failed: " + ex.getMessage());
                }
            }
        }
    }
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) RenditionDefinitionRegistry2(org.alfresco.repo.rendition2.RenditionDefinitionRegistry2) FileExistsException(org.alfresco.service.cmr.model.FileExistsException) PermissionDeniedException(org.alfresco.rest.framework.core.exceptions.PermissionDeniedException) AccessDeniedException(org.alfresco.repo.security.permissions.AccessDeniedException) DuplicateChildNodeNameException(org.alfresco.service.cmr.repository.DuplicateChildNodeNameException) NotFoundException(org.alfresco.rest.framework.core.exceptions.NotFoundException) ConcurrencyFailureException(org.springframework.dao.ConcurrencyFailureException) ConstraintViolatedException(org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException) IntegrityException(org.alfresco.repo.node.integrity.IntegrityException) IOException(java.io.IOException) RequestEntityTooLargeException(org.alfresco.rest.framework.core.exceptions.RequestEntityTooLargeException) DisabledServiceException(org.alfresco.rest.framework.core.exceptions.DisabledServiceException) InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) FileNotFoundException(org.alfresco.service.cmr.model.FileNotFoundException) ContentQuotaException(org.alfresco.service.cmr.usage.ContentQuotaException) UnsupportedMediaTypeException(org.alfresco.rest.framework.core.exceptions.UnsupportedMediaTypeException) AssociationExistsException(org.alfresco.service.cmr.repository.AssociationExistsException) InsufficientStorageException(org.alfresco.rest.framework.core.exceptions.InsufficientStorageException) EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException) InvalidNodeRefException(org.alfresco.service.cmr.repository.InvalidNodeRefException) NodeLockedException(org.alfresco.service.cmr.lock.NodeLockedException) ContentIOException(org.alfresco.service.cmr.repository.ContentIOException) ContentLimitViolationException(org.alfresco.repo.content.ContentLimitViolationException)

Aggregations

RenditionDefinition2 (org.alfresco.repo.rendition2.RenditionDefinition2)6 RenditionDefinitionRegistry2 (org.alfresco.repo.rendition2.RenditionDefinitionRegistry2)6 NodeRef (org.alfresco.service.cmr.repository.NodeRef)5 Rendition (org.alfresco.rest.api.model.Rendition)3 NotFoundException (org.alfresco.rest.framework.core.exceptions.NotFoundException)3 ContentData (org.alfresco.service.cmr.repository.ContentData)3 ConstraintViolatedException (org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException)2 DisabledServiceException (org.alfresco.rest.framework.core.exceptions.DisabledServiceException)2 IOException (java.io.IOException)1 Serializable (java.io.Serializable)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 StringJoiner (java.util.StringJoiner)1 TreeMap (java.util.TreeMap)1 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)1 ContentLimitViolationException (org.alfresco.repo.content.ContentLimitViolationException)1 UnimportantTransformException (org.alfresco.repo.content.transform.UnimportantTransformException)1 IntegrityException (org.alfresco.repo.node.integrity.IntegrityException)1 AccessDeniedException (org.alfresco.repo.security.permissions.AccessDeniedException)1 ThumbnailDefinition (org.alfresco.repo.thumbnail.ThumbnailDefinition)1