diff --git a/remote-api/src/main/java/org/alfresco/rest/api/Renditions.java b/remote-api/src/main/java/org/alfresco/rest/api/Renditions.java index 3464bad52d..aa1e352798 100644 --- a/remote-api/src/main/java/org/alfresco/rest/api/Renditions.java +++ b/remote-api/src/main/java/org/alfresco/rest/api/Renditions.java @@ -2,7 +2,7 @@ * #%L * Alfresco Remote API * %% - * Copyright (C) 2005 - 2020 Alfresco Software Limited + * Copyright (C) 2005 - 2021 Alfresco Software Limited * %% * This file is part of the Alfresco software. * If the software was purchased under a paid Alfresco license, the terms of @@ -32,7 +32,9 @@ import org.alfresco.rest.framework.core.exceptions.NotFoundException; import org.alfresco.rest.framework.resource.content.BinaryResource; import org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo; import org.alfresco.rest.framework.resource.parameters.Parameters; +import org.alfresco.service.cmr.repository.DirectAccessUrl; import org.alfresco.service.cmr.repository.NodeRef; +import org.alfresco.service.cmr.repository.StoreRef; import java.util.List; @@ -186,5 +188,58 @@ public interface Renditions * @return the rendition stream */ BinaryResource getContentNoValidation(NodeRef nodeRef, String versionId, String renditionId, Parameters parameters); + + /** + * Gets a presigned URL to directly access content. + * @param nodeId the node id for which to obtain the direct access {@code URL} + * @param versionId the version id (aka version label) + * @param renditionId the rendition id + * @param attachment {@code true} if an attachment {@code URL} is requested, {@code false} for an embedded {@code URL} + * @return a direct access {@code URL} object for the content + */ + default DirectAccessUrl requestContentDirectUrl(String nodeId, String versionId, String renditionId, boolean attachment) + { + NodeRef nodeRef = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, nodeId); + return requestContentDirectUrl(nodeRef, versionId, renditionId, attachment); + } + + /** + * Gets a presigned URL to directly access content. + * @param nodeId the node id for which to obtain the direct access {@code URL} + * @param versionId the version id (aka version label) + * @param renditionId the rendition id + * @param attachment {@code true} if an attachment {@code URL} is requested, {@code false} for an embedded {@code URL} + * @param validFor the time at which the direct access {@code URL} will expire + * @return a direct access {@code URL} object for the content + */ + default DirectAccessUrl requestContentDirectUrl(String nodeId, String versionId, String renditionId, boolean attachment, Long validFor) + { + NodeRef nodeRef = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, nodeId); + return requestContentDirectUrl(nodeRef, versionId, renditionId, attachment, validFor); + } + + /** + * Gets a presigned URL to directly access content. + * @param nodeRef the node reference for which to obtain the direct access {@code URL} + * @param versionId the version id (aka version label) + * @param renditionId the rendition id + * @param attachment {@code true} if an attachment {@code URL} is requested, {@code false} for an embedded {@code URL} + * @return a direct access {@code URL} object for the content. + */ + default DirectAccessUrl requestContentDirectUrl(NodeRef nodeRef, String versionId, String renditionId, boolean attachment) + { + return requestContentDirectUrl(nodeRef, versionId, renditionId, attachment, null); + } + + /** + * Gets a presigned URL to directly access content. + * @param nodeRef the node reference for which to obtain the direct access {@code URL} + * @param versionId the version id (aka version label) + * @param renditionId the rendition id + * @param attachment {@code true} if an attachment {@code URL} is requested, {@code false} for an embedded {@code URL} + * @param validFor the time at which the direct access {@code URL} will expire + * @return a direct access {@code URL} object for the content. + */ + DirectAccessUrl requestContentDirectUrl(NodeRef nodeRef, String versionId, String renditionId, boolean attachment, Long validFor); } diff --git a/remote-api/src/main/java/org/alfresco/rest/api/impl/RenditionsImpl.java b/remote-api/src/main/java/org/alfresco/rest/api/impl/RenditionsImpl.java index 3c1b4f0353..d253addecf 100644 --- a/remote-api/src/main/java/org/alfresco/rest/api/impl/RenditionsImpl.java +++ b/remote-api/src/main/java/org/alfresco/rest/api/impl/RenditionsImpl.java @@ -2,7 +2,7 @@ * #%L * Alfresco Remote API * %% - * Copyright (C) 2005 - 2020 Alfresco Software LimitedP + * Copyright (C) 2005 - 2021 Alfresco Software LimitedP * %% * This file is part of the Alfresco software. * If the software was purchased under a paid Alfresco license, the terms of @@ -26,6 +26,19 @@ package org.alfresco.rest.api.impl; +import java.io.File; +import java.io.InputStream; +import java.io.Serializable; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Date; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.StringJoiner; +import java.util.TreeMap; + import org.alfresco.heartbeat.RenditionsDataCollector; import org.alfresco.model.ContentModel; import org.alfresco.query.PagingResults; @@ -61,6 +74,7 @@ import org.alfresco.rest.workflow.api.impl.MapBasedQueryWalker; import org.alfresco.service.ServiceRegistry; import org.alfresco.service.cmr.repository.ChildAssociationRef; import org.alfresco.service.cmr.repository.ContentData; +import org.alfresco.service.cmr.repository.DirectAccessUrl; import org.alfresco.service.cmr.repository.MimetypeService; import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.NodeService; @@ -78,19 +92,6 @@ import org.apache.commons.logging.LogFactory; import org.springframework.context.ResourceLoaderAware; import org.springframework.core.io.ResourceLoader; -import java.io.File; -import java.io.InputStream; -import java.io.Serializable; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Date; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.StringJoiner; -import java.util.TreeMap; - /** * @author Jamal Kaabi-Mofrad, janv */ @@ -483,6 +484,22 @@ public class RenditionsImpl implements Renditions, ResourceLoaderAware return getContentImpl(nodeRef, renditionId, parameters); } + /** + * {@inheritDoc} + */ + public DirectAccessUrl requestContentDirectUrl(NodeRef nodeRef, String versionId, String renditionId, boolean attachment, Long validFor) + { + final NodeRef validatedNodeRef = validateNode(nodeRef.getStoreRef(), nodeRef.getId(), versionId, null); + NodeRef renditionNodeRef = getRenditionByName(validatedNodeRef, renditionId, null); + + if (renditionNodeRef == null) + { + throw new NotFoundException("The rendition with id: " + renditionId + " was not found."); + } + + return nodes.requestContentDirectUrl(renditionNodeRef, attachment, validFor); + } + private BinaryResource getContentImpl(NodeRef nodeRef, String renditionId, Parameters parameters) { NodeRef renditionNodeRef = getRenditionByName(nodeRef, renditionId, parameters); diff --git a/remote-api/src/main/java/org/alfresco/rest/api/nodes/NodeRenditionsRelation.java b/remote-api/src/main/java/org/alfresco/rest/api/nodes/NodeRenditionsRelation.java index f9702f1c62..f2faf3ef4a 100644 --- a/remote-api/src/main/java/org/alfresco/rest/api/nodes/NodeRenditionsRelation.java +++ b/remote-api/src/main/java/org/alfresco/rest/api/nodes/NodeRenditionsRelation.java @@ -2,7 +2,7 @@ * #%L * Alfresco Remote API * %% - * Copyright (C) 2005 - 2016 Alfresco Software Limited + * Copyright (C) 2005 - 2021 Alfresco Software Limited * %% * This file is part of the Alfresco software. * If the software was purchased under a paid Alfresco license, the terms of @@ -26,16 +26,27 @@ package org.alfresco.rest.api.nodes; +import javax.servlet.http.HttpServletResponse; + +import org.alfresco.repo.content.directurl.DirectAccessUrlDisabledException; +import org.alfresco.rest.api.DirectAccessUrlHelper; import org.alfresco.rest.api.Renditions; +import org.alfresco.rest.api.model.DirectAccessUrlRequest; import org.alfresco.rest.api.model.Rendition; import org.alfresco.rest.framework.BinaryProperties; +import org.alfresco.rest.framework.Operation; import org.alfresco.rest.framework.WebApiDescription; +import org.alfresco.rest.framework.WebApiParam; +import org.alfresco.rest.framework.core.ResourceParameter; +import org.alfresco.rest.framework.core.exceptions.DisabledServiceException; import org.alfresco.rest.framework.resource.RelationshipResource; import org.alfresco.rest.framework.resource.actions.interfaces.RelationshipResourceAction; import org.alfresco.rest.framework.resource.actions.interfaces.RelationshipResourceBinaryAction; import org.alfresco.rest.framework.resource.content.BinaryResource; import org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo; import org.alfresco.rest.framework.resource.parameters.Parameters; +import org.alfresco.rest.framework.webscripts.WithResponse; +import org.alfresco.service.cmr.repository.DirectAccessUrl; import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.StoreRef; import org.alfresco.util.PropertyCheck; @@ -58,12 +69,18 @@ public class NodeRenditionsRelation implements RelationshipResourceAction.Read + @@ -1423,6 +1424,7 @@ +