Search in sources :

Example 1 with TransformOptionValue

use of org.alfresco.transform.client.model.config.TransformOptionValue 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;
}
Also used : TransformOption(org.alfresco.transform.client.model.config.TransformOption) ArrayList(java.util.ArrayList) TransformOptionValue(org.alfresco.transform.client.model.config.TransformOptionValue)

Example 2 with TransformOptionValue

use of org.alfresco.transform.client.model.config.TransformOptionValue 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, "");
}
Also used : TransformOption(org.alfresco.transform.client.model.config.TransformOption) SupportedTransform(org.alfresco.transform.client.registry.SupportedTransform) HashMap(java.util.HashMap) TransformOptionValue(org.alfresco.transform.client.model.config.TransformOptionValue) TransformOptionGroup(org.alfresco.transform.client.model.config.TransformOptionGroup) ArrayList(java.util.ArrayList) List(java.util.List) TransformRegistryTest(org.alfresco.transform.client.registry.TransformRegistryTest) Test(org.junit.Test)

Aggregations

ArrayList (java.util.ArrayList)2 TransformOption (org.alfresco.transform.client.model.config.TransformOption)2 TransformOptionValue (org.alfresco.transform.client.model.config.TransformOptionValue)2 HashMap (java.util.HashMap)1 List (java.util.List)1 TransformOptionGroup (org.alfresco.transform.client.model.config.TransformOptionGroup)1 SupportedTransform (org.alfresco.transform.client.registry.SupportedTransform)1 TransformRegistryTest (org.alfresco.transform.client.registry.TransformRegistryTest)1 Test (org.junit.Test)1