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 431a4b2c..c373fafe 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 @@ -44,7 +44,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.transform.client.util.RequestParamMap.CONFIG_VERSION_DEFAULT; +import static org.alfresco.transformer.util.RequestParamMap.CONFIG_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; @@ -92,11 +93,11 @@ public class AIOController extends AbstractTransformerController @Override public ResponseEntity info( - @RequestParam(value = INCLUDE_CORE_VERSION, required = false) Boolean includeCoreVersion) + @RequestParam(value = CONFIG_VERSION, defaultValue = CONFIG_VERSION_DEFAULT) int configVersion) { - logger.info("GET Transform Config" + (includeCoreVersion != null && includeCoreVersion ? " including coreVersion" : "")); + logger.info("GET Transform Config version: " + configVersion); TransformConfig transformConfig = transformRegistry.getTransformConfig(); - transformConfig = setOrClearCoreVersion(transformConfig, includeCoreVersion); + transformConfig = setOrClearCoreVersion(transformConfig, configVersion); return new ResponseEntity<>(transformConfig, OK); } 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 fb5ceb67..7f01dc9c 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 - 2021 Alfresco Software Limited + * Copyright (C) 2005 - 2022 Alfresco Software Limited * %% * This file is part of the Alfresco software. * - @@ -85,6 +85,9 @@ public class AIOCustomConfig @Value("${transform.core.tika.pdfBox.notExtractBookmarksTextDefault:false}") private boolean notExtractBookmarksTextDefault; + @Value("${transform.core.version}") + private String coreVersion; + /** * * @return Override the TransformRegistryImpl used in {@link AbstractTransformerController} @@ -94,13 +97,14 @@ public class AIOCustomConfig public TransformServiceRegistry aioTransformRegistry() throws Exception { AIOTransformRegistry aioTransformRegistry = new AIOTransformRegistry(); + aioTransformRegistry.setCoreVersion(coreVersion); // 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.registerTransformer(tEngine); // now a poor name - should be combineTransformers } aioTransformRegistry.registerCombinedTransformers(); return aioTransformRegistry; 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 82f6508f..1dc97d3b 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 @@ -29,15 +29,26 @@ package org.alfresco.transformer; import java.io.IOException; import org.alfresco.transform.client.model.TransformRequest; +import org.alfresco.transform.client.model.config.TransformConfig; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; import org.springframework.context.annotation.Import; +import org.springframework.http.ResponseEntity; + +import static org.alfresco.transform.client.util.RequestParamMap.CONFIG_VERSION_DEFAULT; +import static org.alfresco.transform.client.util.RequestParamMap.CONFIG_VERSION_LATEST; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; @WebMvcTest(AIOController.class) @Import(AIOCustomConfig.class) public class AIOControllerTest //extends AbstractTransformerControllerTest { + @Value("${transform.core.version}") + private String coreVersion; + @Autowired AIOController aioController; @@ -63,12 +74,20 @@ public class AIOControllerTest //extends AbstractTransformerControllerTest @Test public void emptyTest() { - aioController.info(null); + ResponseEntity responseEntity = aioController.info(Integer.valueOf(CONFIG_VERSION_DEFAULT)); + responseEntity.getBody().getTransformers().forEach(transformer -> { + assertNull(transformer.getCoreVersion(), transformer.getTransformerName() + + " should have had a null coreValue but was " + transformer.getCoreVersion()); + }); } @Test - public void emptyTestWithIncludeCoreVersion() + public void emptyTestWithLatestVersion() { - aioController.info(true); + ResponseEntity responseEntity = aioController.info(CONFIG_VERSION_LATEST); + responseEntity.getBody().getTransformers().forEach(transformer -> { + assertNotNull(transformer.getCoreVersion(), transformer.getTransformerName() + + " should have had a coreValue but was null. Should have been " + coreVersion); + }); } } \ No newline at end of file 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 3e86fc87..71d6b799 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 - 2021 Alfresco Software Limited + * Copyright (C) 2005 - 2022 Alfresco Software Limited * %% * This file is part of the Alfresco software. * - @@ -34,6 +34,7 @@ import org.alfresco.transform.client.registry.TransformCache; import org.alfresco.transformer.executors.Transformer; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Value; import java.io.IOException; import java.io.InputStream; @@ -43,6 +44,7 @@ import java.util.HashMap; import java.util.Map; import static java.nio.charset.StandardCharsets.UTF_8; +import static org.alfresco.transform.client.model.config.CoreVersionDecorator.setCoreVersionOnSingleStepTransformers; /** * AIOTransformRegistry manages all of the sub transformers registered to it and provides aggregated TransformConfig. @@ -53,6 +55,8 @@ public class AIOTransformRegistry extends AbstractTransformRegistry private static final String ENGINE_CONFIG_LOCATION_POSTFIX = "_engine_config.json"; + private String coreVersion; + private CombinedTransformConfig combinedTransformConfig = new CombinedTransformConfig(); // Holds the structures used by AbstractTransformRegistry to look up what is supported. @@ -64,20 +68,26 @@ public class AIOTransformRegistry extends AbstractTransformRegistry // Represents the mapping between a transform and a transformer, multiple mappings can point to the same transformer. private Map transformerEngineMapping = new HashMap(); + public void setCoreVersion(String coreVersion) + { + this.coreVersion = coreVersion; + } + /** * 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 + * @param tEngine 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. */ - public void registerTransformer(final Transformer transformer) throws Exception + public void registerTransformer(final Transformer tEngine) throws Exception { // Load config for the transformer - String location = getTransformConfigLocation(transformer); + String location = getTransformConfigLocation(tEngine); TransformConfig transformConfig = loadTransformConfig(location); - String transformerId = transformer.getTransformerId(); + setCoreVersionOnSingleStepTransformers(transformConfig.getTransformers(), coreVersion); + String transformerId = tEngine.getTransformerId(); combinedTransformConfig.addTransformConfig(transformConfig, location, transformerId, this); // Map all of the transforms defined in the config to this Transformer implementation @@ -90,7 +100,7 @@ public class AIOTransformRegistry extends AbstractTransformRegistry { log.debug("Overriding transform with name: '{}' originally defined in '{}'.", transformerName, originalTEngine.getTransformerId()); } - transformerEngineMapping.put(transformerName, transformer); + transformerEngineMapping.put(transformerName, tEngine); log.debug("Registered transform with name: '{}' defined in '{}'.", transformerName, transformerId); } } diff --git a/alfresco-transform-imagemagick/alfresco-transform-imagemagick-boot/src/test/java/org/alfresco/transformer/ImageMagickControllerTest.java b/alfresco-transform-imagemagick/alfresco-transform-imagemagick-boot/src/test/java/org/alfresco/transformer/ImageMagickControllerTest.java index 7f1709dd..12d10691 100644 --- a/alfresco-transform-imagemagick/alfresco-transform-imagemagick-boot/src/test/java/org/alfresco/transformer/ImageMagickControllerTest.java +++ b/alfresco-transform-imagemagick/alfresco-transform-imagemagick-boot/src/test/java/org/alfresco/transformer/ImageMagickControllerTest.java @@ -26,6 +26,7 @@ */ package org.alfresco.transformer; +import static org.alfresco.transform.client.util.RequestParamMap.ENDPOINT_TRANSFORM; import static org.alfresco.transformer.util.MimetypeMap.PREFIX_IMAGE; import static org.hamcrest.Matchers.containsString; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -227,7 +228,7 @@ public class ImageMagickControllerTest extends AbstractTransformerControllerTest expectedOptions = "-auto-orient " + "-gravity " + value + " +repage"; mockMvc .perform(MockMvcRequestBuilders - .multipart("/transform") + .multipart(ENDPOINT_TRANSFORM) .file(sourceFile) .param("targetExtension", targetExtension) .param("targetMimetype", targetMimetype) @@ -244,7 +245,7 @@ public class ImageMagickControllerTest extends AbstractTransformerControllerTest { mockMvc .perform(MockMvcRequestBuilders - .multipart("/transform") + .multipart(ENDPOINT_TRANSFORM) .file(sourceFile) .param("targetExtension", targetExtension) .param("targetMimetype", targetMimetype) @@ -260,7 +261,7 @@ public class ImageMagickControllerTest extends AbstractTransformerControllerTest expectedSourceSuffix = "[2-3]"; mockMvc .perform(MockMvcRequestBuilders - .multipart("/transform") + .multipart(ENDPOINT_TRANSFORM) .file(sourceFile) .param("targetExtension", targetExtension) .param("targetMimetype", targetMimetype) @@ -298,7 +299,7 @@ public class ImageMagickControllerTest extends AbstractTransformerControllerTest expectedSourceSuffix = "[2-3]"; mockMvc .perform(MockMvcRequestBuilders - .multipart("/transform") + .multipart(ENDPOINT_TRANSFORM) .file(sourceFile) .param("targetExtension", targetExtension) .param("targetMimetype", targetMimetype) @@ -336,7 +337,7 @@ public class ImageMagickControllerTest extends AbstractTransformerControllerTest expectedOptions = "( horrible command / ); -auto-orient -resize 321x654"; mockMvc .perform(MockMvcRequestBuilders - .multipart("/transform") + .multipart(ENDPOINT_TRANSFORM) .file(sourceFile) .param("targetExtension", targetExtension) .param("targetMimetype", targetMimetype) @@ -365,7 +366,7 @@ public class ImageMagickControllerTest extends AbstractTransformerControllerTest { when(mockExecutionResult.getExitValue()).thenReturn(1); - mockMvc.perform(mockMvcRequest("/transform", sourceFile, "targetExtension", "xxx")) + mockMvc.perform(mockMvcRequest(ENDPOINT_TRANSFORM, sourceFile, "targetExtension", "xxx")) .andExpect(status().is(BAD_REQUEST.value())) .andExpect( status().reason(containsString("Transformer exit code was not 0: \nSTDERR"))); @@ -399,7 +400,7 @@ public class ImageMagickControllerTest extends AbstractTransformerControllerTest String tr = objectMapper.writeValueAsString(transformRequest); String transformationReplyAsString = mockMvc .perform(MockMvcRequestBuilders - .post("/transform") + .post(ENDPOINT_TRANSFORM) .header(ACCEPT, APPLICATION_JSON_VALUE) .header(CONTENT_TYPE, APPLICATION_JSON_VALUE) .content(tr)) diff --git a/alfresco-transform-libreoffice/alfresco-transform-libreoffice-boot/src/test/java/org/alfresco/transformer/LibreOfficeControllerTest.java b/alfresco-transform-libreoffice/alfresco-transform-libreoffice-boot/src/test/java/org/alfresco/transformer/LibreOfficeControllerTest.java index c9a71509..298f335a 100644 --- a/alfresco-transform-libreoffice/alfresco-transform-libreoffice-boot/src/test/java/org/alfresco/transformer/LibreOfficeControllerTest.java +++ b/alfresco-transform-libreoffice/alfresco-transform-libreoffice-boot/src/test/java/org/alfresco/transformer/LibreOfficeControllerTest.java @@ -27,6 +27,7 @@ package org.alfresco.transformer; import static org.alfresco.transform.client.model.Mimetype.MIMETYPE_PDF; +import static org.alfresco.transform.client.util.RequestParamMap.ENDPOINT_TRANSFORM; import static org.alfresco.transformer.util.RequestParamMap.SOURCE_MIMETYPE; import static org.alfresco.transformer.util.RequestParamMap.TARGET_EXTENSION; import static org.alfresco.transformer.util.RequestParamMap.TARGET_MIMETYPE; @@ -200,7 +201,7 @@ public class LibreOfficeControllerTest extends AbstractTransformerControllerTest mockMvc .perform(MockMvcRequestBuilders - .multipart("/transform") + .multipart(ENDPOINT_TRANSFORM) .file(sourceFile) .param(TARGET_EXTENSION, "xxx") .param(SOURCE_MIMETYPE,sourceMimetype) @@ -247,7 +248,7 @@ public class LibreOfficeControllerTest extends AbstractTransformerControllerTest String tr = objectMapper.writeValueAsString(transformRequest); String transformationReplyAsString = mockMvc .perform(MockMvcRequestBuilders - .post("/transform") + .post(ENDPOINT_TRANSFORM) .header(ACCEPT, APPLICATION_JSON_VALUE) .header(CONTENT_TYPE, APPLICATION_JSON_VALUE) .content(tr)) diff --git a/alfresco-transform-misc/alfresco-transform-misc-boot/src/test/java/org/alfresco/transformer/MiscControllerTest.java b/alfresco-transform-misc/alfresco-transform-misc-boot/src/test/java/org/alfresco/transformer/MiscControllerTest.java index d4b4ff86..89c1f71b 100644 --- a/alfresco-transform-misc/alfresco-transform-misc-boot/src/test/java/org/alfresco/transformer/MiscControllerTest.java +++ b/alfresco-transform-misc/alfresco-transform-misc-boot/src/test/java/org/alfresco/transformer/MiscControllerTest.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. * - @@ -35,6 +35,7 @@ import static org.alfresco.transform.client.model.Mimetype.MIMETYPE_OPENXML_WORD import static org.alfresco.transform.client.model.Mimetype.MIMETYPE_PDF; import static org.alfresco.transform.client.model.Mimetype.MIMETYPE_RFC822; import static org.alfresco.transform.client.model.Mimetype.MIMETYPE_TEXT_PLAIN; +import static org.alfresco.transform.client.util.RequestParamMap.ENDPOINT_TRANSFORM; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -490,7 +491,7 @@ public class MiscControllerTest extends AbstractTransformerControllerTest "test_file." + sourceExtension, sourceMimetype, content); final MockHttpServletRequestBuilder requestBuilder = super - .mockMvcRequest("/transform", sourceFile) + .mockMvcRequest(ENDPOINT_TRANSFORM, sourceFile) .param("targetExtension", targetExtension) .param("targetMimetype", targetMimetype) .param("sourceMimetype", sourceMimetype); diff --git a/alfresco-transform-pdf-renderer/alfresco-transform-pdf-renderer-boot/src/test/java/org/alfresco/transformer/AlfrescoPdfRendererControllerTest.java b/alfresco-transform-pdf-renderer/alfresco-transform-pdf-renderer-boot/src/test/java/org/alfresco/transformer/AlfrescoPdfRendererControllerTest.java index 0f729862..22a38754 100644 --- a/alfresco-transform-pdf-renderer/alfresco-transform-pdf-renderer-boot/src/test/java/org/alfresco/transformer/AlfrescoPdfRendererControllerTest.java +++ b/alfresco-transform-pdf-renderer/alfresco-transform-pdf-renderer-boot/src/test/java/org/alfresco/transformer/AlfrescoPdfRendererControllerTest.java @@ -26,6 +26,7 @@ */ package org.alfresco.transformer; +import static org.alfresco.transform.client.util.RequestParamMap.ENDPOINT_TRANSFORM; import static org.hamcrest.Matchers.containsString; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; @@ -221,7 +222,7 @@ public class AlfrescoPdfRendererControllerTest extends AbstractTransformerContro expectedOptions = "--width=321 --height=654 --allow-enlargement --maintain-aspect-ratio --page=2"; mockMvc .perform(MockMvcRequestBuilders - .multipart("/transform") + .multipart(ENDPOINT_TRANSFORM) .file(sourceFile) .param("targetExtension", targetExtension) .param("targetMimetype", targetMimetype) @@ -245,7 +246,7 @@ public class AlfrescoPdfRendererControllerTest extends AbstractTransformerContro expectedOptions = "--width=321 --height=654 --page=2"; mockMvc .perform(MockMvcRequestBuilders - .multipart("/transform") + .multipart(ENDPOINT_TRANSFORM) .file(sourceFile) .param("targetExtension", targetExtension) .param("targetMimetype", targetMimetype) @@ -277,7 +278,7 @@ public class AlfrescoPdfRendererControllerTest extends AbstractTransformerContro { when(mockExecutionResult.getExitValue()).thenReturn(1); - mockMvc.perform(mockMvcRequest("/transform", sourceFile, "targetExtension", "xxx")) + mockMvc.perform(mockMvcRequest(ENDPOINT_TRANSFORM, sourceFile, "targetExtension", "xxx")) .andExpect(status().is(BAD_REQUEST.value())) .andExpect(status() .reason(containsString("Transformer exit code was not 0: \nSTDERR"))); @@ -311,7 +312,7 @@ public class AlfrescoPdfRendererControllerTest extends AbstractTransformerContro String tr = objectMapper.writeValueAsString(transformRequest); String transformationReplyAsString = mockMvc .perform(MockMvcRequestBuilders - .post("/transform") + .post(ENDPOINT_TRANSFORM) .header(ACCEPT, APPLICATION_JSON_VALUE) .header(CONTENT_TYPE, APPLICATION_JSON_VALUE) .content(tr)) diff --git a/alfresco-transform-tika/alfresco-transform-tika-boot/src/test/java/org/alfresco/transformer/TikaControllerTest.java b/alfresco-transform-tika/alfresco-transform-tika-boot/src/test/java/org/alfresco/transformer/TikaControllerTest.java index 2727d292..c379e567 100644 --- a/alfresco-transform-tika/alfresco-transform-tika-boot/src/test/java/org/alfresco/transformer/TikaControllerTest.java +++ b/alfresco-transform-tika/alfresco-transform-tika-boot/src/test/java/org/alfresco/transformer/TikaControllerTest.java @@ -27,6 +27,7 @@ package org.alfresco.transformer; import static java.nio.file.Files.readAllBytes; +import static org.alfresco.transform.client.util.RequestParamMap.ENDPOINT_TRANSFORM; import static org.alfresco.transformer.executors.Tika.ARCHIVE; import static org.alfresco.transformer.executors.Tika.CSV; import static org.alfresco.transformer.executors.Tika.DOC; @@ -249,9 +250,9 @@ public class TikaControllerTest extends AbstractTransformerControllerTest System.out.println("Test " + transform + " " + sourceExtension + " to " + targetExtension); MockHttpServletRequestBuilder requestBuilder = includeContents == null - ? mockMvcRequest("/transform", sourceFile, + ? mockMvcRequest(ENDPOINT_TRANSFORM, sourceFile, "targetExtension", this.targetExtension) - : mockMvcRequest("/transform", sourceFile, + : mockMvcRequest(ENDPOINT_TRANSFORM, sourceFile, "targetExtension", this.targetExtension, INCLUDE_CONTENTS, includeContents.toString()); MvcResult result = mockMvc.perform(requestBuilder) .andExpect(status().is(OK.value())) @@ -368,7 +369,7 @@ public class TikaControllerTest extends AbstractTransformerControllerTest mockTransformCommand(PDF, TXT, MIMETYPE_PDF, true); targetEncoding = "rubbish"; mockMvc.perform( - mockMvcRequest("/transform", sourceFile, "targetExtension", targetExtension)) + mockMvcRequest(ENDPOINT_TRANSFORM, sourceFile, "targetExtension", targetExtension)) .andExpect(status().is(INTERNAL_SERVER_ERROR.value())); } @@ -553,7 +554,7 @@ public class TikaControllerTest extends AbstractTransformerControllerTest "\"{http://www.alfresco.org/model/content/1.0}created\":\"created1\"}"; MockHttpServletRequestBuilder requestBuilder = - super.mockMvcRequest("/transform", sourceFile, + super.mockMvcRequest(ENDPOINT_TRANSFORM, sourceFile, "targetExtension", XSLX, "metadata", metadata, "targetMimetype", MIMETYPE_METADATA_EMBED, @@ -583,7 +584,7 @@ public class TikaControllerTest extends AbstractTransformerControllerTest { mockTransformCommand(PDF, TXT, MIMETYPE_PDF, true); mockMvc.perform( - mockMvcRequest("/transform", sourceFile, "targetExtension", targetExtension).param( + mockMvcRequest(ENDPOINT_TRANSFORM, sourceFile, "targetExtension", targetExtension).param( NOT_EXTRACT_BOOKMARKS_TEXT, "true")) .andExpect(status().is(OK.value())) .andExpect(header().string("Content-Disposition", @@ -628,7 +629,7 @@ public class TikaControllerTest extends AbstractTransformerControllerTest String tr = objectMapper.writeValueAsString(transformRequest); String transformationReplyAsString = mockMvc .perform(MockMvcRequestBuilders - .post("/transform") + .post(ENDPOINT_TRANSFORM) .header(ACCEPT, APPLICATION_JSON_VALUE) .header(CONTENT_TYPE, APPLICATION_JSON_VALUE) .content(tr)) 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 3a7b64bf..af22c2ad 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 @@ -64,7 +64,10 @@ 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.transform.client.util.RequestParamMap.CONFIG_VERSION; +import static org.alfresco.transform.client.util.RequestParamMap.CONFIG_VERSION_DEFAULT; +import static org.alfresco.transform.client.util.RequestParamMap.ENDPOINT_TRANSFORM; +import static org.alfresco.transform.client.util.RequestParamMap.ENDPOINT_TRANSFORM_CONFIG; 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; @@ -141,17 +144,17 @@ public abstract class AbstractTransformerController implements TransformControll @Autowired private TransformerDebug transformerDebug; - @GetMapping(value = "/transform/config") + @GetMapping(value = ENDPOINT_TRANSFORM_CONFIG) public ResponseEntity info( - @RequestParam(value = INCLUDE_CORE_VERSION, required = false) Boolean includeCoreVersion) + @RequestParam(value = CONFIG_VERSION, defaultValue = CONFIG_VERSION_DEFAULT) int configVersion) { - logger.info("GET Transform Config" + (includeCoreVersion != null && includeCoreVersion ? " including coreVersion" : "")); + logger.info("GET Transform Config version: " + configVersion); TransformConfig transformConfig = ((TransformRegistryImpl) transformRegistry).getTransformConfig(); - transformConfig = setOrClearCoreVersion(transformConfig, includeCoreVersion); + transformConfig = setOrClearCoreVersion(transformConfig, configVersion); return new ResponseEntity<>(transformConfig, OK); } - @PostMapping(value = "/transform", consumes = MULTIPART_FORM_DATA_VALUE) + @PostMapping(value = ENDPOINT_TRANSFORM, consumes = MULTIPART_FORM_DATA_VALUE) public ResponseEntity transform(HttpServletRequest request, @RequestParam(FILE) MultipartFile sourceMultipartFile, @RequestParam(TARGET_EXTENSION) String targetExtension, @@ -206,7 +209,7 @@ public abstract class AbstractTransformerController implements TransformControll * @param timeout Transformation timeout * @return A transformation reply */ - @PostMapping(value = "/transform", produces = APPLICATION_JSON_VALUE) + @PostMapping(value = ENDPOINT_TRANSFORM, produces = APPLICATION_JSON_VALUE) @ResponseBody public ResponseEntity transform(@RequestBody TransformRequest request, @RequestParam(value = "timeout", required = false) Long timeout) diff --git a/alfresco-transformer-base/src/main/java/org/alfresco/transformer/config/WebApplicationConfig.java b/alfresco-transformer-base/src/main/java/org/alfresco/transformer/config/WebApplicationConfig.java index 467bd9e6..0efd8d23 100644 --- a/alfresco-transformer-base/src/main/java/org/alfresco/transformer/config/WebApplicationConfig.java +++ b/alfresco-transformer-base/src/main/java/org/alfresco/transformer/config/WebApplicationConfig.java @@ -38,6 +38,8 @@ import org.springframework.web.client.RestTemplate; import org.springframework.web.servlet.config.annotation.InterceptorRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; +import static org.alfresco.transform.client.util.RequestParamMap.ENDPOINT_TRANSFORM; + @Configuration public class WebApplicationConfig implements WebMvcConfigurer { @@ -46,7 +48,7 @@ public class WebApplicationConfig implements WebMvcConfigurer { registry .addInterceptor(transformInterceptor()) - .addPathPatterns("/transform", "/live", "/ready"); + .addPathPatterns(ENDPOINT_TRANSFORM, "/live", "/ready"); } @Bean diff --git a/alfresco-transformer-base/src/test/java/org/alfresco/transformer/AbstractHttpRequestTest.java b/alfresco-transformer-base/src/test/java/org/alfresco/transformer/AbstractHttpRequestTest.java index 1398f80d..7bafa372 100644 --- a/alfresco-transformer-base/src/test/java/org/alfresco/transformer/AbstractHttpRequestTest.java +++ b/alfresco-transformer-base/src/test/java/org/alfresco/transformer/AbstractHttpRequestTest.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. * - @@ -26,6 +26,7 @@ */ package org.alfresco.transformer; +import static org.alfresco.transform.client.util.RequestParamMap.ENDPOINT_TRANSFORM; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.springframework.http.HttpMethod.POST; import static org.springframework.http.MediaType.MULTIPART_FORM_DATA; @@ -125,7 +126,7 @@ public abstract class AbstractHttpRequestTest protected void sendTranformationRequest( final HttpEntity> entity, final String errorMessage) { - final ResponseEntity response = restTemplate.exchange("/transform", POST, entity, + final ResponseEntity response = restTemplate.exchange(ENDPOINT_TRANSFORM, POST, entity, String.class, ""); assertEquals(errorMessage, getErrorMessage(response.getBody())); } 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 193096ec..77ce416d 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 @@ -27,6 +27,9 @@ package org.alfresco.transformer; import static java.nio.file.StandardCopyOption.REPLACE_EXISTING; +import static org.alfresco.transform.client.util.RequestParamMap.ENDPOINT_TRANSFORM; +import static org.alfresco.transform.client.util.RequestParamMap.ENDPOINT_TRANSFORM_CONFIG_LATEST; +import static org.alfresco.transform.client.util.RequestParamMap.ENDPOINT_TRANSFORM_CONFIG; import static org.hamcrest.Matchers.containsString; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; @@ -105,7 +108,7 @@ public abstract class AbstractTransformerControllerTest protected TransformServiceRegistry transformRegistry; @Value("${transform.core.version}") - private String currentCoreVersion; + private String coreVersion; protected String sourceExtension; protected String targetExtension; @@ -213,7 +216,7 @@ public abstract class AbstractTransformerControllerTest protected MockHttpServletRequestBuilder mockMvcRequest(String url, MockMultipartFile sourceFile, String... params) { - MockHttpServletRequestBuilder builder = MockMvcRequestBuilders.multipart("/transform").file( + MockHttpServletRequestBuilder builder = MockMvcRequestBuilders.multipart(ENDPOINT_TRANSFORM).file( sourceFile); if (params.length % 2 != 0) @@ -256,7 +259,7 @@ public abstract class AbstractTransformerControllerTest public void simpleTransformTest() throws Exception { mockMvc.perform( - mockMvcRequest("/transform", sourceFile, "targetExtension", targetExtension)) + mockMvcRequest(ENDPOINT_TRANSFORM, sourceFile, "targetExtension", targetExtension)) .andExpect(status().is(OK.value())) .andExpect(content().bytes(expectedTargetFileBytes)) .andExpect(header().string("Content-Disposition", @@ -267,7 +270,7 @@ public abstract class AbstractTransformerControllerTest public void testDelayTest() throws Exception { long start = System.currentTimeMillis(); - mockMvc.perform(mockMvcRequest("/transform", sourceFile, "targetExtension", targetExtension, + mockMvc.perform(mockMvcRequest(ENDPOINT_TRANSFORM, sourceFile, "targetExtension", targetExtension, "testDelay", "400")) .andExpect(status().is(OK.value())) .andExpect(content().bytes(expectedTargetFileBytes)) @@ -282,7 +285,7 @@ public abstract class AbstractTransformerControllerTest @Test public void noTargetFileTest() throws Exception { - mockMvc.perform(mockMvcRequest("/transform", sourceFile, "targetExtension", "xxx")) + mockMvc.perform(mockMvcRequest(ENDPOINT_TRANSFORM, sourceFile, "targetExtension", "xxx")) .andExpect(status().is(INTERNAL_SERVER_ERROR.value())); } @@ -294,7 +297,7 @@ public abstract class AbstractTransformerControllerTest expectedSourceFileBytes); mockMvc.perform( - mockMvcRequest("/transform", sourceFile, "targetExtension", targetExtension)) + mockMvcRequest(ENDPOINT_TRANSFORM, sourceFile, "targetExtension", targetExtension)) .andExpect(status().is(OK.value())) .andExpect(content().bytes(expectedTargetFileBytes)) .andExpect(header().string("Content-Disposition", @@ -309,7 +312,7 @@ public abstract class AbstractTransformerControllerTest expectedSourceFileBytes); mockMvc.perform( - mockMvcRequest("/transform", sourceFile, "targetExtension", targetExtension)) + mockMvcRequest(ENDPOINT_TRANSFORM, sourceFile, "targetExtension", targetExtension)) .andExpect(status().is(OK.value())) .andExpect(content().bytes(expectedTargetFileBytes)) .andExpect(header().string("Content-Disposition", @@ -323,7 +326,7 @@ public abstract class AbstractTransformerControllerTest sourceFile = new MockMultipartFile("file", "abc/", sourceMimetype, expectedSourceFileBytes); mockMvc.perform( - mockMvcRequest("/transform", sourceFile, "targetExtension", targetExtension)) + mockMvcRequest(ENDPOINT_TRANSFORM, sourceFile, "targetExtension", targetExtension)) .andExpect(status().is(BAD_REQUEST.value())) .andExpect(status().reason(containsString("The source filename was not supplied"))); } @@ -334,14 +337,14 @@ public abstract class AbstractTransformerControllerTest sourceFile = new MockMultipartFile("file", "", sourceMimetype, expectedSourceFileBytes); mockMvc.perform( - mockMvcRequest("/transform", sourceFile, "targetExtension", targetExtension)) + mockMvcRequest(ENDPOINT_TRANSFORM, sourceFile, "targetExtension", targetExtension)) .andExpect(status().is(BAD_REQUEST.value())); } @Test public void noTargetExtensionTest() throws Exception { - mockMvc.perform(mockMvcRequest("/transform", sourceFile)) + mockMvc.perform(mockMvcRequest(ENDPOINT_TRANSFORM, sourceFile)) .andExpect(status().is(BAD_REQUEST.value())) .andExpect(status().reason( containsString("Request parameter 'targetExtension' is missing"))); @@ -386,7 +389,7 @@ public abstract class AbstractTransformerControllerTest String tr = objectMapper.writeValueAsString(transformRequest); String transformationReplyAsString = mockMvc .perform(MockMvcRequestBuilders - .post("/transform") + .post(ENDPOINT_TRANSFORM) .header(ACCEPT, APPLICATION_JSON_VALUE) .header(CONTENT_TYPE, APPLICATION_JSON_VALUE) .content(tr)) @@ -415,13 +418,13 @@ public abstract class AbstractTransformerControllerTest TransformConfig expectedTransformConfig = objectMapper .readValue(getTestFile(getEngineConfigName(), true), TransformConfig.class); - expectedTransformConfig.getTransformers().forEach(transformer -> transformer.setCoreVersion(currentCoreVersion)); + expectedTransformConfig.getTransformers().forEach(transformer -> transformer.setCoreVersion(coreVersion)); ReflectionTestUtils.setField(transformRegistry, "engineConfig", new ClassPathResource(getEngineConfigName())); String response = mockMvc - .perform(MockMvcRequestBuilders.get("/transform/config?includeCoreVersion=true")) + .perform(MockMvcRequestBuilders.get(ENDPOINT_TRANSFORM_CONFIG_LATEST)) .andExpect(status().is(OK.value())) .andExpect(header().string(CONTENT_TYPE, APPLICATION_JSON_VALUE)) .andReturn().getResponse().getContentAsString(); @@ -442,7 +445,7 @@ public abstract class AbstractTransformerControllerTest new ClassPathResource(getEngineConfigName())); String response = mockMvc - .perform(MockMvcRequestBuilders.get("/transform/config")) + .perform(MockMvcRequestBuilders.get(ENDPOINT_TRANSFORM_CONFIG)) .andExpect(status().is(OK.value())) .andExpect(header().string(CONTENT_TYPE, APPLICATION_JSON_VALUE)) .andReturn().getResponse().getContentAsString(); @@ -460,7 +463,7 @@ public abstract class AbstractTransformerControllerTest new ClassPathResource("engine_config_with_duplicates.json")); String response = mockMvc - .perform(MockMvcRequestBuilders.get("/transform/config")) + .perform(MockMvcRequestBuilders.get(ENDPOINT_TRANSFORM_CONFIG)) .andExpect(status().is(OK.value())) .andExpect(header().string(CONTENT_TYPE, APPLICATION_JSON_VALUE)) .andReturn().getResponse().getContentAsString(); @@ -487,7 +490,7 @@ public abstract class AbstractTransformerControllerTest new ClassPathResource("engine_config_incomplete.json")); String response = mockMvc - .perform(MockMvcRequestBuilders.get("/transform/config")) + .perform(MockMvcRequestBuilders.get(ENDPOINT_TRANSFORM_CONFIG)) .andExpect(status().is(OK.value())) .andExpect(header().string(CONTENT_TYPE, APPLICATION_JSON_VALUE)) .andReturn().getResponse().getContentAsString(); @@ -510,7 +513,7 @@ public abstract class AbstractTransformerControllerTest new ClassPathResource("engine_config_no_transform_options.json")); String response = mockMvc - .perform(MockMvcRequestBuilders.get("/transform/config")) + .perform(MockMvcRequestBuilders.get(ENDPOINT_TRANSFORM_CONFIG)) .andExpect(status().is(OK.value())) .andExpect(header().string(CONTENT_TYPE, APPLICATION_JSON_VALUE)) .andReturn().getResponse().getContentAsString(); diff --git a/alfresco-transformer-base/src/test/java/org/alfresco/transformer/EngineClient.java b/alfresco-transformer-base/src/test/java/org/alfresco/transformer/EngineClient.java index cdb83032..78a2c7cc 100644 --- a/alfresco-transformer-base/src/test/java/org/alfresco/transformer/EngineClient.java +++ b/alfresco-transformer-base/src/test/java/org/alfresco/transformer/EngineClient.java @@ -1,5 +1,5 @@ /* - * Copyright 2015-2019 Alfresco Software, Ltd. All rights reserved. + * Copyright 2015-2022 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 @@ -8,6 +8,7 @@ package org.alfresco.transformer; import static java.util.Collections.emptyMap; +import static org.alfresco.transform.client.util.RequestParamMap.ENDPOINT_TRANSFORM; import static org.springframework.http.MediaType.MULTIPART_FORM_DATA; import java.util.Map; @@ -63,6 +64,6 @@ public class EngineClient final HttpEntity> entity = new HttpEntity<>(body, headers); - return REST_TEMPLATE.postForEntity(engineUrl + "/transform", entity, Resource.class); + return REST_TEMPLATE.postForEntity(engineUrl + ENDPOINT_TRANSFORM, entity, Resource.class); } } diff --git a/pom.xml b/pom.xml index 5f8a7eb9..fd28f68b 100644 --- a/pom.xml +++ b/pom.xml @@ -21,7 +21,7 @@ 2.0.25 3.0.1.12 ${project.version} - 1.4.9 + 1.4.10 5.16.3 2.13.1 ${dependency.jackson.version}