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 * -
2929import com .fasterxml .jackson .databind .ObjectMapper ;
3030import org .alfresco .transform .client .model .config .TransformConfig ;
3131import org .alfresco .transform .client .registry .AbstractTransformRegistry ;
32+ import org .alfresco .transform .client .registry .CombinedTransformConfig ;
3233import org .alfresco .transform .client .registry .TransformCache ;
3334import org .alfresco .transformer .executors .Transformer ;
3435import 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 )
0 commit comments