From 00c8fc7b34023c4c5dd61376de08641936b32d26 Mon Sep 17 00:00:00 2001 From: Alan Davis Date: Sat, 13 Nov 2021 11:29:21 +0000 Subject: [PATCH] ACS-1998 Enhance the transform config (#484) --- .../alfresco/transformer/AIOCustomConfig.java | 3 +- .../transformer/AIOTransformRegistry.java | 31 ++++++++++++------- .../transformer/AIOTransformRegistryTest.java | 11 +------ .../transformer/TransformRegistryImpl.java | 6 ++-- .../AbstractTransformerControllerTest.java | 5 ++- pom.xml | 12 +++---- 6 files changed, 35 insertions(+), 33 deletions(-) diff --git a/alfresco-transform-core-aio/alfresco-transform-core-aio-boot/src/main/java/org/alfresco/transformer/AIOCustomConfig.java b/alfresco-transform-core-aio/alfresco-transform-core-aio-boot/src/main/java/org/alfresco/transformer/AIOCustomConfig.java index a15857d2..9bf7201d 100644 --- a/alfresco-transform-core-aio/alfresco-transform-core-aio-boot/src/main/java/org/alfresco/transformer/AIOCustomConfig.java +++ b/alfresco-transform-core-aio/alfresco-transform-core-aio-boot/src/main/java/org/alfresco/transformer/AIOCustomConfig.java @@ -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; } } diff --git a/alfresco-transform-core-aio/alfresco-transform-core-aio/src/main/java/org/alfresco/transformer/AIOTransformRegistry.java b/alfresco-transform-core-aio/alfresco-transform-core-aio/src/main/java/org/alfresco/transformer/AIOTransformRegistry.java index 2c8d90eb..3e86fc87 100644 --- a/alfresco-transform-core-aio/alfresco-transform-core-aio/src/main/java/org/alfresco/transformer/AIOTransformRegistry.java +++ b/alfresco-transform-core-aio/alfresco-transform-core-aio/src/main/java/org/alfresco/transformer/AIOTransformRegistry.java @@ -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 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) diff --git a/alfresco-transform-core-aio/alfresco-transform-core-aio/src/test/java/org/alfresco/transformer/AIOTransformRegistryTest.java b/alfresco-transform-core-aio/alfresco-transform-core-aio/src/test/java/org/alfresco/transformer/AIOTransformRegistryTest.java index 8fa9a309..f54b5196 100644 --- a/alfresco-transform-core-aio/alfresco-transform-core-aio/src/test/java/org/alfresco/transformer/AIOTransformRegistryTest.java +++ b/alfresco-transform-core-aio/alfresco-transform-core-aio/src/test/java/org/alfresco/transformer/AIOTransformRegistryTest.java @@ -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 diff --git a/alfresco-transformer-base/src/main/java/org/alfresco/transformer/TransformRegistryImpl.java b/alfresco-transformer-base/src/main/java/org/alfresco/transformer/TransformRegistryImpl.java index a5646baa..25c620c0 100644 --- a/alfresco-transformer-base/src/main/java/org/alfresco/transformer/TransformRegistryImpl.java +++ b/alfresco-transformer-base/src/main/java/org/alfresco/transformer/TransformRegistryImpl.java @@ -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. diff --git a/alfresco-transformer-base/src/test/java/org/alfresco/transformer/AbstractTransformerControllerTest.java b/alfresco-transformer-base/src/test/java/org/alfresco/transformer/AbstractTransformerControllerTest.java index 34a942db..073af004 100644 --- a/alfresco-transformer-base/src/test/java/org/alfresco/transformer/AbstractTransformerControllerTest.java +++ b/alfresco-transformer-base/src/test/java/org/alfresco/transformer/AbstractTransformerControllerTest.java @@ -503,7 +503,10 @@ public abstract class AbstractTransformerControllerTest private Transformer buildTransformer(String sourceMediaType, String targetMediaType) { Set supportedSourceAndTargetList = ImmutableSet.of( - new SupportedSourceAndTarget(sourceMediaType, targetMediaType, -1)); + SupportedSourceAndTarget.builder() + .withSourceMediaType(sourceMediaType) + .withTargetMediaType(targetMediaType) + .build()); Transformer transformer = new Transformer(); transformer.setSupportedSourceAndTargetList(supportedSourceAndTargetList); diff --git a/pom.xml b/pom.xml index 34911d5f..c6eec8c1 100644 --- a/pom.xml +++ b/pom.xml @@ -1,19 +1,17 @@ 4.0.0 + org.alfresco + alfresco-transform-core + 2.5.4-SNAPSHOT + pom org.springframework.boot spring-boot-starter-parent 2.5.6 - - org.alfresco - alfresco-transform-core - 2.5.4-SNAPSHOT - pom - 11 11 @@ -23,7 +21,7 @@ 2.0.24 3.0.1.12 ${project.version} - 1.4.0 + 1.4.3 5.16.3 2.13.0 ${dependency.jackson.version}