ACS-1998 Enhance the transform config (#484)

This commit is contained in:
Alan Davis 2021-11-13 11:29:21 +00:00 committed by GitHub
parent 3b6169bb34
commit 00c8fc7b34
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 35 additions and 33 deletions

View File

@ -2,7 +2,7 @@
* #%L
* Alfresco Transform Core
* %%
* Copyright (C) 2005 - 2020 Alfresco Software Limited
* Copyright (C) 2005 - 2021 Alfresco Software Limited
* %%
* This file is part of the Alfresco software.
* -
@ -93,6 +93,7 @@ public class AIOCustomConfig
aioTransformRegistry.registerTransformer(new ImageMagickCommandExecutor(imageMagickExePath, imageMagickDynPath, imageMagickRootPath, imageMagickCodersPath, imageMagickConfigPath));
aioTransformRegistry.registerTransformer(new LibreOfficeJavaExecutor(libreofficePath, libreofficeMaxTasksPerProcess, libreofficeTimeout, libreofficePortNumbers, libreofficeTemplateProfileDir, libreofficeIsEnabled));
aioTransformRegistry.registerTransformer(new PdfRendererCommandExecutor(pdfRendererPath));
aioTransformRegistry.registerCombinedTransformers();
return aioTransformRegistry;
}
}

View File

@ -2,7 +2,7 @@
* #%L
* Alfresco Transform Core
* %%
* Copyright (C) 2005 - 2020 Alfresco Software Limited
* Copyright (C) 2005 - 2021 Alfresco Software Limited
* %%
* This file is part of the Alfresco software.
* -
@ -29,6 +29,7 @@ package org.alfresco.transformer;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.alfresco.transform.client.model.config.TransformConfig;
import org.alfresco.transform.client.registry.AbstractTransformRegistry;
import org.alfresco.transform.client.registry.CombinedTransformConfig;
import org.alfresco.transform.client.registry.TransformCache;
import org.alfresco.transformer.executors.Transformer;
import org.slf4j.Logger;
@ -52,7 +53,7 @@ public class AIOTransformRegistry extends AbstractTransformRegistry
private static final String ENGINE_CONFIG_LOCATION_POSTFIX = "_engine_config.json";
private TransformConfig aggregatedConfig = new TransformConfig();
private CombinedTransformConfig combinedTransformConfig = new CombinedTransformConfig();
// Holds the structures used by AbstractTransformRegistry to look up what is supported.
// Unlike other sub classes this class does not extend Data or replace it at run time.
@ -64,34 +65,40 @@ public class AIOTransformRegistry extends AbstractTransformRegistry
private Map<String, Transformer> transformerEngineMapping = new HashMap();
/**
* The registration will go through all supported sub transformers and map them to the transformer implementation.
* Adds a transformer's (T-Engine) config to the configuration and creates a map of transforms to the T-Engine.
* The name of this method is now misleading as the registry of transforms takes place in
* {@link #registerCombinedTransformers()} .
* @param transformer The transformer implementation, this could be a single transformer
* or a transformer managing multiple sub transformers. The transformer's configuration file will
* be read based on the {@link Transformer#getTransformerId()} value.
* @throws Exception Exception is thrown if a mapping for a transformer name already exists.
*/
public void registerTransformer(final Transformer transformer) throws Exception
{
// Load config for the transformer
String location = getTransformConfigLocation(transformer);
TransformConfig transformConfig = loadTransformConfig(location);
String transformerId = transformer.getTransformerId();
combinedTransformConfig.addTransformConfig(transformConfig, location, transformerId, this);
// Map all of the transforms defined in the config to this Transformer implementation
for (org.alfresco.transform.client.model.config.Transformer transformerConfig : transformConfig.getTransformers())
{
String transformerName = transformerConfig.getTransformerName();
if (transformerEngineMapping.containsKey(transformerName))
// A later tEngine 'might' override one that has already been defined. That is fine.
Transformer originalTEngine = transformerEngineMapping.get(transformerName);
if (originalTEngine != null)
{
throw new Exception("Transformer name " + transformerName + " is already registered.");
log.debug("Overriding transform with name: '{}' originally defined in '{}'.", transformerName, originalTEngine.getTransformerId());
}
transformerEngineMapping.put(transformerName, transformer);
log.debug("Registered transformer with name: '{}'.", transformerName);
log.debug("Registered transform with name: '{}' defined in '{}'.", transformerName, transformerId);
}
}
// Add the new transformer configuration to the aggregate config
aggregatedConfig.getTransformers().addAll(transformConfig.getTransformers());
aggregatedConfig.getTransformOptions().putAll(transformConfig.getTransformOptions());
registerAll(transformConfig, location, location);
public void registerCombinedTransformers()
{
combinedTransformConfig.combineTransformerConfig(this);
combinedTransformConfig.registerCombinedTransformers(this);
}
/**
@ -110,7 +117,7 @@ public class AIOTransformRegistry extends AbstractTransformRegistry
*/
public TransformConfig getTransformConfig()
{
return aggregatedConfig;
return combinedTransformConfig.buildTransformConfig();
}
protected String getTransformConfigLocation(final Transformer transformer)

View File

@ -71,7 +71,7 @@ public class AIOTransformRegistryTest
{
aioTransformerRegistry.registerTransformer(new SelectingTransformer());
aioTransformerRegistry.registerTransformer(new TikaJavaExecutor());
aioTransformerRegistry.registerCombinedTransformers();
}
private void writeToFile(File file, String content, String encoding) throws Exception
@ -155,15 +155,6 @@ public class AIOTransformRegistryTest
}
}
@Test
public void testDuplicateTransformsException() throws Exception
{
assertThrows(Exception.class, () ->{
// The Misc transformers are already registered
aioTransformerRegistry.registerTransformer(new SelectingTransformer());
});
}
// Test copied from Misc (HtmlParserContentTransformerTest) See ATS-712 aioTransformerRegistry - html
@Test
public void testMiscHtml() throws Exception

View File

@ -2,7 +2,7 @@
* #%L
* Alfresco Repository
* %%
* Copyright (C) 2005 - 2018 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
@ -36,6 +36,7 @@ import javax.annotation.PostConstruct;
import org.alfresco.transform.client.model.config.TransformConfig;
import org.alfresco.transform.client.registry.AbstractTransformRegistry;
import org.alfresco.transform.client.registry.CombinedTransformConfig;
import org.alfresco.transform.client.registry.TransformCache;
import org.alfresco.transform.exceptions.TransformException;
import org.slf4j.Logger;
@ -67,7 +68,8 @@ public class TransformRegistryImpl extends AbstractTransformRegistry
{
engineConfig = resourceLoader.getResource(locationFromProperty);
TransformConfig transformConfig = getTransformConfig();
registerAll(transformConfig, null, locationFromProperty);
// There is only one TransformConfig in a T-Engine so the following call is fine
CombinedTransformConfig.combineAndRegister(transformConfig, locationFromProperty, "---", this);
}
// Holds the structures used by AbstractTransformRegistry to look up what is supported.

View File

@ -503,7 +503,10 @@ public abstract class AbstractTransformerControllerTest
private Transformer buildTransformer(String sourceMediaType, String targetMediaType)
{
Set<SupportedSourceAndTarget> supportedSourceAndTargetList = ImmutableSet.of(
new SupportedSourceAndTarget(sourceMediaType, targetMediaType, -1));
SupportedSourceAndTarget.builder()
.withSourceMediaType(sourceMediaType)
.withTargetMediaType(targetMediaType)
.build());
Transformer transformer = new Transformer();
transformer.setSupportedSourceAndTargetList(supportedSourceAndTargetList);

12
pom.xml
View File

@ -1,19 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.alfresco</groupId>
<artifactId>alfresco-transform-core</artifactId>
<version>2.5.4-SNAPSHOT</version>
<packaging>pom</packaging>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.5.6</version>
<relativePath />
</parent>
<groupId>org.alfresco</groupId>
<artifactId>alfresco-transform-core</artifactId>
<version>2.5.4-SNAPSHOT</version>
<packaging>pom</packaging>
<properties>
<java.version>11</java.version>
<maven.compiler.source>11</maven.compiler.source>
@ -23,7 +21,7 @@
<dependency.pdfbox.version>2.0.24</dependency.pdfbox.version>
<dependency.alfresco-jodconverter-core.version>3.0.1.12</dependency.alfresco-jodconverter-core.version>
<env.project_version>${project.version}</env.project_version>
<dependency.alfresco-transform-model.version>1.4.0</dependency.alfresco-transform-model.version>
<dependency.alfresco-transform-model.version>1.4.3</dependency.alfresco-transform-model.version>
<dependency.activemq.version>5.16.3</dependency.activemq.version>
<dependency.jackson.version>2.13.0</dependency.jackson.version>
<dependency.jackson-databind.version>${dependency.jackson.version}</dependency.jackson-databind.version>