Skip to content

Commit 00c8fc7

Browse files
authored
ACS-1998 Enhance the transform config (#484)
1 parent 3b6169b commit 00c8fc7

File tree

6 files changed

+35
-33
lines changed

6 files changed

+35
-33
lines changed

alfresco-transform-core-aio/alfresco-transform-core-aio-boot/src/main/java/org/alfresco/transformer/AIOCustomConfig.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* #%L
33
* Alfresco Transform Core
44
* %%
5-
* Copyright (C) 2005 - 2020 Alfresco Software Limited
5+
* Copyright (C) 2005 - 2021 Alfresco Software Limited
66
* %%
77
* This file is part of the Alfresco software.
88
* -
@@ -93,6 +93,7 @@ public TransformServiceRegistry aioTransformRegistry() throws Exception
9393
aioTransformRegistry.registerTransformer(new ImageMagickCommandExecutor(imageMagickExePath, imageMagickDynPath, imageMagickRootPath, imageMagickCodersPath, imageMagickConfigPath));
9494
aioTransformRegistry.registerTransformer(new LibreOfficeJavaExecutor(libreofficePath, libreofficeMaxTasksPerProcess, libreofficeTimeout, libreofficePortNumbers, libreofficeTemplateProfileDir, libreofficeIsEnabled));
9595
aioTransformRegistry.registerTransformer(new PdfRendererCommandExecutor(pdfRendererPath));
96+
aioTransformRegistry.registerCombinedTransformers();
9697
return aioTransformRegistry;
9798
}
9899
}

alfresco-transform-core-aio/alfresco-transform-core-aio/src/main/java/org/alfresco/transformer/AIOTransformRegistry.java

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* #%L
33
* Alfresco Transform Core
44
* %%
5-
* Copyright (C) 2005 - 2020 Alfresco Software Limited
5+
* Copyright (C) 2005 - 2021 Alfresco Software Limited
66
* %%
77
* This file is part of the Alfresco software.
88
* -
@@ -29,6 +29,7 @@
2929
import com.fasterxml.jackson.databind.ObjectMapper;
3030
import org.alfresco.transform.client.model.config.TransformConfig;
3131
import org.alfresco.transform.client.registry.AbstractTransformRegistry;
32+
import org.alfresco.transform.client.registry.CombinedTransformConfig;
3233
import org.alfresco.transform.client.registry.TransformCache;
3334
import org.alfresco.transformer.executors.Transformer;
3435
import org.slf4j.Logger;
@@ -52,7 +53,7 @@ public class AIOTransformRegistry extends AbstractTransformRegistry
5253

5354
private static final String ENGINE_CONFIG_LOCATION_POSTFIX = "_engine_config.json";
5455

55-
private TransformConfig aggregatedConfig = new TransformConfig();
56+
private CombinedTransformConfig combinedTransformConfig = new CombinedTransformConfig();
5657

5758
// Holds the structures used by AbstractTransformRegistry to look up what is supported.
5859
// 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
6465
private Map<String, Transformer> transformerEngineMapping = new HashMap();
6566

6667
/**
67-
* The registration will go through all supported sub transformers and map them to the transformer implementation.
68+
* Adds a transformer's (T-Engine) config to the configuration and creates a map of transforms to the T-Engine.
69+
* The name of this method is now misleading as the registry of transforms takes place in
70+
* {@link #registerCombinedTransformers()} .
6871
* @param transformer The transformer implementation, this could be a single transformer
6972
* or a transformer managing multiple sub transformers. The transformer's configuration file will
7073
* be read based on the {@link Transformer#getTransformerId()} value.
71-
* @throws Exception Exception is thrown if a mapping for a transformer name already exists.
7274
*/
7375
public void registerTransformer(final Transformer transformer) throws Exception
7476
{
7577
// Load config for the transformer
7678
String location = getTransformConfigLocation(transformer);
7779
TransformConfig transformConfig = loadTransformConfig(location);
80+
String transformerId = transformer.getTransformerId();
81+
combinedTransformConfig.addTransformConfig(transformConfig, location, transformerId, this);
7882

7983
// Map all of the transforms defined in the config to this Transformer implementation
8084
for (org.alfresco.transform.client.model.config.Transformer transformerConfig : transformConfig.getTransformers())
8185
{
8286
String transformerName = transformerConfig.getTransformerName();
83-
if (transformerEngineMapping.containsKey(transformerName))
87+
// A later tEngine 'might' override one that has already been defined. That is fine.
88+
Transformer originalTEngine = transformerEngineMapping.get(transformerName);
89+
if (originalTEngine != null)
8490
{
85-
throw new Exception("Transformer name " + transformerName + " is already registered.");
91+
log.debug("Overriding transform with name: '{}' originally defined in '{}'.", transformerName, originalTEngine.getTransformerId());
8692
}
8793
transformerEngineMapping.put(transformerName, transformer);
88-
log.debug("Registered transformer with name: '{}'.", transformerName);
94+
log.debug("Registered transform with name: '{}' defined in '{}'.", transformerName, transformerId);
8995
}
96+
}
9097

91-
// Add the new transformer configuration to the aggregate config
92-
aggregatedConfig.getTransformers().addAll(transformConfig.getTransformers());
93-
aggregatedConfig.getTransformOptions().putAll(transformConfig.getTransformOptions());
94-
registerAll(transformConfig, location, location);
98+
public void registerCombinedTransformers()
99+
{
100+
combinedTransformConfig.combineTransformerConfig(this);
101+
combinedTransformConfig.registerCombinedTransformers(this);
95102
}
96103

97104
/**
@@ -110,7 +117,7 @@ public Transformer getByTransformName(final String transformName)
110117
*/
111118
public TransformConfig getTransformConfig()
112119
{
113-
return aggregatedConfig;
120+
return combinedTransformConfig.buildTransformConfig();
114121
}
115122

116123
protected String getTransformConfigLocation(final Transformer transformer)

alfresco-transform-core-aio/alfresco-transform-core-aio/src/test/java/org/alfresco/transformer/AIOTransformRegistryTest.java

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public void before() throws Exception
7171
{
7272
aioTransformerRegistry.registerTransformer(new SelectingTransformer());
7373
aioTransformerRegistry.registerTransformer(new TikaJavaExecutor());
74-
74+
aioTransformerRegistry.registerCombinedTransformers();
7575
}
7676

7777
private void writeToFile(File file, String content, String encoding) throws Exception
@@ -155,15 +155,6 @@ public void testTransformerMapping()
155155
}
156156
}
157157

158-
@Test
159-
public void testDuplicateTransformsException() throws Exception
160-
{
161-
assertThrows(Exception.class, () ->{
162-
// The Misc transformers are already registered
163-
aioTransformerRegistry.registerTransformer(new SelectingTransformer());
164-
});
165-
}
166-
167158
// Test copied from Misc (HtmlParserContentTransformerTest) See ATS-712 aioTransformerRegistry - html
168159
@Test
169160
public void testMiscHtml() throws Exception

alfresco-transformer-base/src/main/java/org/alfresco/transformer/TransformRegistryImpl.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* #%L
33
* Alfresco Repository
44
* %%
5-
* Copyright (C) 2005 - 2018 Alfresco Software Limited
5+
* Copyright (C) 2005 - 2021 Alfresco Software Limited
66
* %%
77
* This file is part of the Alfresco software.
88
* If the software was purchased under a paid Alfresco license, the terms of
@@ -36,6 +36,7 @@
3636

3737
import org.alfresco.transform.client.model.config.TransformConfig;
3838
import org.alfresco.transform.client.registry.AbstractTransformRegistry;
39+
import org.alfresco.transform.client.registry.CombinedTransformConfig;
3940
import org.alfresco.transform.client.registry.TransformCache;
4041
import org.alfresco.transform.exceptions.TransformException;
4142
import org.slf4j.Logger;
@@ -67,7 +68,8 @@ public void afterPropertiesSet()
6768
{
6869
engineConfig = resourceLoader.getResource(locationFromProperty);
6970
TransformConfig transformConfig = getTransformConfig();
70-
registerAll(transformConfig, null, locationFromProperty);
71+
// There is only one TransformConfig in a T-Engine so the following call is fine
72+
CombinedTransformConfig.combineAndRegister(transformConfig, locationFromProperty, "---", this);
7173
}
7274

7375
// Holds the structures used by AbstractTransformRegistry to look up what is supported.

alfresco-transformer-base/src/test/java/org/alfresco/transformer/AbstractTransformerControllerTest.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,10 @@ private Transformer buildTransformer(String sourceMediaType, String targetMediaT
503503
private Transformer buildTransformer(String sourceMediaType, String targetMediaType)
504504
{
505505
Set<SupportedSourceAndTarget> supportedSourceAndTargetList = ImmutableSet.of(
506-
new SupportedSourceAndTarget(sourceMediaType, targetMediaType, -1));
506+
SupportedSourceAndTarget.builder()
507+
.withSourceMediaType(sourceMediaType)
508+
.withTargetMediaType(targetMediaType)
509+
.build());
507510

508511
Transformer transformer = new Transformer();
509512
transformer.setSupportedSourceAndTargetList(supportedSourceAndTargetList);

pom.xml

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
33
<modelVersion>4.0.0</modelVersion>
4+
<groupId>org.alfresco</groupId>
5+
<artifactId>alfresco-transform-core</artifactId>
6+
<version>2.5.4-SNAPSHOT</version>
7+
<packaging>pom</packaging>
48

59
<parent>
610
<groupId>org.springframework.boot</groupId>
711
<artifactId>spring-boot-starter-parent</artifactId>
812
<version>2.5.6</version>
9-
<relativePath />
1013
</parent>
1114

12-
<groupId>org.alfresco</groupId>
13-
<artifactId>alfresco-transform-core</artifactId>
14-
<version>2.5.4-SNAPSHOT</version>
15-
<packaging>pom</packaging>
16-
1715
<properties>
1816
<java.version>11</java.version>
1917
<maven.compiler.source>11</maven.compiler.source>
@@ -23,7 +21,7 @@
2321
<dependency.pdfbox.version>2.0.24</dependency.pdfbox.version>
2422
<dependency.alfresco-jodconverter-core.version>3.0.1.12</dependency.alfresco-jodconverter-core.version>
2523
<env.project_version>${project.version}</env.project_version>
26-
<dependency.alfresco-transform-model.version>1.4.0</dependency.alfresco-transform-model.version>
24+
<dependency.alfresco-transform-model.version>1.4.3</dependency.alfresco-transform-model.version>
2725
<dependency.activemq.version>5.16.3</dependency.activemq.version>
2826
<dependency.jackson.version>2.13.0</dependency.jackson.version>
2927
<dependency.jackson-databind.version>${dependency.jackson.version}</dependency.jackson-databind.version>

0 commit comments

Comments
 (0)