Merged 5.1.N (5.1.1) to HEAD (5.2)

122983 rmunteanu: Merged 5.0.N (5.0.4) to 5.1.N (5.1.1)
      122910 rmunteanu: Merged V4.2-BUG-FIX (4.2.7) to 5.0.N (5.0.4)
         122808 adavis: MNT-15738 Property to disable transformers by use (e.g. doclib thumbnail generation) in 4.2 is not working
            - Allow 'use' style properties to be set
            - Combine 'use' properties more flexibly with the default ones.


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@123686 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Alan Davis
2016-03-11 22:32:22 +00:00
parent c6eef005f3
commit 9aea46c7ae
4 changed files with 90 additions and 14 deletions

View File

@@ -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.<p>
*
* <li>If there is a system wide property with the use value, all other properties without
* the same use value are ignored.</li>
* <li>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.
* <li>If there is mimetype property with the use value, the default property for
* the same combination is ignored.</li>
* @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<TransformerSourceTargetSuffixValue> getPropertiesForUse(String use,
Map<TransformerSourceTargetSuffixKey, TransformerSourceTargetSuffixValue> allUseMap)
{
Collection<TransformerSourceTargetSuffixValue> properties = new ArrayList<TransformerSourceTargetSuffixValue>();
boolean systemWideUse = false;
Set<String> 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;
}

View File

@@ -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)

View File

@@ -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

View File

@@ -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()
{