ACS-938 metadata is not added when using Transform Service #176

This commit is contained in:
Alan Davis
2020-11-26 12:35:33 +00:00
committed by GitHub
parent 396a590e56
commit ed4f353f9c
6 changed files with 47 additions and 22 deletions

View File

@@ -31,6 +31,8 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import org.alfresco.model.ContentModel; import org.alfresco.model.ContentModel;
import org.alfresco.repo.action.executer.ContentMetadataExtracter; import org.alfresco.repo.action.executer.ContentMetadataExtracter;
import org.alfresco.repo.content.transform.TransformerDebug; import org.alfresco.repo.content.transform.TransformerDebug;
import org.alfresco.repo.rendition2.RenditionDefinitionRegistry2;
import org.alfresco.repo.rendition2.RenditionDefinitionRegistry2Impl;
import org.alfresco.repo.rendition2.RenditionService2; import org.alfresco.repo.rendition2.RenditionService2;
import org.alfresco.repo.rendition2.TransformDefinition; import org.alfresco.repo.rendition2.TransformDefinition;
import org.alfresco.repo.security.authentication.AuthenticationUtil; import org.alfresco.repo.security.authentication.AuthenticationUtil;
@@ -99,6 +101,7 @@ public class AsynchronousExtractor extends AbstractMappingMetadataExtracter
private NamespacePrefixResolver namespacePrefixResolver; private NamespacePrefixResolver namespacePrefixResolver;
private TransformerDebug transformerDebug; private TransformerDebug transformerDebug;
private RenditionService2 renditionService2; private RenditionService2 renditionService2;
private RenditionDefinitionRegistry2Impl renditionDefinitionRegistry2;
private ContentService contentService; private ContentService contentService;
private TransactionService transactionService; private TransactionService transactionService;
private TransformServiceRegistry transformServiceRegistry; private TransformServiceRegistry transformServiceRegistry;
@@ -125,6 +128,11 @@ public class AsynchronousExtractor extends AbstractMappingMetadataExtracter
this.renditionService2 = renditionService2; this.renditionService2 = renditionService2;
} }
public void setRenditionDefinitionRegistry2(RenditionDefinitionRegistry2Impl renditionDefinitionRegistry2)
{
this.renditionDefinitionRegistry2 = renditionDefinitionRegistry2;
}
public void setContentService(ContentService contentService) public void setContentService(ContentService contentService)
{ {
this.contentService = contentService; this.contentService = contentService;
@@ -326,9 +334,13 @@ public class AsynchronousExtractor extends AbstractMappingMetadataExtracter
// This needs to be specific to each source mimetype and the extract or embed as the name // This needs to be specific to each source mimetype and the extract or embed as the name
// is used to cache the transform name that will be used. // is used to cache the transform name that will be used.
String transformName = targetMimetype + '/' + sourceMimetype; String transformName = targetMimetype + '/' + sourceMimetype;
String renditionName = TransformDefinition.convertToRenditionName(transformName);
TransformDefinition transformDefinition = new TransformDefinition(transformName, targetMimetype, TransformDefinition transformDefinition = (TransformDefinition) renditionDefinitionRegistry2.getRenditionDefinition(renditionName);
options, null, null, null); if (transformDefinition == null)
{
transformDefinition = new TransformDefinition(transformName, targetMimetype,
options, null, null, null, renditionDefinitionRegistry2);
}
if (logger.isTraceEnabled()) if (logger.isTraceEnabled())
{ {

View File

@@ -44,6 +44,9 @@ import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.stream.Collectors;
import static org.alfresco.repo.rendition2.TransformDefinition.TRANSFORM_NAMESPACE;
/** /**
* A registry of rendition definitions. * A registry of rendition definitions.
@@ -351,7 +354,8 @@ public class RenditionDefinitionRegistry2Impl implements RenditionDefinitionRegi
@Override @Override
public Set<String> getRenditionNames() public Set<String> getRenditionNames()
{ {
return getData().renditionDefinitions.keySet(); // transform definitions are hidden
return getData().renditionDefinitions.keySet().stream().filter(name -> !name.startsWith(TRANSFORM_NAMESPACE)).collect(Collectors.toSet());
} }
@Override @Override
@@ -396,8 +400,10 @@ public class RenditionDefinitionRegistry2Impl implements RenditionDefinitionRegi
for (Map.Entry<String, RenditionDefinition2> entry : data.renditionDefinitions.entrySet()) for (Map.Entry<String, RenditionDefinition2> entry : data.renditionDefinitions.entrySet())
{ {
RenditionDefinition2 renditionDefinition2 = entry.getValue(); RenditionDefinition2 renditionDefinition2 = entry.getValue();
String targetMimetype = renditionDefinition2.getTargetMimetype();
String renditionName = renditionDefinition2.getRenditionName(); String renditionName = renditionDefinition2.getRenditionName();
if (!renditionName.startsWith(TRANSFORM_NAMESPACE))
{
String targetMimetype = renditionDefinition2.getTargetMimetype();
Map<String, String> options = renditionDefinition2.getTransformOptions(); Map<String, String> options = renditionDefinition2.getTransformOptions();
Long maxSize = transformServiceRegistry.findMaxSize(sourceMimetype, targetMimetype, options, renditionName); Long maxSize = transformServiceRegistry.findMaxSize(sourceMimetype, targetMimetype, options, renditionName);
if (maxSize != null) if (maxSize != null)
@@ -407,6 +413,7 @@ public class RenditionDefinitionRegistry2Impl implements RenditionDefinitionRegi
renditions.add(pair); renditions.add(pair);
} }
} }
}
return renditions; return renditions;
} }

View File

@@ -54,27 +54,28 @@ public class TransformDefinition extends RenditionDefinition2Impl
* if the transform will take place, will be cached against the transformName. * if the transform will take place, will be cached against the transformName.
*/ */
public TransformDefinition(String transformName, String targetMimetype, Map<String, String> transformOptions, public TransformDefinition(String transformName, String targetMimetype, Map<String, String> transformOptions,
String clientData, String replyQueue, String requestId) String clientData, String replyQueue, String requestId,
RenditionDefinitionRegistry2Impl registry)
{ {
super(convertToRenditionName(transformName), targetMimetype, transformOptions, null); super(convertToRenditionName(transformName), targetMimetype, transformOptions, registry);
this.clientData = clientData; this.clientData = clientData;
this.replyQueue = replyQueue; this.replyQueue = replyQueue;
this.requestId = requestId; this.requestId = requestId;
this.errorMessage = null; this.errorMessage = null;
} }
static String convertToRenditionName(String transformName)
{
return transformName == null ? null : TRANSFORM_NAMESPACE+transformName;
}
/** /**
* Constructor where the targetMimetype and transformOptions are unlikely to be repeated. * Constructor where the targetMimetype and transformOptions are unlikely to be repeated.
*/ */
public TransformDefinition(String targetMimetype, Map<String, String> transformOptions, public TransformDefinition(String targetMimetype, Map<String, String> transformOptions,
String clientData, String replyQueue, String requestId) String clientData, String replyQueue, String requestId)
{ {
this(null, targetMimetype, transformOptions, clientData, replyQueue, requestId); this(null, targetMimetype, transformOptions, clientData, replyQueue, requestId, null);
}
public static String convertToRenditionName(String transformName)
{
return transformName == null ? null : TRANSFORM_NAMESPACE+transformName;
} }
public String getTransformName() public String getTransformName()

View File

@@ -2,7 +2,7 @@
* #%L * #%L
* Alfresco Repository * Alfresco Repository
* %% * %%
* Copyright (C) 2005 - 2019 Alfresco Software Limited * Copyright (C) 2005 - 2020 Alfresco Software Limited
* %% * %%
* This file is part of the Alfresco software. * This file is part of the Alfresco software.
* If the software was purchased under a paid Alfresco license, the terms of * If the software was purchased under a paid Alfresco license, the terms of
@@ -32,7 +32,6 @@ import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.transaction.TransactionService; import org.alfresco.service.transaction.TransactionService;
import org.alfresco.util.ParameterCheck; import org.alfresco.util.ParameterCheck;
import org.apache.camel.Exchange; import org.apache.camel.Exchange;
import org.apache.camel.NoSuchEndpointException;
import org.apache.camel.Processor; import org.apache.camel.Processor;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
@@ -125,7 +124,7 @@ public class TransformRequestProcessor implements Processor
String requestId = event.getRequestId(); String requestId = event.getRequestId();
TransformDefinition transformDefinition = new TransformDefinition(transformName, targetMediaType, transformOptions, TransformDefinition transformDefinition = new TransformDefinition(transformName, targetMediaType, transformOptions,
clientData, replyQueue, requestId); clientData, replyQueue, requestId, null);
NodeRef nodeRef = new NodeRef(event.getNodeRef()); NodeRef nodeRef = new NodeRef(event.getNodeRef());

View File

@@ -295,6 +295,7 @@
<property name="namespacePrefixResolver" ref="namespaceService" /> <property name="namespacePrefixResolver" ref="namespaceService" />
<property name="transformerDebug" ref="transformerDebug" /> <property name="transformerDebug" ref="transformerDebug" />
<property name="renditionService2" ref="renditionService2" /> <property name="renditionService2" ref="renditionService2" />
<property name="renditionDefinitionRegistry2" ref="renditionDefinitionRegistry2" />
<property name="contentService" ref="ContentService" /> <property name="contentService" ref="ContentService" />
<property name="transactionService" ref="transactionService" /> <property name="transactionService" ref="transactionService" />
<property name="transformServiceRegistry" ref="transformServiceRegistry" /> <property name="transformServiceRegistry" ref="transformServiceRegistry" />

View File

@@ -36,6 +36,8 @@ import org.alfresco.repo.content.transform.AbstractContentTransformerTest;
import org.alfresco.repo.content.transform.TransformerDebug; import org.alfresco.repo.content.transform.TransformerDebug;
import org.alfresco.repo.content.transform.UnsupportedTransformationException; import org.alfresco.repo.content.transform.UnsupportedTransformationException;
import org.alfresco.repo.rendition2.RenditionDefinition2; import org.alfresco.repo.rendition2.RenditionDefinition2;
import org.alfresco.repo.rendition2.RenditionDefinitionRegistry2;
import org.alfresco.repo.rendition2.RenditionDefinitionRegistry2Impl;
import org.alfresco.repo.rendition2.RenditionService2Impl; import org.alfresco.repo.rendition2.RenditionService2Impl;
import org.alfresco.repo.rendition2.TransformClient; import org.alfresco.repo.rendition2.TransformClient;
import org.alfresco.repo.search.impl.noindex.NoIndexCategoryServiceImpl; import org.alfresco.repo.search.impl.noindex.NoIndexCategoryServiceImpl;
@@ -130,6 +132,7 @@ public class AsynchronousExtractorTest extends BaseSpringTest
private TransformerDebug transformerDebug; private TransformerDebug transformerDebug;
private TransactionService transactionService; private TransactionService transactionService;
private TransformServiceRegistry transformServiceRegistry; private TransformServiceRegistry transformServiceRegistry;
private RenditionDefinitionRegistry2Impl renditionDefinitionRegistry2;
private TaggingServiceImpl taggingService; private TaggingServiceImpl taggingService;
private ContentMetadataExtracter contentMetadataExtracter; private ContentMetadataExtracter contentMetadataExtracter;
private ContentMetadataEmbedder contentMetadataEmbedder; private ContentMetadataEmbedder contentMetadataEmbedder;
@@ -186,6 +189,7 @@ public class AsynchronousExtractorTest extends BaseSpringTest
setContentService(contentService); setContentService(contentService);
setTransactionService(transactionService); setTransactionService(transactionService);
setTransformServiceRegistry(transformServiceRegistry); setTransformServiceRegistry(transformServiceRegistry);
setRenditionDefinitionRegistry2(renditionDefinitionRegistry2);
setEnableStringTagging(true); setEnableStringTagging(true);
setTaggingService(taggingService); setTaggingService(taggingService);
setRegistry(metadataExtracterRegistry); setRegistry(metadataExtracterRegistry);
@@ -330,6 +334,7 @@ public class AsynchronousExtractorTest extends BaseSpringTest
renditionService2 = (RenditionService2Impl) applicationContext.getBean("renditionService2"); renditionService2 = (RenditionService2Impl) applicationContext.getBean("renditionService2");
transactionService = (TransactionService) applicationContext.getBean("transactionService"); transactionService = (TransactionService) applicationContext.getBean("transactionService");
transformServiceRegistry = (TransformServiceRegistry) applicationContext.getBean("transformServiceRegistry"); transformServiceRegistry = (TransformServiceRegistry) applicationContext.getBean("transformServiceRegistry");
renditionDefinitionRegistry2 = (RenditionDefinitionRegistry2Impl) applicationContext.getBean("renditionDefinitionRegistry2");
taggingService = (TaggingServiceImpl) applicationContext.getBean("taggingService"); taggingService = (TaggingServiceImpl) applicationContext.getBean("taggingService");
transformClient = (TransformClient) applicationContext.getBean("transformClient"); transformClient = (TransformClient) applicationContext.getBean("transformClient");
asynchronousExtractor = (AsynchronousExtractor) applicationContext.getBean("extractor.Asynchronous"); asynchronousExtractor = (AsynchronousExtractor) applicationContext.getBean("extractor.Asynchronous");