mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-31 17:39:05 +00:00
File name param for direct acccess url requests
Adds optional file name parameter for all direct access url requests https://github.com/Alfresco/alfresco-community-repo/issues/2064
This commit is contained in:
@@ -627,7 +627,7 @@ public class ContentServiceImpl implements ContentService, ApplicationContextAwa
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public DirectAccessUrl requestContentDirectUrl(NodeRef nodeRef, QName propertyQName, boolean attachment, Long validFor)
|
||||
public DirectAccessUrl requestContentDirectUrl(NodeRef nodeRef, QName propertyQName, boolean attachment, Long validFor, String fileNameOverride)
|
||||
{
|
||||
if (!systemWideDirectUrlConfig.isEnabled())
|
||||
{
|
||||
@@ -643,7 +643,7 @@ public class ContentServiceImpl implements ContentService, ApplicationContextAwa
|
||||
|
||||
String contentUrl = contentData.getContentUrl();
|
||||
String contentMimetype = contentData.getMimetype();
|
||||
String fileName = getFileName(nodeRef);
|
||||
String fileName = fileNameOverride == null ? getFileName(nodeRef) : fileNameOverride;
|
||||
|
||||
validFor = adjustValidFor(validFor);
|
||||
attachment = adjustAttachment(nodeRef, contentMimetype, attachment);
|
||||
|
@@ -213,7 +213,7 @@ public interface ContentService
|
||||
*/
|
||||
default DirectAccessUrl requestContentDirectUrl(NodeRef nodeRef, QName propertyQName, boolean attachment)
|
||||
{
|
||||
return requestContentDirectUrl(nodeRef, propertyQName, attachment, null);
|
||||
return requestContentDirectUrl(nodeRef, propertyQName, attachment, null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -230,7 +230,7 @@ public interface ContentService
|
||||
@Deprecated
|
||||
default public DirectAccessUrl requestContentDirectUrl(NodeRef nodeRef, boolean attachment, Long validFor)
|
||||
{
|
||||
return requestContentDirectUrl(nodeRef, ContentModel.PROP_CONTENT, attachment, validFor);
|
||||
return requestContentDirectUrl(nodeRef, ContentModel.PROP_CONTENT, attachment, validFor, null);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -241,11 +241,12 @@ public interface ContentService
|
||||
* @param propertyQName the name of the property, which must be of type <b>content</b>
|
||||
* @param attachment {@code true} if an attachment URL is requested, {@code false} for an embedded {@code URL}.
|
||||
* @param validFor The time at which the direct access {@code URL} will expire.
|
||||
* @param fileName Optional name for the file when downloaded
|
||||
* @return A direct access {@code URL} object for the content.
|
||||
* @throws UnsupportedOperationException if the store is unable to provide the information.
|
||||
*/
|
||||
@Auditable(parameters = {"nodeRef", "propertyQName", "validFor"})
|
||||
DirectAccessUrl requestContentDirectUrl(NodeRef nodeRef, QName propertyQName, boolean attachment, Long validFor);
|
||||
DirectAccessUrl requestContentDirectUrl(NodeRef nodeRef, QName propertyQName, boolean attachment, Long validFor, String fileName);
|
||||
|
||||
/**
|
||||
* Gets a key-value (String-String) collection of storage headers/properties with their respective values for a specific node reference.
|
||||
|
@@ -135,7 +135,7 @@ public class ContentServiceImplUnitTest
|
||||
{
|
||||
setupSystemWideDirectAccessConfig(DISABLED);
|
||||
assertThrows(DirectAccessUrlDisabledException.class, () -> {
|
||||
contentService.requestContentDirectUrl(NODE_REF, PROP_CONTENT_QNAME, true, 20L);
|
||||
contentService.requestContentDirectUrl(NODE_REF, PROP_CONTENT_QNAME, true, 20L, null);
|
||||
});
|
||||
verify(mockContentStore, never()).isContentDirectUrlEnabled();
|
||||
}
|
||||
@@ -146,7 +146,7 @@ public class ContentServiceImplUnitTest
|
||||
setupSystemWideDirectAccessConfig(ENABLED);
|
||||
when(mockContentStore.isContentDirectUrlEnabled()).thenReturn(DISABLED);
|
||||
|
||||
DirectAccessUrl directAccessUrl = contentService.requestContentDirectUrl(NODE_REF, PROP_CONTENT_QNAME,true, 20L);
|
||||
DirectAccessUrl directAccessUrl = contentService.requestContentDirectUrl(NODE_REF, PROP_CONTENT_QNAME,true, 20L, null);
|
||||
assertNull(directAccessUrl);
|
||||
verify(mockContentStore, never()).requestContentDirectUrl(anyString(), eq(true), anyString(), anyString(), anyLong());
|
||||
}
|
||||
@@ -157,7 +157,7 @@ public class ContentServiceImplUnitTest
|
||||
setupSystemWideDirectAccessConfig(ENABLED);
|
||||
when(mockContentStore.isContentDirectUrlEnabled()).thenReturn(ENABLED);
|
||||
|
||||
DirectAccessUrl directAccessUrl = contentService.requestContentDirectUrl(NODE_REF, PROP_CONTENT_QNAME, true, 20L);
|
||||
DirectAccessUrl directAccessUrl = contentService.requestContentDirectUrl(NODE_REF, PROP_CONTENT_QNAME, true, 20L, null);
|
||||
assertNull(directAccessUrl);
|
||||
verify(mockContentStore, times(1)).requestContentDirectUrl(anyString(), eq(true), anyString(), anyString(), anyLong());
|
||||
}
|
||||
|
@@ -164,11 +164,11 @@ public class ContentServiceImplTest extends BaseVersionStoreTest
|
||||
NodeRef nodeRef = this.dbNodeService
|
||||
.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName("{test}MyNoContentNode"), TEST_TYPE_QNAME, this.nodeProperties).getChildRef();
|
||||
|
||||
assertNull(contentService.requestContentDirectUrl(nodeRef, QNAME, true, validFor));
|
||||
assertNull(contentService.requestContentDirectUrl(nodeRef, QNAME, true, validFor, null));
|
||||
});
|
||||
|
||||
assertThrows("nodeRef is null", IllegalArgumentException.class, () -> {
|
||||
assertNull(contentService.requestContentDirectUrl(null, null, true, null));
|
||||
assertNull(contentService.requestContentDirectUrl(null, null, true, null, null));
|
||||
});
|
||||
|
||||
assertThrows("propertyQName has no content", NullPointerException.class, () -> {
|
||||
@@ -176,13 +176,13 @@ public class ContentServiceImplTest extends BaseVersionStoreTest
|
||||
NodeRef nodeRef = this.dbNodeService
|
||||
.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName("{test}MyNoContentNode"), TEST_TYPE_QNAME, this.nodeProperties).getChildRef();
|
||||
|
||||
contentService.requestContentDirectUrl(nodeRef, null, true, validFor);
|
||||
contentService.requestContentDirectUrl(nodeRef, null, true, validFor, null);
|
||||
});
|
||||
|
||||
// Create a node with content
|
||||
NodeRef nodeRef = createNewVersionableNode();
|
||||
|
||||
assertNull(contentService.requestContentDirectUrl(nodeRef, QNAME, true, null));
|
||||
assertNull(contentService.requestContentDirectUrl(nodeRef, QNAME, true, validFor));
|
||||
assertNull(contentService.requestContentDirectUrl(nodeRef, QNAME, true, null, null));
|
||||
assertNull(contentService.requestContentDirectUrl(nodeRef, QNAME, true, validFor, null));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user