mirror of
https://github.com/Alfresco/alfresco-transform-core.git
synced 2025-08-14 17:58:27 +00:00
Allow T-Router to be a T-Engine
This commit is contained in:
@@ -49,7 +49,7 @@ public class AIOTransformEngine implements TransformEngine
|
||||
@Override
|
||||
public String getTransformEngineName()
|
||||
{
|
||||
return "0060-AllInOne";
|
||||
return "0060 AllInOne";
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -77,7 +77,7 @@ public class AIOTransformEngine implements TransformEngine
|
||||
@Override
|
||||
public ProbeTransform getProbeTransform()
|
||||
{
|
||||
return new ProbeTransform("quick.pdf", MIMETYPE_PDF, MIMETYPE_TEXT_PLAIN, Collections.emptyMap(),
|
||||
return new ProbeTransform("probe.pdf", MIMETYPE_PDF, MIMETYPE_TEXT_PLAIN, Collections.emptyMap(),
|
||||
60, 16, 400, 10240, 60 * 30 + 1, 60 * 15 + 20);
|
||||
}
|
||||
}
|
||||
|
@@ -41,7 +41,7 @@ package org.alfresco.transform.example;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import org.alfresco.transform.base.TransformEngine;
|
||||
import org.alfresco.transform.base.probes.ProbeTransform;
|
||||
import org.alfresco.transform.common.TransformConfigResourceReader;
|
||||
import org.alfresco.transform.config.reader.TransformConfigResourceReader;
|
||||
import org.alfresco.transform.config.TransformConfig;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
@@ -66,10 +66,6 @@
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-activemq</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.activemq</groupId>
|
||||
<artifactId>activemq-client</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-annotations</artifactId>
|
||||
@@ -86,7 +82,6 @@
|
||||
<dependency>
|
||||
<groupId>ch.qos.logback</groupId>
|
||||
<artifactId>logback-classic</artifactId>
|
||||
<version>1.2.6</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.httpcomponents</groupId>
|
||||
|
@@ -162,7 +162,7 @@ public class TransformController
|
||||
@ResponseBody
|
||||
public String version()
|
||||
{
|
||||
return transformEngine.getTransformEngineName() + ' ' + coreVersion + " available";
|
||||
return transformEngine.getTransformEngineName() + ' ' + coreVersion;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -211,7 +211,7 @@ public class TransformController
|
||||
String pathPrefix = "";
|
||||
if (behindIngres)
|
||||
{
|
||||
int i = transformEngineName.lastIndexOf('-');
|
||||
int i = transformEngineName.indexOf(' ');
|
||||
if (i != -1)
|
||||
{
|
||||
transformEngineName = transformEngineName.substring(i + 1);
|
||||
|
@@ -27,7 +27,7 @@
|
||||
package org.alfresco.transform.base;
|
||||
|
||||
import org.alfresco.transform.base.probes.ProbeTransform;
|
||||
import org.alfresco.transform.common.TransformConfigResourceReader;
|
||||
import org.alfresco.transform.config.reader.TransformConfigResourceReader;
|
||||
import org.alfresco.transform.config.TransformConfig;
|
||||
|
||||
/**
|
||||
|
@@ -26,14 +26,10 @@
|
||||
*/
|
||||
package org.alfresco.transform.base.config;
|
||||
|
||||
import org.alfresco.transform.base.clients.AlfrescoSharedFileStoreClient;
|
||||
import org.alfresco.transform.base.html.TransformInterceptor;
|
||||
import org.alfresco.transform.base.registry.TransformConfigSource;
|
||||
import org.alfresco.transform.base.registry.TransformRegistry;
|
||||
import org.alfresco.transform.common.TransformerDebug;
|
||||
import org.alfresco.transform.messages.TransformRequestValidator;
|
||||
import org.alfresco.transform.registry.TransformServiceRegistry;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
@@ -58,6 +54,9 @@ public class WebApplicationConfig implements WebMvcConfigurer
|
||||
@Value("${transform.core.version}")
|
||||
private String coreVersionString;
|
||||
|
||||
@Value("${container.isTRouter}")
|
||||
private boolean isTRouter;
|
||||
|
||||
@Override
|
||||
public void addInterceptors(InterceptorRegistry registry)
|
||||
{
|
||||
@@ -80,7 +79,7 @@ public class WebApplicationConfig implements WebMvcConfigurer
|
||||
@Bean
|
||||
public TransformerDebug transformerDebug()
|
||||
{
|
||||
return new TransformerDebug().setIsTEngine(true);
|
||||
return new TransformerDebug().setIsTRouter(isTRouter);
|
||||
}
|
||||
|
||||
@Bean
|
||||
|
@@ -56,8 +56,6 @@ import org.springframework.transaction.PlatformTransactionManager;
|
||||
@ConditionalOnProperty(name = "activemq.url")
|
||||
public class MessagingConfig implements JmsListenerConfigurer
|
||||
{
|
||||
private static final Logger logger = LoggerFactory.getLogger(MessagingConfig.class);
|
||||
|
||||
@Override
|
||||
public void configureJmsListeners(@NonNull JmsListenerEndpointRegistrar registrar)
|
||||
{
|
||||
@@ -65,7 +63,6 @@ public class MessagingConfig implements JmsListenerConfigurer
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnProperty(name = "activemq.url")
|
||||
public DefaultMessageHandlerMethodFactory methodFactory()
|
||||
{
|
||||
DefaultMessageHandlerMethodFactory factory = new DefaultMessageHandlerMethodFactory();
|
||||
@@ -74,21 +71,20 @@ public class MessagingConfig implements JmsListenerConfigurer
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnProperty(name = "activemq.url")
|
||||
public DefaultJmsListenerContainerFactory jmsListenerContainerFactory(
|
||||
final ConnectionFactory connectionFactory,
|
||||
final TransformMessageConverter transformMessageConverter)
|
||||
final TransformMessageConverter transformMessageConverter,
|
||||
final MessagingErrorHandler messagingErrorHandler)
|
||||
{
|
||||
final DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
|
||||
factory.setConnectionFactory(connectionFactory);
|
||||
factory.setMessageConverter(transformMessageConverter);
|
||||
factory.setErrorHandler(t -> logger.error("JMS error: " + t.getMessage(), t));
|
||||
factory.setErrorHandler(messagingErrorHandler);
|
||||
factory.setTransactionManager(transactionManager(connectionFactory));
|
||||
return factory;
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnProperty(name = "activemq.url")
|
||||
public PlatformTransactionManager transactionManager(final ConnectionFactory connectionFactory)
|
||||
{
|
||||
final JmsTransactionManager transactionManager = new JmsTransactionManager();
|
||||
@@ -97,7 +93,6 @@ public class MessagingConfig implements JmsListenerConfigurer
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnProperty(name = "activemq.url")
|
||||
public Queue engineRequestQueue(
|
||||
@Value("${queue.engineRequestQueue}") String engineRequestQueueValue)
|
||||
{
|
||||
|
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright 2015-2018 Alfresco Software, Ltd. All rights reserved.
|
||||
*
|
||||
* License rights for this program may be obtained from Alfresco Software, Ltd.
|
||||
* pursuant to a written agreement and any use of this program without such an
|
||||
* agreement is prohibited.
|
||||
*/
|
||||
|
||||
package org.alfresco.transform.base.messaging;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.ErrorHandler;
|
||||
|
||||
/**
|
||||
* Extensible Error Handler for JMS exceptions
|
||||
*
|
||||
* @author Cezar Leahu
|
||||
*/
|
||||
@Service
|
||||
public class MessagingErrorHandler implements ErrorHandler
|
||||
{
|
||||
private static final Logger logger = LoggerFactory.getLogger(MessagingErrorHandler.class);
|
||||
|
||||
@Override
|
||||
public void handleError(Throwable t)
|
||||
{
|
||||
logger.error("JMS error: " + t.getMessage(), t);
|
||||
}
|
||||
}
|
@@ -36,8 +36,7 @@ import org.springframework.jms.core.JmsTemplate;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* Copied from the t-router. We would need to create a common dependency between t-engine base and t-router that
|
||||
* knows about jms to remove this duplication.
|
||||
* Copied from the t-router.
|
||||
*
|
||||
* @author Cezar Leahu
|
||||
*/
|
||||
|
@@ -35,15 +35,20 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Configuration
|
||||
@ConfigurationProperties(prefix = "transform")
|
||||
@ConfigurationProperties(prefix = "transform.config")
|
||||
public class TransformConfigFiles
|
||||
{
|
||||
// Populated from Spring Boot properties or such as transform.config.<engineName> or environment variables like
|
||||
// TRANSFORM_CONFIG_<engineName>.
|
||||
private final Map<String, String> config = new HashMap<>();
|
||||
// Populated from Spring Boot properties or such as transform.config.file.<engineName> or environment variables like
|
||||
// TRANSFORM_CONFIG_FILE_<engineName>.
|
||||
private final Map<String, String> files = new HashMap<>();
|
||||
|
||||
public Map<String, String> getFile()
|
||||
{
|
||||
return files;
|
||||
}
|
||||
|
||||
public List<Resource> retrieveResources()
|
||||
{
|
||||
return TransformConfigFromFiles.retrieveResources(config);
|
||||
return TransformConfigFromFiles.retrieveResources(files);
|
||||
}
|
||||
}
|
||||
|
@@ -26,7 +26,7 @@
|
||||
*/
|
||||
package org.alfresco.transform.base.registry;
|
||||
|
||||
import org.alfresco.transform.common.TransformConfigResourceReader;
|
||||
import org.alfresco.transform.config.reader.TransformConfigResourceReader;
|
||||
import org.alfresco.transform.config.TransformConfig;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
|
@@ -26,12 +26,18 @@
|
||||
package org.alfresco.transform.base.registry;
|
||||
|
||||
import org.alfresco.transform.config.TransformConfig;
|
||||
import org.alfresco.transform.config.TransformOption;
|
||||
import org.alfresco.transform.config.TransformOptionGroup;
|
||||
import org.alfresco.transform.config.TransformOptionValue;
|
||||
import org.alfresco.transform.config.Transformer;
|
||||
import org.alfresco.transform.registry.AbstractTransformRegistry;
|
||||
import org.alfresco.transform.registry.CombinedTransformConfig;
|
||||
import org.alfresco.transform.registry.Origin;
|
||||
import org.alfresco.transform.registry.TransformCache;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.event.ContextRefreshedEvent;
|
||||
import org.springframework.context.event.EventListener;
|
||||
@@ -44,11 +50,22 @@ import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.locks.ReadWriteLock;
|
||||
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static java.util.Collections.emptyMap;
|
||||
import static java.util.Objects.isNull;
|
||||
import static java.util.stream.Collectors.toUnmodifiableMap;
|
||||
import static java.util.stream.Collectors.toUnmodifiableSet;
|
||||
import static org.alfresco.transform.config.CoreVersionDecorator.setCoreVersionOnSingleStepTransformers;
|
||||
import static org.springframework.util.CollectionUtils.isEmpty;
|
||||
|
||||
@Service
|
||||
public class TransformRegistry extends AbstractTransformRegistry
|
||||
@@ -59,30 +76,53 @@ public class TransformRegistry extends AbstractTransformRegistry
|
||||
private String coreVersion;
|
||||
@Autowired
|
||||
private List<TransformConfigSource> transformConfigSources;
|
||||
@Value("${container.isTRouter}")
|
||||
private boolean isTRouter;
|
||||
|
||||
private static class Data extends TransformCache
|
||||
{
|
||||
private TransformConfig transformConfigBeforeIncompleteTransformsAreRemoved;
|
||||
private TransformConfig transformConfig;
|
||||
private TransformConfig uncombinedTransformConfig;
|
||||
private Map<String,Origin<Transformer>> transformerByNameMap;
|
||||
|
||||
public TransformConfig getTransformConfigBeforeIncompleteTransformsAreRemoved()
|
||||
public TransformConfig getTransformConfig()
|
||||
{
|
||||
return transformConfigBeforeIncompleteTransformsAreRemoved;
|
||||
return transformConfig;
|
||||
}
|
||||
|
||||
public void setTransformConfigBeforeIncompleteTransformsAreRemoved(
|
||||
TransformConfig transformConfigBeforeIncompleteTransformsAreRemoved)
|
||||
public void setTransformConfig(TransformConfig transformConfig)
|
||||
{
|
||||
this.transformConfigBeforeIncompleteTransformsAreRemoved = transformConfigBeforeIncompleteTransformsAreRemoved;
|
||||
this.transformConfig = transformConfig;
|
||||
}
|
||||
|
||||
public TransformConfig getUncombinedTransformConfig()
|
||||
{
|
||||
return uncombinedTransformConfig;
|
||||
}
|
||||
|
||||
public void setUncombinedTransformConfig(TransformConfig uncombinedTransformConfig)
|
||||
{
|
||||
this.uncombinedTransformConfig = uncombinedTransformConfig;
|
||||
}
|
||||
|
||||
public Map<String, Origin<Transformer>> getTransformerByNameMap()
|
||||
{
|
||||
return transformerByNameMap;
|
||||
}
|
||||
|
||||
public void setTransformerByNameMap(Map<String, Origin<Transformer>> transformerByNameMap)
|
||||
{
|
||||
this.transformerByNameMap = transformerByNameMap;
|
||||
}
|
||||
}
|
||||
|
||||
private Data data = new Data();
|
||||
|
||||
// Ensures that read operations are blocked while config is being updated
|
||||
private ReadWriteLock configRefreshLock = new ReentrantReadWriteLock();
|
||||
private final ReadWriteLock configRefreshLock = new ReentrantReadWriteLock();
|
||||
|
||||
@EventListener(ContextRefreshedEvent.class)
|
||||
void handleContextRefreshedEvent(final ContextRefreshedEvent event)
|
||||
public void handleContextRefreshedEvent(final ContextRefreshedEvent event)
|
||||
{
|
||||
final ApplicationContext context = event.getApplicationContext();
|
||||
// the local "initEngineConfigs" method has to be called through the Spring proxy
|
||||
@@ -135,14 +175,27 @@ public class TransformRegistry extends AbstractTransformRegistry
|
||||
this);
|
||||
});
|
||||
|
||||
TransformConfig transformConfigBeforeIncompleteTransformsAreRemoved = combinedTransformConfig.buildTransformConfig();
|
||||
TransformConfig uncombinedTransformConfig = combinedTransformConfig.buildTransformConfig();
|
||||
combinedTransformConfig.combineTransformerConfig(this);
|
||||
concurrentUpdate(combinedTransformConfig, transformConfigBeforeIncompleteTransformsAreRemoved);
|
||||
TransformConfig transformConfig = combinedTransformConfig.buildTransformConfig();
|
||||
Map<String, Origin<Transformer>> transformerByNameMap = combinedTransformConfig.getTransformerByNameMap();
|
||||
concurrentUpdate(combinedTransformConfig, uncombinedTransformConfig, transformConfig, transformerByNameMap);
|
||||
}
|
||||
|
||||
public TransformConfig getTransformConfig()
|
||||
{
|
||||
return getData().getTransformConfigBeforeIncompleteTransformsAreRemoved();
|
||||
Data data = getData();
|
||||
return isTRouter
|
||||
? data.getTransformConfig()
|
||||
: data.getUncombinedTransformConfig();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns true if transform information has been loaded.
|
||||
*/
|
||||
public boolean isReadyForTransformRequests()
|
||||
{
|
||||
return getData().getTransforms().size() > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -155,13 +208,16 @@ public class TransformRegistry extends AbstractTransformRegistry
|
||||
* Lock for reads while updating, use {@link #concurrentRead} to access locked fields
|
||||
*/
|
||||
private void concurrentUpdate(CombinedTransformConfig combinedTransformConfig,
|
||||
TransformConfig transformConfigBeforeIncompleteTransformsAreRemoved)
|
||||
TransformConfig uncombinedTransformConfig, TransformConfig transformConfig,
|
||||
Map<String, Origin<Transformer>> transformerByNameMap)
|
||||
{
|
||||
configRefreshLock.writeLock().lock();
|
||||
try
|
||||
{
|
||||
data = new Data(); // clear data
|
||||
data.setTransformConfigBeforeIncompleteTransformsAreRemoved(transformConfigBeforeIncompleteTransformsAreRemoved);
|
||||
data.setTransformConfig(transformConfig);
|
||||
data.setUncombinedTransformConfig(uncombinedTransformConfig);
|
||||
data.setTransformerByNameMap(transformerByNameMap);
|
||||
combinedTransformConfig.registerCombinedTransformers(this);
|
||||
}
|
||||
finally
|
||||
@@ -195,4 +251,86 @@ public class TransformRegistry extends AbstractTransformRegistry
|
||||
{
|
||||
logger.warn(msg);
|
||||
}
|
||||
|
||||
public Transformer getTransformer(final String sourceMediaType, final Long fileSizeBytes,
|
||||
final String targetMediaType, final Map<String, String> transformOptions)
|
||||
{
|
||||
return concurrentRead(() ->
|
||||
{
|
||||
long fileSize = fileSizeBytes == null ? 0 : fileSizeBytes;
|
||||
String transformerName = findTransformerName(sourceMediaType, fileSize, targetMediaType, transformOptions, null);
|
||||
return getTransformer(transformerName);
|
||||
});
|
||||
}
|
||||
|
||||
public Transformer getTransformer(String transformerName)
|
||||
{
|
||||
return getTransformer(getData(), transformerName);
|
||||
}
|
||||
|
||||
private Transformer getTransformer(Data data, String transformerName)
|
||||
{
|
||||
return data.getTransformerByNameMap().get(transformerName).get();
|
||||
}
|
||||
|
||||
public boolean checkSourceSize(String transformerName, String sourceMediaType, Long sourceSize, String targetMediaType)
|
||||
{
|
||||
return Optional.ofNullable(getTransformer(transformerName)).
|
||||
map(transformer -> transformer.getSupportedSourceAndTargetList().stream().
|
||||
filter(supported -> supported.getSourceMediaType().equals(sourceMediaType) &&
|
||||
supported.getTargetMediaType().equals(targetMediaType)).
|
||||
findFirst().
|
||||
map(supported -> supported.getMaxSourceSizeBytes() == -1 ||
|
||||
supported.getMaxSourceSizeBytes() >= sourceSize).
|
||||
orElse(false)).
|
||||
orElse(false);
|
||||
}
|
||||
|
||||
public String getEngineName(String transformerName)
|
||||
{
|
||||
return getData().getTransformerByNameMap().get(transformerName).getReadFrom();
|
||||
}
|
||||
|
||||
/**
|
||||
* Filters the transform options for a given transformer. In a pipeline there may be options for different steps.
|
||||
*/
|
||||
public Map<String, String> filterOptions(final String transformerName, final Map<String, String> options)
|
||||
{
|
||||
Data data = getData();
|
||||
final Map<String, Set<TransformOption>> configOptions = data.getTransformConfig().getTransformOptions();
|
||||
final Transformer transformer = getTransformer(data, transformerName);
|
||||
if (isNull(transformer) || isEmpty(options) || isEmpty(configOptions))
|
||||
{
|
||||
return emptyMap();
|
||||
}
|
||||
|
||||
final Set<String> knownOptions = transformer.getTransformOptions()
|
||||
.stream()
|
||||
.flatMap(name -> configOptions.get(name).stream())
|
||||
.filter(Objects::nonNull)
|
||||
.flatMap(TransformRegistry::retrieveOptionsStrings)
|
||||
.collect(toUnmodifiableSet());
|
||||
if (isEmpty(knownOptions))
|
||||
{
|
||||
return emptyMap();
|
||||
}
|
||||
|
||||
return options
|
||||
.entrySet()
|
||||
.stream()
|
||||
.filter(e -> knownOptions.contains(e.getKey()))
|
||||
.collect(toUnmodifiableMap(Entry::getKey, Entry::getValue));
|
||||
}
|
||||
|
||||
private static Stream<String> retrieveOptionsStrings(final TransformOption option)
|
||||
{
|
||||
if (option instanceof TransformOptionGroup)
|
||||
{
|
||||
return ((TransformOptionGroup) option)
|
||||
.getTransformOptions()
|
||||
.stream()
|
||||
.flatMap(TransformRegistry::retrieveOptionsStrings);
|
||||
}
|
||||
return Stream.of(((TransformOptionValue) option).getName());
|
||||
}
|
||||
}
|
||||
|
@@ -184,31 +184,17 @@ abstract class ProcessHandler extends FragmentHandler
|
||||
private String getTransformerName(final String sourceMimetype, long sourceSizeInBytes, final String targetMimetype,
|
||||
final Map<String, String> transformOptions)
|
||||
{
|
||||
// The transformOptions always contains sourceEncoding when sent to a T-Engine, even though it should not be
|
||||
// used to select a transformer. Similar to source and target mimetypes and extensions, but these are not
|
||||
// passed in transformOptions.
|
||||
String sourceEncoding = transformOptions.remove(SOURCE_ENCODING);
|
||||
try
|
||||
final String transformerName = transformRegistry.findTransformerName(sourceMimetype,
|
||||
sourceSizeInBytes, targetMimetype, transformOptions, null);
|
||||
if (transformerName == null)
|
||||
{
|
||||
final String transformerName = transformRegistry.findTransformerName(sourceMimetype,
|
||||
sourceSizeInBytes, targetMimetype, transformOptions, null);
|
||||
if (transformerName == null)
|
||||
{
|
||||
throw new TransformException(BAD_REQUEST, "No transforms for: "+
|
||||
sourceMimetype+" -> "+targetMimetype+transformOptions.entrySet().stream()
|
||||
.map(entry -> entry.getKey()+"="+entry.getValue())
|
||||
.collect(Collectors.joining(", ", " ", "")));
|
||||
}
|
||||
return transformerName;
|
||||
throw new TransformException(BAD_REQUEST, "No transforms for: "+
|
||||
sourceMimetype+" -> "+targetMimetype+transformOptions.entrySet().stream()
|
||||
.map(entry -> entry.getKey()+"="+entry.getValue())
|
||||
.collect(Collectors.joining(", ", " ", "")));
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (sourceEncoding != null)
|
||||
{
|
||||
transformOptions.put(SOURCE_ENCODING, sourceEncoding);
|
||||
}
|
||||
}
|
||||
}
|
||||
return transformerName;
|
||||
}
|
||||
|
||||
private CustomTransformer getCustomTransformer(String transformName)
|
||||
{
|
||||
|
@@ -22,6 +22,15 @@ server:
|
||||
error:
|
||||
include-message: ALWAYS
|
||||
|
||||
# Historic values (AVOID) - Exist to help with transition to newer versions
|
||||
transformer-routes-path: ${TRANSFORMER_ROUTES_FILE_LOCATION:transformer-pipelines.json}
|
||||
|
||||
logging:
|
||||
level:
|
||||
org.alfresco.transform.common.TransformerDebug: debug
|
||||
|
||||
fileStoreUrl: ${FILE_STORE_URL:http://localhost:8099/alfresco/api/-default-/private/sfs/versions/1/file}
|
||||
|
||||
transform:
|
||||
core:
|
||||
version: @project.version@
|
||||
@@ -32,17 +41,6 @@ transform:
|
||||
attempts: 10
|
||||
timeout: 10 # seconds
|
||||
|
||||
# Historic values (AVOID) - Exist to help with transition to newer versions
|
||||
transformer-routes-path: ${TRANSFORMER_ROUTES_FILE_LOCATION:transformer-pipelines.json}
|
||||
|
||||
logging:
|
||||
level:
|
||||
# org.alfresco.util.exec.RuntimeExec: debug
|
||||
# org.alfresco.transform.base.metadataExtractors: debug
|
||||
org.alfresco.transform.common.TransformerDebug: debug
|
||||
|
||||
fileStoreUrl: ${FILE_STORE_URL:http://localhost:8099/alfresco/api/-default-/private/sfs/versions/1/file}
|
||||
|
||||
jms-listener:
|
||||
concurrency: ${JMS_LISTENER_CONCURRENCY:1-10}
|
||||
|
||||
@@ -62,12 +60,5 @@ management:
|
||||
|
||||
container:
|
||||
name: ${HOSTNAME:t-engine}
|
||||
behind-ingres: false
|
||||
|
||||
async-task-executor:
|
||||
core-pool-size: 1
|
||||
max-pool-size: 2147483647
|
||||
keep-alive-seconds: 60
|
||||
queue-capacity: 2147483647
|
||||
allow-core-thread-time-out: false
|
||||
prestart-all-core-threads: false
|
||||
isTRouter: false
|
||||
behind-ingres: false
|
@@ -124,7 +124,7 @@ public class TransformControllerAllInOneTest
|
||||
{
|
||||
mockMvc.perform(MockMvcRequestBuilders.get(ENDPOINT_VERSION))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().string("AllInOne "+coreVersion+" available"));
|
||||
.andExpect(content().string("AllInOne "+coreVersion));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@@ -206,7 +206,7 @@ public class TransformControllerTest
|
||||
{
|
||||
mockMvc.perform(MockMvcRequestBuilders.get(ENDPOINT_VERSION))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().string("TwoCustomTransformers "+coreVersion+" available"));
|
||||
.andExpect(content().string("TwoCustomTransformers "+coreVersion));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@@ -47,7 +47,7 @@ public class TransformRegistryRefreshTest
|
||||
verify(transformRegistry, atLeast(1)).retrieveConfig();
|
||||
|
||||
// As we can't change the content of a classpath resource, lets change what is read.
|
||||
ReflectionTestUtils.setField(transformConfigFiles, "config", ImmutableMap.of(
|
||||
ReflectionTestUtils.setField(transformConfigFiles, "files", ImmutableMap.of(
|
||||
"a", "config/addA2B.json",
|
||||
"foo", "config/addB2C.json"));
|
||||
transformConfigFromFiles.initFileConfig();
|
||||
|
@@ -45,6 +45,8 @@ import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
@AutoConfigureMockMvc
|
||||
@SpringBootTest(classes={org.alfresco.transform.base.Application.class})
|
||||
@@ -68,8 +70,9 @@ public class TransformRegistryTest
|
||||
{
|
||||
transformConfigSources.clear();
|
||||
ReflectionTestUtils.setField(transformConfigFromTransformEngines, "transformEngines", Collections.emptyList());
|
||||
ReflectionTestUtils.setField(transformConfigFiles, "config", Collections.emptyMap());
|
||||
ReflectionTestUtils.setField(transformConfigFiles, "files", Collections.emptyMap());
|
||||
ReflectionTestUtils.setField(transformConfigFilesHistoric, "additional", Collections.emptyMap());
|
||||
ReflectionTestUtils.setField(transformRegistry, "isTRouter", false);
|
||||
transformRegistry.retrieveConfig();
|
||||
}
|
||||
|
||||
@@ -112,12 +115,46 @@ public class TransformRegistryTest
|
||||
getTransformerNames(transformRegistry.getTransformConfig()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void uncombinedConfigFromEngine()
|
||||
{
|
||||
ReflectionTestUtils.setField(transformConfigFromTransformEngines, "transformEngines", ImmutableList.of(
|
||||
new FakeTransformEngineWithAllInOne(),
|
||||
new FakeTransformEngineWithTwoCustomTransformers()));
|
||||
transformConfigFromTransformEngines.initTransformEngineConfig();
|
||||
transformRegistry.retrieveConfig();
|
||||
|
||||
assertEquals("Pdf2Png, TxT2Pdf, Txt2JpgViaPdf, Txt2PngViaPdf",
|
||||
getTransformerNames(transformRegistry.getTransformConfig()));
|
||||
|
||||
ReflectionTestUtils.setField(transformRegistry, "isTRouter", true);
|
||||
transformConfigFromTransformEngines.initTransformEngineConfig();
|
||||
transformRegistry.retrieveConfig();
|
||||
|
||||
assertEquals("Pdf2Png, TxT2Pdf, Txt2PngViaPdf",
|
||||
getTransformerNames(transformRegistry.getTransformConfig()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void combinedConfigFromRouter()
|
||||
{
|
||||
ReflectionTestUtils.setField(transformRegistry, "isTRouter", true);
|
||||
ReflectionTestUtils.setField(transformConfigFromTransformEngines, "transformEngines", ImmutableList.of(
|
||||
new FakeTransformEngineWithAllInOne(),
|
||||
new FakeTransformEngineWithTwoCustomTransformers()));
|
||||
transformConfigFromTransformEngines.initTransformEngineConfig();
|
||||
transformRegistry.retrieveConfig();
|
||||
|
||||
assertEquals("Pdf2Png, TxT2Pdf, Txt2PngViaPdf",
|
||||
getTransformerNames(transformRegistry.getTransformConfig()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void singleTransformEngineWithAdditionalConfig()
|
||||
{
|
||||
ReflectionTestUtils.setField(transformConfigFromTransformEngines, "transformEngines", ImmutableList.of(
|
||||
new FakeTransformEngineWithOneCustomTransformer()));
|
||||
ReflectionTestUtils.setField(transformConfigFiles, "config", ImmutableMap.of(
|
||||
ReflectionTestUtils.setField(transformConfigFiles, "files", ImmutableMap.of(
|
||||
"a", "config/addA2B.json",
|
||||
"foo", "config/addB2C.json"));
|
||||
|
||||
@@ -175,4 +212,19 @@ public class TransformRegistryTest
|
||||
|
||||
assertEquals("A2Z", getTransformerNames(transformRegistry.getTransformConfig()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isReadyForTransformRequests()
|
||||
{
|
||||
transformConfigFromTransformEngines.initTransformEngineConfig();
|
||||
transformRegistry.retrieveConfig();
|
||||
assertFalse(transformRegistry.isReadyForTransformRequests());
|
||||
|
||||
ReflectionTestUtils.setField(transformConfigFromTransformEngines, "transformEngines", ImmutableList.of(
|
||||
new FakeTransformEngineWithOneCustomTransformer()));
|
||||
transformConfigFromTransformEngines.initTransformEngineConfig();
|
||||
transformRegistry.retrieveConfig();
|
||||
|
||||
assertTrue(transformRegistry.isReadyForTransformRequests());
|
||||
}
|
||||
}
|
||||
|
@@ -29,7 +29,7 @@ package org.alfresco.transform.example;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import org.alfresco.transform.base.TransformEngine;
|
||||
import org.alfresco.transform.base.probes.ProbeTransform;
|
||||
import org.alfresco.transform.common.TransformConfigResourceReader;
|
||||
import org.alfresco.transform.config.reader.TransformConfigResourceReader;
|
||||
import org.alfresco.transform.config.TransformConfig;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
@@ -43,7 +43,7 @@ public class HelloTransformEngine implements TransformEngine
|
||||
@Override
|
||||
public String getTransformEngineName()
|
||||
{
|
||||
return "0200_hello";
|
||||
return "0200 Hello";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -28,7 +28,7 @@ package org.alfresco.transform.imagemagick;
|
||||
|
||||
import org.alfresco.transform.base.TransformEngine;
|
||||
import org.alfresco.transform.base.probes.ProbeTransform;
|
||||
import org.alfresco.transform.common.TransformConfigResourceReader;
|
||||
import org.alfresco.transform.config.reader.TransformConfigResourceReader;
|
||||
import org.alfresco.transform.config.TransformConfig;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
@@ -48,7 +48,7 @@ public class ImageMagickTransformEngine implements TransformEngine
|
||||
@Override
|
||||
public String getTransformEngineName()
|
||||
{
|
||||
return "0030-ImageMagick";
|
||||
return "0030 ImageMagick";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -28,7 +28,7 @@ package org.alfresco.transform.libreoffice;
|
||||
|
||||
import org.alfresco.transform.base.TransformEngine;
|
||||
import org.alfresco.transform.base.probes.ProbeTransform;
|
||||
import org.alfresco.transform.common.TransformConfigResourceReader;
|
||||
import org.alfresco.transform.config.reader.TransformConfigResourceReader;
|
||||
import org.alfresco.transform.config.TransformConfig;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
@@ -48,7 +48,7 @@ public class LibreOfficeTransformEngine implements TransformEngine
|
||||
@Override
|
||||
public String getTransformEngineName()
|
||||
{
|
||||
return "0020-LibreOffice";
|
||||
return "0020 LibreOffice";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -12,8 +12,8 @@
|
||||
</parent>
|
||||
|
||||
<properties>
|
||||
<image.name>alfresco/alfresco-transform-misc</image.name>
|
||||
<image.registry>quay.io</image.registry>
|
||||
<image.name>alfresco/alfresco-transform-misc</image.name>
|
||||
<env.project_artifactId>${project.artifactId}</env.project_artifactId>
|
||||
</properties>
|
||||
|
||||
|
@@ -29,7 +29,7 @@ package org.alfresco.transform.misc;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import org.alfresco.transform.base.TransformEngine;
|
||||
import org.alfresco.transform.base.probes.ProbeTransform;
|
||||
import org.alfresco.transform.common.TransformConfigResourceReader;
|
||||
import org.alfresco.transform.config.reader.TransformConfigResourceReader;
|
||||
import org.alfresco.transform.config.TransformConfig;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
@@ -52,7 +52,7 @@ public class MiscTransformEngine implements TransformEngine
|
||||
@Override
|
||||
public String getTransformEngineName()
|
||||
{
|
||||
return "0050-Misc";
|
||||
return "0050 Misc";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -28,7 +28,7 @@ package org.alfresco.transform.pdfrenderer;
|
||||
|
||||
import org.alfresco.transform.base.TransformEngine;
|
||||
import org.alfresco.transform.base.probes.ProbeTransform;
|
||||
import org.alfresco.transform.common.TransformConfigResourceReader;
|
||||
import org.alfresco.transform.config.reader.TransformConfigResourceReader;
|
||||
import org.alfresco.transform.config.TransformConfig;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
@@ -48,7 +48,7 @@ public class PdfRendererTransformEngine implements TransformEngine
|
||||
@Override
|
||||
public String getTransformEngineName()
|
||||
{
|
||||
return "0040-PdfRenderer";
|
||||
return "0040 PdfRenderer";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -28,7 +28,7 @@ package org.alfresco.transform.tika;
|
||||
|
||||
import org.alfresco.transform.base.TransformEngine;
|
||||
import org.alfresco.transform.base.probes.ProbeTransform;
|
||||
import org.alfresco.transform.common.TransformConfigResourceReader;
|
||||
import org.alfresco.transform.config.reader.TransformConfigResourceReader;
|
||||
import org.alfresco.transform.config.TransformConfig;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
@@ -48,7 +48,7 @@ public class TikaTransformEngine implements TransformEngine
|
||||
@Override
|
||||
public String getTransformEngineName()
|
||||
{
|
||||
return "0010-Tika";
|
||||
return "0010 Tika";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Reference in New Issue
Block a user