mirror of
https://github.com/Alfresco/alfresco-transform-core.git
synced 2025-08-14 17:58:27 +00:00
ACS-2498 Switch to using a configVersion parameter on the /transform/config endpoint (#530)
* Fixed the config returned by the AIO as it did not include the coreVersion even though the individual ones did.
This commit is contained in:
@@ -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<TransformConfig> 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);
|
||||
}
|
||||
|
||||
|
@@ -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;
|
||||
|
@@ -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<TransformConfig> 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<TransformConfig> 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);
|
||||
});
|
||||
}
|
||||
}
|
@@ -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<String, Transformer> 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);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user