diff --git a/source/java/org/alfresco/repo/content/transform/TransformerConfigLimits.java b/source/java/org/alfresco/repo/content/transform/TransformerConfigLimits.java index 6db250b203..0aa0246428 100644 --- a/source/java/org/alfresco/repo/content/transform/TransformerConfigLimits.java +++ b/source/java/org/alfresco/repo/content/transform/TransformerConfigLimits.java @@ -102,13 +102,45 @@ public class TransformerConfigLimits extends TransformerPropertyNameExtractor } } - // Returns the 'effective' properties for the given 'use'. These will be made up from the - // properties defined for that use plus default properties that don't have a matching use - // property. + /** + * Returns the 'effective' properties for the given 'use'. + * + * These will be made up from the properties defined for that use plus default properties + * that don't have a matching use property, as long as there is not a matching use at a + * higher level.

+ * + *

  • If there is a system wide property with the use value, all other properties without + * the same use value are ignored.
  • + *
  • If there is a transformer wide property with this use value, all other transformer + * wide properties for the same transformer without a use value are ignored. + *
  • If there is mimetype property with the use value, the default property for + * the same combination is ignored.
  • + * @param use value such as "doclib" or "index" + * @param allUseMap the complete set of transformer properties that includes blank and all + * use values. + * @return a set of properties for the specific use. + */ private Collection getPropertiesForUse(String use, Map allUseMap) { Collection properties = new ArrayList(); + + boolean systemWideUse = false; + Set transformerWideUse = new HashSet<>(); + for (TransformerSourceTargetSuffixValue property: allUseMap.values()) + { + String propertyUse = property.use == null ? ANY : property.use; + if (propertyUse.equals(use)) + { + if (DEFAULT_TRANSFORMER.equals(property.transformerName)) + { + systemWideUse = true; + break; + } + + transformerWideUse.add(property.transformerName); + } + } for (TransformerSourceTargetSuffixValue property: allUseMap.values()) { @@ -117,14 +149,21 @@ public class TransformerConfigLimits extends TransformerPropertyNameExtractor { properties.add(property); } - else if (propertyUse.equals(ANY) && - getProperty(property.transformerName, property.sourceExt, property.targetExt, - property.suffix, use, allUseMap) == null) + else if (!systemWideUse && propertyUse.equals(ANY)) { - properties.add(property); + if (DEFAULT_TRANSFORMER.equals(property.transformerName) || + !transformerWideUse.contains(property.transformerName)) + { + // If there is NOT a similar 'use' property... + if (getProperty(property.transformerName, property.sourceExt, property.targetExt, + property.suffix, use, allUseMap) == null) + { + properties.add(property); + } + } } } - + return properties; } diff --git a/source/java/org/alfresco/repo/content/transform/TransformerPropertySetter.java b/source/java/org/alfresco/repo/content/transform/TransformerPropertySetter.java index cfbede5bf7..a1705a18a3 100644 --- a/source/java/org/alfresco/repo/content/transform/TransformerPropertySetter.java +++ b/source/java/org/alfresco/repo/content/transform/TransformerPropertySetter.java @@ -264,6 +264,21 @@ public class TransformerPropertySetter String transformerName = null; String suffix = null; String separator = null; + + int k = propertyName.lastIndexOf(TransformerConfig.USE); + if (k != -1) + { + int l = k+TransformerConfig.USE.length(); + + if (propertyName.length()-l > 0) + { + propertyName = propertyName.substring(0, k); + } + else + { + throw unexpectedProperty("Missing use value after ...use. ", line); + } + } suffixesLoop: for (String aSuffix: TransformerConfig.ALL_SUFFIXES) diff --git a/source/test-java/org/alfresco/repo/content/transform/TransformerConfigLimitsTest.java b/source/test-java/org/alfresco/repo/content/transform/TransformerConfigLimitsTest.java index 6895781122..d0be79092f 100644 --- a/source/test-java/org/alfresco/repo/content/transform/TransformerConfigLimitsTest.java +++ b/source/test-java/org/alfresco/repo/content/transform/TransformerConfigLimitsTest.java @@ -210,15 +210,20 @@ public class TransformerConfigLimitsTest public void transformerUseTest() { mockProperties(transformerProperties, - "content.transformer.transformer1.maxSourceSizeKBytes", "10", - "content.transformer.transformer1.maxSourceSizeKBytes.use.index", "20"); + "content.transformer.transformer2.maxSourceSizeKBytes", "10", + "content.transformer.transformer1.maxSourceSizeKBytes.use.index", "20", + // The following is ignored when "index" is specified, as the 'use' property is transformer wide. + "content.transformer.transformer1.maxSourceSizeKBytes", "30"); extractor = new TransformerConfigLimits(transformerProperties, mimetypeService); TransformationOptionLimits limits = extractor.getLimits(transformer1, "application/pdf", "image/png", null); - assertEquals(10, limits.getMaxSourceSizeKBytes()); + assertEquals(30, limits.getMaxSourceSizeKBytes()); limits = extractor.getLimits(transformer1, "application/pdf", "image/png", "index"); assertEquals(20, limits.getMaxSourceSizeKBytes()); + + limits = extractor.getLimits(transformer2, "application/pdf", "image/png", "index"); + assertEquals(10, limits.getMaxSourceSizeKBytes()); } @Test @@ -227,13 +232,18 @@ public class TransformerConfigLimitsTest { mockProperties(transformerProperties, "content.transformer.default.extensions.pdf.png.maxSourceSizeKBytes", "10", - "content.transformer.default.extensions.pdf.png.maxSourceSizeKBytes.use.index", "20"); + "content.transformer.default.extensions.pdf.png.maxSourceSizeKBytes.use.index", "20", + // The following is ignored when "index" is specified, as the 'use' property is system wide. + "content.transformer.transformer2.maxSourceSizeKBytes", "30"); extractor = new TransformerConfigLimits(transformerProperties, mimetypeService); TransformationOptionLimits limits = extractor.getLimits(transformer1, "application/pdf", "image/png", null); assertEquals(10, limits.getMaxSourceSizeKBytes()); - limits = extractor.getLimits(transformer1, "application/pdf", "image/png", "index"); + limits = extractor.getLimits(transformer2, "application/pdf", "image/png", "doclib"); + assertEquals(30, limits.getMaxSourceSizeKBytes()); + + limits = extractor.getLimits(transformer2, "application/pdf", "image/png", "index"); assertEquals(20, limits.getMaxSourceSizeKBytes()); } @@ -260,6 +270,7 @@ public class TransformerConfigLimitsTest mockProperties(transformerProperties, "content.transformer.default.maxSourceSizeKBytes", "10", "content.transformer.default.maxSourceSizeKBytes.use.index", "20", + // The following is ignored when "index" is specified, as the 'use' property is system wide. "content.transformer.transformer2.maxSourceSizeKBytes", "30"); extractor = new TransformerConfigLimits(transformerProperties, mimetypeService); @@ -273,7 +284,7 @@ public class TransformerConfigLimitsTest assertEquals(20, limits.getMaxSourceSizeKBytes()); limits = extractor.getLimits(transformer2, "application/pdf", "image/png", "index"); - assertEquals(30, limits.getMaxSourceSizeKBytes()); + assertEquals(20, limits.getMaxSourceSizeKBytes()); } @Test diff --git a/source/test-java/org/alfresco/repo/content/transform/TransformerPropertySetterTest.java b/source/test-java/org/alfresco/repo/content/transform/TransformerPropertySetterTest.java index 07652474c0..09404b227b 100644 --- a/source/test-java/org/alfresco/repo/content/transform/TransformerPropertySetterTest.java +++ b/source/test-java/org/alfresco/repo/content/transform/TransformerPropertySetterTest.java @@ -232,6 +232,17 @@ public class TransformerPropertySetterTest "content.transformer.default.maxPages", "-1")); } + + @Test + public void defaultUseTransformerTest() + { + setter.setProperties( + "content.transformer.default.maxSourceSizeKBytes.use.doclib=67"); + + verify(transformerProperties).setProperties(expectedProperties( + "content.transformer.default.maxSourceSizeKBytes.use.doclib", "67")); + } + @Test public void commentAndWhiteSpaceTest() {