use of org.alfresco.transform.client.model.config.TransformOption in project alfresco-repository by Alfresco.
the class TransformServiceRegistryConfigTest method retrieveTransformOptionByPropertyName.
private TransformOption retrieveTransformOptionByPropertyName(TransformOptionGroup transformOptionGroup, String propertyName, String propertyType) {
Iterator<TransformOption> iterator = transformOptionGroup.getTransformOptions().iterator();
List<TransformOption> transformOptionsList = new ArrayList<>();
while (iterator.hasNext()) {
transformOptionsList.add(iterator.next());
}
for (TransformOption t : transformOptionsList) {
if (t instanceof TransformOptionValue) {
TransformOptionValue value = (TransformOptionValue) t;
if (propertyType.equalsIgnoreCase("TransformOptionValue")) {
if (value.getName().equalsIgnoreCase(propertyName))
return value;
} else {
if (value.getName().contains(propertyName))
return transformOptionGroup;
}
} else {
TransformOption result = retrieveTransformOptionByPropertyName((TransformOptionGroup) t, propertyName, propertyType);
if (result != null)
return result;
}
}
return null;
}
use of org.alfresco.transform.client.model.config.TransformOption in project alfresco-repository by Alfresco.
the class LocalTransformServiceRegistry method lookupTransformOptions.
/**
* Returns the set of TransformOptions for this transform. In the JSON structure, each transform lists the names
* of each set of transform options it uses. In the case of pipelines and failovers transforms, there is typically
* more than one set. Typically there is one for each child transform.
* @param transformOptionNames the names of the transform options used by this transform.
* @param transformOptions a map keyed on transform option name of all the TransformOptions
* @param readFrom used in debug messages to indicate where the transformer config was read from.
* @param logError used to log an error message if a transformOptionName is invalid.
*/
private static Set<TransformOption> lookupTransformOptions(final Set<String> transformOptionNames, final Map<String, Set<TransformOption>> transformOptions, final String readFrom, final Consumer<String> logError) {
if (transformOptionNames == null) {
return emptySet();
}
final Set<TransformOption> options = new HashSet<>();
for (String name : transformOptionNames) {
final Set<TransformOption> oneSetOfTransformOptions = transformOptions.get(name);
if (oneSetOfTransformOptions == null) {
logError.accept("transformOptions in " + readFrom + " with the name " + name + " does not exist. Ignored");
continue;
}
options.add(new TransformOptionGroup(false, oneSetOfTransformOptions));
}
// rather than having a nested structure.
return options.size() == 1 ? ((TransformOptionGroup) options.iterator().next()).getTransformOptions() : options;
}
use of org.alfresco.transform.client.model.config.TransformOption in project alfresco-repository by Alfresco.
the class TransformServiceRegistryConfigTest method testJsonPipeline.
@Test
public void testJsonPipeline() throws IOException {
register(getTransformServiceConfigPipeline());
// Check the count of transforms supported
int expectedTransforms = getExpectedTransformsForTestJsonPipeline();
assertEquals("The number of UNIQUE source to target mimetypes transforms has changed. Config change?", expectedTransforms, countSupportedTransforms(true));
assertEquals("The number of source to target mimetypes transforms has changed. " + "There may be multiple transformers for the same combination. Config change?", expectedTransforms, countSupportedTransforms(false));
// Check required and optional default correctly
Map<String, List<SupportedTransform>> transformsToWord = registry.getData().getTransforms().get(DOC);
List<SupportedTransform> supportedTransforms = transformsToWord.get(GIF);
SupportedTransform supportedTransform = supportedTransforms.get(0);
Set<TransformOption> transformOptionsSet = supportedTransform.getTransformOptions().getTransformOptions();
Iterator<TransformOption> iterator = transformOptionsSet.iterator();
assertTrue("Expected transform values", iterator.hasNext());
// Because Set is unordered we don't know which TransformOptionGroup we retrieve
TransformOptionGroup transformOptions1 = (TransformOptionGroup) iterator.next();
assertTrue("Expected transform values", iterator.hasNext());
TransformOptionGroup transformOptions2 = (TransformOptionGroup) iterator.next();
TransformOptionGroup imagemagick;
TransformOptionGroup pdf;
if (containsTransformOptionValueName(transformOptions1, "alphaRemove")) {
imagemagick = transformOptions1;
pdf = transformOptions2;
} else {
imagemagick = transformOptions2;
pdf = transformOptions1;
}
TransformOptionValue alphaRemove = (TransformOptionValue) retrieveTransformOptionByPropertyName(imagemagick, "alphaRemove", "TransformOptionValue");
TransformOptionGroup crop = (TransformOptionGroup) retrieveTransformOptionByPropertyName(imagemagick, "crop", "TransformOptionGroup");
TransformOptionValue cropGravity = (TransformOptionValue) retrieveTransformOptionByPropertyName(crop, "cropGravity", "TransformOptionValue");
TransformOptionValue cropWidth = (TransformOptionValue) retrieveTransformOptionByPropertyName(crop, "cropWidth", "TransformOptionValue");
assertTrue("The holding group should be required", supportedTransform.getTransformOptions().isRequired());
assertFalse("imagemagick should be optional as it is not set", imagemagick.isRequired());
assertFalse("pdf should be optional as required is not set", pdf.isRequired());
assertEquals("alphaRemove", alphaRemove.getName());
assertEquals("cropGravity", cropGravity.getName());
assertEquals("cropWidth", cropWidth.getName());
assertFalse("alphaRemove should be optional as required is not set", alphaRemove.isRequired());
assertFalse("crop should be optional as required is not set", crop.isRequired());
assertTrue("cropGravity should be required as it is set", cropGravity.isRequired());
assertFalse("cropWidth should be optional as required is not set", cropWidth.isRequired());
// Check a supported transform for each transformer.
assertSupported(DOC, 1234, GIF, emptyMap(), null, "");
assertSupported(DOC, 1234, PNG, emptyMap(), null, "");
assertSupported(DOC, 1234, JPEG, emptyMap(), null, "");
assertSupported(DOC, 1234, TIFF, emptyMap(), null, "");
Map<String, String> actualOptions = new HashMap<>();
actualOptions.put("thumbnail", "true");
actualOptions.put("resizeWidth", "100");
actualOptions.put("resizeHeight", "100");
actualOptions.put("allowEnlargement", "false");
actualOptions.put("maintainAspectRatio", "true");
assertSupported(DOC, 1234, PNG, actualOptions, null, "");
}
Aggregations