mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-10-01 14:41:46 +00:00
ACS-1778 Common transform routing code for Repo and t-router (#648)
Main change is the removal of code from CombinedConfig into alfresco-transform-model as CombinedTransformConfig.The Code within LocalCombinedConfig has now moved to CombinedConfig as there is only one type of config now. * Bump alfresco-transform-model from 1.3.1.1 to 1.4.0 * Add logWarn method
This commit is contained in:
@@ -235,7 +235,6 @@ import org.junit.runners.Suite;
|
||||
org.alfresco.repo.events.ClientUtilTest.class,
|
||||
org.alfresco.repo.rendition2.RenditionService2Test.class,
|
||||
org.alfresco.repo.rendition2.TransformationOptionsConverterTest.class,
|
||||
org.alfresco.transform.client.registry.TransformServiceRegistryConfigTest.class,
|
||||
|
||||
org.alfresco.repo.event2.RepoEvent2UnitSuite.class,
|
||||
|
||||
|
@@ -28,16 +28,19 @@ package org.alfresco.transform.client.registry;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.alfresco.repo.content.MimetypeMap;
|
||||
import org.alfresco.repo.content.transform.AbstractLocalTransform;
|
||||
import org.alfresco.repo.content.transform.LocalCombinedConfig;
|
||||
import org.alfresco.repo.content.transform.LocalPipelineTransform;
|
||||
import org.alfresco.repo.content.transform.LocalTransformImpl;
|
||||
import org.alfresco.repo.content.transform.LocalTransformServiceRegistry;
|
||||
import org.alfresco.repo.content.transform.TransformerDebug;
|
||||
import org.alfresco.transform.client.model.config.SupportedSourceAndTarget;
|
||||
import org.alfresco.transform.client.model.config.TransformOption;
|
||||
import org.alfresco.transform.client.model.config.TransformOptionGroup;
|
||||
import org.alfresco.transform.client.model.config.TransformOptionValue;
|
||||
import org.alfresco.transform.client.model.config.Transformer;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.apache.log4j.Level;
|
||||
import org.apache.log4j.LogManager;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mock;
|
||||
@@ -48,6 +51,7 @@ import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
@@ -55,7 +59,9 @@ import java.util.Set;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static java.util.Collections.emptyMap;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
@@ -63,11 +69,9 @@ import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
/**
|
||||
* Extends the {@link TransformServiceRegistryConfigTest} (used to test the config received from the Transform Service)
|
||||
* so that configuration for the local transformations may be tested. This includes pipelines and options specific
|
||||
* transform steps.
|
||||
* Testing LocalTransformServiceRegistry.
|
||||
*/
|
||||
public class LocalTransformServiceRegistryConfigTest extends TransformServiceRegistryConfigTest
|
||||
public class LocalTransformServiceRegistryConfigTest extends TransformRegistryTest
|
||||
{
|
||||
public static final String HARD_CODED_VALUE = "hard coded value";
|
||||
|
||||
@@ -135,6 +139,12 @@ public class LocalTransformServiceRegistryConfigTest extends TransformServiceReg
|
||||
super.logError(msg);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void logWarn(String msg)
|
||||
{
|
||||
logError(msg);
|
||||
}
|
||||
|
||||
public Data assertDataChanged(Data prevData, String msg)
|
||||
{
|
||||
// If the data changes, there has been a read
|
||||
@@ -169,10 +179,14 @@ public class LocalTransformServiceRegistryConfigTest extends TransformServiceReg
|
||||
|
||||
private static Log log = LogFactory.getLog(LocalTransformServiceRegistry.class);
|
||||
|
||||
public static final String PNG = "image/png";
|
||||
public static final String TIFF = "image/tiff";
|
||||
|
||||
public static final ObjectMapper JSON_OBJECT_MAPPER = new ObjectMapper();
|
||||
|
||||
private static final String LOCAL_TRANSFORM_SERVICE_CONFIG = "alfresco/local-transform-service-config-test.json";
|
||||
private static final String LOCAL_TRANSFORM_SERVICE_CONFIG_PIPELINE = "alfresco/local-transform-service-config-pipeline-test.json";
|
||||
|
||||
private static final ObjectMapper JSON_OBJECT_MAPPER = new ObjectMapper();
|
||||
private static final String LOCAL_TRANSFORM = "localTransform.";
|
||||
private static final String URL = ".url";
|
||||
|
||||
@@ -202,8 +216,10 @@ public class LocalTransformServiceRegistryConfigTest extends TransformServiceReg
|
||||
initTestData();
|
||||
|
||||
super.setUp();
|
||||
LogManager.getLogger(LocalTransformServiceRegistryConfigTest.class).setLevel(Level.DEBUG);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected LocalTransformServiceRegistry buildTransformServiceRegistryImpl() throws Exception
|
||||
{
|
||||
registry = new TestLocalTransformServiceRegistry();
|
||||
@@ -222,19 +238,6 @@ public class LocalTransformServiceRegistryConfigTest extends TransformServiceReg
|
||||
return (System.currentTimeMillis() - startMs) + "ms: ";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getTransformServiceConfig()
|
||||
{
|
||||
return LOCAL_TRANSFORM_SERVICE_CONFIG;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getTransformServiceConfigPipeline()
|
||||
{
|
||||
return LOCAL_TRANSFORM_SERVICE_CONFIG_PIPELINE;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getExpectedTransformsForTestJsonPipeline()
|
||||
{
|
||||
// imagemagick
|
||||
@@ -259,7 +262,7 @@ public class LocalTransformServiceRegistryConfigTest extends TransformServiceReg
|
||||
*/
|
||||
private void retrieveLocalTransformList(String path)
|
||||
{
|
||||
CombinedConfig combinedConfig = new LocalCombinedConfig(log);
|
||||
CombinedConfig combinedConfig = new CombinedConfig(log);
|
||||
combinedConfig.addLocalConfig(path);
|
||||
combinedConfig.register(registry);
|
||||
mapOfTransformOptions = combinedConfig.combinedTransformOptions;
|
||||
@@ -379,11 +382,166 @@ public class LocalTransformServiceRegistryConfigTest extends TransformServiceReg
|
||||
return i;
|
||||
}
|
||||
|
||||
private void register(String path) throws IOException
|
||||
{
|
||||
CombinedConfig combinedConfig = new CombinedConfig(log);
|
||||
combinedConfig.addLocalConfig(path);
|
||||
combinedConfig.register((TransformServiceRegistryImpl)registry);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testJsonConfig() throws IOException
|
||||
{
|
||||
internalTestJsonConfig(64, 70);
|
||||
register(LOCAL_TRANSFORM_SERVICE_CONFIG);
|
||||
|
||||
// Check the count of transforms supported
|
||||
assertEquals("The number of UNIQUE source to target mimetypes transforms has changed. Config change?",
|
||||
64, countSupportedTransforms(true));
|
||||
assertEquals("The number of source to target mimetypes transforms has changed. " +
|
||||
"There may be multiple transformers for the same combination. Config change?",
|
||||
70, countSupportedTransforms(false));
|
||||
|
||||
// Check a supported transform for each transformer.
|
||||
assertSupported(DOC, 1234, PDF, emptyMap(), null, ""); // libreoffice
|
||||
assertSupported(DOC, 1234, PDF, emptyMap(), null, ""); // libreoffice
|
||||
assertSupported(PDF, 1234, PNG, emptyMap(), null, ""); // pdfrenderer
|
||||
assertSupported(JPEG,1234, GIF, emptyMap(), null, ""); // imagemagick
|
||||
assertSupported(MSG, 1234, TXT, emptyMap(), null, ""); // tika
|
||||
assertSupported(MSG, 1234, GIF, emptyMap(), null, ""); // officeToImageViaPdf
|
||||
|
||||
Map<String, String> invalidPdfOptions = new HashMap<>();
|
||||
invalidPdfOptions.put("allowEnlargement", "false");
|
||||
assertSupported(DOC, 1234, PDF, invalidPdfOptions, null, "Invalid as there is a extra option");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJsonPipeline() throws IOException
|
||||
{
|
||||
register(LOCAL_TRANSFORM_SERVICE_CONFIG_PIPELINE);
|
||||
|
||||
// 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, "");
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
private boolean containsTransformOptionValueName (TransformOptionGroup transformOptionGroup, String propertyName)
|
||||
{
|
||||
return retrieveTransformOptionByPropertyName(transformOptionGroup, propertyName, "TransformOptionValue") != null;
|
||||
}
|
||||
|
||||
private int countSupportedTransforms(boolean unique)
|
||||
{
|
||||
int count = 0;
|
||||
int uniqueCount = 0;
|
||||
for (Map<String, List<SupportedTransform>> targetMap : registry.getData().getTransforms().values())
|
||||
{
|
||||
for (List<SupportedTransform> supportedTransforms : targetMap.values())
|
||||
{
|
||||
uniqueCount++;
|
||||
count += supportedTransforms.size();
|
||||
}
|
||||
}
|
||||
return unique ? uniqueCount : count;
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -635,7 +793,7 @@ public class LocalTransformServiceRegistryConfigTest extends TransformServiceReg
|
||||
public void testNoName()
|
||||
{
|
||||
retrieveLocalTransformList("alfresco/local-transform-service-config-no-name-test.json");
|
||||
registry.assertErrorLogged("Local transformer names may not be null.*no-name-test.*");
|
||||
registry.assertErrorLogged("Transformer names may not be null.*no-name-test.*");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -649,7 +807,7 @@ public class LocalTransformServiceRegistryConfigTest extends TransformServiceReg
|
||||
public void testTEngineDuplicateNames()
|
||||
{
|
||||
retrieveLocalTransformList("alfresco/local-transform-service-config-dup-name-test.json");
|
||||
registry.assertErrorLogged("Local T-Engine transformer .* must be a unique name.*dup-name.*");
|
||||
registry.assertErrorLogged("Transformer \"pdfrenderer\" must be a unique name.*dup-name.*");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -657,21 +815,22 @@ public class LocalTransformServiceRegistryConfigTest extends TransformServiceReg
|
||||
{
|
||||
registry.setResetBaseUrl(false);
|
||||
retrieveLocalTransformList("alfresco/local-transform-service-config-no-base-url-test.json");
|
||||
registry.assertErrorLogged("Local T-Engine transformer .* must have its baseUrl set .*no-base-url.*");
|
||||
registry.assertErrorLogged("Single step transformers \\(such as \"pdfrenderer\"\\) must be defined in a " +
|
||||
"T-Engine rather than in a pipeline file, unless they are overriding an existing single step definition.*no-base-url.*");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPipelineMissingStepTransform()
|
||||
{
|
||||
retrieveLocalTransformList("alfresco/transform-service-config-pipeline-missing-step-test.json");
|
||||
registry.assertErrorLogged("Transformer .* ignored as step transforms do not exist.*pipeline-missing-step.*");
|
||||
registry.assertErrorLogged("Transformer \"missingPdfrenderer\" ignored as step transforms \\(\"pdfrenderer\"\\) do not exist.*pipeline-missing-step-test.*");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailoverMissingStepTransform()
|
||||
{
|
||||
retrieveLocalTransformList("alfresco/transform-service-config-failover-missing-step-test.json");
|
||||
registry.assertErrorLogged("Transformer .* ignored as step transforms do not exist.*failover-missing-step.*");
|
||||
registry.assertErrorLogged("Transformer \"missingPdfrenderer\" ignored as step transforms \\(\"pdfrenderer\"\\) do not exist.*failover-missing-step-test.*");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@@ -1,295 +0,0 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2019 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.transform.client.registry;
|
||||
|
||||
import static java.util.Collections.emptyMap;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.alfresco.transform.client.model.config.TransformOption;
|
||||
import org.alfresco.transform.client.model.config.TransformOptionGroup;
|
||||
import org.alfresco.transform.client.model.config.TransformOptionValue;
|
||||
import org.alfresco.transform.client.registry.SupportedTransform;
|
||||
import org.alfresco.transform.client.registry.TransformRegistryTest;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.apache.log4j.Level;
|
||||
import org.apache.log4j.LogManager;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
/**
|
||||
* Test the config received from the Transform Service about what it supports.
|
||||
*
|
||||
* @author adavis
|
||||
*/
|
||||
public class TransformServiceRegistryConfigTest extends TransformRegistryTest
|
||||
{
|
||||
private static Log log = LogFactory.getLog(TransformServiceRegistryConfigTest.class);
|
||||
|
||||
public static final String PNG = "image/png";
|
||||
public static final String TIFF = "image/tiff";
|
||||
|
||||
private static final String TRANSFORM_SERVICE_CONFIG = "alfresco/transform-service-config-test.json";
|
||||
private static final String TRANSFORM_SERVICE_CONFIG_PIPELINE = "alfresco/transform-service-config-pipeline-test.json";
|
||||
|
||||
public static final ObjectMapper JSON_OBJECT_MAPPER = new ObjectMapper();
|
||||
|
||||
@Before
|
||||
@Override
|
||||
public void setUp() throws Exception
|
||||
{
|
||||
super.setUp();
|
||||
LogManager.getLogger(TransformServiceRegistryConfigTest.class).setLevel(Level.DEBUG);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected TransformServiceRegistryImpl buildTransformServiceRegistryImpl() throws Exception
|
||||
{
|
||||
TransformServiceRegistryImpl registry = new TransformServiceRegistryImpl()
|
||||
{
|
||||
@Override
|
||||
public boolean readConfig() throws IOException
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Log getLog()
|
||||
{
|
||||
return log;
|
||||
}
|
||||
};
|
||||
registry.setJsonObjectMapper(JSON_OBJECT_MAPPER);
|
||||
registry.setCronExpression(null); // just read once
|
||||
registry.afterPropertiesSet();
|
||||
return registry;
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown()
|
||||
{
|
||||
// shut down
|
||||
}
|
||||
|
||||
protected String getTransformServiceConfig()
|
||||
{
|
||||
return TRANSFORM_SERVICE_CONFIG;
|
||||
}
|
||||
|
||||
protected String getTransformServiceConfigPipeline()
|
||||
{
|
||||
return TRANSFORM_SERVICE_CONFIG_PIPELINE;
|
||||
}
|
||||
|
||||
private void register(String path) throws IOException
|
||||
{
|
||||
CombinedConfig combinedConfig = new CombinedConfig(log);
|
||||
combinedConfig.addLocalConfig(path);
|
||||
combinedConfig.register((TransformServiceRegistryImpl)registry);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJsonConfig() throws IOException
|
||||
{
|
||||
internalTestJsonConfig(60, 60);
|
||||
}
|
||||
|
||||
protected void internalTestJsonConfig(int expectedSourceTargetUniqueCount, int expectedSourceTargetCount) throws IOException
|
||||
{
|
||||
register(getTransformServiceConfig());
|
||||
|
||||
// Check the count of transforms supported
|
||||
assertEquals("The number of UNIQUE source to target mimetypes transforms has changed. Config change?",
|
||||
expectedSourceTargetUniqueCount, countSupportedTransforms(true));
|
||||
assertEquals("The number of source to target mimetypes transforms has changed. " +
|
||||
"There may be multiple transformers for the same combination. Config change?",
|
||||
expectedSourceTargetCount, countSupportedTransforms(false));
|
||||
|
||||
// Check a supported transform for each transformer.
|
||||
assertSupported(DOC, 1234, PDF, emptyMap(), null, ""); // libreoffice
|
||||
assertSupported(DOC, 1234, PDF, emptyMap(), null, ""); // libreoffice
|
||||
assertSupported(PDF, 1234, PNG, emptyMap(), null, ""); // pdfrenderer
|
||||
assertSupported(JPEG,1234, GIF, emptyMap(), null, ""); // imagemagick
|
||||
assertSupported(MSG, 1234, TXT, emptyMap(), null, ""); // tika
|
||||
assertSupported(MSG, 1234, GIF, emptyMap(), null, ""); // officeToImageViaPdf
|
||||
|
||||
Map<String, String> invalidPdfOptions = new HashMap<>();
|
||||
invalidPdfOptions.put("allowEnlargement", "false");
|
||||
assertSupported(DOC, 1234, PDF, invalidPdfOptions, null, "Invalid as there is a extra option");
|
||||
}
|
||||
|
||||
@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, "");
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
private boolean containsTransformOptionValueName (TransformOptionGroup transformOptionGroup, String propertyName)
|
||||
{
|
||||
return retrieveTransformOptionByPropertyName(transformOptionGroup, propertyName, "TransformOptionValue") != null;
|
||||
}
|
||||
|
||||
protected int getExpectedTransformsForTestJsonPipeline()
|
||||
{
|
||||
// {"sourceMediaType": "application/msword", "targetMediaType": "image/gif" },
|
||||
// {"sourceMediaType": "application/msword", "targetMediaType": "image/jpeg"},
|
||||
// {"sourceMediaType": "application/msword", "targetMediaType": "image/png" },
|
||||
// {"sourceMediaType": "application/msword", "targetMediaType": "image/tiff"}
|
||||
return 4;
|
||||
}
|
||||
|
||||
private int countSupportedTransforms(boolean unique)
|
||||
{
|
||||
int count = 0;
|
||||
int uniqueCount = 0;
|
||||
for (Map<String, List<SupportedTransform>> targetMap : registry.getData().getTransforms().values())
|
||||
{
|
||||
for (List<SupportedTransform> supportedTransforms : targetMap.values())
|
||||
{
|
||||
uniqueCount++;
|
||||
count += supportedTransforms.size();
|
||||
}
|
||||
}
|
||||
return unique ? uniqueCount : count;
|
||||
}
|
||||
}
|
@@ -1,47 +0,0 @@
|
||||
{
|
||||
"transformOptions": {
|
||||
"imageMagickOptions": [
|
||||
{"value": {"name": "alphaRemove"}},
|
||||
{"value": {"name": "autoOrient"}},
|
||||
{"value": {"name": "startPage"}},
|
||||
{"value": {"name": "endPage"}},
|
||||
{"group": {"transformOptions": [
|
||||
{"value": {"required": "true", "name": "cropGravity"}},
|
||||
{"value": {"name": "cropWidth"}},
|
||||
{"value": {"name": "cropHeight"}},
|
||||
{"value": {"name": "cropPercentage"}},
|
||||
{"value": {"name": "cropXOffset"}},
|
||||
{"value": {"name": "cropYOffset"}}
|
||||
]}},
|
||||
{"group": {"transformOptions": [
|
||||
{"value": {"name": "thumbnail"}},
|
||||
{"value": {"name": "resizeHeight"}},
|
||||
{"value": {"name": "resizeWidth"}},
|
||||
{"value": {"name": "resizePercentage"}},
|
||||
{"value": {"name": "allowEnlargement"}},
|
||||
{"value": {"name": "maintainAspectRatio"}}
|
||||
]}}
|
||||
],
|
||||
"pdfRendererOptions": [
|
||||
{"value": {"name": "page"}},
|
||||
{"value": {"name": "width"}},
|
||||
{"value": {"name": "height"}},
|
||||
{"value": {"name": "allowPdfEnlargement"}},
|
||||
{"value": {"name": "maintainPdfAspectRatio"}}
|
||||
]
|
||||
},
|
||||
"transformers": [
|
||||
{
|
||||
"supportedSourceAndTargetList": [
|
||||
{"sourceMediaType": "application/msword", "targetMediaType": "image/gif" },
|
||||
{"sourceMediaType": "application/msword", "targetMediaType": "image/jpeg"},
|
||||
{"sourceMediaType": "application/msword", "targetMediaType": "image/png" },
|
||||
{"sourceMediaType": "application/msword", "targetMediaType": "image/tiff"}
|
||||
],
|
||||
"transformOptions": [
|
||||
"pdfRendererOptions",
|
||||
"imageMagickOptions"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
@@ -1,144 +0,0 @@
|
||||
{
|
||||
"transformOptions": {
|
||||
"imageMagickOptions": [
|
||||
{"value": {"name": "alphaRemove"}},
|
||||
{"value": {"name": "autoOrient"}},
|
||||
{"value": {"name": "startPage"}},
|
||||
{"value": {"name": "endPage"}},
|
||||
{"group": {"transformOptions": [
|
||||
{"value": {"name": "cropGravity"}},
|
||||
{"value": {"name": "cropWidth"}},
|
||||
{"value": {"name": "cropHeight"}},
|
||||
{"value": {"name": "cropPercentage"}},
|
||||
{"value": {"name": "cropXOffset"}},
|
||||
{"value": {"name": "cropYOffset"}}
|
||||
]}},
|
||||
{"group": {"transformOptions": [
|
||||
{"value": {"name": "thumbnail"}},
|
||||
{"value": {"name": "resizeHeight"}},
|
||||
{"value": {"name": "resizeWidth"}},
|
||||
{"value": {"name": "resizePercentage"}},
|
||||
{"value": {"name": "allowEnlargement"}},
|
||||
{"value": {"name": "maintainAspectRatio"}}
|
||||
]}}
|
||||
],
|
||||
"tikaOptions": [
|
||||
{"value": {"name": "transform"}},
|
||||
{"value": {"name": "includeContents"}},
|
||||
{"value": {"name": "notExtractBookmarksText"}},
|
||||
{"value": {"name": "targetMimetype"}},
|
||||
{"value": {"name": "targetEncoding"}}
|
||||
],
|
||||
"pdfRendererOptions": [
|
||||
{"value": {"name": "page"}},
|
||||
{"value": {"name": "width"}},
|
||||
{"value": {"name": "height"}},
|
||||
{"value": {"name": "allowPdfEnlargement"}},
|
||||
{"value": {"name": "maintainPdfAspectRatio"}}
|
||||
]
|
||||
},
|
||||
"transformers": [
|
||||
{
|
||||
"supportedSourceAndTargetList": [
|
||||
{"sourceMediaType": "image/gif", "targetMediaType": "image/gif" },
|
||||
{"sourceMediaType": "image/gif", "targetMediaType": "image/jpeg"},
|
||||
{"sourceMediaType": "image/gif", "targetMediaType": "image/png" },
|
||||
{"sourceMediaType": "image/gif", "targetMediaType": "image/tiff"},
|
||||
|
||||
{"sourceMediaType": "image/jpeg", "targetMediaType": "image/gif" },
|
||||
{"sourceMediaType": "image/jpeg", "targetMediaType": "image/jpeg"},
|
||||
{"sourceMediaType": "image/jpeg", "targetMediaType": "image/png" },
|
||||
{"sourceMediaType": "image/jpeg", "targetMediaType": "image/tiff"},
|
||||
|
||||
{"sourceMediaType": "image/png", "targetMediaType": "image/gif" },
|
||||
{"sourceMediaType": "image/png", "targetMediaType": "image/jpeg"},
|
||||
{"sourceMediaType": "image/png", "targetMediaType": "image/png" },
|
||||
{"sourceMediaType": "image/png", "targetMediaType": "image/tiff"},
|
||||
|
||||
{"sourceMediaType": "image/tiff", "targetMediaType": "image/gif" },
|
||||
{"sourceMediaType": "image/tiff", "targetMediaType": "image/tiff"}
|
||||
],
|
||||
"transformOptions": [
|
||||
"imageMagickOptions"
|
||||
]
|
||||
},
|
||||
{
|
||||
"supportedSourceAndTargetList": [
|
||||
{"sourceMediaType": "application/pdf", "maxSourceSizeBytes": 26214400, "targetMediaType": "text/plain" },
|
||||
{"sourceMediaType": "application/msword", "targetMediaType": "text/plain"},
|
||||
{"sourceMediaType": "application/vnd.ms-excel", "targetMediaType": "text/plain" },
|
||||
{"sourceMediaType": "application/vnd.ms-powerpoint", "targetMediaType": "text/plain" },
|
||||
{"sourceMediaType": "application/vnd.openxmlformats-officedocument.wordprocessingml.document", "targetMediaType": "text/plain"},
|
||||
{"sourceMediaType": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "targetMediaType": "text/plain" },
|
||||
{"sourceMediaType": "application/vnd.openxmlformats-officedocument.presentationml.presentation", "targetMediaType": "text/plain" },
|
||||
{"sourceMediaType": "application/vnd.ms-outlook", "targetMediaType": "text/plain"}
|
||||
],
|
||||
"transformOptions": [
|
||||
"tikaOptions"
|
||||
]
|
||||
},
|
||||
{
|
||||
"supportedSourceAndTargetList": [
|
||||
{"sourceMediaType": "application/pdf", "targetMediaType": "image/png" }
|
||||
],
|
||||
"transformOptions": [
|
||||
"pdfRendererOptions"
|
||||
]
|
||||
},
|
||||
{
|
||||
"supportedSourceAndTargetList": [
|
||||
{"sourceMediaType": "application/msword", "targetMediaType": "application/msword" },
|
||||
{"sourceMediaType": "application/vnd.openxmlformats-officedocument.wordprocessingml.document", "targetMediaType": "application/msword" },
|
||||
{"sourceMediaType": "application/msword", "maxSourceSizeBytes": 10485760, "targetMediaType": "application/pdf" },
|
||||
{"sourceMediaType": "application/vnd.ms-excel", "maxSourceSizeBytes": 10485760, "targetMediaType": "application/pdf"},
|
||||
{"sourceMediaType": "application/vnd.ms-powerpoint", "maxSourceSizeBytes": 6291456, "targetMediaType": "application/pdf" },
|
||||
{"sourceMediaType": "application/vnd.openxmlformats-officedocument.wordprocessingml.document", "maxSourceSizeBytes": 786432, "targetMediaType": "application/pdf" },
|
||||
{"sourceMediaType": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "maxSourceSizeBytes": 1572864, "targetMediaType": "application/pdf"},
|
||||
{"sourceMediaType": "application/vnd.openxmlformats-officedocument.presentationml.presentation", "maxSourceSizeBytes": 4194304, "targetMediaType": "application/pdf" },
|
||||
{"sourceMediaType": "application/vnd.ms-outlook", "targetMediaType": "application/pdf"}
|
||||
]
|
||||
},
|
||||
{
|
||||
"supportedSourceAndTargetList": [
|
||||
{"sourceMediaType": "application/msword", "targetMediaType": "image/gif" },
|
||||
{"sourceMediaType": "application/msword", "targetMediaType": "image/jpeg"},
|
||||
{"sourceMediaType": "application/msword", "targetMediaType": "image/png" },
|
||||
{"sourceMediaType": "application/msword", "targetMediaType": "image/tiff"},
|
||||
|
||||
{"sourceMediaType": "application/vnd.ms-excel", "targetMediaType": "image/gif" },
|
||||
{"sourceMediaType": "application/vnd.ms-excel", "targetMediaType": "image/jpeg"},
|
||||
{"sourceMediaType": "application/vnd.ms-excel", "targetMediaType": "image/png" },
|
||||
{"sourceMediaType": "application/vnd.ms-excel", "targetMediaType": "image/tiff"},
|
||||
|
||||
{"sourceMediaType": "application/vnd.ms-powerpoint", "targetMediaType": "image/gif" },
|
||||
{"sourceMediaType": "application/vnd.ms-powerpoint", "targetMediaType": "image/jpeg"},
|
||||
{"sourceMediaType": "application/vnd.ms-powerpoint", "targetMediaType": "image/png" },
|
||||
{"sourceMediaType": "application/vnd.ms-powerpoint", "targetMediaType": "image/tiff"},
|
||||
|
||||
{"sourceMediaType": "application/vnd.openxmlformats-officedocument.wordprocessingml.document", "targetMediaType": "image/gif" },
|
||||
{"sourceMediaType": "application/vnd.openxmlformats-officedocument.wordprocessingml.document", "targetMediaType": "image/jpeg"},
|
||||
{"sourceMediaType": "application/vnd.openxmlformats-officedocument.wordprocessingml.document", "targetMediaType": "image/png" },
|
||||
{"sourceMediaType": "application/vnd.openxmlformats-officedocument.wordprocessingml.document", "targetMediaType": "image/tiff"},
|
||||
|
||||
{"sourceMediaType": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "targetMediaType": "image/gif" },
|
||||
{"sourceMediaType": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "targetMediaType": "image/jpeg"},
|
||||
{"sourceMediaType": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "targetMediaType": "image/png" },
|
||||
{"sourceMediaType": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "targetMediaType": "image/tiff"},
|
||||
|
||||
{"sourceMediaType": "application/vnd.openxmlformats-officedocument.presentationml.presentation", "targetMediaType": "image/gif" },
|
||||
{"sourceMediaType": "application/vnd.openxmlformats-officedocument.presentationml.presentation", "targetMediaType": "image/jpeg"},
|
||||
{"sourceMediaType": "application/vnd.openxmlformats-officedocument.presentationml.presentation", "targetMediaType": "image/png" },
|
||||
{"sourceMediaType": "application/vnd.openxmlformats-officedocument.presentationml.presentation", "targetMediaType": "image/tiff"},
|
||||
|
||||
{"sourceMediaType": "application/vnd.ms-outlook", "targetMediaType": "image/gif" },
|
||||
{"sourceMediaType": "application/vnd.ms-outlook", "targetMediaType": "image/jpeg"},
|
||||
{"sourceMediaType": "application/vnd.ms-outlook", "targetMediaType": "image/png" },
|
||||
{"sourceMediaType": "application/vnd.ms-outlook", "targetMediaType": "image/tiff"}
|
||||
],
|
||||
"transformOptions": [
|
||||
"pdfRendererOptions",
|
||||
"imageMagickOptions"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
Reference in New Issue
Block a user