From df519cfd6f74c904b8baadc2b80c3e98361e6ba1 Mon Sep 17 00:00:00 2001 From: Alan Davis Date: Wed, 9 Feb 2022 22:39:40 +0000 Subject: [PATCH] ACS-2498 Add coreVersion to T-Engine config (#526) The bulk of the changes in this PR are to do with adding a coreVersion element to the transform element in the T-Engine config. For more detail see the class header of CoreVersionDecorator. * Support the use of coreVersion so that it is possible to upgrade pods in any order * Moved the majority of the RequestParamMap static finals to alfresco-transform-model and added a new one: "includeCoreVersion" parameter. --- _ci/source_clear.sh | 2 +- .../alfresco/transformer/AIOController.java | 13 +++++-- .../main/resources/application-default.yaml | 1 + .../AIOControllerImageMagickTest.java | 8 ++++ .../AIOControllerLibreOfficeTest.java | 7 ++++ .../transformer/AIOControllerMiscTest.java | 11 +++++- .../AIOControllerPdfRendererTest.java | 10 ++++- .../transformer/AIOControllerTest.java | 11 ++++-- .../transformer/AIOControllerTikaTest.java | 8 ++++ .../main/resources/application-default.yaml | 1 + .../main/resources/application-default.yaml | 1 + .../alfresco/transformer/MiscController.java | 4 +- .../main/resources/application-default.yaml | 1 + .../HtmlParserContentTransformer.java | 4 +- .../transformers/SelectableTransformer.java | 5 +-- .../StringExtractingContentTransformer.java | 5 ++- .../TextToPdfContentTransformer.java | 4 +- .../HtmlParserContentTransformerTest.java | 4 +- .../main/resources/application-default.yaml | 1 + .../main/resources/application-default.yaml | 1 + .../AbstractTransformerController.java | 11 ++++-- .../transformer/TransformRegistryImpl.java | 8 +++- .../transformer/util/RequestParamMap.java | 39 ++++--------------- .../AbstractTransformerControllerTest.java | 28 ++++++++++++- pom.xml | 2 +- 25 files changed, 128 insertions(+), 62 deletions(-) diff --git a/_ci/source_clear.sh b/_ci/source_clear.sh index 6ab40f79..7842730b 100644 --- a/_ci/source_clear.sh +++ b/_ci/source_clear.sh @@ -5,7 +5,7 @@ PS4="\[\e[35m\]+ \[\e[m\]" set +e -v -x pushd "$(dirname "${BASH_SOURCE[0]}")/../" -mvn -B -q clean install \ +mvn -B -U -q clean install \ -DskipTests \ -Dmaven.javadoc.skip=true \ com.srcclr:srcclr-maven-plugin:scan \ diff --git a/alfresco-transform-core-aio/alfresco-transform-core-aio-boot/src/main/java/org/alfresco/transformer/AIOController.java b/alfresco-transform-core-aio/alfresco-transform-core-aio-boot/src/main/java/org/alfresco/transformer/AIOController.java index 5d1beca4..431a4b2c 100644 --- a/alfresco-transform-core-aio/alfresco-transform-core-aio-boot/src/main/java/org/alfresco/transformer/AIOController.java +++ b/alfresco-transform-core-aio/alfresco-transform-core-aio-boot/src/main/java/org/alfresco/transformer/AIOController.java @@ -2,7 +2,7 @@ * #%L * Alfresco Transform Core * %% - * Copyright (C) 2005 - 2020 Alfresco Software Limited + * Copyright (C) 2005 - 2022 Alfresco Software Limited * %% * This file is part of the Alfresco software. * - @@ -35,6 +35,7 @@ import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestParam; import java.io.File; import java.util.HashMap; @@ -42,6 +43,8 @@ import java.util.Map; import static org.alfresco.transform.client.model.Mimetype.MIMETYPE_HTML; import static org.alfresco.transform.client.model.Mimetype.MIMETYPE_TEXT_PLAIN; +import static org.alfresco.transform.client.model.config.CoreVersionDecorator.setOrClearCoreVersion; +import static org.alfresco.transformer.util.RequestParamMap.INCLUDE_CORE_VERSION; import static org.alfresco.transformer.util.RequestParamMap.SOURCE_ENCODING; import static org.alfresco.transformer.util.RequestParamMap.TRANSFORM_NAME_PARAMETER; import static org.springframework.http.HttpStatus.INTERNAL_SERVER_ERROR; @@ -88,10 +91,12 @@ public class AIOController extends AbstractTransformerController } @Override - public ResponseEntity info() + public ResponseEntity info( + @RequestParam(value = INCLUDE_CORE_VERSION, required = false) Boolean includeCoreVersion) { - logger.info("GET Transform Config."); + logger.info("GET Transform Config" + (includeCoreVersion != null && includeCoreVersion ? " including coreVersion" : "")); TransformConfig transformConfig = transformRegistry.getTransformConfig(); + transformConfig = setOrClearCoreVersion(transformConfig, includeCoreVersion); return new ResponseEntity<>(transformConfig, OK); } @@ -105,7 +110,7 @@ public class AIOController extends AbstractTransformerController Transformer transformer = transformRegistry.getByTransformName(transformName); if (transformer == null) { - new TransformException(INTERNAL_SERVER_ERROR.value(), "No transformer mapping for - transform:" + throw new TransformException(INTERNAL_SERVER_ERROR.value(), "No transformer mapping for - transform:" + transformName + " sourceMimetype:" + sourceMimetype + " targetMimetype:" + targetMimetype); } diff --git a/alfresco-transform-core-aio/alfresco-transform-core-aio-boot/src/main/resources/application-default.yaml b/alfresco-transform-core-aio/alfresco-transform-core-aio-boot/src/main/resources/application-default.yaml index 3a55ed6b..da6e68a3 100644 --- a/alfresco-transform-core-aio/alfresco-transform-core-aio-boot/src/main/resources/application-default.yaml +++ b/alfresco-transform-core-aio/alfresco-transform-core-aio-boot/src/main/resources/application-default.yaml @@ -2,6 +2,7 @@ queue: engineRequestQueue: ${TRANSFORM_ENGINE_REQUEST_QUEUE:org.alfresco.transform.engine.aio.acs} transform: core: + version: @project.version@ pdfrenderer: exe: ${PDFRENDERER_EXE:/usr/bin/alfresco-pdf-renderer} libreoffice: diff --git a/alfresco-transform-core-aio/alfresco-transform-core-aio-boot/src/test/java/org/alfresco/transformer/AIOControllerImageMagickTest.java b/alfresco-transform-core-aio/alfresco-transform-core-aio-boot/src/test/java/org/alfresco/transformer/AIOControllerImageMagickTest.java index 0be23b4b..04ba2954 100644 --- a/alfresco-transform-core-aio/alfresco-transform-core-aio-boot/src/test/java/org/alfresco/transformer/AIOControllerImageMagickTest.java +++ b/alfresco-transform-core-aio/alfresco-transform-core-aio-boot/src/test/java/org/alfresco/transformer/AIOControllerImageMagickTest.java @@ -106,6 +106,14 @@ public class AIOControllerImageMagickTest extends ImageMagickControllerTest } + + @Test + @Override + public void testGetTransformConfigInfoExcludingCoreVersion() + { + // Ignore the test in super class as the way the AIO transformer provides config is fundamentally different. + } + @Test @Override public void testGetInfoFromConfigWithDuplicates() diff --git a/alfresco-transform-core-aio/alfresco-transform-core-aio-boot/src/test/java/org/alfresco/transformer/AIOControllerLibreOfficeTest.java b/alfresco-transform-core-aio/alfresco-transform-core-aio-boot/src/test/java/org/alfresco/transformer/AIOControllerLibreOfficeTest.java index b0613dc4..8bf1a2ef 100644 --- a/alfresco-transform-core-aio/alfresco-transform-core-aio-boot/src/test/java/org/alfresco/transformer/AIOControllerLibreOfficeTest.java +++ b/alfresco-transform-core-aio/alfresco-transform-core-aio-boot/src/test/java/org/alfresco/transformer/AIOControllerLibreOfficeTest.java @@ -88,6 +88,13 @@ public class AIOControllerLibreOfficeTest extends LibreOfficeControllerTest } + @Test + @Override + public void testGetTransformConfigInfoExcludingCoreVersion() + { + // Ignore the test in super class as the way the AIO transformer provides config is fundamentally different. + } + @Test @Override public void testGetInfoFromConfigWithDuplicates() diff --git a/alfresco-transform-core-aio/alfresco-transform-core-aio-boot/src/test/java/org/alfresco/transformer/AIOControllerMiscTest.java b/alfresco-transform-core-aio/alfresco-transform-core-aio-boot/src/test/java/org/alfresco/transformer/AIOControllerMiscTest.java index 5b94df75..4e4be7c4 100644 --- a/alfresco-transform-core-aio/alfresco-transform-core-aio-boot/src/test/java/org/alfresco/transformer/AIOControllerMiscTest.java +++ b/alfresco-transform-core-aio/alfresco-transform-core-aio-boot/src/test/java/org/alfresco/transformer/AIOControllerMiscTest.java @@ -45,15 +45,22 @@ public class AIOControllerMiscTest extends MiscControllerTest // just test that we are actually testing against the AIOController (instead of MiscController) assertTrue(controller instanceof AIOController, "Wrong controller wired for test"); } - + @Test @Override public void testGetTransformConfigInfo() { - // Ignore the test in super class as the way the AIO transformer provides config is fundamentality different. + // Ignore the test in super class as the way the AIO transformer provides config is fundamentally different. } + @Test + @Override + public void testGetTransformConfigInfoExcludingCoreVersion() + { + // Ignore the test in super class as the way the AIO transformer provides config is fundamentally different. + } + @Test @Override public void testGetInfoFromConfigWithDuplicates() diff --git a/alfresco-transform-core-aio/alfresco-transform-core-aio-boot/src/test/java/org/alfresco/transformer/AIOControllerPdfRendererTest.java b/alfresco-transform-core-aio/alfresco-transform-core-aio-boot/src/test/java/org/alfresco/transformer/AIOControllerPdfRendererTest.java index a944aaf4..063cb1db 100644 --- a/alfresco-transform-core-aio/alfresco-transform-core-aio-boot/src/test/java/org/alfresco/transformer/AIOControllerPdfRendererTest.java +++ b/alfresco-transform-core-aio/alfresco-transform-core-aio-boot/src/test/java/org/alfresco/transformer/AIOControllerPdfRendererTest.java @@ -84,9 +84,15 @@ public class AIOControllerPdfRendererTest extends AlfrescoPdfRendererControllerT public void testGetTransformConfigInfo() { // Ignore the test in super class as the way the AIO transformer provides config is fundamentally different. - - } + + @Test + @Override + public void testGetTransformConfigInfoExcludingCoreVersion() + { + // Ignore the test in super class as the way the AIO transformer provides config is fundamentally different. + } + @Test @Override public void testGetInfoFromConfigWithDuplicates() diff --git a/alfresco-transform-core-aio/alfresco-transform-core-aio-boot/src/test/java/org/alfresco/transformer/AIOControllerTest.java b/alfresco-transform-core-aio/alfresco-transform-core-aio-boot/src/test/java/org/alfresco/transformer/AIOControllerTest.java index 2b62642f..82f6508f 100644 --- a/alfresco-transform-core-aio/alfresco-transform-core-aio-boot/src/test/java/org/alfresco/transformer/AIOControllerTest.java +++ b/alfresco-transform-core-aio/alfresco-transform-core-aio-boot/src/test/java/org/alfresco/transformer/AIOControllerTest.java @@ -2,7 +2,7 @@ * #%L * Alfresco Transform Core * %% - * Copyright (C) 2005 - 2021 Alfresco Software Limited + * Copyright (C) 2005 - 2022 Alfresco Software Limited * %% * This file is part of the Alfresco software. * - @@ -38,7 +38,6 @@ import org.springframework.context.annotation.Import; @Import(AIOCustomConfig.class) public class AIOControllerTest //extends AbstractTransformerControllerTest { - @Autowired AIOController aioController; @@ -64,6 +63,12 @@ public class AIOControllerTest //extends AbstractTransformerControllerTest @Test public void emptyTest() { - aioController.info(); + aioController.info(null); + } + + @Test + public void emptyTestWithIncludeCoreVersion() + { + aioController.info(true); } } \ No newline at end of file diff --git a/alfresco-transform-core-aio/alfresco-transform-core-aio-boot/src/test/java/org/alfresco/transformer/AIOControllerTikaTest.java b/alfresco-transform-core-aio/alfresco-transform-core-aio-boot/src/test/java/org/alfresco/transformer/AIOControllerTikaTest.java index 9c720faa..12e62476 100644 --- a/alfresco-transform-core-aio/alfresco-transform-core-aio-boot/src/test/java/org/alfresco/transformer/AIOControllerTikaTest.java +++ b/alfresco-transform-core-aio/alfresco-transform-core-aio-boot/src/test/java/org/alfresco/transformer/AIOControllerTikaTest.java @@ -57,6 +57,14 @@ public class AIOControllerTikaTest extends TikaControllerTest } + + @Test + @Override + public void testGetTransformConfigInfoExcludingCoreVersion() + { + // Ignore the test in super class as the way the AIO transformer provides config is fundamentally different. + } + @Test @Override public void testGetInfoFromConfigWithDuplicates() diff --git a/alfresco-transform-imagemagick/alfresco-transform-imagemagick-boot/src/main/resources/application-default.yaml b/alfresco-transform-imagemagick/alfresco-transform-imagemagick-boot/src/main/resources/application-default.yaml index 6b813c68..30851c71 100644 --- a/alfresco-transform-imagemagick/alfresco-transform-imagemagick-boot/src/main/resources/application-default.yaml +++ b/alfresco-transform-imagemagick/alfresco-transform-imagemagick-boot/src/main/resources/application-default.yaml @@ -2,6 +2,7 @@ queue: engineRequestQueue: ${TRANSFORM_ENGINE_REQUEST_QUEUE:org.alfresco.transform.engine.imagemagick.acs} transform: core: + version: @project.version@ config: location: classpath:imagemagick_engine_config.json imagemagick: diff --git a/alfresco-transform-libreoffice/alfresco-transform-libreoffice-boot/src/main/resources/application-default.yaml b/alfresco-transform-libreoffice/alfresco-transform-libreoffice-boot/src/main/resources/application-default.yaml index 2c286ef4..53d01728 100644 --- a/alfresco-transform-libreoffice/alfresco-transform-libreoffice-boot/src/main/resources/application-default.yaml +++ b/alfresco-transform-libreoffice/alfresco-transform-libreoffice-boot/src/main/resources/application-default.yaml @@ -2,6 +2,7 @@ queue: engineRequestQueue: ${TRANSFORM_ENGINE_REQUEST_QUEUE:org.alfresco.transform.engine.libreoffice.acs} transform: core: + version: @project.version@ config: location: classpath:libreoffice_engine_config.json libreoffice: diff --git a/alfresco-transform-misc/alfresco-transform-misc-boot/src/main/java/org/alfresco/transformer/MiscController.java b/alfresco-transform-misc/alfresco-transform-misc-boot/src/main/java/org/alfresco/transformer/MiscController.java index 6a5498fe..d987a430 100644 --- a/alfresco-transform-misc/alfresco-transform-misc-boot/src/main/java/org/alfresco/transformer/MiscController.java +++ b/alfresco-transform-misc/alfresco-transform-misc-boot/src/main/java/org/alfresco/transformer/MiscController.java @@ -2,7 +2,7 @@ * #%L * Alfresco Transform Core * %% - * Copyright (C) 2005 - 2020 Alfresco Software Limited + * Copyright (C) 2005 - 2022 Alfresco Software Limited * %% * This file is part of the Alfresco software. * - @@ -38,7 +38,7 @@ import java.util.Map; import static org.alfresco.transform.client.model.Mimetype.MIMETYPE_HTML; import static org.alfresco.transform.client.model.Mimetype.MIMETYPE_TEXT_PLAIN; -import static org.alfresco.transformer.transformers.HtmlParserContentTransformer.SOURCE_ENCODING; +import static org.alfresco.transformer.util.RequestParamMap.SOURCE_ENCODING; import static org.alfresco.transformer.util.RequestParamMap.TRANSFORM_NAME_PARAMETER; @Controller diff --git a/alfresco-transform-misc/alfresco-transform-misc-boot/src/main/resources/application-default.yaml b/alfresco-transform-misc/alfresco-transform-misc-boot/src/main/resources/application-default.yaml index 30fea7ee..2624c89b 100644 --- a/alfresco-transform-misc/alfresco-transform-misc-boot/src/main/resources/application-default.yaml +++ b/alfresco-transform-misc/alfresco-transform-misc-boot/src/main/resources/application-default.yaml @@ -2,5 +2,6 @@ queue: engineRequestQueue: ${TRANSFORM_ENGINE_REQUEST_QUEUE:org.alfresco.transform.engine.misc.acs} transform: core: + version: @project.version@ config: location: classpath:misc_engine_config.json \ No newline at end of file diff --git a/alfresco-transform-misc/alfresco-transform-misc/src/main/java/org/alfresco/transformer/transformers/HtmlParserContentTransformer.java b/alfresco-transform-misc/alfresco-transform-misc/src/main/java/org/alfresco/transformer/transformers/HtmlParserContentTransformer.java index 4c64016d..eb84e5f8 100644 --- a/alfresco-transform-misc/alfresco-transform-misc/src/main/java/org/alfresco/transformer/transformers/HtmlParserContentTransformer.java +++ b/alfresco-transform-misc/alfresco-transform-misc/src/main/java/org/alfresco/transformer/transformers/HtmlParserContentTransformer.java @@ -2,7 +2,7 @@ * #%L * Alfresco Transform Core * %% - * Copyright (C) 2005 - 2020 Alfresco Software Limited + * Copyright (C) 2005 - 2022 Alfresco Software Limited * %% * This file is part of the Alfresco software. * - @@ -42,6 +42,8 @@ import java.nio.charset.Charset; import java.nio.charset.IllegalCharsetNameException; import java.util.Map; +import static org.alfresco.transform.client.util.RequestParamMap.SOURCE_ENCODING; + /** * Content transformer which wraps the HTML Parser library for * parsing HTML content. diff --git a/alfresco-transform-misc/alfresco-transform-misc/src/main/java/org/alfresco/transformer/transformers/SelectableTransformer.java b/alfresco-transform-misc/alfresco-transform-misc/src/main/java/org/alfresco/transformer/transformers/SelectableTransformer.java index dd9c712f..af89da91 100644 --- a/alfresco-transform-misc/alfresco-transform-misc/src/main/java/org/alfresco/transformer/transformers/SelectableTransformer.java +++ b/alfresco-transform-misc/alfresco-transform-misc/src/main/java/org/alfresco/transformer/transformers/SelectableTransformer.java @@ -2,7 +2,7 @@ * #%L * Alfresco Transform Core * %% - * Copyright (C) 2005 - 2020 Alfresco Software Limited + * Copyright (C) 2005 - 2022 Alfresco Software Limited * %% * This file is part of the Alfresco software. * - @@ -36,9 +36,6 @@ import java.util.Map; */ public interface SelectableTransformer { - String SOURCE_ENCODING = "sourceEncoding"; - String TARGET_ENCODING = "targetEncoding"; - default void transform(String sourceMimetype, String targetMimetype, Map parameters, File sourceFile, File targetFile) throws Exception { diff --git a/alfresco-transform-misc/alfresco-transform-misc/src/main/java/org/alfresco/transformer/transformers/StringExtractingContentTransformer.java b/alfresco-transform-misc/alfresco-transform-misc/src/main/java/org/alfresco/transformer/transformers/StringExtractingContentTransformer.java index 0c006de9..0a1760a6 100644 --- a/alfresco-transform-misc/alfresco-transform-misc/src/main/java/org/alfresco/transformer/transformers/StringExtractingContentTransformer.java +++ b/alfresco-transform-misc/alfresco-transform-misc/src/main/java/org/alfresco/transformer/transformers/StringExtractingContentTransformer.java @@ -2,7 +2,7 @@ * #%L * Alfresco Transform Core * %% - * Copyright (C) 2005 - 2020 Alfresco Software Limited + * Copyright (C) 2005 - 2022 Alfresco Software Limited * %% * This file is part of the Alfresco software. * - @@ -42,6 +42,9 @@ import java.nio.charset.Charset; import java.nio.charset.IllegalCharsetNameException; import java.util.Map; +import static org.alfresco.transform.client.util.RequestParamMap.SOURCE_ENCODING; +import static org.alfresco.transform.client.util.RequestParamMap.TARGET_ENCODING; + /** * Converts any textual format to plain text. *

diff --git a/alfresco-transform-misc/alfresco-transform-misc/src/main/java/org/alfresco/transformer/transformers/TextToPdfContentTransformer.java b/alfresco-transform-misc/alfresco-transform-misc/src/main/java/org/alfresco/transformer/transformers/TextToPdfContentTransformer.java index 1cf823bd..253d1c88 100644 --- a/alfresco-transform-misc/alfresco-transform-misc/src/main/java/org/alfresco/transformer/transformers/TextToPdfContentTransformer.java +++ b/alfresco-transform-misc/alfresco-transform-misc/src/main/java/org/alfresco/transformer/transformers/TextToPdfContentTransformer.java @@ -2,7 +2,7 @@ * #%L * Alfresco Transform Core * %% - * Copyright (C) 2005 - 2021 Alfresco Software Limited + * Copyright (C) 2005 - 2022 Alfresco Software Limited * %% * This file is part of the Alfresco software. * - @@ -50,6 +50,8 @@ import java.nio.charset.Charset; import java.util.HashMap; import java.util.Map; +import static org.alfresco.transform.client.util.RequestParamMap.SOURCE_ENCODING; + /** *

* This code is based on a class of the same name originally implemented in alfresco-repository. diff --git a/alfresco-transform-misc/alfresco-transform-misc/src/test/java/org/alfresco/transformer/transformers/HtmlParserContentTransformerTest.java b/alfresco-transform-misc/alfresco-transform-misc/src/test/java/org/alfresco/transformer/transformers/HtmlParserContentTransformerTest.java index c41b7220..775a4408 100644 --- a/alfresco-transform-misc/alfresco-transform-misc/src/test/java/org/alfresco/transformer/transformers/HtmlParserContentTransformerTest.java +++ b/alfresco-transform-misc/alfresco-transform-misc/src/test/java/org/alfresco/transformer/transformers/HtmlParserContentTransformerTest.java @@ -2,7 +2,7 @@ * #%L * Alfresco Transform Core * %% - * Copyright (C) 2005 - 2020 Alfresco Software Limited + * Copyright (C) 2005 - 2022 Alfresco Software Limited * %% * This file is part of the Alfresco software. * - @@ -35,7 +35,7 @@ import java.nio.file.Files; import java.util.HashMap; import java.util.Map; -import static org.alfresco.transformer.transformers.StringExtractingContentTransformer.SOURCE_ENCODING; +import static org.alfresco.transform.client.util.RequestParamMap.SOURCE_ENCODING; import static org.junit.jupiter.api.Assertions.assertEquals; public class HtmlParserContentTransformerTest diff --git a/alfresco-transform-pdf-renderer/alfresco-transform-pdf-renderer-boot/src/main/resources/application-default.yaml b/alfresco-transform-pdf-renderer/alfresco-transform-pdf-renderer-boot/src/main/resources/application-default.yaml index 75860056..1602d74e 100644 --- a/alfresco-transform-pdf-renderer/alfresco-transform-pdf-renderer-boot/src/main/resources/application-default.yaml +++ b/alfresco-transform-pdf-renderer/alfresco-transform-pdf-renderer-boot/src/main/resources/application-default.yaml @@ -2,6 +2,7 @@ queue: engineRequestQueue: ${TRANSFORM_ENGINE_REQUEST_QUEUE:org.alfresco.transform.engine.alfresco-pdf-renderer.acs} transform: core: + version: @project.version@ config: location: classpath:pdfrenderer_engine_config.json pdfrenderer: diff --git a/alfresco-transform-tika/alfresco-transform-tika-boot/src/main/resources/application-default.yaml b/alfresco-transform-tika/alfresco-transform-tika-boot/src/main/resources/application-default.yaml index 559c09c3..729549ac 100644 --- a/alfresco-transform-tika/alfresco-transform-tika-boot/src/main/resources/application-default.yaml +++ b/alfresco-transform-tika/alfresco-transform-tika-boot/src/main/resources/application-default.yaml @@ -2,6 +2,7 @@ queue: engineRequestQueue: ${TRANSFORM_ENGINE_REQUEST_QUEUE:org.alfresco.transform.engine.tika.acs} transform: core: + version: @project.version@ config: location: classpath:tika_engine_config.json tika: diff --git a/alfresco-transformer-base/src/main/java/org/alfresco/transformer/AbstractTransformerController.java b/alfresco-transformer-base/src/main/java/org/alfresco/transformer/AbstractTransformerController.java index 936265e8..3a7b64bf 100644 --- a/alfresco-transformer-base/src/main/java/org/alfresco/transformer/AbstractTransformerController.java +++ b/alfresco-transformer-base/src/main/java/org/alfresco/transformer/AbstractTransformerController.java @@ -63,6 +63,8 @@ import java.util.List; import java.util.Map; import static java.util.stream.Collectors.joining; +import static org.alfresco.transform.client.model.config.CoreVersionDecorator.setOrClearCoreVersion; +import static org.alfresco.transform.client.util.RequestParamMap.INCLUDE_CORE_VERSION; import static org.alfresco.transformer.fs.FileManager.TempFileProvider.createTempFile; import static org.alfresco.transformer.fs.FileManager.buildFile; import static org.alfresco.transformer.fs.FileManager.createAttachment; @@ -140,11 +142,12 @@ public abstract class AbstractTransformerController implements TransformControll private TransformerDebug transformerDebug; @GetMapping(value = "/transform/config") - public ResponseEntity info() + public ResponseEntity info( + @RequestParam(value = INCLUDE_CORE_VERSION, required = false) Boolean includeCoreVersion) { - logger.info("GET Transform Config."); - final TransformConfig transformConfig = - ((TransformRegistryImpl) transformRegistry).getTransformConfig(); + logger.info("GET Transform Config" + (includeCoreVersion != null && includeCoreVersion ? " including coreVersion" : "")); + TransformConfig transformConfig = ((TransformRegistryImpl) transformRegistry).getTransformConfig(); + transformConfig = setOrClearCoreVersion(transformConfig, includeCoreVersion); return new ResponseEntity<>(transformConfig, OK); } 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 25c620c0..29e506a5 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 @@ -26,6 +26,7 @@ package org.alfresco.transformer; import static java.nio.charset.StandardCharsets.UTF_8; +import static org.alfresco.transform.client.model.config.CoreVersionDecorator.setCoreVersionOnSingleStepTransformers; import static org.springframework.http.HttpStatus.INTERNAL_SERVER_ERROR; import java.io.IOException; @@ -61,6 +62,9 @@ public class TransformRegistryImpl extends AbstractTransformRegistry @Value("${transform.core.config.location:classpath:engine_config.json}") private String locationFromProperty; + @Value("${transform.core.version}") + private String coreVersion; + private Resource engineConfig; @PostConstruct @@ -82,7 +86,9 @@ public class TransformRegistryImpl extends AbstractTransformRegistry { try (Reader reader = new InputStreamReader(engineConfig.getInputStream(), UTF_8)) { - return jsonObjectMapper.readValue(reader, TransformConfig.class); + TransformConfig transformConfig = jsonObjectMapper.readValue(reader, TransformConfig.class); + setCoreVersionOnSingleStepTransformers(transformConfig.getTransformers(), coreVersion); + return transformConfig; } catch (IOException e) { diff --git a/alfresco-transformer-base/src/main/java/org/alfresco/transformer/util/RequestParamMap.java b/alfresco-transformer-base/src/main/java/org/alfresco/transformer/util/RequestParamMap.java index 544fb31d..7ffa3e4a 100644 --- a/alfresco-transformer-base/src/main/java/org/alfresco/transformer/util/RequestParamMap.java +++ b/alfresco-transformer-base/src/main/java/org/alfresco/transformer/util/RequestParamMap.java @@ -2,7 +2,7 @@ * #%L * Alfresco Transform Core * %% - * Copyright (C) 2005 - 2020 Alfresco Software Limited + * Copyright (C) 2005 - 2022 Alfresco Software Limited * %% * This file is part of the Alfresco software. * - @@ -26,7 +26,11 @@ */ package org.alfresco.transformer.util; -public interface RequestParamMap +/** + * Extends the list of transform options with historic request parameters or 'extra' parameters used in testing + * or communication in the all-in-one transformer. + */ +public interface RequestParamMap extends org.alfresco.transform.client.util.RequestParamMap { // This property can be sent by acs repository's legacy transformers to force a transform, // instead of letting this T-Engine determine it based on the request parameters. @@ -35,41 +39,12 @@ public interface RequestParamMap // See ATS-731. @Deprecated String TRANSFORM_NAME_PROPERTY = "transformName"; - String TRANSFORM_NAME_PARAMETER = "alfresco.transform-name-parameter"; - String FILE = "file"; - String SOURCE_ENCODING = "sourceEncoding"; + String FILE = "file"; String SOURCE_EXTENSION = "sourceExtension"; String SOURCE_MIMETYPE = "sourceMimetype"; String TARGET_EXTENSION = "targetExtension"; String TARGET_MIMETYPE = "targetMimetype"; - String TARGET_ENCODING = "targetEncoding"; String TEST_DELAY = "testDelay"; - String PAGE_REQUEST_PARAM = "page"; - String WIDTH_REQUEST_PARAM = "width"; - String HEIGHT_REQUEST_PARAM = "height"; - String ALLOW_PDF_ENLARGEMENT = "allowPdfEnlargement"; - String MAINTAIN_PDF_ASPECT_RATIO = "maintainPdfAspectRatio"; - String START_PAGE = "startPage"; - String END_PAGE = "endPage"; - String ALPHA_REMOVE = "alphaRemove"; - String AUTO_ORIENT = "autoOrient"; - String CROP_GRAVITY = "cropGravity"; - String CROP_WIDTH = "cropWidth"; - String CROP_HEIGHT = "cropHeight"; - String CROP_PERCENTAGE = "cropPercentage"; - String CROP_X_OFFSET = "cropXOffset"; - String CROP_Y_OFFSET = "cropYOffset"; - String THUMBNAIL = "thumbnail"; - String RESIZE_WIDTH = "resizeWidth"; - String RESIZE_HEIGHT = "resizeHeight"; - String RESIZE_PERCENTAGE = "resizePercentage"; - String ALLOW_ENLARGEMENT = "allowEnlargement"; - String MAINTAIN_ASPECT_RATIO = "maintainAspectRatio"; - String COMMAND_OPTIONS = "commandOptions"; - String TIMEOUT = "timeout"; - String INCLUDE_CONTENTS = "includeContents"; - String NOT_EXTRACT_BOOKMARKS_TEXT = "notExtractBookmarksText"; - String PAGE_LIMIT = "pageLimit"; } 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 b0344ef7..193096ec 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 @@ -69,6 +69,7 @@ import org.alfresco.transformer.probes.ProbeTestTransform; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.boot.test.mock.mockito.SpyBean; import org.springframework.core.io.ClassPathResource; @@ -103,6 +104,9 @@ public abstract class AbstractTransformerControllerTest @SpyBean protected TransformServiceRegistry transformRegistry; + @Value("${transform.core.version}") + private String currentCoreVersion; + protected String sourceExtension; protected String targetExtension; protected String sourceMimetype; @@ -196,7 +200,7 @@ public abstract class AbstractTransformerControllerTest " does not exist in the resources directory"); } // added as part of ATS-702 to allow test resources to be read from the imported jar files to prevent test resource duplication - if(testFileUrl!=null) + if (testFileUrl!=null) { // Each use of the tempDir should result in a unique directory being used testFile = new File(tempDir, testFilename); @@ -407,6 +411,28 @@ public abstract class AbstractTransformerControllerTest @Test public void testGetTransformConfigInfo() throws Exception + { + TransformConfig expectedTransformConfig = objectMapper + .readValue(getTestFile(getEngineConfigName(), true), + TransformConfig.class); + expectedTransformConfig.getTransformers().forEach(transformer -> transformer.setCoreVersion(currentCoreVersion)); + + ReflectionTestUtils.setField(transformRegistry, "engineConfig", + new ClassPathResource(getEngineConfigName())); + + String response = mockMvc + .perform(MockMvcRequestBuilders.get("/transform/config?includeCoreVersion=true")) + .andExpect(status().is(OK.value())) + .andExpect(header().string(CONTENT_TYPE, APPLICATION_JSON_VALUE)) + .andReturn().getResponse().getContentAsString(); + + TransformConfig transformConfig = objectMapper.readValue(response, TransformConfig.class); + assertEquals(expectedTransformConfig, transformConfig); + } + + @Test + // Test for case when T-Router or Repository is a version that does not expect it + public void testGetTransformConfigInfoExcludingCoreVersion() throws Exception { TransformConfig expectedTransformConfig = objectMapper .readValue(getTestFile(getEngineConfigName(), true), diff --git a/pom.xml b/pom.xml index f4ca8202..5f8a7eb9 100644 --- a/pom.xml +++ b/pom.xml @@ -21,7 +21,7 @@ 2.0.25 3.0.1.12 ${project.version} - 1.4.8 + 1.4.9 5.16.3 2.13.1 ${dependency.jackson.version}