From 3ab25de00ef0c0dc824616c7dd45b07af46b1845 Mon Sep 17 00:00:00 2001 From: Alan Davis Date: Sat, 22 Feb 2020 22:22:42 +0000 Subject: [PATCH] Repo-4710 Exclude duplicates wildcard with the first transformer, if it has the same options. --- .../client/registry/CombinedConfig.java | 33 +++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/alfresco/transform/client/registry/CombinedConfig.java b/src/main/java/org/alfresco/transform/client/registry/CombinedConfig.java index dfe100b7c8..a8b1f2a11d 100644 --- a/src/main/java/org/alfresco/transform/client/registry/CombinedConfig.java +++ b/src/main/java/org/alfresco/transform/client/registry/CombinedConfig.java @@ -48,6 +48,7 @@ import org.apache.http.util.EntityUtils; import java.io.IOException; import java.io.StringReader; import java.util.ArrayList; +import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -369,6 +370,7 @@ public class CombinedConfig boolean first = true; String sourceMediaType = null; Set sourceMediaTypesAndMaxSizes = null; + Set firstTransformOptions = null; for (TransformStep step : pipeline) { String name = step.getTransformerName(); @@ -386,6 +388,7 @@ public class CombinedConfig filter(s -> stepTrg.equals(s.getTargetMediaType())). collect(Collectors.toSet()); sourceMediaType = stepTrg; + firstTransformOptions = stepTransformer.getTransformOptions(); } else { @@ -405,8 +408,13 @@ public class CombinedConfig withTargetMediaType(trg).build())). collect(Collectors.toSet()); - // Exclude duplicates with the first transformer, as there is no point doing more work. - supportedSourceAndTargets.removeAll(sourceMediaTypesAndMaxSizes); + // Exclude duplicates with the first transformer, if it has the same options. + // There is no point doing more work. + Set transformOptions = transformer.getTransformOptions(); + if (sameOptions(transformOptions, firstTransformOptions)) + { + supportedSourceAndTargets.removeAll(sourceMediaTypesAndMaxSizes); + } transformer.setSupportedSourceAndTargetList(supportedSourceAndTargets); } @@ -428,4 +436,25 @@ public class CombinedConfig } }); } + + private boolean sameOptions(Set transformOptionNames1, Set transformOptionNames2) + { + // They have the same names + if (transformOptionNames1.equals(transformOptionNames2)) + { + return true; + } + + // Check the actual options. + Set transformOptions1 = getTransformOptions(transformOptionNames1); + Set transformOptions2 = getTransformOptions(transformOptionNames2); + return transformOptions1.equals(transformOptions2); + } + + private Set getTransformOptions(Set transformOptionNames) + { + Set transformOptions = new HashSet<>(); + transformOptionNames.forEach(name->transformOptions.addAll(combinedTransformOptions.get(name))); + return transformOptions; + } }