From 0c5b497a532e0c210e04c39e77352d5d04612149 Mon Sep 17 00:00:00 2001 From: Alan Davis Date: Mon, 22 Nov 2021 12:59:09 +0000 Subject: [PATCH] ACS-2270 Read T-Engine config in alphabetical order (#485) * T-Engines config need to be combined in the same predefined order in the all-in-one transformer, T-Router and the Content Repository with individual T-Engines. --- .../alfresco/transformer/AIOCustomConfig.java | 30 +++++++++-- .../transformer/AIOCustomConfigTest.java | 53 +++++++++++++++++++ 2 files changed, 78 insertions(+), 5 deletions(-) create mode 100644 alfresco-transform-core-aio/alfresco-transform-core-aio-boot/src/test/java/org/alfresco/transformer/AIOCustomConfigTest.java 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 9bf7201d..fb5ceb67 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 @@ -31,12 +31,18 @@ import org.alfresco.transformer.executors.ImageMagickCommandExecutor; import org.alfresco.transformer.executors.LibreOfficeJavaExecutor; import org.alfresco.transformer.executors.PdfRendererCommandExecutor; import org.alfresco.transformer.executors.TikaJavaExecutor; +import org.alfresco.transformer.executors.Transformer; import org.alfresco.transformer.transformers.SelectingTransformer; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Primary; +import java.util.Comparator; +import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.Stream; + @Configuration public class AIOCustomConfig { @@ -88,12 +94,26 @@ public class AIOCustomConfig public TransformServiceRegistry aioTransformRegistry() throws Exception { AIOTransformRegistry aioTransformRegistry = new AIOTransformRegistry(); - aioTransformRegistry.registerTransformer(new SelectingTransformer()); - aioTransformRegistry.registerTransformer(new TikaJavaExecutor(notExtractBookmarksTextDefault)); - aioTransformRegistry.registerTransformer(new ImageMagickCommandExecutor(imageMagickExePath, imageMagickDynPath, imageMagickRootPath, imageMagickCodersPath, imageMagickConfigPath)); - aioTransformRegistry.registerTransformer(new LibreOfficeJavaExecutor(libreofficePath, libreofficeMaxTasksPerProcess, libreofficeTimeout, libreofficePortNumbers, libreofficeTemplateProfileDir, libreofficeIsEnabled)); - aioTransformRegistry.registerTransformer(new PdfRendererCommandExecutor(pdfRendererPath)); + + // T-Engines are sorted by name so they are combined in the same order as in the T-Router + // and Content Repository with individual T-Engines. See TransformersConfigRegistry#retrieveRemoteConfig and + // LocalTransformServiceRegistry#getTEngineUrlsSortedByName. + for (Transformer tEngine : getTEnginesSortedByName()) + { + aioTransformRegistry.registerTransformer(tEngine); // now a poor name - should be combinedTransformers + } aioTransformRegistry.registerCombinedTransformers(); return aioTransformRegistry; } + + List getTEnginesSortedByName() + { + return Stream.of(new SelectingTransformer(), + new TikaJavaExecutor(notExtractBookmarksTextDefault), + new ImageMagickCommandExecutor(imageMagickExePath, imageMagickDynPath, imageMagickRootPath, imageMagickCodersPath, imageMagickConfigPath), + new LibreOfficeJavaExecutor(libreofficePath, libreofficeMaxTasksPerProcess, libreofficeTimeout, libreofficePortNumbers, libreofficeTemplateProfileDir, libreofficeIsEnabled), + new PdfRendererCommandExecutor(pdfRendererPath)) + .sorted(Comparator.comparing(Transformer::getTransformerId)) + .collect(Collectors.toList()); + } } diff --git a/alfresco-transform-core-aio/alfresco-transform-core-aio-boot/src/test/java/org/alfresco/transformer/AIOCustomConfigTest.java b/alfresco-transform-core-aio/alfresco-transform-core-aio-boot/src/test/java/org/alfresco/transformer/AIOCustomConfigTest.java new file mode 100644 index 00000000..2865c1df --- /dev/null +++ b/alfresco-transform-core-aio/alfresco-transform-core-aio-boot/src/test/java/org/alfresco/transformer/AIOCustomConfigTest.java @@ -0,0 +1,53 @@ +/* + * #%L + * Alfresco Transform Core + * %% + * 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 + * the paid license agreement will prevail. Otherwise, the software is + * provided under the following open source license terms: + * - + * Alfresco is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * - + * Alfresco is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * - + * You should have received a copy of the GNU Lesser General Public License + * along with Alfresco. If not, see . + * #L% + */ +package org.alfresco.transformer; + +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; +import org.springframework.context.annotation.Import; + +import java.util.StringJoiner; + +import static org.junit.jupiter.api.Assertions.*; + +@WebMvcTest(AIOController.class) +@Import(AIOCustomConfig.class) +class AIOCustomConfigTest +{ + @Autowired + AIOCustomConfig aioCustomConfig; + + @Test + void testGetTEnginesSortedByName() + { + // T-Engine config must be read in a predictable order (alphabetically on T-Engine name) as they may override each other. + StringJoiner sortedTEngines = new StringJoiner(","); + aioCustomConfig.getTEnginesSortedByName().stream().forEach(tEngine -> sortedTEngines.add(tEngine.getTransformerId())); + assertEquals("imagemagick,libreoffice,misc,pdfrenderer,tika", sortedTEngines.toString()); + } +}