result = getCheckResult();
return result;
}
@@ -243,11 +240,6 @@ public class RemoteTransformerClient
String url = baseUrl + "/version";
HttpGet httpGet = new HttpGet(url);
- if (logger.isDebugEnabled())
- {
- logger.debug("Remote "+name+' '+" check" +url);
- }
-
try
{
try (CloseableHttpClient httpclient = HttpClients.createDefault())
@@ -257,7 +249,7 @@ public class RemoteTransformerClient
StatusLine statusLine = response.getStatusLine();
if (statusLine == null)
{
- throw new AlfrescoRuntimeException("Remote "+name+" check returned no status " + url);
+ throw new AlfrescoRuntimeException(name+" check returned no status " + url);
}
HttpEntity resEntity = response.getEntity();
if (resEntity != null)
@@ -269,12 +261,12 @@ public class RemoteTransformerClient
{
String version = getContent(resEntity);
- if (logger.isDebugEnabled())
+ if (logger.isTraceEnabled())
{
long responseContentLength = resEntity.getContentLength();
Header responseContentType = resEntity.getContentType();
Header responseContentEncoding = resEntity.getContentEncoding();
- logger.debug("Remote " + name +
+ logger.trace(name +
" check returned. length=" + responseContentLength +
" type=" + responseContentType +
" encoding=" + responseContentEncoding+
@@ -289,28 +281,28 @@ public class RemoteTransformerClient
}
catch (IOException e)
{
- throw new AlfrescoRuntimeException("Remote " + name + " check failed to read the returned content", e);
+ throw new AlfrescoRuntimeException(name + " check failed to read the returned content", e);
}
}
else
{
String message = getErrorMessage(resEntity);
- throw new AlfrescoRuntimeException("Remote " + name + " check returned a " + statusCode + " status " + message + ' ' + url);
+ throw new AlfrescoRuntimeException(name + " check returned a " + statusCode + " status " + message + ' ' + url);
}
}
else
{
- throw new AlfrescoRuntimeException("Remote " + name + " check did not return an entity " + url);
+ throw new AlfrescoRuntimeException(name + " check did not return an entity " + url);
}
}
catch (IOException e)
{
- throw new AlfrescoRuntimeException("Remote " + name + " check failed to connect or to read the response", e);
+ throw new AlfrescoRuntimeException(name + " check failed to connect or to read the response", e);
}
}
catch (IOException e)
{
- throw new AlfrescoRuntimeException("Remote " + name + " check failed to create an HttpClient", e);
+ throw new AlfrescoRuntimeException(name + " check failed to create an HttpClient", e);
}
}
catch (AlfrescoRuntimeException e)
diff --git a/src/main/java/org/alfresco/repo/content/transform/StringExtractingContentTransformer.java b/src/main/java/org/alfresco/repo/content/transform/StringExtractingContentTransformer.java
index f7b247108e..69d967ddcb 100644
--- a/src/main/java/org/alfresco/repo/content/transform/StringExtractingContentTransformer.java
+++ b/src/main/java/org/alfresco/repo/content/transform/StringExtractingContentTransformer.java
@@ -4,21 +4,21 @@
* %%
* Copyright (C) 2005 - 2016 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
+ * 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 .
* #L%
@@ -41,18 +41,18 @@ import org.apache.commons.logging.LogFactory;
* Converts any textual format to plain text.
*
* The transformation is sensitive to the source and target string encodings.
- *
+ *
* @author Derek Hulley
*
* @deprecated The transformations code is being moved out of the codebase and replaced by the new async RenditionService2 or other external libraries.
*/
@Deprecated
-public class StringExtractingContentTransformer extends AbstractContentTransformer2
+public class StringExtractingContentTransformer extends AbstractRemoteContentTransformer
{
public static final String PREFIX_TEXT = "text/";
-
+
private static final Log logger = LogFactory.getLog(StringExtractingContentTransformer.class);
-
+
/**
* Gives a high reliability for all translations from text/sometype to
* text/plain. As the text formats are already text, the characters
@@ -69,13 +69,13 @@ public class StringExtractingContentTransformer extends AbstractContentTransform
return false;
}
else if (sourceMimetype.equals(MimetypeMap.MIMETYPE_TEXT_PLAIN) ||
- sourceMimetype.equals(MimetypeMap.MIMETYPE_JAVASCRIPT))
+ sourceMimetype.equals(MimetypeMap.MIMETYPE_JAVASCRIPT))
{
// conversions from any plain text format are very reliable
return true;
}
else if (sourceMimetype.startsWith(PREFIX_TEXT) ||
- sourceMimetype.equals(MimetypeMap.MIMETYPE_DITA))
+ sourceMimetype.equals(MimetypeMap.MIMETYPE_DITA))
{
// the source is text, but probably with some kind of markup
return true;
@@ -98,22 +98,28 @@ public class StringExtractingContentTransformer extends AbstractContentTransform
return sb.toString();
}
+ @Override
+ protected Log getLogger()
+ {
+ return logger;
+ }
+
/**
* Text to text conversions are done directly using the content reader and writer string
* manipulation methods.
*
* Extraction of text from binary content attempts to take the possible character
* encoding into account. The text produced from this will, if the encoding was correct,
- * be unformatted but valid.
+ * be unformatted but valid.
*/
@Override
- public void transformInternal(ContentReader reader, ContentWriter writer, TransformationOptions options)
+ public void transformLocal(ContentReader reader, ContentWriter writer, TransformationOptions options)
throws Exception
{
// is this a straight text-text transformation
transformText(reader, writer, options);
}
-
+
/**
* Transformation optimized for text-to-text conversion
*/
@@ -164,4 +170,22 @@ public class StringExtractingContentTransformer extends AbstractContentTransform
}
// done
}
+
+ @Override
+ protected void transformRemote(RemoteTransformerClient remoteTransformerClient, ContentReader reader,
+ ContentWriter writer, TransformationOptions options, String sourceMimetype,
+ String targetMimetype, String sourceExtension, String targetExtension,
+ String targetEncoding) throws Exception
+ {
+ String sourceEncoding = reader.getEncoding();
+ long timeoutMs = options.getTimeoutMs();
+
+ remoteTransformerClient.request(reader, writer, sourceMimetype, sourceExtension, targetExtension,
+ timeoutMs, logger,
+ "sourceMimetype", sourceMimetype,
+ "targetMimetype", targetMimetype,
+ "sourceEncoding", sourceEncoding,
+ "targetEncoding", targetEncoding);
+
+ }
}
diff --git a/src/main/java/org/alfresco/repo/content/transform/TextToPdfContentTransformer.java b/src/main/java/org/alfresco/repo/content/transform/TextToPdfContentTransformer.java
index 99f21edf70..4abd28dcfe 100644
--- a/src/main/java/org/alfresco/repo/content/transform/TextToPdfContentTransformer.java
+++ b/src/main/java/org/alfresco/repo/content/transform/TextToPdfContentTransformer.java
@@ -59,7 +59,7 @@ import java.util.Map;
* @deprecated The transformations code is being moved out of the codebase and replaced by the new async RenditionService2 or other external libraries.
*/
@Deprecated
-public class TextToPdfContentTransformer extends AbstractContentTransformer2
+public class TextToPdfContentTransformer extends AbstractRemoteContentTransformer
{
private static final Log logger = LogFactory.getLog(TextToPdfContentTransformer.class);
@@ -126,7 +126,13 @@ public class TextToPdfContentTransformer extends AbstractContentTransformer2
}
@Override
- protected void transformInternal(
+ protected Log getLogger()
+ {
+ return logger;
+ }
+
+ @Override
+ protected void transformLocal(
ContentReader reader,
ContentWriter writer,
TransformationOptions options) throws Exception
@@ -168,7 +174,28 @@ public class TextToPdfContentTransformer extends AbstractContentTransformer2
}
}
}
-
+
+ @Override
+ protected void transformRemote(RemoteTransformerClient remoteTransformerClient, ContentReader reader,
+ ContentWriter writer, TransformationOptions options, String sourceMimetype,
+ String targetMimetype, String sourceExtension, String targetExtension,
+ String targetEncoding) throws Exception
+ {
+ String sourceEncoding = reader.getEncoding();
+ long timeoutMs = options.getTimeoutMs();
+
+ TransformationOptionLimits limits = getLimits(reader, writer, options);
+ TransformationOptionPair pageLimits = limits.getPagesPair();
+ int pageLimit = (int)pageLimits.getValue();
+
+ remoteTransformerClient.request(reader, writer, sourceMimetype, sourceExtension, targetExtension,
+ timeoutMs, logger,
+ "sourceMimetype", sourceMimetype,
+ "targetMimetype", targetMimetype,
+ "sourceEncoding", sourceEncoding,
+ "pageLimit", String.valueOf(pageLimit));
+ }
+
protected InputStreamReader buildReader(InputStream is, String encoding, String node)
{
// If they gave an encoding, try to use it
diff --git a/src/main/java/org/alfresco/repo/content/transform/TransformerDebug.java b/src/main/java/org/alfresco/repo/content/transform/TransformerDebug.java
index 6ffabb4cc9..67b3cdc3f1 100644
--- a/src/main/java/org/alfresco/repo/content/transform/TransformerDebug.java
+++ b/src/main/java/org/alfresco/repo/content/transform/TransformerDebug.java
@@ -25,8 +25,37 @@
*/
package org.alfresco.repo.content.transform;
+import org.alfresco.model.ContentModel;
+import org.alfresco.repo.content.filestore.FileContentWriter;
+import org.alfresco.repo.model.Repository;
+import org.alfresco.repo.rendition2.RenditionDefinition2;
+import org.alfresco.repo.rendition2.RenditionDefinition2Impl;
+import org.alfresco.repo.rendition2.RenditionDefinitionRegistry2Impl;
+import org.alfresco.repo.rendition2.TransformClient;
+import org.alfresco.repo.transaction.RetryingTransactionHelper;
+import org.alfresco.service.cmr.repository.ContentData;
+import org.alfresco.service.cmr.repository.ContentService;
+import org.alfresco.service.cmr.repository.ContentWriter;
+import org.alfresco.service.cmr.repository.MimetypeService;
+import org.alfresco.service.cmr.repository.NodeRef;
+import org.alfresco.service.cmr.repository.NodeService;
+import org.alfresco.service.cmr.repository.TransformationOptions;
+import org.alfresco.service.namespace.NamespaceService;
+import org.alfresco.service.namespace.QName;
+import org.alfresco.service.transaction.TransactionService;
+import org.alfresco.util.EqualsHelper;
+import org.alfresco.util.LogTee;
+import org.alfresco.util.PropertyCheck;
+import org.alfresco.util.TempFileProvider;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.springframework.beans.BeansException;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.ApplicationContextAware;
+
import java.io.File;
-import java.io.IOException;
+import java.io.Serializable;
+import java.net.URI;
import java.net.URL;
import java.util.ArrayDeque;
import java.util.ArrayList;
@@ -34,8 +63,11 @@ import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.Deque;
+import java.util.HashMap;
import java.util.Iterator;
+import java.util.LinkedList;
import java.util.List;
+import java.util.Map;
import java.util.Set;
import java.util.SortedMap;
import java.util.TreeMap;
@@ -43,24 +75,7 @@ import java.util.TreeSet;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.regex.Pattern;
-import org.alfresco.api.AlfrescoPublicApi;
-import org.alfresco.error.AlfrescoRuntimeException;
-import org.alfresco.model.ContentModel;
-import org.alfresco.repo.content.filestore.FileContentReader;
-import org.alfresco.repo.content.filestore.FileContentWriter;
-import org.alfresco.service.cmr.repository.ContentReader;
-import org.alfresco.service.cmr.repository.ContentService;
-import org.alfresco.service.cmr.repository.ContentWriter;
-import org.alfresco.service.cmr.repository.MimetypeService;
-import org.alfresco.service.cmr.repository.NodeRef;
-import org.alfresco.service.cmr.repository.NodeService;
-import org.alfresco.service.cmr.repository.TransformationOptions;
-import org.alfresco.util.EqualsHelper;
-import org.alfresco.util.LogTee;
-import org.alfresco.util.TempFileProvider;
-import org.apache.commons.io.FileUtils;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
+import static org.alfresco.repo.rendition2.RenditionService2Impl.SOURCE_HAS_NO_CONTENT;
/**
* Debugs transformers selection and activity.
@@ -79,21 +94,26 @@ import org.apache.commons.logging.LogFactory;
* transformers) and {@link #popAvailable} are called.
*
* @author Alan Davis
- *
- * @deprecated The transformations code is being moved out of the codebase and replaced by the new async RenditionService2 or other external libraries.
*/
-@Deprecated
-@AlfrescoPublicApi
-public class TransformerDebug
+public class TransformerDebug implements ApplicationContextAware
{
private static final String FINISHED_IN = "Finished in ";
private static final String NO_TRANSFORMERS = "No transformers";
- private final Log logger;
- private final Log info;
+ private Log info;
+ private Log logger;
+ private NodeService nodeService;
+ private MimetypeService mimetypeService;
+ private ContentTransformerRegistry transformerRegistry;
+ private TransformerConfig transformerConfig;
+
+ private ApplicationContext applicationContext;
+ private ContentService contentService;
+ private TransformClient transformClient;
+ private Repository repositoryHelper;
+ private TransactionService transactionService;
+ private RenditionDefinitionRegistry2Impl renditionDefinitionRegistry2;
- @Deprecated
- @AlfrescoPublicApi
private enum Call
{
AVAILABLE,
@@ -101,8 +121,6 @@ public class TransformerDebug
AVAILABLE_AND_TRANSFORM
};
- @Deprecated
- @AlfrescoPublicApi
private static class ThreadInfo
{
private static final ThreadLocal threadInfo = new ThreadLocal()
@@ -153,8 +171,6 @@ public class TransformerDebug
}
}
- @Deprecated
- @AlfrescoPublicApi
private static class Frame
{
private static final AtomicInteger uniqueId = new AtomicInteger(0);
@@ -163,7 +179,8 @@ public class TransformerDebug
private final String fromUrl;
private final String sourceMimetype;
private final String targetMimetype;
- private final TransformationOptions options;
+ private final NodeRef sourceNodeRef;
+ private final String renditionName;
private final boolean origDebugOutput;
private long start;
@@ -176,7 +193,7 @@ public class TransformerDebug
private String transformerName;
private Frame(Frame parent, String transformerName, String fromUrl, String sourceMimetype, String targetMimetype,
- long sourceSize, TransformationOptions options, Call pushCall, boolean origDebugOutput)
+ long sourceSize, String renditionName, NodeRef sourceNodeRef, Call pushCall, boolean origDebugOutput)
{
this.id = -1;
this.parent = parent;
@@ -185,7 +202,8 @@ public class TransformerDebug
this.sourceMimetype = sourceMimetype;
this.targetMimetype = targetMimetype;
this.sourceSize = sourceSize;
- this.options = options;
+ this.renditionName = renditionName;
+ this.sourceNodeRef = sourceNodeRef;
this.callType = pushCall;
this.origDebugOutput = origDebugOutput;
start = System.currentTimeMillis();
@@ -232,7 +250,6 @@ public class TransformerDebug
}
@Deprecated
- @AlfrescoPublicApi
private class UnavailableTransformer implements Comparable
{
private final String name;
@@ -282,27 +299,50 @@ public class TransformerDebug
return name.compareTo(o.name);
}
}
-
- private final NodeService nodeService;
- private final MimetypeService mimetypeService;
- private final ContentTransformerRegistry transformerRegistry;
- private final TransformerConfig transformerConfig;
- private ContentService contentService;
-
- /**
- * Constructor
- */
- public TransformerDebug(NodeService nodeService, MimetypeService mimetypeService,
- ContentTransformerRegistry transformerRegistry, TransformerConfig transformerConfig,
- Log transformerLog, Log transformerDebugLog)
+
+ public void setTransformerLog(Log transformerLog)
+ {
+ info = new LogTee(LogFactory.getLog(TransformerLog.class), transformerLog);
+ }
+
+ public void setTransformerDebugLog(Log transformerDebugLog)
+ {
+ logger = new LogTee(LogFactory.getLog(TransformerDebug.class), transformerDebugLog);
+ }
+
+ public void setNodeService(NodeService nodeService)
{
this.nodeService = nodeService;
+ }
+
+ public void setMimetypeService(MimetypeService mimetypeService)
+ {
this.mimetypeService = mimetypeService;
+ }
+
+ public void setTransformerRegistry(ContentTransformerRegistry transformerRegistry)
+ {
this.transformerRegistry = transformerRegistry;
+ }
+
+ public void setTransformerConfig(TransformerConfig transformerConfig)
+ {
this.transformerConfig = transformerConfig;
-
- logger = new LogTee(LogFactory.getLog(TransformerDebug.class), transformerDebugLog);
- info = new LogTee(LogFactory.getLog(TransformerLog.class), transformerLog);
+ }
+
+ @Override
+ public void setApplicationContext(ApplicationContext applicationContext) throws BeansException
+ {
+ this.applicationContext = applicationContext;
+ }
+
+ private ContentService getContentService()
+ {
+ if (contentService == null)
+ {
+ contentService = (ContentService) applicationContext.getBean("contentService");
+ }
+ return contentService;
}
public void setContentService(ContentService contentService)
@@ -310,40 +350,138 @@ public class TransformerDebug
this.contentService = contentService;
}
+ private TransformClient getTransformClient()
+ {
+ if (transformClient == null)
+ {
+ transformClient = (TransformClient) applicationContext.getBean("transformClient");
+ }
+ return transformClient;
+ }
+
+ public void setTransformClient(TransformClient transformClient)
+ {
+ this.transformClient = transformClient;
+ }
+
+ public Repository getRepositoryHelper()
+ {
+ if (repositoryHelper == null)
+ {
+ repositoryHelper = (Repository) applicationContext.getBean("repositoryHelper");
+ }
+ return repositoryHelper;
+ }
+
+ public void setRepositoryHelper(Repository repositoryHelper)
+ {
+ this.repositoryHelper = repositoryHelper;
+ }
+
+ public TransactionService getTransactionService()
+ {
+ if (transactionService == null)
+ {
+ transactionService = (TransactionService) applicationContext.getBean("transactionService");
+ }
+ return transactionService;
+ }
+
+ public void setTransactionService(TransactionService transactionService)
+ {
+ this.transactionService = transactionService;
+ }
+
+ public RenditionDefinitionRegistry2Impl getRenditionDefinitionRegistry2Impl()
+ {
+ if (renditionDefinitionRegistry2 == null)
+ {
+ renditionDefinitionRegistry2 = (RenditionDefinitionRegistry2Impl) applicationContext.getBean("renditionDefinitionRegistry2");
+ }
+ return renditionDefinitionRegistry2;
+ }
+
+ public void setRenditionDefinitionRegistry2(RenditionDefinitionRegistry2Impl renditionDefinitionRegistry2)
+ {
+ this.renditionDefinitionRegistry2 = renditionDefinitionRegistry2;
+ }
+
+ public void afterPropertiesSet() throws Exception
+ {
+ PropertyCheck.mandatory(this, "transformerLog", info);
+ PropertyCheck.mandatory(this, "transformerDebugLog", logger);
+ PropertyCheck.mandatory(this, "nodeService", nodeService);
+ PropertyCheck.mandatory(this, "mimetypeService", mimetypeService);
+ PropertyCheck.mandatory(this, "transformerRegistry", transformerRegistry);
+ PropertyCheck.mandatory(this, "transformerConfig", transformerConfig);
+ }
+
+ @Deprecated
+ public void pushAvailable(String fromUrl, String sourceMimetype, String targetMimetype,
+ TransformationOptions options)
+ {
+ String renditionName = options == null ? null : options.getUse();
+ NodeRef sourceNodeRef = options == null ? null : options.getSourceNodeRef();
+ pushAvailable(fromUrl, sourceMimetype, targetMimetype, renditionName, sourceNodeRef);
+ }
+
/**
* Called prior to working out what transformers are available.
*/
+ @Deprecated
public void pushAvailable(String fromUrl, String sourceMimetype, String targetMimetype,
- TransformationOptions options)
+ String renditionName, NodeRef sourceNodeRef)
{
if (isEnabled())
{
- push(null, fromUrl, sourceMimetype, targetMimetype, -1, options, Call.AVAILABLE);
+ push(null, fromUrl, sourceMimetype, targetMimetype, -1, renditionName,
+ sourceNodeRef, Call.AVAILABLE);
}
}
/**
* Called when a transformer has been ignored because of a blacklist entry.
*/
+ @Deprecated
public void blacklistTransform(ContentTransformer transformer, String sourceMimetype,
String targetMimetype, TransformationOptions options)
{
log("Blacklist "+getName(transformer)+" "+getMimetypeExt(sourceMimetype)+getMimetypeExt(targetMimetype));
}
-
+
+ @Deprecated
+ public void pushTransform(ContentTransformer transformer, String fromUrl, String sourceMimetype,
+ String targetMimetype, long sourceSize, TransformationOptions options)
+ {
+ String renditionName = options == null ? null : options.getUse();
+ NodeRef sourceNodeRef = options == null ? null : options.getSourceNodeRef();
+ pushTransform(transformer, fromUrl, sourceMimetype, targetMimetype, sourceSize, renditionName, sourceNodeRef);
+ }
+
/**
* Called prior to performing a transform.
*/
+ @Deprecated
public void pushTransform(ContentTransformer transformer, String fromUrl, String sourceMimetype,
- String targetMimetype, long sourceSize, TransformationOptions options)
+ String targetMimetype, long sourceSize, String renditionName, NodeRef sourceNodeRef)
{
if (isEnabled())
{
push(getName(transformer), fromUrl, sourceMimetype, targetMimetype, sourceSize,
- options, Call.TRANSFORM);
+ renditionName, sourceNodeRef, Call.TRANSFORM);
}
}
-
+
+ public void pushTransform(String transformerName, String fromUrl, String sourceMimetype,
+ String targetMimetype, long sourceSize, String renditionName, NodeRef sourceNodeRef)
+ {
+ if (isEnabled())
+ {
+ push(transformerName, fromUrl, sourceMimetype, targetMimetype, sourceSize,
+ renditionName, sourceNodeRef, Call.TRANSFORM);
+ }
+ }
+
/**
* Adds a new level to the stack to get a new request number or nesting number.
* Called prior to working out what transformers are active
@@ -353,13 +491,14 @@ public class TransformerDebug
{
if (isEnabled())
{
- push(null, null, null, null, -1, null, Call.AVAILABLE);
+ push(null, null, null, null, -1, null, null, Call.AVAILABLE);
}
}
/**
* Called prior to calling a nested isTransformable.
*/
+ @Deprecated
public void pushIsTransformableSize(ContentTransformer transformer)
{
if (isEnabled())
@@ -369,7 +508,7 @@ public class TransformerDebug
}
private void push(String transformerName, String fromUrl, String sourceMimetype, String targetMimetype,
- long sourceSize, TransformationOptions options, Call callType)
+ long sourceSize, String renditionName, NodeRef sourceNodeRef, Call callType)
{
Deque ourStack = ThreadInfo.getStack();
Frame frame = ourStack.peek();
@@ -383,13 +522,14 @@ public class TransformerDebug
// Create a new frame. Logging level is set to trace if the file size is 0
boolean origDebugOutput = ThreadInfo.setDebugOutput(ThreadInfo.getDebugOutput() && sourceSize != 0);
- frame = new Frame(frame, transformerName, fromUrl, sourceMimetype, targetMimetype, sourceSize, options, callType, origDebugOutput);
+ frame = new Frame(frame, transformerName, fromUrl, sourceMimetype, targetMimetype, sourceSize, renditionName,
+ sourceNodeRef, callType, origDebugOutput);
ourStack.push(frame);
if (callType == Call.TRANSFORM)
{
// Log the basic info about this transformation
- logBasicDetails(frame, sourceSize, options.getUse(), transformerName, (ourStack.size() == 1));
+ logBasicDetails(frame, sourceSize, renditionName, transformerName, (ourStack.size() == 1));
}
}
@@ -397,6 +537,7 @@ public class TransformerDebug
* Called to identify a transformer that cannot be used during working out
* available transformers.
*/
+ @Deprecated
public void unavailableTransformer(ContentTransformer transformer, String sourceMimetype, String targetMimetype, long maxSourceSizeKBytes)
{
if (isEnabled())
@@ -421,11 +562,21 @@ public class TransformerDebug
}
}
+ @Deprecated
+ public void availableTransformers(List transformers, long sourceSize,
+ TransformationOptions options, String calledFrom)
+ {
+ String renditionName = options == null ? null : options.getUse();
+ NodeRef sourceNodeRef = options == null ? null : options.getSourceNodeRef();
+ availableTransformers(transformers, sourceSize, renditionName, sourceNodeRef, calledFrom);
+ }
+
/**
* Called once all available transformers have been identified.
*/
+ @Deprecated
public void availableTransformers(List transformers, long sourceSize,
- TransformationOptions options, String calledFrom)
+ String renditionName, NodeRef sourceNodeRef, String calledFrom)
{
if (isEnabled())
{
@@ -447,7 +598,7 @@ public class TransformerDebug
frame.setSourceSize(sourceSize);
// Log the basic info about this transformation
- logBasicDetails(frame, sourceSize, options.getUse(),
+ logBasicDetails(frame, sourceSize, renditionName,
calledFrom + ((transformers.size() == 0) ? " NO transformers" : ""), firstLevel);
// Report available and unavailable transformers
@@ -457,7 +608,11 @@ public class TransformerDebug
{
String name = getName(trans);
int padName = longestNameLength - name.length() + 1;
- long maxSourceSizeKBytes = trans.getMaxSourceSizeKBytes(frame.sourceMimetype, frame.targetMimetype, frame.options);
+ // TODO replace with call to RenditionService2 or leave as a deprecated method using ContentService.
+ TransformationOptions options = new TransformationOptions();
+ options.setUse(frame.renditionName);
+ options.setSourceNodeRef(frame.sourceNodeRef);
+ long maxSourceSizeKBytes = trans.getMaxSourceSizeKBytes(frame.sourceMimetype, frame.targetMimetype, options);
String size = maxSourceSizeKBytes > 0 ? "< "+fileSize(maxSourceSizeKBytes*1024) : "";
int padSize = 10 - size.length();
String priority = gePriority(trans, frame.sourceMimetype, frame.targetMimetype);
@@ -491,11 +646,13 @@ public class TransformerDebug
return priority;
}
+ @Deprecated
public void inactiveTransformer(ContentTransformer transformer)
{
log(getName(transformer)+' '+ms(transformer.getTransformationTime(null, null))+" INACTIVE");
}
+ @Deprecated
public void activeTransformer(int mimetypePairCount, ContentTransformer transformer, String sourceMimetype,
String targetMimetype, long maxSourceSizeKBytes, boolean firstMimetypePair)
{
@@ -510,8 +667,9 @@ public class TransformerDebug
' '+fileSize((maxSourceSizeKBytes > 0) ? maxSourceSizeKBytes*1024 : maxSourceSizeKBytes)+
(maxSourceSizeKBytes == 0 ? " disabled" : ""));
}
-
- public void activeTransformer(String sourceMimetype, String targetMimetype,
+
+ @Deprecated
+ public void activeTransformer(String sourceMimetype, String targetMimetype,
int transformerCount, ContentTransformer transformer, long maxSourceSizeKBytes,
boolean firstTransformer)
{
@@ -548,7 +706,7 @@ public class TransformerDebug
return longestNameLength;
}
- private void logBasicDetails(Frame frame, long sourceSize, String use, String message, boolean firstLevel)
+ private void logBasicDetails(Frame frame, long sourceSize, String renditionName, String message, boolean firstLevel)
{
// Log the source URL, but there is no point if the parent has logged it
if (frame.fromUrl != null && (firstLevel || frame.id != 1))
@@ -557,14 +715,14 @@ public class TransformerDebug
}
log(frame.sourceMimetype+' '+frame.targetMimetype, false);
- String fileName = getFileName(frame.options, firstLevel, sourceSize);
+ String fileName = getFileName(frame.sourceNodeRef, firstLevel, sourceSize);
log(getMimetypeExt(frame.sourceMimetype)+getMimetypeExt(frame.targetMimetype) +
((fileName != null) ? fileName+' ' : "")+
((sourceSize >= 0) ? fileSize(sourceSize)+' ' : "") +
- (firstLevel && use != null ? "-- "+use+" -- " : "") + message);
+ (firstLevel && renditionName != null ? "-- "+renditionName+" -- " : "") + message);
if (firstLevel)
{
- String nodeRef = getNodeRef(frame.options, firstLevel, sourceSize);
+ String nodeRef = getNodeRef(frame.sourceNodeRef, firstLevel, sourceSize);
if (!nodeRef.isEmpty())
{
log(nodeRef);
@@ -659,7 +817,7 @@ public class TransformerDebug
boolean firstLevel = size == 1;
String sourceExt = getMimetypeExt(frame.sourceMimetype);
String targetExt = getMimetypeExt(frame.targetMimetype);
- String fileName = getFileName(frame.options, firstLevel, frame.sourceSize);
+ String fileName = getFileName(frame.sourceNodeRef, firstLevel, frame.sourceSize);
long sourceSize = frame.getSourceSize();
String transformerName = frame.getTransformerName();
String level = null;
@@ -893,9 +1051,11 @@ public class TransformerDebug
* @param toString indicates that a String value should be returned in addition to any debug.
* @param format42 indicates the old 4.1.4 format should be used which did not order the transformers
* and only included top level transformers.
- * @param use to which the transformation will be put (such as "Index", "Preview", null).
+ * @param renditionName to which the transformation will be put (such as "Index", "Preview", null).
+ * @deprecated The transformations code is being moved out of the codebase and replaced by the new async RenditionService2 or other external libraries.
*/
- public String transformationsByTransformer(String transformerName, boolean toString, boolean format42, String use)
+ @Deprecated
+ public String transformationsByTransformer(String transformerName, boolean toString, boolean format42, String renditionName)
{
// Do not generate this type of debug if already generating other debug to a StringBuilder
// (for example a test transform).
@@ -915,7 +1075,7 @@ public class TransformerDebug
: mimetypeService.getMimetypes();
TransformationOptions options = new TransformationOptions();
- options.setUse(use);
+ options.setUse(renditionName);
StringBuilder sb = null;
try
{
@@ -977,10 +1137,12 @@ public class TransformerDebug
* level transformers.
* @param onlyNonDeterministic if true only report transformations where there is more than
* one transformer available with the same priority.
- * @param use to which the transformation will be put (such as "Index", "Preview", null).
+ * @param renditionName to which the transformation will be put (such as "Index", "Preview", null).
+ * @deprecated The transformations code is being moved out of the codebase and replaced by the new async RenditionService2 or other external libraries.
*/
+ @Deprecated
public String transformationsByExtension(String sourceExtension, String targetExtension, boolean toString,
- boolean format42, boolean onlyNonDeterministic, String use)
+ boolean format42, boolean onlyNonDeterministic, String renditionName)
{
// Do not generate this type of debug if already generating other debug to a StringBuilder
// (for example a test transform).
@@ -1000,7 +1162,7 @@ public class TransformerDebug
: mimetypeService.getMimetypes();
TransformationOptions options = new TransformationOptions();
- options.setUse(use);
+ options.setUse(renditionName);
StringBuilder sb = null;
try
{
@@ -1248,24 +1410,30 @@ public class TransformerDebug
return !transformerRegistry.getTransformers().contains(transformer);
}
+ @Deprecated
public String getFileName(TransformationOptions options, boolean firstLevel, long sourceSize)
{
- return getFileNameOrNodeRef(options, firstLevel, sourceSize, true);
+ NodeRef sourceNodeRef = options == null ? null : options.getSourceNodeRef();
+ return getFileName(sourceNodeRef, firstLevel, sourceSize);
}
-
- private String getNodeRef(TransformationOptions options, boolean firstLevel, long sourceSize)
+
+ public String getFileName(NodeRef sourceNodeRef, boolean firstLevel, long sourceSize)
{
- return getFileNameOrNodeRef(options, firstLevel, sourceSize, false);
+ return getFileNameOrNodeRef(sourceNodeRef, firstLevel, sourceSize, true);
+ }
+
+ private String getNodeRef(NodeRef sourceNodeRef, boolean firstLevel, long sourceSize)
+ {
+ return getFileNameOrNodeRef(sourceNodeRef, firstLevel, sourceSize, false);
}
- private String getFileNameOrNodeRef(TransformationOptions options, boolean firstLevel, long sourceSize, boolean getName)
+ private String getFileNameOrNodeRef(NodeRef sourceNodeRef, boolean firstLevel, long sourceSize, boolean getName)
{
String result = getName ? null : "";
- if (options != null)
+ if (sourceNodeRef != null)
{
try
{
- NodeRef sourceNodeRef = options.getSourceNodeRef();
result = getName
? (String)nodeService.getProperty(sourceNodeRef, ContentModel.PROP_NAME)
: sourceNodeRef.toString()+" ";
@@ -1368,7 +1536,9 @@ public class TransformerDebug
* @param transformerName to restrict the collection to one entry
* @return a new Collection of sorted transformers
* @throws IllegalArgumentException if transformerName is not found.
+ * @deprecated The transformations code is being moved out of the codebase and replaced by the new async RenditionService2 or other external libraries.
*/
+ @Deprecated
public Collection sortTransformersByName(String transformerName)
{
Collection transformers = (transformerName != null)
@@ -1389,13 +1559,14 @@ public class TransformerDebug
* Debugs a request to the Transform Service
*/
public int debugTransformServiceRequest(String sourceMimetype, long sourceSize, NodeRef sourceNodeRef,
- int contentHashcode, String fileName, String targetMimetype, String use)
+ int contentHashcode, String fileName, String targetMimetype,
+ String renditionName)
{
pushMisc();
debug(getMimetypeExt(sourceMimetype)+getMimetypeExt(targetMimetype) +
((fileName != null) ? fileName+' ' : "")+
((sourceSize >= 0) ? fileSize(sourceSize)+' ' : "") +
- (use != null ? "-- "+use+" -- " : "") + " RenditionService2");
+ (renditionName != null ? "-- "+renditionName+" -- " : "") + " RenditionService2");
debug(sourceNodeRef.toString() + ' ' +contentHashcode);
debug(" **a) [01] TransformService");
return pop(Call.AVAILABLE, true, false);
@@ -1426,35 +1597,22 @@ public class TransformerDebug
pop(Call.AVAILABLE, suppressFinish, true);
}
- public String testTransform(String sourceExtension, String targetExtension, String use)
+ public String testTransform(String sourceExtension, String targetExtension, String renditionName)
{
- return new TestTransform()
- {
- protected void transform(ContentReader reader, ContentWriter writer, TransformationOptions options)
- {
- contentService.transform(reader, writer, options);
- }
- }.run(sourceExtension, targetExtension, use);
+ return new TestTransform().run(sourceExtension, targetExtension, renditionName);
}
-
- public String testTransform(final String transformerName, String sourceExtension,
- String targetExtension, String use)
- {
- final ContentTransformer transformer = transformerRegistry.getTransformer(transformerName);
- return new TestTransform()
- {
- protected String isTransformable(String sourceMimetype, long sourceSize, String targetMimetype, TransformationOptions options)
- {
- return transformer.isTransformable(sourceMimetype, sourceSize, targetMimetype, options)
- ? null
- : transformerName+" does not support this transformation.";
- }
- protected void transform(ContentReader reader, ContentWriter writer, TransformationOptions options)
- {
- transformer.transform(reader, writer, options);
- }
- }.run(sourceExtension, targetExtension, use);
+ /**
+ * @deprecated The transformations code is being moved out of the codebase and replaced by the new async RenditionService2 or other external libraries.
+ */
+ @Deprecated
+ public String testTransform(final String transformerName, String sourceExtension,
+ String targetExtension, String renditionName)
+ {
+ logger.error("The testTransform operation for a specific transformer is no longer supported. " +
+ "Direct transforms have been deprecated in favour of async renditions. " +
+ "Request redirected to the version of this method without a transformerName.");
+ return testTransform(sourceExtension, targetExtension, renditionName);
}
public String[] getTestFileExtensionsAndMimetypes()
@@ -1499,70 +1657,72 @@ public class TransformerDebug
}
@Deprecated
- @AlfrescoPublicApi
- private abstract class TestTransform
+ private class TestTransform
{
- String run(String sourceExtension, String targetExtension, String use)
+ protected LinkedList nodesToDeleteAfterTest = new LinkedList();
+
+ String run(String sourceExtension, String targetExtension, String renditionName)
{
- String debug;
-
+ RetryingTransactionHelper.RetryingTransactionCallback makeNodeCallback = new RetryingTransactionHelper.RetryingTransactionCallback()
+ {
+ public String execute() throws Throwable
+ {
+ return runWithinTransaction(sourceExtension, targetExtension);
+ }
+ };
+ return getTransactionService().getRetryingTransactionHelper().doInTransaction(makeNodeCallback, false, true);
+ }
+
+ private String runWithinTransaction(String sourceExtension, String targetExtension)
+ {
+ RenditionDefinitionRegistry2Impl renditionDefinitionRegistry2 = getRenditionDefinitionRegistry2Impl();
+
String targetMimetype = getMimetype(targetExtension, false);
String sourceMimetype = getMimetype(sourceExtension, true);
- URL sourceURL = loadQuickTestFile(sourceExtension);
- if (sourceURL == null)
- {
- throw new IllegalArgumentException("There is no test file with a "+sourceExtension+" extension.");
- }
-
- // This URL may point to a file on the filesystem or to an entry in a jar.
- // To use the transform method below, we need the content to be accessible from a ContentReader.
- // This is possible for a File but not a (non-file) URL.
- //
- // Therefore, we'll always copy the URL content to a temporary local file.
- final File sourceFile = TempFileProvider.createTempFile(TransformerDebug.class.getSimpleName() + "-tmp-", "");
-
- try { FileUtils.copyURLToFile(sourceURL, sourceFile); }
- catch (IOException shouldNeverHappen)
- {
- // The sourceURL should always be readable as we're reading data that Alfresco is distributing.
- // But just in case...
- throw new IllegalArgumentException("Cannot read content of test file with a " +
- sourceExtension + " extension.", shouldNeverHappen);
- }
-
- ContentReader reader = new FileContentReader(sourceFile);
- reader.setMimetype(sourceMimetype);
File tempFile = TempFileProvider.createTempFile(
"TestTransform_" + sourceExtension + "_", "." + targetExtension);
ContentWriter writer = new FileContentWriter(tempFile);
writer.setMimetype(targetMimetype);
- long sourceSize = reader.getSize();
- TransformationOptions options = new TransformationOptions();
- options.setUse(use);
-
- debug = isTransformable(sourceMimetype, sourceSize, targetMimetype, options);
- if (debug == null)
+ String testRenditionName = "testTransform"+System.currentTimeMillis();
+ NodeRef sourceNodeRef = null;
+ StringBuilder sb = new StringBuilder();
+ try
{
- StringBuilder sb = new StringBuilder();
- try
+ setStringBuilder(sb);
+ RenditionDefinition2 renditionDefinition = new RenditionDefinition2Impl(testRenditionName, targetMimetype,
+ Collections.emptyMap(), renditionDefinitionRegistry2);
+
+ sourceNodeRef = createSourceNode(sourceExtension, sourceMimetype);
+ ContentData contentData = (ContentData) nodeService.getProperty(sourceNodeRef, ContentModel.PROP_CONTENT);
+ if (contentData != null)
{
- setStringBuilder(sb);
- transform(reader, writer, options);
+ String contentUrl = contentData.getContentUrl();
+ if (contentUrl != null)
+ {
+ long size = contentData.getSize();
+ int sourceContentHashCode = SOURCE_HAS_NO_CONTENT;
+ String contentString = contentData.getContentUrl()+contentData.getMimetype();
+ if (contentString != null)
+ {
+ sourceContentHashCode = contentString.hashCode();
+ }
+
+ TransformClient transformClient = getTransformClient();
+ transformClient.checkSupported(sourceNodeRef, renditionDefinition, sourceMimetype, size, contentUrl);
+ transformClient.transform(sourceNodeRef, renditionDefinition, "testTransform", sourceContentHashCode);
+ }
}
- catch (AlfrescoRuntimeException e)
- {
- sb.append(e.getMessage());
- }
- finally
- {
- setStringBuilder(null);
- }
- debug = sb.toString();
}
- return debug;
+ finally
+ {
+ setStringBuilder(null);
+ renditionDefinitionRegistry2.unregister(testRenditionName);
+ deleteSourceNode(sourceNodeRef);
+ }
+ return sb.toString();
}
-
+
private String getMimetype(String extension, boolean isSource)
{
String mimetype = null;
@@ -1581,11 +1741,57 @@ public class TransformerDebug
return mimetype;
}
- protected String isTransformable(String sourceMimetype, long sourceSize, String targetMimetype, TransformationOptions options)
+ public NodeRef createSourceNode(String extension, String sourceMimetype)
{
- return null;
+ // Create a content node which will serve as test data for our transformations.
+ RetryingTransactionHelper.RetryingTransactionCallback makeNodeCallback = new RetryingTransactionHelper.RetryingTransactionCallback()
+ {
+ public NodeRef execute() throws Throwable
+ {
+ // Create a source node loaded with a quick file.
+ URL url = loadQuickTestFile(extension);
+ URI uri = url.toURI();
+ File sourceFile = new File(uri);
+
+ final NodeRef companyHome = getRepositoryHelper().getCompanyHome();
+
+ Map props = new HashMap();
+ String localName = "TestTransform." + extension;
+ props.put(ContentModel.PROP_NAME, localName);
+ NodeRef node = nodeService.createNode(
+ companyHome,
+ ContentModel.ASSOC_CONTAINS,
+ QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, localName),
+ ContentModel.TYPE_CONTENT,
+ props).getChildRef();
+
+ ContentWriter writer = getContentService().getWriter(node, ContentModel.PROP_CONTENT, true);
+ writer.setMimetype(sourceMimetype);
+ writer.setEncoding("UTF-8");
+ writer.putContent(sourceFile);
+
+ return node;
+ }
+ };
+ NodeRef contentNodeRef = getTransactionService().getRetryingTransactionHelper().doInTransaction(makeNodeCallback);
+ this.nodesToDeleteAfterTest.add(contentNodeRef);
+ return contentNodeRef;
+ }
+
+ public void deleteSourceNode(NodeRef sourceNodeRef)
+ {
+ if (sourceNodeRef != null)
+ {
+ getTransactionService().getRetryingTransactionHelper().doInTransaction(
+ (RetryingTransactionHelper.RetryingTransactionCallback) () ->
+ {
+ if (nodeService.exists(sourceNodeRef))
+ {
+ nodeService.deleteNode(sourceNodeRef);
+ }
+ return null;
+ });
+ }
}
-
- protected abstract void transform(ContentReader reader, ContentWriter writer, TransformationOptions options);
}
}
diff --git a/src/main/java/org/alfresco/repo/content/transform/UnsupportedTransformationException.java b/src/main/java/org/alfresco/repo/content/transform/UnsupportedTransformationException.java
index 6fcb7b2e2d..cf614de863 100644
--- a/src/main/java/org/alfresco/repo/content/transform/UnsupportedTransformationException.java
+++ b/src/main/java/org/alfresco/repo/content/transform/UnsupportedTransformationException.java
@@ -30,16 +30,12 @@ import org.alfresco.error.AlfrescoRuntimeException;
/**
* Exception indicates that a transformer is unable to transform a requested
- * transformation. Normally the transformer is a component of a complex (compound) transformer
- * and has been asked to transform a file that is too large (see transformation limits) as the
+ * transformation. Normally the transformer is a component of a pipeline transformer
+ * and has been asked to transform a file that is too large as the
* size of the intermediate file is unknown at the start.
*
* @author Alan Davis
- *
- * @deprecated The transformations code is being moved out of the codebase and replaced by the new async RenditionService2 or other external libraries.
*/
-@Deprecated
-@AlfrescoPublicApi
public class UnsupportedTransformationException extends AlfrescoRuntimeException
{
private static final long serialVersionUID = 9039331287661301086L;
diff --git a/src/main/java/org/alfresco/repo/content/transform/magick/ImageMagickContentTransformerWorker.java b/src/main/java/org/alfresco/repo/content/transform/magick/ImageMagickContentTransformerWorker.java
index b9779b16da..24f6c5e95e 100644
--- a/src/main/java/org/alfresco/repo/content/transform/magick/ImageMagickContentTransformerWorker.java
+++ b/src/main/java/org/alfresco/repo/content/transform/magick/ImageMagickContentTransformerWorker.java
@@ -81,12 +81,14 @@ public class ImageMagickContentTransformerWorker extends AbstractImageMagickCont
/** the system command executer */
private RuntimeExec executer;
+ private boolean enabled = true;
+
/** the check command executer */
private RuntimeExec checkCommand;
-
+
/** the output from the check command */
private String versionString;
-
+
/**
* Default constructor
*/
@@ -116,6 +118,11 @@ public class ImageMagickContentTransformerWorker extends AbstractImageMagickCont
this.executer = executer;
}
+ public void setEnabled(boolean enabled)
+ {
+ this.enabled = enabled;
+ }
+
/**
* Sets the command that must be executed in order to retrieve version information from the converting executable
* and thus test that the executable itself is present.
@@ -127,7 +134,7 @@ public class ImageMagickContentTransformerWorker extends AbstractImageMagickCont
{
this.checkCommand = checkCommand;
}
-
+
/**
* Gets the version string captured from the check command.
*
@@ -146,54 +153,57 @@ public class ImageMagickContentTransformerWorker extends AbstractImageMagickCont
@Override
public void afterPropertiesSet()
{
- if (!remoteTransformerClientConfigured() && executer == null)
+ if (enabled)
{
- throw new AlfrescoRuntimeException("System runtime executer not set");
- }
- super.afterPropertiesSet();
- if (!remoteTransformerClientConfigured())
- {
- if (isAvailable())
+ if (!remoteTransformerClientConfigured() && executer == null)
{
- try
- {
- // On some platforms / versions, the -version command seems to return an error code whilst still
- // returning output, so let's not worry about the exit code!
- ExecutionResult result = this.checkCommand.execute();
- this.versionString = result.getStdOut().trim();
- }
- catch (Throwable e)
- {
- setAvailable(false);
- logger.error(getClass().getSimpleName() + " not available: "
- + (e.getMessage() != null ? e.getMessage() : ""));
- // debug so that we can trace the issue if required
- logger.debug(e);
- }
+ throw new AlfrescoRuntimeException("System runtime executer not set");
}
- }
- else
- {
- Pair result = remoteTransformerClient.check(logger);
- Boolean isAvailable = result.getFirst();
- if (isAvailable != null && isAvailable)
+ super.afterPropertiesSet();
+ if (!remoteTransformerClientConfigured())
{
- setAvailable(true);
- versionString = result.getSecond().trim();
- logger.info("Using remote ImageMagick: "+versionString);
+ if (isAvailable())
+ {
+ try
+ {
+ // On some platforms / versions, the -version command seems to return an error code whilst still
+ // returning output, so let's not worry about the exit code!
+ ExecutionResult result = this.checkCommand.execute();
+ this.versionString = result.getStdOut().trim();
+ }
+ catch (Throwable e)
+ {
+ setAvailable(false);
+ logger.error(getClass().getSimpleName() + " not available: "
+ + (e.getMessage() != null ? e.getMessage() : ""));
+ // debug so that we can trace the issue if required
+ logger.debug(e);
+ }
+ }
}
else
{
- setAvailable(false);
- versionString = "unknown";
- String message = "Remote ImageMagick is not available for transformations. " + result.getSecond();
- if (isAvailable == null)
+ Pair result = remoteTransformerClient.check(logger);
+ Boolean isAvailable = result.getFirst();
+ if (isAvailable != null && isAvailable)
{
- logger.debug(message);
+ setAvailable(true);
+ versionString = result.getSecond().trim();
+ logger.info("Using legacy ImageMagick: " + versionString);
}
else
{
- logger.error(message);
+ setAvailable(false);
+ versionString = "unknown";
+ String message = "Legacy remote ImageMagick is not available for transformations. " + result.getSecond();
+ if (isAvailable == null)
+ {
+ logger.debug(message);
+ }
+ else
+ {
+ logger.error(message);
+ }
}
}
}
diff --git a/src/main/java/org/alfresco/repo/content/transform/pdfrenderer/AlfrescoPdfRendererContentTransformerWorker.java b/src/main/java/org/alfresco/repo/content/transform/pdfrenderer/AlfrescoPdfRendererContentTransformerWorker.java
index 4c97cc2a9e..f0ca882334 100644
--- a/src/main/java/org/alfresco/repo/content/transform/pdfrenderer/AlfrescoPdfRendererContentTransformerWorker.java
+++ b/src/main/java/org/alfresco/repo/content/transform/pdfrenderer/AlfrescoPdfRendererContentTransformerWorker.java
@@ -77,6 +77,8 @@ public class AlfrescoPdfRendererContentTransformerWorker extends ContentTransfor
/** the system command executer */
private RuntimeExec executer;
+ private boolean enabled = true;
+
/** the check command executer */
private RuntimeExec checkCommand;
@@ -110,6 +112,11 @@ public class AlfrescoPdfRendererContentTransformerWorker extends ContentTransfor
this.executer = executer;
}
+ public void setEnabled(boolean enabled)
+ {
+ this.enabled = enabled;
+ }
+
/**
* Sets the optional remote transformer client which will be used in preference to a local command if available.
*
@@ -141,41 +148,44 @@ public class AlfrescoPdfRendererContentTransformerWorker extends ContentTransfor
@Override
public void afterPropertiesSet()
{
- PropertyCheck.mandatory(this, "executer", executer);
- PropertyCheck.mandatory(this, "isAvailable", checkCommand);
- // check availability
- try
+ if (enabled)
{
- Pair result = remoteTransformerClientConfigured()
- ? remoteTransformerClient.check(logger)
- : remoteTransformerClient.check(checkCommand);
- Boolean isAvailable = result.getFirst();
- if (isAvailable != null && isAvailable)
+ PropertyCheck.mandatory(this, "executer", executer);
+ PropertyCheck.mandatory(this, "isAvailable", checkCommand);
+ // check availability
+ try
{
- versionString = result.getSecond();
- setAvailable(true);
- logger.info("Using remote Alfresco PDF Renderer: "+versionString);
- }
- else
- {
- setAvailable(false);
- String message = "Remote Alfresco PDF Renderer is not available for transformations. " + result.getSecond();
- if (isAvailable == null)
+ Pair result = remoteTransformerClientConfigured()
+ ? remoteTransformerClient.check(logger)
+ : remoteTransformerClient.check(checkCommand);
+ Boolean isAvailable = result.getFirst();
+ if (isAvailable != null && isAvailable)
{
- logger.debug(message);
+ versionString = result.getSecond();
+ setAvailable(true);
+ logger.info("Using legacy Alfresco PDF Renderer: " + versionString);
}
else
{
- logger.error(message);
+ setAvailable(false);
+ String message = "Legacy Alfresco PDF Renderer is not available for transformations. " + result.getSecond();
+ if (isAvailable == null)
+ {
+ logger.debug(message);
+ }
+ else
+ {
+ logger.error(message);
+ }
}
}
- }
- catch (Throwable e)
- {
- setAvailable(false);
- logger.error("Remote Alfresco PDF Renderer is not available: " + (e.getMessage() != null ? e.getMessage() : ""));
- // debug so that we can trace the issue if required
- logger.debug(e);
+ catch (Throwable e)
+ {
+ setAvailable(false);
+ logger.error("Remote Alfresco PDF Renderer is not available: " + (e.getMessage() != null ? e.getMessage() : ""));
+ // debug so that we can trace the issue if required
+ logger.debug(e);
+ }
}
}
diff --git a/src/main/java/org/alfresco/repo/rendition2/LegacyLocalTransformClient.java b/src/main/java/org/alfresco/repo/rendition2/LegacyTransformClient.java
similarity index 91%
rename from src/main/java/org/alfresco/repo/rendition2/LegacyLocalTransformClient.java
rename to src/main/java/org/alfresco/repo/rendition2/LegacyTransformClient.java
index dccfa89c70..c1a9418ac7 100644
--- a/src/main/java/org/alfresco/repo/rendition2/LegacyLocalTransformClient.java
+++ b/src/main/java/org/alfresco/repo/rendition2/LegacyTransformClient.java
@@ -37,6 +37,7 @@ import org.alfresco.service.transaction.TransactionService;
import org.alfresco.util.PropertyCheck;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.springframework.beans.factory.InitializingBean;
import java.io.InputStream;
import java.util.Map;
@@ -52,9 +53,9 @@ import java.util.concurrent.Executors;
* @author adavis
*/
@Deprecated
-public class LegacyLocalTransformClient extends AbstractTransformClient implements TransformClient
+public class LegacyTransformClient implements TransformClient, InitializingBean
{
- private static Log logger = LogFactory.getLog(LegacyLocalTransformClient.class);
+ private static Log logger = LogFactory.getLog(LegacyTransformClient.class);
private TransactionService transactionService;
@@ -94,7 +95,7 @@ public class LegacyLocalTransformClient extends AbstractTransformClient implemen
@Override
public void afterPropertiesSet() throws Exception
{
- super.afterPropertiesSet();
+ PropertyCheck.mandatory(this, "transactionService", transactionService);
PropertyCheck.mandatory(this, "contentService", contentService);
PropertyCheck.mandatory(this, "renditionService2", renditionService2);
PropertyCheck.mandatory(this, "converter", converter);
@@ -117,13 +118,13 @@ public class LegacyLocalTransformClient extends AbstractTransformClient implemen
ContentTransformer transformer = contentService.getTransformer(contentUrl, sourceMimetype, size, targetMimetype, transformationOptions);
if (transformer == null)
{
- String message = "Unsupported rendition " + renditionName + " from " + sourceMimetype + " size: " + size;
+ String message = "Unsupported rendition " + renditionName + " from " + sourceMimetype + " size: " + size + " using legacy transform";
logger.debug(message);
throw new UnsupportedOperationException(message);
}
if (logger.isDebugEnabled())
{
- logger.debug("Rendition of " + renditionName + " from " + sourceMimetype + " will use " + transformer.getName());
+ logger.debug("Rendition of " + renditionName + " from " + sourceMimetype + " will use legacy transform " + transformer.getName());
}
}
@@ -144,7 +145,7 @@ public class LegacyLocalTransformClient extends AbstractTransformClient implemen
TransformationOptions transformationOptions = converter.getTransformationOptions(renditionName, options);
transformationOptions.setSourceNodeRef(sourceNodeRef);
- ContentReader reader = LegacyLocalTransformClient.this.contentService.getReader(sourceNodeRef, ContentModel.PROP_CONTENT);
+ ContentReader reader = LegacyTransformClient.this.contentService.getReader(sourceNodeRef, ContentModel.PROP_CONTENT);
if (null == reader || !reader.exists())
{
throw new IllegalArgumentException("The supplied sourceNodeRef "+sourceNodeRef+" has no content.");
diff --git a/src/main/java/org/alfresco/repo/rendition2/LegacyLocalTransformServiceRegistry.java b/src/main/java/org/alfresco/repo/rendition2/LegacyTransformServiceRegistry.java
similarity index 81%
rename from src/main/java/org/alfresco/repo/rendition2/LegacyLocalTransformServiceRegistry.java
rename to src/main/java/org/alfresco/repo/rendition2/LegacyTransformServiceRegistry.java
index 0ddd2e9993..1e73405a80 100644
--- a/src/main/java/org/alfresco/repo/rendition2/LegacyLocalTransformServiceRegistry.java
+++ b/src/main/java/org/alfresco/repo/rendition2/LegacyTransformServiceRegistry.java
@@ -35,13 +35,13 @@ import org.springframework.beans.factory.InitializingBean;
import java.util.Map;
/**
- * Implements {@link TransformServiceRegistry} providing a mechanism of validating if a legacy local transformation
+ * Implements {@link TransformServiceRegistry} providing a mechanism of validating if a legacy transformation
* (based on {@link org.alfresco.repo.content.transform.AbstractContentTransformer2} request is supported.
*
* @author adavis
*/
@Deprecated
-public class LegacyLocalTransformServiceRegistry extends AbstractTransformServiceRegistry implements InitializingBean
+public class LegacyTransformServiceRegistry extends AbstractTransformServiceRegistry implements InitializingBean
{
private ContentService contentService;
private TransformationOptionsConverter converter;
@@ -85,14 +85,21 @@ public class LegacyLocalTransformServiceRegistry extends AbstractTransformServic
if (firstTime)
{
firstTime = false;
- transformerDebug.debug("Local legacy transformers are " + (enabled ? "enabled" : "disabled"));
+ transformerDebug.debug("Legacy transforms are " + (enabled ? "enabled" : "disabled"));
}
long maxSize = 0;
if (enabled)
{
- TransformationOptions transformationOptions = converter.getTransformationOptions(renditionName, options);
- maxSize = contentService.getMaxSourceSizeBytes(sourceMimetype, targetMimetype, transformationOptions);
+ try
+ {
+ TransformationOptions transformationOptions = converter.getTransformationOptions(renditionName, options);
+ maxSize = contentService.getMaxSourceSizeBytes(sourceMimetype, targetMimetype, transformationOptions);
+ }
+ catch (IllegalArgumentException ignore)
+ {
+ // Typically if the mimetype is invalid.
+ }
}
return maxSize;
}
diff --git a/src/main/java/org/alfresco/repo/rendition2/LocalTransformClient.java b/src/main/java/org/alfresco/repo/rendition2/LocalTransformClient.java
new file mode 100644
index 0000000000..76d2587111
--- /dev/null
+++ b/src/main/java/org/alfresco/repo/rendition2/LocalTransformClient.java
@@ -0,0 +1,177 @@
+/*
+ * #%L
+ * Alfresco Repository
+ * %%
+ * Copyright (C) 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 .
+ * #L%
+ */
+package org.alfresco.repo.rendition2;
+
+import org.alfresco.model.ContentModel;
+import org.alfresco.repo.content.transform.LocalTransform;
+import org.alfresco.repo.content.transform.LocalTransformServiceRegistry;
+import org.alfresco.repo.security.authentication.AuthenticationUtil;
+import org.alfresco.service.cmr.repository.ContentReader;
+import org.alfresco.service.cmr.repository.ContentService;
+import org.alfresco.service.cmr.repository.ContentWriter;
+import org.alfresco.service.cmr.repository.NodeRef;
+import org.alfresco.service.transaction.TransactionService;
+import org.alfresco.util.PropertyCheck;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.springframework.beans.factory.InitializingBean;
+
+import java.io.InputStream;
+import java.util.Map;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+/**
+ * Requests rendition transforms take place using transforms available on the local machine (based on
+ * {@link LocalTransform}. The transform and consumption of the
+ * resulting content is linked into a single operation that will take place at some point in the future on the local
+ * machine.
+ *
+ * @author adavis
+ */
+public class LocalTransformClient implements TransformClient, InitializingBean
+{
+ private static Log logger = LogFactory.getLog(LocalTransformClient.class);
+
+ private LocalTransformServiceRegistry localTransformServiceRegistry;
+ private TransactionService transactionService;
+ private ContentService contentService;
+ private RenditionService2Impl renditionService2;
+
+ private ExecutorService executorService;
+
+ public void setLocalTransformServiceRegistry(LocalTransformServiceRegistry localTransformServiceRegistry)
+ {
+ this.localTransformServiceRegistry = localTransformServiceRegistry;
+ }
+
+ public void setTransactionService(TransactionService transactionService)
+ {
+ this.transactionService = transactionService;
+ }
+
+ public void setContentService(ContentService contentService)
+ {
+ this.contentService = contentService;
+ }
+
+ public void setRenditionService2(RenditionService2Impl renditionService2)
+ {
+ this.renditionService2 = renditionService2;
+ }
+
+ public void setExecutorService(ExecutorService executorService)
+ {
+ this.executorService = executorService;
+ }
+
+ @Override
+ public void afterPropertiesSet() throws Exception
+ {
+ PropertyCheck.mandatory(this, "localTransformServiceRegistry", localTransformServiceRegistry);
+ PropertyCheck.mandatory(this, "transactionService", transactionService);
+ PropertyCheck.mandatory(this, "contentService", contentService);
+ PropertyCheck.mandatory(this, "renditionService2", renditionService2);
+ if (executorService == null)
+ {
+ executorService = Executors.newCachedThreadPool();
+ }
+ }
+
+ @Override
+ public void checkSupported(NodeRef sourceNodeRef, RenditionDefinition2 renditionDefinition, String sourceMimetype, long size, String contentUrl)
+ {
+ String targetMimetype = renditionDefinition.getTargetMimetype();
+ String renditionName = renditionDefinition.getRenditionName();
+
+ Map options = renditionDefinition.getTransformOptions();
+ if (!localTransformServiceRegistry.isSupported(sourceMimetype, size, targetMimetype, options, renditionName))
+ {
+ String message = "Unsupported rendition " + renditionName + " from " + sourceMimetype + " size: " + size + " using local transforms";
+ logger.debug(message);
+ throw new UnsupportedOperationException(message);
+ }
+
+ if (logger.isDebugEnabled())
+ {
+ logger.debug("Rendition of " + renditionName + " from " + sourceMimetype + " will use local transforms");
+ }
+ }
+
+ @Override
+ public void transform(NodeRef sourceNodeRef, RenditionDefinition2 renditionDefinition, String user, int sourceContentHashCode)
+ {
+ executorService.submit(() ->
+ {
+ AuthenticationUtil.runAs((AuthenticationUtil.RunAsWork) () ->
+ transactionService.getRetryingTransactionHelper().doInTransaction(() ->
+ {
+ try
+ {
+ String targetMimetype = renditionDefinition.getTargetMimetype();
+ String renditionName = renditionDefinition.getRenditionName();
+ Map options = renditionDefinition.getTransformOptions();
+
+ ContentReader reader = contentService.getReader(sourceNodeRef, ContentModel.PROP_CONTENT);
+ if (null == reader || !reader.exists())
+ {
+ throw new IllegalArgumentException("The supplied sourceNodeRef "+sourceNodeRef+" has no content.");
+ }
+
+ ContentWriter writer = contentService.getTempWriter();
+ writer.setMimetype(targetMimetype);
+ if (logger.isDebugEnabled())
+ {
+ logger.debug("Local transform requested for rendition of " + renditionDefinition.getRenditionName());
+ }
+ localTransformServiceRegistry.transform(reader, writer, options, renditionName, sourceNodeRef);
+
+ InputStream inputStream = writer.getReader().getContentInputStream();
+ if (logger.isDebugEnabled())
+ {
+ logger.debug("Local transform to be consumed for rendition of " + renditionDefinition.getRenditionName());
+ }
+ renditionService2.consume(sourceNodeRef, inputStream, renditionDefinition, sourceContentHashCode);
+ if (logger.isDebugEnabled())
+ {
+ logger.debug("Local transform consumed for rendition of " + renditionDefinition.getRenditionName());
+ }
+ }
+ catch (Exception e)
+ {
+ if (logger.isDebugEnabled())
+ {
+ String renditionName = renditionDefinition.getRenditionName();
+ logger.error("Rendition of "+renditionName+" failed", e);
+ }
+ renditionService2.failure(sourceNodeRef, renditionDefinition, sourceContentHashCode);
+ throw e;
+ }
+ return null;
+ }), user);
+ });
+ }
+}
diff --git a/src/main/java/org/alfresco/repo/rendition2/RenditionDefinitionRegistry2Impl.java b/src/main/java/org/alfresco/repo/rendition2/RenditionDefinitionRegistry2Impl.java
index 12e9f92f18..5890440539 100644
--- a/src/main/java/org/alfresco/repo/rendition2/RenditionDefinitionRegistry2Impl.java
+++ b/src/main/java/org/alfresco/repo/rendition2/RenditionDefinitionRegistry2Impl.java
@@ -49,16 +49,18 @@ public class RenditionDefinitionRegistry2Impl implements RenditionDefinitionRegi
public void setTransformServiceRegistry(TransformServiceRegistry transformServiceRegistry)
{
this.transformServiceRegistry = transformServiceRegistry;
+ renditionsFor.clear();
}
/**
* Obtains a {@link RenditionDefinition2} by name.
* @param renditionName to be returned
* @return the {@link RenditionDefinition2} or null if not registered.
+ * @deprecated use {@link #getRenditionDefinition(String)}
*/
public RenditionDefinition2 getDefinition(String renditionName)
{
- return renditionDefinitions.get(renditionName);
+ return getRenditionDefinition(renditionName);
}
public void register(RenditionDefinition2 renditionDefinition)
diff --git a/src/main/java/org/alfresco/repo/rendition2/SwitchingTransformClient.java b/src/main/java/org/alfresco/repo/rendition2/SwitchingTransformClient.java
index d1f66aba76..65038a476a 100644
--- a/src/main/java/org/alfresco/repo/rendition2/SwitchingTransformClient.java
+++ b/src/main/java/org/alfresco/repo/rendition2/SwitchingTransformClient.java
@@ -38,7 +38,7 @@ public class SwitchingTransformClient implements TransformClient
{
private final TransformClient primary;
private final TransformClient secondary;
- private ThreadLocal usePrimary = new ThreadLocal<>();
+ private ThreadLocal usePrimary = ThreadLocal.withInitial(()->Boolean.FALSE);
public SwitchingTransformClient(TransformClient primary, TransformClient secondary)
{
diff --git a/src/main/java/org/alfresco/repo/thumbnail/ThumbnailRegistry.java b/src/main/java/org/alfresco/repo/thumbnail/ThumbnailRegistry.java
index 7e6f2a610f..1c712cf0ee 100644
--- a/src/main/java/org/alfresco/repo/thumbnail/ThumbnailRegistry.java
+++ b/src/main/java/org/alfresco/repo/thumbnail/ThumbnailRegistry.java
@@ -166,6 +166,7 @@ public class ThumbnailRegistry implements ApplicationContextAware, ApplicationLi
public void setTransformServiceRegistry(TransformServiceRegistry transformServiceRegistry)
{
this.transformServiceRegistry = transformServiceRegistry;
+ mimetypeMap.clear();
}
public void setRenditionDefinitionRegistry2(RenditionDefinitionRegistry2 renditionDefinitionRegistry2)
diff --git a/src/main/java/org/alfresco/transform/client/model/config/ExtensionMap.java b/src/main/java/org/alfresco/transform/client/model/config/AbstractTransformOption.java
similarity index 72%
rename from src/main/java/org/alfresco/transform/client/model/config/ExtensionMap.java
rename to src/main/java/org/alfresco/transform/client/model/config/AbstractTransformOption.java
index a8f91d0c00..5566128979 100644
--- a/src/main/java/org/alfresco/transform/client/model/config/ExtensionMap.java
+++ b/src/main/java/org/alfresco/transform/client/model/config/AbstractTransformOption.java
@@ -2,7 +2,7 @@
* #%L
* Alfresco Repository
* %%
- * Copyright (C) 2005 - 2018 Alfresco Software Limited
+ * 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
@@ -26,10 +26,21 @@
package org.alfresco.transform.client.model.config;
/**
- * Helper class to be supplied by the client to map file extensions to mimetypes, so the json description of what
- * is supported by the Transform Service includes file extensions rather than mmetypes, so is more readable.
+ * Abstract implementation of TransformOption.
*/
-public interface ExtensionMap
+public abstract class AbstractTransformOption implements TransformOption
{
- String toMimetype(String extension);
+ private boolean required;
+
+ @Override
+ public boolean isRequired()
+ {
+ return required;
+ }
+
+ @Override
+ public void setRequired(boolean required)
+ {
+ this.required = required;
+ }
}
diff --git a/src/main/java/org/alfresco/transform/client/model/config/CombinedConfig.java b/src/main/java/org/alfresco/transform/client/model/config/CombinedConfig.java
new file mode 100644
index 0000000000..2ce2e0979b
--- /dev/null
+++ b/src/main/java/org/alfresco/transform/client/model/config/CombinedConfig.java
@@ -0,0 +1,508 @@
+/*
+ * #%L
+ * Alfresco Repository
+ * %%
+ * Copyright (C) 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 .
+ * #L%
+ */
+package org.alfresco.transform.client.model.config;
+
+import com.fasterxml.jackson.core.type.TypeReference;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.ArrayNode;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import org.alfresco.error.AlfrescoRuntimeException;
+import org.apache.commons.logging.Log;
+import org.apache.http.HttpEntity;
+import org.apache.http.StatusLine;
+import org.apache.http.client.methods.CloseableHttpResponse;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClients;
+import org.apache.http.util.EntityUtils;
+
+import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.io.StringReader;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.jar.JarEntry;
+import java.util.jar.JarFile;
+
+/**
+ * This class recreates the json format used in ACS 6.1 where we just had an array of transformers and each
+ * transformer has a list of node options. The idea of this code is that it replaces the references with the
+ * actual node options that have been separated out into their own section.
+ *
+ * The T-Router and T-Engines return the format with the node option separated into their own section. Pipeline
+ * definitions used by the LocalTransformServiceRegistry may use node reference options defined in the json
+ * returned by T-Engines. with the actual definitions from the node options
+ * reference section. It also combines multiple json sources into a single jsonNode structure that can be parsed as
+ * before.
+ */
+public class CombinedConfig
+{
+ private static final String TRANSFORMER_NAME = "transformerName";
+ private static final String TRANSFORM_CONFIG = "/transform/config";
+ private static final String TRANSFORM_OPTIONS = "transformOptions";
+ private static final String GROUP = "group";
+ private static final String TRANSFORMERS = "transformers";
+
+ private final Log log;
+ private Map allTransformOptions = new HashMap<>();
+ private List allTransforms = new ArrayList<>();
+ private ObjectMapper jsonObjectMapper = new ObjectMapper();
+
+ static class TransformNodeAndItsOrigin
+ {
+ final ObjectNode node;
+ final String baseUrl;
+ final String readFrom;
+
+ TransformNodeAndItsOrigin(ObjectNode node, String baseUrl, String readFrom)
+ {
+ this.node = node;
+ this.baseUrl = baseUrl;
+ this.readFrom = readFrom;
+ }
+ }
+
+ static class TransformAndItsOrigin
+ {
+ final Transformer transform;
+ final String baseUrl;
+ final String readFrom;
+
+ TransformAndItsOrigin(Transformer transform, String baseUrl, String readFrom)
+ {
+ this.transform = transform;
+ this.baseUrl = baseUrl;
+ this.readFrom = readFrom;
+ }
+ }
+
+ public CombinedConfig(Log log)
+ {
+ this.log = log;
+ }
+
+ public boolean addRemoteConfig(List urls, String remoteType)
+ {
+ boolean successReadingRemoteConfig = true;
+ for (String url : urls)
+ {
+ if (!addRemoteConfig(url, remoteType))
+ {
+ successReadingRemoteConfig = false;
+ }
+ }
+ return successReadingRemoteConfig;
+ }
+
+ private boolean addRemoteConfig(String baseUrl, String remoteType)
+ {
+ String url = baseUrl + TRANSFORM_CONFIG;
+ HttpGet httpGet = new HttpGet(url);
+ boolean successReadingRemoteConfig = true;
+ try
+ {
+ try (CloseableHttpClient httpclient = HttpClients.createDefault())
+ {
+ try (CloseableHttpResponse response = execute(httpclient, httpGet))
+ {
+ StatusLine statusLine = response.getStatusLine();
+ if (statusLine == null)
+ {
+ throw new AlfrescoRuntimeException(remoteType+" on " + url+" returned no status ");
+ }
+ HttpEntity resEntity = response.getEntity();
+ if (resEntity != null)
+ {
+ int statusCode = statusLine.getStatusCode();
+ if (statusCode == 200)
+ {
+ try
+ {
+ String content = getContent(resEntity);
+
+ try (StringReader reader = new StringReader(content))
+ {
+ int transformCount = allTransforms.size();
+ addJsonSource(reader, baseUrl, remoteType+" on "+baseUrl);
+ if (transformCount == allTransforms.size())
+ {
+ successReadingRemoteConfig = false;
+ }
+ }
+
+ EntityUtils.consume(resEntity);
+ }
+ catch (IOException e)
+ {
+ throw new AlfrescoRuntimeException("Failed to read the returned content from "+
+ remoteType+" on " + url, e);
+ }
+ }
+ else
+ {
+ String message = getErrorMessage(resEntity);
+ throw new AlfrescoRuntimeException(remoteType+" on " + url+" returned a " + statusCode +
+ " status " + message);
+ }
+ }
+ else
+ {
+ throw new AlfrescoRuntimeException(remoteType+" on " + url+" did not return an entity " + url);
+ }
+ }
+ catch (IOException e)
+ {
+ throw new AlfrescoRuntimeException("Failed to connect or to read the response from "+remoteType+
+ " on " + url, e);
+ }
+ }
+ catch (IOException e)
+ {
+ throw new AlfrescoRuntimeException(remoteType+" on " + url+" failed to create an HttpClient", e);
+ }
+ }
+ catch (AlfrescoRuntimeException e)
+ {
+ log.error(e.getMessage());
+ successReadingRemoteConfig = false;
+ }
+ return successReadingRemoteConfig;
+ }
+
+ // Tests mock the return values
+ CloseableHttpResponse execute(CloseableHttpClient httpclient, HttpGet httpGet) throws IOException
+ {
+ return httpclient.execute(httpGet);
+ }
+
+ // Tests mock the return values
+ String getContent(HttpEntity resEntity) throws IOException
+ {
+ return EntityUtils.toString(resEntity);
+ }
+
+ // Strip out just the error message in the response
+ private String getErrorMessage(HttpEntity resEntity) throws IOException
+ {
+ String message = "";
+ String content = getContent(resEntity);
+ int i = content.indexOf("\"message\":\"");
+ if (i != -1)
+ {
+ int j = content.indexOf("\",\"path\":", i);
+ if (j != -1)
+ {
+ message = content.substring(i+11, j);
+ }
+ }
+ return message;
+ }
+
+ public void addLocalConfig(String path) throws IOException
+ {
+ boolean somethingRead = false;
+ final File jarFile = new File(getClass().getProtectionDomain().getCodeSource().getLocation().getPath());
+ if (jarFile.isFile())
+ {
+ JarFile jar = new JarFile(jarFile);
+ Enumeration entries = jar.entries(); // gives ALL entries in jar
+ String prefix = path + "/";
+ List names = new ArrayList<>();
+ while (entries.hasMoreElements())
+ {
+ final String name = entries.nextElement().getName();
+ if (name.startsWith(prefix) && name.length() > prefix.length())
+ {
+ names.add(name);
+ }
+ }
+ Collections.sort(names);
+ for (String name : names)
+ {
+ somethingRead = true;
+ addJsonSource(new InputStreamReader(getResourceAsStream(name)), null,
+ name+" from jar "+jarFile.getName());
+ }
+
+ jar.close();
+ }
+ else
+ {
+ URL url = getClass().getClassLoader().getResource(path);
+ if (url != null)
+ {
+ File root = new File(url.getPath());
+ String rootPath = root.getPath();
+ if (root.isDirectory())
+ {
+ File[] files = root.listFiles();
+ Arrays.sort(files, (file1, file2) -> file1.getName().compareTo(file2.getName()));
+ for (File file: files)
+ {
+ somethingRead = true;
+ addJsonSource(new FileReader(file), null,"File " + file.getPath());
+ }
+ }
+ else
+ {
+ somethingRead = true;
+ addJsonSource(new FileReader(root), null, "File " + rootPath);
+ }
+ }
+ }
+
+ if (!somethingRead)
+ {
+ log.warn("No config read from "+path);
+ }
+ }
+
+ private InputStream getResourceAsStream(String resource)
+ {
+ final InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream(resource);
+ return in == null ? getClass().getResourceAsStream(resource) : in;
+ }
+
+ private void addJsonSource(Reader reader, String baseUrl, String readFrom) throws IOException
+ {
+ JsonNode jsonNode = jsonObjectMapper.readValue(reader, new TypeReference() {});
+ if (log.isTraceEnabled())
+ {
+ log.trace(readFrom+" config is: "+jsonNode);
+ }
+ else
+ {
+ log.debug(readFrom+" config read");
+ }
+
+ JsonNode transformOptions = jsonNode.get(TRANSFORM_OPTIONS);
+ if (transformOptions != null && transformOptions.isObject())
+ {
+ Iterator> iterator = transformOptions.fields();
+ while (iterator.hasNext())
+ {
+ Map.Entry entry = iterator.next();
+
+ JsonNode options = entry.getValue();
+ if (options.isArray())
+ {
+ String optionsName = entry.getKey();
+ allTransformOptions.put(optionsName, (ArrayNode)options);
+ }
+ }
+ }
+
+ JsonNode transformers = jsonNode.get(TRANSFORMERS);
+ if (transformers != null && transformers.isArray())
+ {
+ for (JsonNode transformer : transformers)
+ {
+ if (transformer.isObject())
+ {
+ allTransforms.add(new TransformNodeAndItsOrigin((ObjectNode)transformer, baseUrl, readFrom));
+ }
+ }
+ }
+ }
+
+ public void register(TransformServiceRegistryImpl.Data data, TransformServiceRegistryImpl registry) throws IOException
+ {
+ List transformers = getTransforms();
+ transformers.forEach(t->registry.register(data, t.transform, t.baseUrl, t.readFrom));
+ }
+
+ public List getTransforms() throws IOException
+ {
+ List transforms = new ArrayList<>();
+
+ // After all json input has been loaded build the output with the options in place.
+ ArrayNode transformersNode = jsonObjectMapper.createArrayNode();
+ for (TransformNodeAndItsOrigin entity : allTransforms)
+ {
+ transformersNode.add(entity.node);
+
+ try
+ {
+ ArrayNode transformOptions = (ArrayNode) entity.node.get(TRANSFORM_OPTIONS);
+ if (transformOptions != null)
+ {
+
+ ArrayNode options;
+ int size = transformOptions.size();
+ if (size == 1)
+ {
+ // If there is a single node option reference, we can just use it.
+ int i = 0;
+ options = getTransformOptions(transformOptions, i, entity.node);
+ }
+ else
+ {
+ // If there are many node option references (typically in a pipeline), then each element
+ // has a group for each set of node options.
+ options = jsonObjectMapper.createArrayNode();
+ for (int i = size - 1; i >= 0; i--)
+ {
+ JsonNode referencedTransformOptions = getTransformOptions(transformOptions, i, entity.node);
+ if (referencedTransformOptions != null)
+ {
+ ObjectNode element = jsonObjectMapper.createObjectNode();
+ options.add(element);
+
+ ObjectNode group = jsonObjectMapper.createObjectNode();
+ group.set(TRANSFORM_OPTIONS, referencedTransformOptions);
+ element.set(GROUP, group);
+ }
+ }
+ }
+ if (options == null || options.size() == 0)
+ {
+ entity.node.remove(TRANSFORM_OPTIONS);
+ }
+ else
+ {
+ entity.node.set(TRANSFORM_OPTIONS, options);
+ }
+ }
+
+ try
+ {
+ Transformer transform = jsonObjectMapper.convertValue(entity.node, Transformer.class);
+ transforms.add(new TransformAndItsOrigin(transform, entity.baseUrl, entity.readFrom));
+ }
+ catch (IllegalArgumentException e)
+ {
+ log.error("Invalid transformer "+getTransformName(entity.node)+" "+e.getMessage()+" baseUrl="+entity.baseUrl);
+ }
+ }
+ catch (IllegalArgumentException e)
+ {
+ String transformString = jsonObjectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(entity.node);
+ log.error(e.getMessage());
+ log.debug(transformString);
+ }
+ }
+ if (log.isTraceEnabled())
+ {
+ log.trace("Combined config:\n"+jsonObjectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(transformersNode));
+ }
+
+ transforms = sortTransformers(transforms);
+ return transforms;
+ }
+
+ // Sort transformers so there are no forward references, if that is possible.
+ private List sortTransformers(List original)
+ {
+ List transformers = new ArrayList<>(original.size());
+ List todo = new ArrayList<>(original.size());
+ Set transformerNames = new HashSet<>();
+ boolean added;
+ do
+ {
+ added = false;
+ for (TransformAndItsOrigin entry : original)
+ {
+ String name = entry.transform.getTransformerName();
+ List pipeline = entry.transform.getTransformerPipeline();
+ boolean addEntry = true;
+ if (pipeline != null && !pipeline.isEmpty())
+ {
+ for (TransformStep step : pipeline)
+ {
+ String stepName = step.getTransformerName();
+ if (!transformerNames.contains(stepName))
+ {
+ todo.add(entry);
+ addEntry = false;
+ break;
+ }
+ }
+ }
+ if (addEntry)
+ {
+ transformers.add(entry);
+ added = true;
+ if (name != null)
+ {
+ transformerNames.add(name);
+ }
+ }
+ }
+
+ original.clear();
+ original.addAll(todo);
+ todo.clear();
+ }
+ while (added && !original.isEmpty());
+
+ transformers.addAll(todo);
+
+ return transformers;
+ }
+
+ private ArrayNode getTransformOptions(ArrayNode transformOptions, int i, ObjectNode transform)
+ {
+ ArrayNode options = null;
+ JsonNode optionName = transformOptions.get(i);
+ if (optionName.isTextual())
+ {
+ String name = optionName.asText();
+ options = allTransformOptions.get(name);
+ if (options == null)
+ {
+ String message = "Reference to \"transformOptions\": \"" + name + "\" not found. Transformer " +
+ getTransformName(transform) + " ignored.";
+ throw new IllegalArgumentException(message);
+ }
+ }
+ return options;
+ }
+
+ private String getTransformName(ObjectNode transform)
+ {
+ String name = "Unknown";
+ JsonNode nameNode = transform.get(TRANSFORMER_NAME);
+ if (nameNode != null && nameNode.isTextual())
+ {
+ name = '"'+nameNode.asText()+'"';
+ }
+ return name;
+ }
+}
diff --git a/src/main/java/org/alfresco/transform/client/model/config/SupportedSourceAndTarget.java b/src/main/java/org/alfresco/transform/client/model/config/SupportedSourceAndTarget.java
index e27c29124d..2f9860bea9 100644
--- a/src/main/java/org/alfresco/transform/client/model/config/SupportedSourceAndTarget.java
+++ b/src/main/java/org/alfresco/transform/client/model/config/SupportedSourceAndTarget.java
@@ -2,7 +2,7 @@
* #%L
* Alfresco Repository
* %%
- * Copyright (C) 2005 - 2018 Alfresco Software Limited
+ * 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
@@ -31,29 +31,36 @@ package org.alfresco.transform.client.model.config;
*/
public class SupportedSourceAndTarget
{
- private String sourceExt;
+ private String sourceMediaType;
private long maxSourceSizeBytes = -1;
- private String targetExt;
+ private String targetMediaType;
+ private int priority = 50;
public SupportedSourceAndTarget()
{
}
- public SupportedSourceAndTarget(String sourceExt, String targetExt, long maxSourceSizeBytes)
+ public SupportedSourceAndTarget(String sourceMediaType, String targetMediaType, long maxSourceSizeBytes)
{
- setSourceExt(sourceExt);
+ this(sourceMediaType, targetMediaType, maxSourceSizeBytes, 50);
+ }
+
+ public SupportedSourceAndTarget(String sourceMediaType, String targetMediaType, long maxSourceSizeBytes, int priority)
+ {
+ setSourceMediaType(sourceMediaType);
setMaxSourceSizeBytes(maxSourceSizeBytes);
- setTargetExt(targetExt);
+ setTargetMediaType(targetMediaType);
+ setPriority(priority);
}
- public String getSourceExt()
+ public String getSourceMediaType()
{
- return sourceExt;
+ return sourceMediaType;
}
- public void setSourceExt(String sourceExt)
+ public void setSourceMediaType(String sourceMediaType)
{
- this.sourceExt = sourceExt;
+ this.sourceMediaType = sourceMediaType;
}
public long getMaxSourceSizeBytes()
@@ -66,13 +73,23 @@ public class SupportedSourceAndTarget
this.maxSourceSizeBytes = maxSourceSizeBytes;
}
- public String getTargetExt()
+ public String getTargetMediaType()
{
- return targetExt;
+ return targetMediaType;
}
- public void setTargetExt(String targetExt)
+ public void setTargetMediaType(String targetMediaType)
{
- this.targetExt = targetExt;
+ this.targetMediaType = targetMediaType;
+ }
+
+ public int getPriority()
+ {
+ return priority;
+ }
+
+ public void setPriority(int priority)
+ {
+ this.priority = priority;
}
}
diff --git a/src/main/java/org/alfresco/transform/client/model/config/TransformOption.java b/src/main/java/org/alfresco/transform/client/model/config/TransformOption.java
index 85dba88f06..dc73be1551 100644
--- a/src/main/java/org/alfresco/transform/client/model/config/TransformOption.java
+++ b/src/main/java/org/alfresco/transform/client/model/config/TransformOption.java
@@ -2,7 +2,7 @@
* #%L
* Alfresco Repository
* %%
- * Copyright (C) 2005 - 2018 Alfresco Software Limited
+ * 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
diff --git a/src/main/java/org/alfresco/transform/client/model/config/TransformOptionGroup.java b/src/main/java/org/alfresco/transform/client/model/config/TransformOptionGroup.java
index 83919c3ec0..a0ad82c951 100644
--- a/src/main/java/org/alfresco/transform/client/model/config/TransformOptionGroup.java
+++ b/src/main/java/org/alfresco/transform/client/model/config/TransformOptionGroup.java
@@ -30,11 +30,12 @@ import java.util.List;
/**
* Represents a group of one or more options. If the group is optional, child options that are marked as required are
* only required if any child in the group is supplied by the client. If the group is required, child options are
- * optional or required based on their own setting alone. The top
+ * optional or required based on their own setting alone.
+ *
+ * In a pipeline transformation, a group of options
*/
-public class TransformOptionGroup implements TransformOption
+public class TransformOptionGroup extends AbstractTransformOption
{
- private boolean required;
List transformOptions;
public TransformOptionGroup()
@@ -47,18 +48,6 @@ public class TransformOptionGroup implements TransformOption
setTransformOptions(transformOptions);
}
- @Override
- public boolean isRequired()
- {
- return required;
- }
-
- @Override
- public void setRequired(boolean required)
- {
- this.required = required;
- }
-
public List getTransformOptions()
{
return transformOptions;
diff --git a/src/main/java/org/alfresco/transform/client/model/config/TransformOptionValue.java b/src/main/java/org/alfresco/transform/client/model/config/TransformOptionValue.java
index 6f40377109..6962162175 100644
--- a/src/main/java/org/alfresco/transform/client/model/config/TransformOptionValue.java
+++ b/src/main/java/org/alfresco/transform/client/model/config/TransformOptionValue.java
@@ -28,9 +28,8 @@ package org.alfresco.transform.client.model.config;
/**
* Represents a single transformation option.
*/
-public class TransformOptionValue implements TransformOption
+public class TransformOptionValue extends AbstractTransformOption
{
- private boolean required;
private String name;
public TransformOptionValue()
@@ -43,18 +42,6 @@ public class TransformOptionValue implements TransformOption
setName(name);
}
- @Override
- public boolean isRequired()
- {
- return required;
- }
-
- @Override
- public void setRequired(boolean required)
- {
- this.required = required;
- }
-
public String getName()
{
return name;
diff --git a/src/main/java/org/alfresco/transform/client/model/config/TransformServiceRegistry.java b/src/main/java/org/alfresco/transform/client/model/config/TransformServiceRegistry.java
index e18dd61af1..c1bcf59f7d 100644
--- a/src/main/java/org/alfresco/transform/client/model/config/TransformServiceRegistry.java
+++ b/src/main/java/org/alfresco/transform/client/model/config/TransformServiceRegistry.java
@@ -25,6 +25,8 @@
*/
package org.alfresco.transform.client.model.config;
+import org.quartz.CronExpression;
+
import java.util.Map;
/**
diff --git a/src/main/java/org/alfresco/transform/client/model/config/TransformServiceRegistryImpl.java b/src/main/java/org/alfresco/transform/client/model/config/TransformServiceRegistryImpl.java
index b76f548fe0..6627c468f5 100644
--- a/src/main/java/org/alfresco/transform/client/model/config/TransformServiceRegistryImpl.java
+++ b/src/main/java/org/alfresco/transform/client/model/config/TransformServiceRegistryImpl.java
@@ -27,6 +27,21 @@ package org.alfresco.transform.client.model.config;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
+import org.alfresco.util.PropertyCheck;
+import org.apache.commons.logging.Log;
+import org.quartz.CronExpression;
+import org.quartz.CronScheduleBuilder;
+import org.quartz.CronTrigger;
+import org.quartz.Job;
+import org.quartz.JobBuilder;
+import org.quartz.JobDataMap;
+import org.quartz.JobDetail;
+import org.quartz.JobExecutionContext;
+import org.quartz.JobExecutionException;
+import org.quartz.Scheduler;
+import org.quartz.SchedulerException;
+import org.quartz.TriggerBuilder;
+import org.quartz.impl.StdSchedulerFactory;
import org.springframework.beans.factory.InitializingBean;
import java.io.IOException;
@@ -44,36 +59,89 @@ import static org.alfresco.repo.rendition2.RenditionDefinition2.TIMEOUT;
/**
* Used by clients to work out if a transformation is supported by the Transform Service.
*/
-public class TransformServiceRegistryImpl implements TransformServiceRegistry, InitializingBean
+public abstract class TransformServiceRegistryImpl implements TransformServiceRegistry, InitializingBean
{
- class SupportedTransform
+ public static class Data
+ {
+ ConcurrentMap>> transformers = new ConcurrentHashMap<>();
+ ConcurrentMap>> cachedSupportedTransformList = new ConcurrentHashMap<>();
+ private int transformerCount = 0;
+ private int transformCount = 0;
+ boolean firstTime = true;
+ boolean successReadingRemoteConfig = true;
+ }
+
+ static class SupportedTransform
{
TransformOptionGroup transformOptions;
- private long maxSourceSizeBytes;
+ long maxSourceSizeBytes;
+ private String name;
+ private int priority;
- public SupportedTransform(List transformOptions, long maxSourceSizeBytes)
+ public SupportedTransform(Data data, String name, List transformOptions, long maxSourceSizeBytes, int priority)
{
// Logically the top level TransformOptionGroup is required, so that child options are optional or required
// based on their own setting.
this.transformOptions = new TransformOptionGroup(true, transformOptions);
this.maxSourceSizeBytes = maxSourceSizeBytes;
+ this.name = name;
+ this.priority = priority;
+ data.transformCount++;
}
}
- private ObjectMapper jsonObjectMapper;
- private ExtensionMap extensionMap;
+ public static class TransformServiceRegistryJob implements Job
+ {
+ @Override
+ public void execute(JobExecutionContext context) throws JobExecutionException
+ {
+ JobDataMap dataMap = context.getJobDetail().getJobDataMap();
+ TransformServiceRegistryImpl registry = (TransformServiceRegistryImpl)dataMap.get("registry");
+ registry.readConfigAndReplace();
+ }
+ }
- ConcurrentMap>> transformers = new ConcurrentHashMap<>();
- ConcurrentMap> cachedMaxSizes = new ConcurrentHashMap<>();
+ protected boolean enabled = true;
+ protected Data data;
+ private ObjectMapper jsonObjectMapper;
+ private Scheduler scheduler;
+ private CronExpression cronExpression;
+ private CronExpression initialAndOnErrorCronExpression;
+ private boolean normalCronSchedule;
public void setJsonObjectMapper(ObjectMapper jsonObjectMapper)
{
this.jsonObjectMapper = jsonObjectMapper;
}
- public void setExtensionMap(ExtensionMap extensionMap)
+ public synchronized Scheduler getScheduler()
{
- this.extensionMap = extensionMap;
+ return scheduler;
+ }
+
+ public synchronized void setScheduler(Scheduler scheduler)
+ {
+ this.scheduler = scheduler;
+ }
+
+ public CronExpression getCronExpression()
+ {
+ return cronExpression;
+ }
+
+ public void setCronExpression(CronExpression cronExpression)
+ {
+ this.cronExpression = cronExpression;
+ }
+
+ public CronExpression getInitialAndOnErrorCronExpression()
+ {
+ return initialAndOnErrorCronExpression;
+ }
+
+ public void setInitialAndOnErrorCronExpression(CronExpression initialAndOnErrorCronExpression)
+ {
+ this.initialAndOnErrorCronExpression = initialAndOnErrorCronExpression;
}
@Override
@@ -83,63 +151,228 @@ public class TransformServiceRegistryImpl implements TransformServiceRegistry, I
{
throw new IllegalStateException("jsonObjectMapper has not been set");
}
- if (extensionMap == null)
+ PropertyCheck.mandatory(this, "cronExpression", cronExpression);
+ PropertyCheck.mandatory(this, "initialAndOnErrorCronExpression", initialAndOnErrorCronExpression);
+
+ setData(null);
+ if (enabled)
{
- throw new IllegalStateException("extensionMap has not been set");
+ schedule();
}
}
- private String toMimetype(String ext)
+ private synchronized void schedule()
{
- String mimetype = extensionMap.toMimetype(ext);
- if (mimetype == null)
+ // Don't do an initial readConfigAndReplace() as the first scheduled read can be done almost instantly and
+ // there is little point doing two in the space of a few seconds. If however the scheduler is already running
+ // we do need to run it (this is only from test cases).
+ if (scheduler == null)
{
- throw new IllegalArgumentException("The mimetype for the file extension "+ext+" cannot be looked up by: "+
- extensionMap.getClass().getName());
+ StdSchedulerFactory sf = new StdSchedulerFactory();
+ String jobName = getClass().getName()+"Job";
+ try
+ {
+ scheduler = sf.getScheduler();
+
+ JobDetail job = JobBuilder.newJob()
+ .withIdentity(jobName)
+ .ofType(TransformServiceRegistryJob.class)
+ .build();
+ job.getJobDataMap().put("registry", this);
+ CronExpression cronExpression = normalCronSchedule ? this.cronExpression : initialAndOnErrorCronExpression;
+ CronTrigger trigger = TriggerBuilder.newTrigger()
+ .withIdentity(jobName+"Trigger", Scheduler.DEFAULT_GROUP)
+ .withSchedule(CronScheduleBuilder.cronSchedule(cronExpression))
+ .build();
+ scheduler.startDelayed(0);
+ scheduler.scheduleJob(job, trigger);
+ }
+ catch (SchedulerException e)
+ {
+ getLog().error("Failed to start "+jobName+" "+e.getMessage());
+ }
+ }
+ else
+ {
+ readConfigAndReplace();
}
- return mimetype;
}
- public void register(Transformer transformer)
+ protected void readConfigAndReplace()
{
- transformer.getSupportedSourceAndTargetList().forEach(
- e -> transformers.computeIfAbsent(toMimetype(e.getSourceExt()),
- k -> new ConcurrentHashMap<>()).computeIfAbsent(toMimetype(e.getTargetExt()),
- k -> new ArrayList<>()).add(
- new SupportedTransform(transformer.getTransformOptions(), e.getMaxSourceSizeBytes())));
+ boolean successReadingRemoteConfig = true;
+ Log log = getLog();
+ log.debug("Config read started");
+ try
+ {
+ Data data = readConfig();
+ successReadingRemoteConfig = data.successReadingRemoteConfig;
+ setData(data);
+ log.debug("Config read finished "+getCounts());
+ }
+ catch (Exception e)
+ {
+ successReadingRemoteConfig = false;
+ log.error("Config read failed. "+e.getMessage(), e);
+ }
+
+ // Switch schedule sequence if we were on the normal schedule and we now have problems or if
+ // we are on the initial/error schedule and there were no errors.
+ if (normalCronSchedule && !successReadingRemoteConfig ||
+ !normalCronSchedule && successReadingRemoteConfig)
+ {
+ normalCronSchedule = !normalCronSchedule;
+ if (scheduler != null)
+ {
+ try
+ {
+ CronExpression cronExpression = normalCronSchedule ? this.cronExpression : initialAndOnErrorCronExpression;
+ scheduler.clear();
+ scheduler = null;
+ schedule();
+ }
+ catch (SchedulerException e)
+ {
+ getLog().error("Problem stopping scheduler for transformer configuration "+e.getMessage());
+ }
+ }
+ else
+ {
+ System.out.println("Switch schedule "+normalCronSchedule+" WITHOUT new schedule");
+ }
+ }
}
- public void register(Reader reader) throws IOException
+ protected abstract Data readConfig() throws IOException;
+
+ private synchronized void setData(Data data)
+ {
+ this.data = data;
+ }
+
+ protected synchronized Data getData()
+ {
+ if (data == null)
+ {
+ data = createData();
+ }
+ return data;
+ }
+
+ protected Data createData()
+ {
+ return new Data();
+ }
+
+ protected void setSuccessReadingRemoteConfig(Data data, boolean successReadingRemoteConfig)
+ {
+ data.successReadingRemoteConfig = successReadingRemoteConfig;
+ }
+
+ public void setEnabled(boolean enabled)
+ {
+ this.enabled = enabled;
+ setFirstTime(true);
+ }
+
+ protected void setFirstTime(boolean firstTime)
+ {
+ getData().firstTime = firstTime;
+ }
+
+ protected boolean getFirstTime()
+ {
+ return getData().firstTime;
+ }
+
+ protected abstract Log getLog();
+
+ public void register(Data data, Reader reader, String readFrom) throws IOException
{
List transformers = jsonObjectMapper.readValue(reader, new TypeReference>(){});
- transformers.forEach(t -> register(t));
+ transformers.forEach(t -> register(data, t, null, readFrom));
+ }
+
+ protected void register(Data data, Transformer transformer, String baseUrl, String readFrom)
+ {
+ data.transformerCount++;
+ transformer.getSupportedSourceAndTargetList().forEach(
+ e -> data.transformers.computeIfAbsent(e.getSourceMediaType(),
+ k -> new ConcurrentHashMap<>()).computeIfAbsent(e.getTargetMediaType(),
+ k -> new ArrayList<>()).add(
+ new SupportedTransform(data, transformer.getTransformerName(),
+ transformer.getTransformOptions(), e.getMaxSourceSizeBytes(), e.getPriority())));
+ }
+
+ protected String getCounts()
+ {
+ return "("+getData().transformerCount+":"+getData().transformCount+")";
}
@Override
public boolean isSupported(String sourceMimetype, long sourceSizeInBytes, String targetMimetype,
- Map actualOptions, String transformName)
+ Map actualOptions, String renditionName)
{
- long maxSize = getMaxSize(sourceMimetype, targetMimetype, actualOptions, transformName);
+ long maxSize = getMaxSize(sourceMimetype, targetMimetype, actualOptions, renditionName);
return maxSize != 0 && (maxSize == -1L || maxSize >= sourceSizeInBytes);
}
+ /**
+ * Works out the name of the transformer (might not map to an actual transformer) that will be used to transform
+ * content of a given source mimetype and size into a target mimetype given a list of actual transform option names
+ * and values (Strings) plus the data contained in the {@Transform} objects registered with this class.
+ * @param sourceMimetype the mimetype of the source content
+ * @param sourceSizeInBytes the size in bytes of the source content. Ignored if negative.
+ * @param targetMimetype the mimetype of the target
+ * @param actualOptions the actual name value pairs available that could be passed to the Transform Service.
+ * @param renditionName (optional) name for the set of options and target mimetype. If supplied is used to cache
+ * results to avoid having to work out if a given transformation is supported a second time.
+ * The sourceMimetype and sourceSizeInBytes may still change. In the case of ACS this is the
+ * rendition name.
+ */
+ protected String getTransformerName(String sourceMimetype, long sourceSizeInBytes, String targetMimetype, Map actualOptions, String renditionName)
+ {
+ List supportedTransforms = getTransformListBySize(sourceMimetype, targetMimetype, actualOptions, renditionName);
+ for (SupportedTransform supportedTransform : supportedTransforms)
+ {
+ if (supportedTransform.maxSourceSizeBytes == -1 || supportedTransform.maxSourceSizeBytes >= sourceSizeInBytes)
+ {
+ return supportedTransform.name;
+ }
+ }
+
+ return null;
+ }
+
@Override
public long getMaxSize(String sourceMimetype, String targetMimetype,
- Map actualOptions, String transformName)
+ Map actualOptions, String renditionName)
+ {
+ List supportedTransforms = getTransformListBySize(sourceMimetype, targetMimetype, actualOptions, renditionName);
+ return supportedTransforms.isEmpty() ? 0 : supportedTransforms.get(supportedTransforms.size()-1).maxSourceSizeBytes;
+ }
+
+ // Returns transformers in increasing supported size order, where lower priority transformers for the same size have
+ // been discarded.
+ private List getTransformListBySize(String sourceMimetype, String targetMimetype,
+ Map actualOptions, String renditionName)
{
if (actualOptions == null)
{
actualOptions = Collections.EMPTY_MAP;
}
- if (transformName != null && transformName.trim().isEmpty())
+ if (renditionName != null && renditionName.trim().isEmpty())
{
- transformName = null;
+ renditionName = null;
}
- Long maxSize = transformName == null ? null : cachedMaxSizes.computeIfAbsent(transformName, k -> new ConcurrentHashMap<>()).get(sourceMimetype);
- if (maxSize != null)
+
+ Data data = getData();
+ List transformListBySize = renditionName == null ? null
+ : data.cachedSupportedTransformList.computeIfAbsent(renditionName, k -> new ConcurrentHashMap<>()).get(sourceMimetype);
+ if (transformListBySize != null)
{
- return maxSize.longValue();
+ return transformListBySize;
}
// Remove the "timeout" property from the actualOptions as it is not used to select a transformer.
@@ -149,8 +382,8 @@ public class TransformServiceRegistryImpl implements TransformServiceRegistry, I
actualOptions.remove(TIMEOUT);
}
- long calculatedMaxSize = 0;
- ConcurrentMap> targetMap = transformers.get(sourceMimetype);
+ transformListBySize = new ArrayList<>();
+ ConcurrentMap> targetMap = data.transformers.get(sourceMimetype);
if (targetMap != null)
{
List supportedTransformList = targetMap.get(targetMimetype);
@@ -163,24 +396,66 @@ public class TransformServiceRegistryImpl implements TransformServiceRegistry, I
addToPossibleTransformOptions(possibleTransformOptions, transformOptions, true, actualOptions);
if (isSupported(possibleTransformOptions, actualOptions))
{
- if (supportedTransform.maxSourceSizeBytes < 0)
- {
- calculatedMaxSize = -1;
- break;
- }
-
- calculatedMaxSize = Math.max(calculatedMaxSize, supportedTransform.maxSourceSizeBytes);
+ addToSupportedTransformList(transformListBySize, supportedTransform);
}
}
}
}
- if (transformName != null)
+ if (renditionName != null)
{
- cachedMaxSizes.get(transformName).put(sourceMimetype, calculatedMaxSize);
+ data.cachedSupportedTransformList.get(renditionName).put(sourceMimetype, transformListBySize);
}
- return calculatedMaxSize;
+ return transformListBySize;
+ }
+
+ // Add newTransform to the transformListBySize in increasing size order and discards lower priority (numerically
+ // higher) transforms with a smaller or equal size.
+ private void addToSupportedTransformList(List transformListBySize, SupportedTransform newTransform)
+ {
+ for (int i=0; i < transformListBySize.size(); i++)
+ {
+ SupportedTransform existingTransform = transformListBySize.get(i);
+ int added = -1;
+ int compare = compare(newTransform.maxSourceSizeBytes, existingTransform.maxSourceSizeBytes);
+ if (compare < 0)
+ {
+ transformListBySize.add(i, newTransform);
+ added = i;
+ }
+ else if (compare == 0)
+ {
+ if (newTransform.priority < existingTransform.priority)
+ {
+ transformListBySize.set(i, newTransform);
+ added = i;
+ }
+ }
+ if (added == i)
+ {
+ for (i--; i >= 0; i--)
+ {
+ existingTransform = transformListBySize.get(i);
+ if (newTransform.priority <= existingTransform.priority)
+ {
+ transformListBySize.remove(i);
+ }
+ }
+ return;
+ }
+ }
+ transformListBySize.add(newTransform);
+ }
+
+ // compare where -1 is unlimited.
+ private int compare(long a, long b)
+ {
+ return a == -1
+ ? b == -1 ? 0 : 1
+ : b == -1 ? -1
+ : a == b ? 0
+ : a > b ? 1 : -1;
}
/**
diff --git a/src/main/java/org/alfresco/transform/client/model/config/TransformStep.java b/src/main/java/org/alfresco/transform/client/model/config/TransformStep.java
new file mode 100644
index 0000000000..cd2a543174
--- /dev/null
+++ b/src/main/java/org/alfresco/transform/client/model/config/TransformStep.java
@@ -0,0 +1,66 @@
+/*
+ * #%L
+ * Alfresco Repository
+ * %%
+ * Copyright (C) 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 .
+ * #L%
+ */
+package org.alfresco.transform.client.model.config;
+
+/**
+ * Represents a single transform step in a transform pipeline. The last step in the pipeline does not specify the
+ * target type as that is based on the supported types and what has been requested.
+ */
+public class TransformStep
+{
+ private String transformerName;
+ private String targetMediaType;
+
+ public TransformStep()
+ {
+ }
+
+ public TransformStep(String transformerName, String targetMediaType)
+ {
+ setTransformerName(transformerName);
+ setTargetMediaType(targetMediaType);
+ }
+
+ public String getTransformerName()
+ {
+ return transformerName;
+ }
+
+ public void setTransformerName(String transformerName)
+ {
+ this.transformerName = transformerName;
+ }
+
+ public String getTargetMediaType()
+ {
+ return targetMediaType;
+ }
+
+ public void setTargetMediaType(String targetMediaType)
+ {
+ this.targetMediaType = targetMediaType;
+ }
+}
diff --git a/src/main/java/org/alfresco/transform/client/model/config/Transformer.java b/src/main/java/org/alfresco/transform/client/model/config/Transformer.java
index 3f18a8bf8f..f707d1cc95 100644
--- a/src/main/java/org/alfresco/transform/client/model/config/Transformer.java
+++ b/src/main/java/org/alfresco/transform/client/model/config/Transformer.java
@@ -2,7 +2,7 @@
* #%L
* Alfresco Repository
* %%
- * Copyright (C) 2005 - 2018 Alfresco Software Limited
+ * 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
@@ -26,28 +26,34 @@
package org.alfresco.transform.client.model.config;
import java.util.List;
-import java.util.Objects;
+import org.alfresco.transform.client.model.config.TransformServiceRegistry;
/**
- * Represents a set of transformations supported by the Transform Service that share the same transform options. Each
- * may be an actual transformer or the amalgamation of multiple transformers. It is possible that more than one
- * transformer may able to perform a transformation from one mimetype to another. The actual selection of transformer
- * is up to the Transform Service to decide. Clients may use {@link TransformServiceRegistry#isSupported} to decide
+ * Represents a set of transformations supported by the Transform Service or Local Transform Service Registry that
+ * share the same transform options. Each may be an actual transformer or a pipeline of multiple transformers. It is
+ * possible that more than one transformer may able to perform a transformation from one mimetype to another. The actual
+ * selection of transformer is up to the Transform Service or Local Transform Service Registry to decide. Clients may
+ * use {@link TransformServiceRegistry#isSupported(String, long, String, java.util.Map, String)} to decide
* if they should send a request to the Transform Service. As a result clients have a simple generic view of
- * transformations which allows new transformations to be added without the need change client data structures other
+ * transformations which allows new transformations to be added without the need to change client data structures other
* than to define new name value pairs. For this to work the Transform Service defines unique names for each option.
*
- * - name - is unique. The client should infer nothing from the name as it is simply a label.
- * - version - of the transformer. The client should infer nothing from the value and should only use it
- * in messages. There should only be one version supplied to the client for each name.
+ * - transformerName - is optional but if supplied should be unique. The client should infer nothing from the name
+ * as it is simply a label, but the Local Transform Service Registry will use the name in pipelines.
* - transformOptions - a grouping of individual transformer transformOptions. The group may be optional and may
* contain nested transformOptions.
*
+ * For local transforms, this structure is extended when defining a pipeline transform.
+ *
+ * - transformerPipeline - an array of pairs of transformer name and target extension for each transformer in the
+ * pipeline. The last one should not have an extension as that is defined by the request and should be in the
+ * supported list.
+ *
*/
public class Transformer
{
- private String name;
- private String version;
+ private String transformerName;
+ private List transformerPipeline;
private List transformOptions;
private List supportedSourceAndTargetList;
@@ -55,32 +61,37 @@ public class Transformer
{
}
- public Transformer(String name, String version, List transformOptions, List supportedSourceAndTargetList)
+ public Transformer(String transformerName, List transformOptions, List supportedSourceAndTargetList)
{
- setName(name);
- setVersion(version);
+ setTransformerName(transformerName);
setTransformOptions(transformOptions);
setSupportedSourceAndTargetList(supportedSourceAndTargetList);
}
- public String getName()
+ public Transformer(String transformerName, List transformerPipeline, List transformOptions, List supportedSourceAndTargetList)
{
- return name;
+ this(transformerName, transformOptions, supportedSourceAndTargetList);
+ setTransformerPipeline(transformerPipeline);
}
- public void setName(String name)
+ public String getTransformerName()
{
- this.name = name;
+ return transformerName;
}
- public String getVersion()
+ public void setTransformerName(String transformerName)
{
- return version;
+ this.transformerName = transformerName;
}
- public void setVersion(String version)
+ public List getTransformerPipeline()
{
- this.version = version;
+ return transformerPipeline;
+ }
+
+ public void setTransformerPipeline(List transformerPipeline)
+ {
+ this.transformerPipeline = transformerPipeline;
}
public List getTransformOptions()
diff --git a/src/main/resources/alfresco/content-services-context.xml b/src/main/resources/alfresco/content-services-context.xml
index 0be62cb8e1..e71092ee8f 100644
--- a/src/main/resources/alfresco/content-services-context.xml
+++ b/src/main/resources/alfresco/content-services-context.xml
@@ -328,33 +328,18 @@
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
@@ -485,10 +470,24 @@
-
+
+ MiscellaneousTransformers
+
+
+ ${transform.misc.url}
+
+
+ ${transform.misc.startupRetryPeriodSeconds}
+
+
+
+
+
@@ -497,16 +496,25 @@
+ parent="baseContentTransformer" >
+
+
+
+
+
+ parent="baseContentTransformer" />
-
-
+
+
+
+
+
+
+
+
+
+
-
-
+
+
+
+
+
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
-
@@ -91,10 +102,30 @@
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
diff --git a/src/main/resources/alfresco/repository.properties b/src/main/resources/alfresco/repository.properties
index a2c9ba91d6..f551df254a 100644
--- a/src/main/resources/alfresco/repository.properties
+++ b/src/main/resources/alfresco/repository.properties
@@ -562,7 +562,7 @@ img.root=./ImageMagick
img.dyn=${img.root}/lib
img.exe=${img.root}/bin/convert
-# Remote server (or docker container) url used to service imagemagick requests.
+# Legacy imageMagick transformer url to T-Engine to service transform requests via http. Disabled by default.
img.url=
# When img.url is set, this value indicates the amount of time to wait after a connection failure
@@ -611,12 +611,29 @@ system.thumbnail.redeployStaticDefsOnStartup=true
# The default timeout for metadata mapping extracters
content.metadataExtracter.default.timeoutMs=20000
-# Remote server (or docker container) url used to service tika requests.
+# Legacy tika and misc transformer url to T-Engines to service transform requests via http. Disabled by default.
tika.url=
+transform.misc.url=
-# When tika.url is set, this value indicates the amount of time to wait after a connection failure
+# When the legacy tika and misc transformer .url is set, this value indicates the amount of time to wait after a connection failure
# before retrying the connection to allow a docker container to (re)start.
tika.startupRetryPeriodSeconds=60
+transform.misc.startupRetryPeriodSeconds=60
+
+# Local transformer urls to T-engines to service transform requests via http. Enabled by default.
+localTransform.pdfrenderer.url=http://localhost:8090/
+localTransform.imagemagick.url=http://localhost:8091/
+localTransform.libreoffice.url=http://localhost:8092/
+localTransform.tika.url=http://localhost:8093/
+localTransform.misc.url=http://localhost:8094/
+
+# When a local transformer .url is set, this value indicates the amount of time to wait after a connection failure
+# before retrying the connection to allow a docker container to (re)start.
+localTransform.pdfrenderer.startupRetryPeriodSeconds=60
+localTransform.imagemagick.startupRetryPeriodSeconds=60
+localTransform.libreoffice.startupRetryPeriodSeconds=60
+localTransform.tika.startupRetryPeriodSeconds=60
+localTransform.misc.startupRetryPeriodSeconds=60
#
content.metadataExtracter.pdf.maxDocumentSizeMB=10
@@ -1062,9 +1079,22 @@ people.search.honor.hint.useCQ=true
# Delays cron jobs after bootstrap to allow server to fully come up before jobs start
system.cronJob.startDelayMilliseconds=60000
+# Optional property to specify an external file or directory that will be read for transformer json config.
+local.transform.pipeline.config.dir=
+
# Used to disable transforms locally.
local.transform.service.enabled=true
+# Schedule for reading local transform config, so that T-Engines and local pipeline config is dynamically
+# picked up, or reintegrated after an outage. Initially checks every 10 seconds and then switches to every 10 minutes
+# after the configuration is read successfully. If there is a error later reading the config, the checks return to
+# every 10 seconds.
+local.transform.service.cronExpression=0 0/10 * * * ?
+local.transform.service.initialAndOnError.cronExpression=0/10 * * * * ?
+
+# Used to disable transforms that extend AbstractContentTransformer2
+legacy.transform.service.enabled=true
+
#
# Check that the declared mimetype (of the Node) is the same as the derived
# mimetype of the content (via Tika) before a transformation takes place.
@@ -1074,13 +1104,15 @@ local.transform.service.enabled=true
#
# There are a few issues with the Tika mimetype detection. So that transformations
# still take place where the detected mimetype is not the same as the declared mimetype,
-# another property (transformer.strict.mimetype.check.whitelist.mimetypes in transformers.properties
-# so can be changed via JMX) contains pairs of declared and detected mimetypes that should
-# be allowed. This parameter value is a sequence of ; separated pairs. The declared and
-# derived mimetypes are also ; separated.
+# another property (transformer.strict.mimetype.check.whitelist.mimetypes) contains pairs
+# of declared and detected mimetypes that should be allowed. This parameter value is a
+# sequence of ; separated pairs. The declared and derived mimetypes are also ; separated.
#
transformer.strict.mimetype.check=true
+# A white list of declared and detected mimetypes, that don't match, but should still be transformed.
+transformer.strict.mimetype.check.whitelist.mimetypes=application/eps;application/postscript;application/illustrator;application/pdf;application/x-tar;application/x-gtar;application/acp;application/zip;application/vnd.stardivision.math;application/x-tika-msoffice
+
#
# Enable transformation retrying if the file has MIME type differ than file extension.
# Ignored if transformer.strict.mimetype.check is true as these transformations
@@ -1257,5 +1289,4 @@ messaging.subsystem.autoStart=true
# Raw events
-acs.repo.rendition.events.endpoint=jms:acs-repo-rendition-events?jmsMessageType=Text
-
+acs.repo.rendition.events.endpoint=jms:acs-repo-rendition-events?jmsMessageType=Text
\ No newline at end of file
diff --git a/src/main/resources/alfresco/subsystems/OOoJodconverter/default/jodconverter-context.xml b/src/main/resources/alfresco/subsystems/OOoJodconverter/default/jodconverter-context.xml
index ef73c93b5e..ac1235ce85 100644
--- a/src/main/resources/alfresco/subsystems/OOoJodconverter/default/jodconverter-context.xml
+++ b/src/main/resources/alfresco/subsystems/OOoJodconverter/default/jodconverter-context.xml
@@ -53,6 +53,7 @@
+
diff --git a/src/main/resources/alfresco/subsystems/thirdparty/default/imagemagick-transform-context.xml b/src/main/resources/alfresco/subsystems/thirdparty/default/imagemagick-transform-context.xml
index 30aaa7baa4..9e98320965 100644
--- a/src/main/resources/alfresco/subsystems/thirdparty/default/imagemagick-transform-context.xml
+++ b/src/main/resources/alfresco/subsystems/thirdparty/default/imagemagick-transform-context.xml
@@ -61,6 +61,7 @@
+
diff --git a/src/main/resources/alfresco/transform-service-config.json b/src/main/resources/alfresco/transform-service-config.json
deleted file mode 100644
index b3cfc347d4..0000000000
--- a/src/main/resources/alfresco/transform-service-config.json
+++ /dev/null
@@ -1,175 +0,0 @@
-[
- {
- "name": "libreOffice",
- "version": "1",
- "supportedSourceAndTargetList": [
- {"sourceExt": "doc", "targetExt": "doc" },
- {"sourceExt": "docx", "targetExt": "doc" },
- {"sourceExt": "doc", "maxSourceSizeBytes": 10485760, "targetExt": "pdf" },
- {"sourceExt": "xls", "maxSourceSizeBytes": 10485760, "targetExt": "pdf"},
- {"sourceExt": "ppt", "maxSourceSizeBytes": 6291456, "targetExt": "pdf" },
- {"sourceExt": "docx", "maxSourceSizeBytes": 786432, "targetExt": "pdf" },
- {"sourceExt": "xlsx", "maxSourceSizeBytes": 1572864, "targetExt": "pdf"},
- {"sourceExt": "pptx", "maxSourceSizeBytes": 4194304, "targetExt": "pdf" },
- {"sourceExt": "msg", "targetExt": "pdf"}
- ]
- },
- {
- "name": "tika",
- "version": "1",
- "transformOptions": [
- {"value": {"name": "transform"}},
- {"value": {"name": "includeContents"}},
- {"value": {"name": "notExtractBookmarksText"}},
- {"value": {"name": "targetMimetype"}},
- {"value": {"name": "targetEncoding"}}
- ],
- "supportedSourceAndTargetList": [
- {"sourceExt": "pdf", "maxSourceSizeBytes": 26214400, "targetExt": "txt" },
- {"sourceExt": "doc", "targetExt": "txt"},
- {"sourceExt": "xls", "targetExt": "txt" },
- {"sourceExt": "ppt", "targetExt": "txt" },
- {"sourceExt": "docx", "targetExt": "txt"},
- {"sourceExt": "xlsx", "targetExt": "txt" },
- {"sourceExt": "pptx", "targetExt": "txt" },
- {"sourceExt": "msg", "targetExt": "txt"}
- ]
- },
- {
- "name": "pdfRenderer",
- "version": "1",
- "transformOptions": [
- {"value": {"name": "page"}},
- {"value": {"name": "width"}},
- {"value": {"name": "height"}},
- {"value": {"name": "allowPdfEnlargement"}},
- {"value": {"name": "maintainPdfAspectRatio"}}
- ],
- "supportedSourceAndTargetList": [
- {"sourceExt": "pdf", "targetExt": "png" }
- ]
- },
- {
- "name": "imageMagick",
- "version": "1",
- "transformOptions": [
- {"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"}}
- ]}}
- ],
- "supportedSourceAndTargetList": [
- {"sourceExt": "gif", "targetExt": "gif" },
- {"sourceExt": "gif", "targetExt": "jpeg"},
- {"sourceExt": "gif", "targetExt": "png" },
- {"sourceExt": "gif", "targetExt": "tiff"},
-
- {"sourceExt": "jpeg", "targetExt": "gif" },
- {"sourceExt": "jpeg", "targetExt": "jpeg"},
- {"sourceExt": "jpeg", "targetExt": "png" },
- {"sourceExt": "jpeg", "targetExt": "tiff"},
-
- {"sourceExt": "png", "targetExt": "gif" },
- {"sourceExt": "png", "targetExt": "jpeg"},
- {"sourceExt": "png", "targetExt": "png" },
- {"sourceExt": "png", "targetExt": "tiff"},
-
- {"sourceExt": "tiff", "targetExt": "gif" },
- {"sourceExt": "tiff", "targetExt": "tiff"}
- ]
- },
- {
- "name": "officeToImageViaPdf",
- "version": "1",
- "transformOptions": [
- {
- "group": {
- "required": true,
- "transformOptions": [
- {"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"}}
- ]}}
- ]}},{
- "group": {
- "required": false,
- "transformOptions": [
- {"value": {"name": "page"}},
- {"value": {"name": "width"}},
- {"value": {"name": "height"}},
- {"value": {"name": "allowPdfEnlargement"}},
- {"value": {"name": "maintainPdfAspectRatio"}}
- ]
- }
- }
- ],
- "supportedSourceAndTargetList": [
- {"sourceExt": "doc", "targetExt": "gif" },
- {"sourceExt": "doc", "targetExt": "jpeg"},
- {"sourceExt": "doc", "targetExt": "png" },
- {"sourceExt": "doc", "targetExt": "tiff"},
-
- {"sourceExt": "xls", "targetExt": "gif" },
- {"sourceExt": "xls", "targetExt": "jpeg"},
- {"sourceExt": "xls", "targetExt": "png" },
- {"sourceExt": "xls", "targetExt": "tiff"},
-
- {"sourceExt": "ppt", "targetExt": "gif" },
- {"sourceExt": "ppt", "targetExt": "jpeg"},
- {"sourceExt": "ppt", "targetExt": "png" },
- {"sourceExt": "ppt", "targetExt": "tiff"},
-
- {"sourceExt": "docx", "targetExt": "gif" },
- {"sourceExt": "docx", "targetExt": "jpeg"},
- {"sourceExt": "docx", "targetExt": "png" },
- {"sourceExt": "docx", "targetExt": "tiff"},
-
- {"sourceExt": "xlsx", "targetExt": "gif" },
- {"sourceExt": "xlsx", "targetExt": "jpeg"},
- {"sourceExt": "xlsx", "targetExt": "png" },
- {"sourceExt": "xlsx", "targetExt": "tiff"},
-
- {"sourceExt": "pptx", "targetExt": "gif" },
- {"sourceExt": "pptx", "targetExt": "jpeg"},
- {"sourceExt": "pptx", "targetExt": "png" },
- {"sourceExt": "pptx", "targetExt": "tiff"},
-
- {"sourceExt": "msg", "targetExt": "gif" },
- {"sourceExt": "msg", "targetExt": "jpeg"},
- {"sourceExt": "msg", "targetExt": "png" },
- {"sourceExt": "msg", "targetExt": "tiff"}
- ]
- }
-]
\ No newline at end of file
diff --git a/src/main/resources/alfresco/transformers/0150-officeToImageViaPdf.json b/src/main/resources/alfresco/transformers/0150-officeToImageViaPdf.json
new file mode 100644
index 0000000000..b03e52b25a
--- /dev/null
+++ b/src/main/resources/alfresco/transformers/0150-officeToImageViaPdf.json
@@ -0,0 +1,52 @@
+{
+ "transformers": [
+ {
+ "transformerName": "officeToImageViaPdf",
+ "transformerPipeline" : [
+ {"transformerName": "libreoffice", "targetMediaType": "application/pdf"},
+ {"transformerName": "pdfrenderer", "targetMediaType": "image/png"},
+ {"transformerName": "imagemagick"}
+ ],
+ "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"
+ ]
+ }
+ ]
+}
\ No newline at end of file
diff --git a/src/main/resources/quick/quickMaskedHtml.jpeg b/src/main/resources/quick/quickMaskedHtml.jpeg
new file mode 100644
index 0000000000..76c633d74c
--- /dev/null
+++ b/src/main/resources/quick/quickMaskedHtml.jpeg
@@ -0,0 +1,17 @@
+
+
+
+
+ The quick brown fox jumps over the lazy dog
+
+
+
+
+
+
+
+The quick brown fox jumps over the lazy dog
+
+
+
+
diff --git a/src/test/java/org/alfresco/AllUnitTestsSuite.java b/src/test/java/org/alfresco/AllUnitTestsSuite.java
index cf541db439..1b75edccdd 100644
--- a/src/test/java/org/alfresco/AllUnitTestsSuite.java
+++ b/src/test/java/org/alfresco/AllUnitTestsSuite.java
@@ -200,7 +200,8 @@ import org.junit.runners.Suite;
org.alfresco.util.bean.HierarchicalBeanLoaderTest.class,
org.alfresco.util.resource.HierarchicalResourceLoaderTest.class,
org.alfresco.repo.events.ClientUtilTest.class,
- org.alfresco.repo.rendition2.RenditionService2Test.class
+ org.alfresco.repo.rendition2.RenditionService2Test.class,
+ org.alfresco.transform.client.model.config.TransformServiceRegistryConfigTest.class
})
public class AllUnitTestsSuite
{
diff --git a/src/test/java/org/alfresco/AppContext06TestSuite.java b/src/test/java/org/alfresco/AppContext06TestSuite.java
index 3e520f569e..5e89f0e768 100644
--- a/src/test/java/org/alfresco/AppContext06TestSuite.java
+++ b/src/test/java/org/alfresco/AppContext06TestSuite.java
@@ -47,11 +47,19 @@ import org.junit.runners.Suite;
// Requires a running ActiveMQ
org.alfresco.repo.rawevents.EventBehaviourTest.class,
org.alfresco.repo.rawevents.TransactionAwareEventProducerTest.class,
+
// Requires running transformers
+ org.alfresco.transform.client.model.config.LocalTransformServiceRegistryConfigTest.class,
org.alfresco.repo.rendition2.RenditionService2IntegrationTest.class,
- org.alfresco.repo.rendition2.LegacyLocalTransformClientIntegrationTest.class,
- org.alfresco.repo.rendition2.LegacyLocalTransformServiceRegistryTest.class,
- org.alfresco.repo.rendition2.RenditionTest.class,
+ org.alfresco.repo.rendition2.LocalTransformServiceRegistryIntegrationTest.class,
+ org.alfresco.repo.rendition2.LocalTransformClientIntegrationTest.class,
+ org.alfresco.repo.rendition2.LegacyTransformServiceRegistryIntegrationTest.class,
+ org.alfresco.repo.rendition2.LegacyTransformClientIntegrationTest.class,
+ org.alfresco.repo.rendition2.LocalRenditionTest.class,
+ org.alfresco.repo.rendition2.LegacyRenditionTest.class,
+ org.alfresco.repo.rendition2.LegacyLocalRenditionTest.class,
+ org.alfresco.repo.rendition2.NoneRenditionTest.class,
+
org.alfresco.repo.solr.SOLRTrackingComponentTest.class,
org.alfresco.repo.tagging.TaggingServiceImplTest.class,
org.alfresco.repo.transaction.AlfrescoTransactionSupportTest.class,
@@ -64,6 +72,7 @@ import org.junit.runners.Suite;
org.alfresco.repo.tenant.MultiTServiceImplTest.class,
org.alfresco.repo.search.SearcherComponentTest.class,
org.alfresco.repo.action.scheduled.ScheduledPersistedActionServiceTest.class,
+
org.alfresco.repo.rendition2.RenditionDefinitionTest.class
})
public class AppContext06TestSuite
diff --git a/src/test/java/org/alfresco/repo/content/RoutingContentServiceTest.java b/src/test/java/org/alfresco/repo/content/RoutingContentServiceTest.java
index e7d993cf2c..1c41601d64 100644
--- a/src/test/java/org/alfresco/repo/content/RoutingContentServiceTest.java
+++ b/src/test/java/org/alfresco/repo/content/RoutingContentServiceTest.java
@@ -1,28 +1,28 @@
-/*
- * #%L
- * Alfresco Repository
- * %%
- * Copyright (C) 2005 - 2016 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 .
- * #L%
- */
+/*
+ * #%L
+ * Alfresco Repository
+ * %%
+ * Copyright (C) 2005 - 2016 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 .
+ * #L%
+ */
package org.alfresco.repo.content;
import java.io.File;
@@ -95,7 +95,7 @@ public class RoutingContentServiceTest extends TestCase
@Override
public void setUp() throws Exception
- {
+ {
ctx = ApplicationContextHelper.getApplicationContext();
transactionService = (TransactionService) ctx.getBean("TransactionService");
nodeService = (NodeService) ctx.getBean("NodeService");
@@ -635,59 +635,6 @@ public class RoutingContentServiceTest extends TestCase
assertEquals("Content check failed", threadContent, checkContent);
}
- public void testTransformation() throws Exception
- {
- // commit node so that threads can see node
- txn.commit();
- txn = null;
-
- UserTransaction txn = getUserTransaction();
- txn.begin();
- txn.setRollbackOnly();
-
- // get a regular writer
- ContentWriter writer = contentService.getTempWriter();
- writer.setMimetype("text/xml");
- // write some stuff
- String content = "";
- writer.putContent(content);
- // get a reader onto the content
- ContentReader reader = writer.getReader();
-
- // get a new writer for the transformation
- writer = contentService.getTempWriter();
- writer.setMimetype("audio/x-wav"); // no such conversion possible
- try
- {
- contentService.transform(reader, writer);
- fail("Transformation attempted with invalid mimetype");
- }
- catch (NoTransformerException e)
- {
- // expected
- }
-
- // at this point, the transaction is unusable
- txn.rollback();
-
- txn = getUserTransaction();
- txn.begin();
- txn.setRollbackOnly();
-
- writer.setMimetype("text/plain");
- ContentTransformer transformer = contentService.getTransformer(reader.getMimetype(), writer.getMimetype());
- assertNotNull("Expected a valid transformer", transformer);
- contentService.transform(reader, writer);
- // get the content from the writer
- reader = writer.getReader();
- assertEquals("Mimetype of target reader incorrect",
- writer.getMimetype(), reader.getMimetype());
- String contentCheck = reader.getContentString();
- assertEquals("Content check failed", content, contentCheck);
-
- txn.rollback();
- }
-
/**
* Writes some content to the writer's output stream and then aquires
* a lock on the writer, waits until notified and then closes the
diff --git a/src/test/java/org/alfresco/repo/content/transform/AppleIWorksContentTransformerTest.java b/src/test/java/org/alfresco/repo/content/transform/AppleIWorksContentTransformerTest.java
index c8bc7b4160..37531b6687 100644
--- a/src/test/java/org/alfresco/repo/content/transform/AppleIWorksContentTransformerTest.java
+++ b/src/test/java/org/alfresco/repo/content/transform/AppleIWorksContentTransformerTest.java
@@ -51,6 +51,7 @@ public class AppleIWorksContentTransformerTest extends AbstractContentTransforme
transformer.setMimetypeService(mimetypeService);
transformer.setTransformerDebug(transformerDebug);
transformer.setTransformerConfig(transformerConfig);
+ transformer.afterPropertiesSet();
}
@Override
diff --git a/src/test/java/org/alfresco/repo/content/transform/HtmlParserContentTransformerTest.java b/src/test/java/org/alfresco/repo/content/transform/HtmlParserContentTransformerTest.java
index fabd983b79..690620727a 100644
--- a/src/test/java/org/alfresco/repo/content/transform/HtmlParserContentTransformerTest.java
+++ b/src/test/java/org/alfresco/repo/content/transform/HtmlParserContentTransformerTest.java
@@ -53,6 +53,7 @@ public class HtmlParserContentTransformerTest extends AbstractContentTransformer
transformer.setMimetypeService(mimetypeService);
transformer.setTransformerDebug(transformerDebug);
transformer.setTransformerConfig(transformerConfig);
+ transformer.afterPropertiesSet();
}
protected ContentTransformer getTransformer(String sourceMimetype, String targetMimetype)
diff --git a/src/test/java/org/alfresco/repo/content/transform/StringExtractingContentTransformerTest.java b/src/test/java/org/alfresco/repo/content/transform/StringExtractingContentTransformerTest.java
index 730f9d25e4..ddc2d83ff5 100644
--- a/src/test/java/org/alfresco/repo/content/transform/StringExtractingContentTransformerTest.java
+++ b/src/test/java/org/alfresco/repo/content/transform/StringExtractingContentTransformerTest.java
@@ -4,21 +4,21 @@
* %%
* Copyright (C) 2005 - 2016 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
+ * 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 .
* #L%
@@ -44,7 +44,7 @@ import org.alfresco.util.TempFileProvider;
/**
* @see org.alfresco.repo.content.transform.StringExtractingContentTransformer
- *
+ *
* @author Derek Hulley
*
* @deprecated The transformations code is being moved out of the codebase and replaced by the new async RenditionService2 or other external libraries.
@@ -65,16 +65,16 @@ public class StringExtractingContentTransformerTest extends AbstractContentTrans
throw new AlfrescoRuntimeException("Encoding not recognised", e);
}
}
-
+
private StringExtractingContentTransformer transformer;
/** the final destination of transformations */
private ContentWriter targetWriter;
-
+
@Override
public void setUp() throws Exception
{
super.setUp();
-
+
transformer = new StringExtractingContentTransformer();
transformer.setMimetypeService(mimetypeService);
transformer.setTransformerDebug(transformerDebug);
@@ -82,8 +82,9 @@ public class StringExtractingContentTransformerTest extends AbstractContentTrans
targetWriter = new FileContentWriter(getTempFile());
targetWriter.setMimetype("text/plain");
targetWriter.setEncoding("UTF-8");
+ transformer.afterPropertiesSet();
}
-
+
protected ContentTransformer getTransformer(String sourceMimetype, String targetMimetype)
{
return transformer;
@@ -93,7 +94,7 @@ public class StringExtractingContentTransformerTest extends AbstractContentTrans
{
assertNotNull(transformer);
}
-
+
/**
* @return Returns a new temp file
*/
@@ -101,10 +102,10 @@ public class StringExtractingContentTransformerTest extends AbstractContentTrans
{
return TempFileProvider.createTempFile(getName(), ".txt");
}
-
+
/**
* Writes some content using the mimetype and encoding specified.
- *
+ *
* @param mimetype String
* @param encoding String
* @return Returns a reader onto the newly written content
@@ -119,39 +120,39 @@ public class StringExtractingContentTransformerTest extends AbstractContentTrans
// return a reader onto the new content
return writer.getReader();
}
-
+
public void testDirectTransform() throws Exception
{
ContentReader reader = writeContent("text/plain", "MacDingbat");
-
+
// check transformability
assertTrue(transformer.isTransformable(reader.getMimetype(), -1, targetWriter.getMimetype(), new TransformationOptions()));
-
+
// transform
transformer.transform(reader, targetWriter);
-
+
// get a reader onto the transformed content and check
ContentReader checkReader = targetWriter.getReader();
String checkContent = checkReader.getContentString();
assertEquals("Content check failed", SOME_CONTENT, checkContent);
}
-
+
public void testInterTextTransform() throws Exception
{
ContentReader reader = writeContent("text/xml", "MacDingbat");
-
+
// check transformability
assertTrue(transformer.isTransformable(reader.getMimetype(), -1, targetWriter.getMimetype(), new TransformationOptions()));
-
+
// transform
transformer.transform(reader, targetWriter);
-
+
// get a reader onto the transformed content and check
ContentReader checkReader = targetWriter.getReader();
String checkContent = checkReader.getContentString();
assertEquals("Content check failed", SOME_CONTENT, checkContent);
}
-
+
/**
* Generate a large file and then transform it using the text extractor.
* We are not creating super-large file (1GB) in order to test the transform
@@ -162,10 +163,10 @@ public class StringExtractingContentTransformerTest extends AbstractContentTrans
public void testLargeFileStreaming() throws Exception
{
File sourceFile = TempFileProvider.createTempFile(getName(), ".txt");
-
+
int chars = 1000000; // a million characters should do the trick
Random random = new Random();
-
+
Writer charWriter = new OutputStreamWriter(new BufferedOutputStream(new FileOutputStream(sourceFile)));
for (int i = 0; i < chars; i++)
{
@@ -173,18 +174,18 @@ public class StringExtractingContentTransformerTest extends AbstractContentTrans
charWriter.write(next);
}
charWriter.close();
-
+
// get a reader and a writer
ContentReader reader = new FileContentReader(sourceFile);
reader.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN);
-
+
File outputFile = TempFileProvider.createTempFile(getName(), ".txt");
ContentWriter writer = new FileContentWriter(outputFile);
writer.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN);
-
+
// transform
transformer.transform(reader, writer);
-
+
// delete files
sourceFile.delete();
outputFile.delete();
diff --git a/src/test/java/org/alfresco/repo/content/transform/TextToPdfContentTransformerTest.java b/src/test/java/org/alfresco/repo/content/transform/TextToPdfContentTransformerTest.java
index 73dfff94ff..49c6de21ab 100644
--- a/src/test/java/org/alfresco/repo/content/transform/TextToPdfContentTransformerTest.java
+++ b/src/test/java/org/alfresco/repo/content/transform/TextToPdfContentTransformerTest.java
@@ -64,6 +64,7 @@ public class TextToPdfContentTransformerTest extends AbstractContentTransformerT
transformer.setStandardFont("Times-Roman");
transformer.setFontSize(20);
transformer.setBeanName("transformer.test"+System.currentTimeMillis()%100000);
+ transformer.afterPropertiesSet();
}
/**
diff --git a/src/test/java/org/alfresco/repo/content/transform/TransformerDebugLogTest.java b/src/test/java/org/alfresco/repo/content/transform/TransformerDebugLogTest.java
index 79a88920a5..8a24feeef9 100644
--- a/src/test/java/org/alfresco/repo/content/transform/TransformerDebugLogTest.java
+++ b/src/test/java/org/alfresco/repo/content/transform/TransformerDebugLogTest.java
@@ -41,10 +41,7 @@ import org.mockito.MockitoAnnotations;
* Test class for TransformerDebugLog.
*
* @author Alan Davis
- *
- * @deprecated The transformations code is being moved out of the codebase and replaced by the new async RenditionService2 or other external libraries.
*/
-@Deprecated
public class TransformerDebugLogTest
{
@Mock
diff --git a/src/test/java/org/alfresco/repo/content/transform/TransformerDebugTest.java b/src/test/java/org/alfresco/repo/content/transform/TransformerDebugTest.java
index fc9b7cb7fb..9df45538e7 100644
--- a/src/test/java/org/alfresco/repo/content/transform/TransformerDebugTest.java
+++ b/src/test/java/org/alfresco/repo/content/transform/TransformerDebugTest.java
@@ -25,9 +25,9 @@
*/
package org.alfresco.repo.content.transform;
+import org.alfresco.repo.rendition2.TransformClient;
import org.alfresco.service.cmr.repository.MimetypeService;
import org.alfresco.service.cmr.repository.NodeService;
-import org.alfresco.service.cmr.repository.TransformationOptions;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
@@ -49,10 +49,7 @@ import static org.mockito.Mockito.when;
* Test class for TransformerDebug.
*
* @author Alan Davis
- *
- * @deprecated The transformations code is being moved out of the codebase and replaced by the new async RenditionService2 or other external libraries.
*/
-@Deprecated
public class TransformerDebugTest
{
@Mock
@@ -68,7 +65,7 @@ public class TransformerDebugTest
private TransformerConfig transformerConfig;
@Mock
- private TransformationOptions options;
+ private TransformClient transformClient;
@Mock
private AbstractContentTransformerLimits transformer1;
@@ -108,7 +105,14 @@ public class TransformerDebugTest
when(transformer3.getName()).thenReturn("transformer3");
when(transformer4.getName()).thenReturn("transformer4");
- transformerDebug = new TransformerDebug(nodeService, mimetypeService, transformerRegistry, transformerConfig, log, debug);
+ transformerDebug = new TransformerDebug();
+ transformerDebug.setNodeService(nodeService);
+ transformerDebug.setMimetypeService(mimetypeService);
+ transformerDebug.setTransformerRegistry(transformerRegistry);
+ transformerDebug.setTransformerConfig(transformerConfig);
+ transformerDebug.setTransformerLog(log);
+ transformerDebug.setTransformerDebugLog(debug);
+ transformerDebug.setTransformClient(transformClient);
log.setTransformerDebug(transformerDebug);
log.setTransformerConfig(transformerConfig);
@@ -151,7 +155,7 @@ public class TransformerDebugTest
{
long sourceSize = 1024*1024*3/2;
- transformerDebug.pushAvailable("sourceUrl", "application/pdf", "text/plain", options);
+ transformerDebug.pushAvailable("sourceUrl", "application/pdf", "text/plain", null, null);
transformerDebug.unavailableTransformer(transformer1, "application/pdf", "text/plain", 50);
transformerDebug.unavailableTransformer(transformer2, "application/pdf", "text/plain", 0);
@@ -160,7 +164,7 @@ public class TransformerDebugTest
List transformers = Arrays.asList(new ContentTransformer[] {});
- transformerDebug.availableTransformers(transformers, sourceSize, options, "ContentService.transform(...)");
+ transformerDebug.availableTransformers(transformers, sourceSize, null, null, "ContentService.transform(...)");
transformerDebug.popAvailable();
diff --git a/src/test/java/org/alfresco/repo/content/transform/TransformerLogTest.java b/src/test/java/org/alfresco/repo/content/transform/TransformerLogTest.java
index 9281a593c4..339e8fba22 100644
--- a/src/test/java/org/alfresco/repo/content/transform/TransformerLogTest.java
+++ b/src/test/java/org/alfresco/repo/content/transform/TransformerLogTest.java
@@ -39,10 +39,7 @@ import org.mockito.MockitoAnnotations;
* Test class for TransformerLog.
*
* @author Alan Davis
- *
- * @deprecated The transformations code is being moved out of the codebase and replaced by the new async RenditionService2 or other external libraries.
*/
-@Deprecated
public class TransformerLogTest
{
@Mock
diff --git a/src/test/java/org/alfresco/repo/rawevents/TransactionAwareEventProducerTest.java b/src/test/java/org/alfresco/repo/rawevents/TransactionAwareEventProducerTest.java
index 70d88acb7c..17ded38875 100644
--- a/src/test/java/org/alfresco/repo/rawevents/TransactionAwareEventProducerTest.java
+++ b/src/test/java/org/alfresco/repo/rawevents/TransactionAwareEventProducerTest.java
@@ -36,6 +36,7 @@ import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import com.fasterxml.jackson.databind.ObjectMapper;
+import org.springframework.beans.factory.annotation.Qualifier;
/**
* Provides a base set of tests for {@link TransactionAwareEventProducer}
@@ -51,6 +52,7 @@ public class TransactionAwareEventProducerTest extends BaseSpringTest
@Autowired
private TransactionAwareEventProducer eventProducer;
@Autowired
+ @Qualifier("alfrescoEventObjectMapper")
private ObjectMapper messagingObjectMapper;
@Test
diff --git a/src/test/java/org/alfresco/repo/rendition2/AbstractRenditionIntegrationTest.java b/src/test/java/org/alfresco/repo/rendition2/AbstractRenditionIntegrationTest.java
index 34a9821fad..2fe276f72a 100644
--- a/src/test/java/org/alfresco/repo/rendition2/AbstractRenditionIntegrationTest.java
+++ b/src/test/java/org/alfresco/repo/rendition2/AbstractRenditionIntegrationTest.java
@@ -28,6 +28,7 @@ package org.alfresco.repo.rendition2;
import junit.framework.AssertionFailedError;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.content.MimetypeMap;
+import org.alfresco.repo.content.transform.LocalTransformServiceRegistry;
import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.repo.thumbnail.ThumbnailRegistry;
import org.alfresco.repo.transaction.RetryingTransactionHelper;
@@ -44,7 +45,7 @@ import org.alfresco.service.cmr.security.PermissionService;
import org.alfresco.service.cmr.security.PersonService;
import org.alfresco.service.namespace.QName;
import org.alfresco.service.transaction.TransactionService;
-import org.alfresco.util.ApplicationContextHelper;
+import org.alfresco.transform.client.model.config.TransformServiceRegistry;
import org.alfresco.util.BaseSpringTest;
import org.alfresco.util.GUID;
import org.alfresco.util.PropertyMap;
@@ -72,10 +73,7 @@ public abstract class AbstractRenditionIntegrationTest extends BaseSpringTest
protected RenditionService2Impl renditionService2;
@Autowired
- protected RenditionDefinitionRegistry2 renditionDefinitionRegistry2;
-
- @Autowired
- protected TransformClient transformClient;
+ protected RenditionDefinitionRegistry2Impl renditionDefinitionRegistry2;
@Autowired
protected RenditionService renditionService;
@@ -107,6 +105,15 @@ public abstract class AbstractRenditionIntegrationTest extends BaseSpringTest
@Autowired
protected PermissionService permissionService;
+ @Autowired
+ protected TransformServiceRegistry transformServiceRegistry;
+
+ @Autowired
+ protected LocalTransformServiceRegistry localTransformServiceRegistry;
+
+ @Autowired
+ protected LegacyTransformServiceRegistry legacyTransformServiceRegistry;
+
static String PASSWORD = "password";
protected static final String ADMIN = "admin";
@@ -115,17 +122,81 @@ public abstract class AbstractRenditionIntegrationTest extends BaseSpringTest
@BeforeClass
public static void before()
{
- // Use the docker images for transforms
+ // Use the docker images for transforms (legacy)
System.setProperty("alfresco-pdf-renderer.url", "http://localhost:8090/");
- System.setProperty("img.url", "http://localhost:8091");
+ System.setProperty("img.url", "http://localhost:8091/");
System.setProperty("jodconverter.url", "http://localhost:8092/");
System.setProperty("tika.url", "http://localhost:8093/");
+ System.setProperty("transform.misc.url", "http://localhost:8094/");
+
+ // Use the docker images for transforms (local)
+ System.setProperty("localTransform.pdfrenderer.url", "http://localhost:8090/");
+ System.setProperty("localTransform.imagemagick.url", "http://localhost:8091/");
+ System.setProperty("localTransform.libreoffice.url", "http://localhost:8092/");
+ System.setProperty("localTransform.tika.url", "http://localhost:8093/");
+ System.setProperty("localTransform.misc.url", "http://localhost:8094/");
+ }
+
+ protected static void none()
+ {
+ System.setProperty("transform.service.enabled", "false");
+ System.setProperty("local.transform.service.enabled", "false");
+ System.setProperty("legacy.transform.service.enabled", "false");
+ }
+
+ protected static void legacy()
+ {
+ System.setProperty("transform.service.enabled", "false");
+ System.setProperty("local.transform.service.enabled", "false");
+ System.setProperty("legacy.transform.service.enabled", "true");
+ }
+
+ protected static void local()
+ {
+ System.setProperty("transform.service.enabled", "false");
+ System.setProperty("local.transform.service.enabled", "true");
+ System.setProperty("legacy.transform.service.enabled", "false");
+
+ // Strict MimetypeCheck
+ System.setProperty("transformer.strict.mimetype.check", "true");
+ // Retry on DifferentMimetype
+ System.setProperty("content.transformer.retryOn.different.mimetype", "true");
+ }
+
+ protected static void service()
+ {
+ System.setProperty("transform.service.enabled", "true");
+ System.setProperty("local.transform.service.enabled", "false");
+ System.setProperty("legacy.transform.service.enabled", "false");
+ }
+
+ protected static void legacyLocal()
+ {
+ System.setProperty("transform.service.enabled", "false");
+ System.setProperty("local.transform.service.enabled", "true");
+ System.setProperty("legacy.transform.service.enabled", "true");
+ }
+
+ protected static void legacyLocalService()
+ {
+ System.setProperty("transform.service.enabled", "true");
+ System.setProperty("local.transform.service.enabled", "true");
+ System.setProperty("legacy.transform.service.enabled", "true");
}
@Before
public void setUp() throws Exception
{
assertTrue("The RenditionService2 needs to be enabled", renditionService2.isEnabled());
+
+ legacyTransformServiceRegistry.setEnabled(Boolean.parseBoolean(System.getProperty("legacy.transform.service.enabled")));
+ legacyTransformServiceRegistry.afterPropertiesSet();
+
+ localTransformServiceRegistry.setEnabled(Boolean.parseBoolean(System.getProperty("local.transform.service.enabled")));
+ localTransformServiceRegistry.afterPropertiesSet();
+
+ renditionDefinitionRegistry2.setTransformServiceRegistry(transformServiceRegistry);
+ thumbnailRegistry.setTransformServiceRegistry(transformServiceRegistry);
}
@After
@@ -141,6 +212,17 @@ public abstract class AbstractRenditionIntegrationTest extends BaseSpringTest
System.clearProperty("img.url");
System.clearProperty("jodconverter.url");
System.clearProperty("tika.url");
+ System.clearProperty("transform.misc.url");
+
+ System.clearProperty("localTransform.pdfrenderer.url");
+ System.clearProperty("localTransform.imagemagick.url");
+ System.clearProperty("localTransform.libreoffice.url");
+ System.clearProperty("localTransform.tika.url");
+ System.clearProperty("localTransform.misc.url");
+
+ System.clearProperty("transform.service.enabled");
+ System.clearProperty("local.transform.service.enabled");
+ System.clearProperty("legacy.transform.service.enabled");
}
protected void checkRendition(String testFileName, String renditionName, boolean expectedToPass)
diff --git a/src/test/java/org/alfresco/repo/rendition2/RenditionTest.java b/src/test/java/org/alfresco/repo/rendition2/AbstractRenditionTest.java
similarity index 78%
rename from src/test/java/org/alfresco/repo/rendition2/RenditionTest.java
rename to src/test/java/org/alfresco/repo/rendition2/AbstractRenditionTest.java
index 8b1dec11fc..2c1073ec03 100644
--- a/src/test/java/org/alfresco/repo/rendition2/RenditionTest.java
+++ b/src/test/java/org/alfresco/repo/rendition2/AbstractRenditionTest.java
@@ -28,7 +28,6 @@ package org.alfresco.repo.rendition2;
import junit.framework.AssertionFailedError;
import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.repo.thumbnail.ThumbnailDefinition;
-import org.alfresco.transform.client.model.config.TransformServiceRegistry;
import org.alfresco.util.testing.category.DebugTests;
import org.junit.Before;
import org.junit.Test;
@@ -45,11 +44,12 @@ import java.util.Set;
import java.util.StringJoiner;
/**
- * Test it is possible to create renditions from the quick files.
+ * Abstract test class to check it is possible to create renditions from the quick files using combinations of
+ * local transforms, legacy transforms and the Transform Service.
*
* @author adavis
*/
-public class RenditionTest extends AbstractRenditionIntegrationTest
+public abstract class AbstractRenditionTest extends AbstractRenditionIntegrationTest
{
// This is the same order as produced by MimetypeMap
public static final List TAS_REST_API_SOURCE_EXTENSIONS = Arrays.asList(
@@ -89,9 +89,7 @@ public class RenditionTest extends AbstractRenditionIntegrationTest
"wpd png avatar32",
"wpd jpg imgpreview");
- @Autowired
- private TransformServiceRegistry transformServiceRegistry;
-
+ @Override
@Before
public void setUp() throws Exception
{
@@ -148,17 +146,15 @@ public class RenditionTest extends AbstractRenditionIntegrationTest
}
else
{
- String task = sourceExtension + " " + targetExtension + " " + renditionName;
-
try
{
checkRendition(testFileName, renditionName, !expectedToFail.contains(sourceTragetRendition));
- successes.add(task);
+ successes.add(sourceTragetRendition);
successCount++;
}
catch (AssertionFailedError e)
{
- failures.add(task + " " + e.getMessage());
+ failures.add(sourceTragetRendition + " " + e.getMessage());
failedCount++;
}
}
@@ -217,48 +213,6 @@ public class RenditionTest extends AbstractRenditionIntegrationTest
Collections.emptyList(), expectedRenditionCount, expectedFailedCount);
}
- @Category(DebugTests.class)
- @Test
- public void testTransformServiceConfig() throws Exception
- {
- internalTestTransformServiceConfig(57, 0);
- }
-
- // Tests all renditions supported by the TransformServiceRegistry (in the case of Transform Service, see
- // transform-service-config.json and the LegacyLocalTransformServiceRegistry see the original ACS config).
- protected void internalTestTransformServiceConfig(int expectedRenditionCount, int expectedFailedCount) throws Exception
- {
- List sourceExtensions = getAllSourceMimetypes();
- List excludeList = new ArrayList<>();
-
- for (String sourceExtension : sourceExtensions)
- {
- String sourceMimetype = mimetypeMap.getMimetype(sourceExtension);
- String testFileName = getTestFileName(sourceMimetype);
- if (testFileName != null)
- {
- Set renditionNames = renditionDefinitionRegistry2.getRenditionNamesFrom(sourceMimetype, -1);
- for (String renditionName : renditionNames)
- {
- RenditionDefinition2 renditionDefinition = renditionDefinitionRegistry2.getRenditionDefinition(renditionName);
- String targetMimetype = renditionDefinition.getTargetMimetype();
- String targetExtension = mimetypeMap.getExtension(targetMimetype);
-
- String sourceTragetRendition = sourceExtension + ' ' + targetExtension + ' ' + renditionName;
- Map actualOptions = renditionDefinition.getTransformOptions();
- if (!transformServiceRegistry.isSupported(sourceMimetype, -1L, targetMimetype,
- actualOptions, null))
- {
- excludeList.add(sourceTragetRendition);
- }
- }
- }
- }
-
- assertRenditionsOkayFromSourceExtension(sourceExtensions, excludeList,
- Collections.emptyList(), expectedRenditionCount, expectedFailedCount);
- }
-
private List getAllSourceMimetypes()
{
List sourceExtensions = new ArrayList<>();
diff --git a/src/main/java/org/alfresco/repo/rendition2/AbstractTransformClient.java b/src/test/java/org/alfresco/repo/rendition2/LegacyLocalRenditionTest.java
similarity index 61%
rename from src/main/java/org/alfresco/repo/rendition2/AbstractTransformClient.java
rename to src/test/java/org/alfresco/repo/rendition2/LegacyLocalRenditionTest.java
index f8ce1d6f6c..0b0d6dc0bf 100644
--- a/src/main/java/org/alfresco/repo/rendition2/AbstractTransformClient.java
+++ b/src/test/java/org/alfresco/repo/rendition2/LegacyLocalRenditionTest.java
@@ -25,30 +25,30 @@
*/
package org.alfresco.repo.rendition2;
-import org.alfresco.model.ContentModel;
-import org.alfresco.service.cmr.repository.ContentData;
-import org.alfresco.service.cmr.repository.NodeRef;
-import org.alfresco.service.cmr.repository.NodeService;
-import org.alfresco.util.PropertyCheck;
-import org.springframework.beans.factory.InitializingBean;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
/**
- * Contains common code used in TransformClients.
+ * Repeats quick file rendition tests with local transforms and legacy transformers enabled.
+ * The Transform Service does not exist for the Community edition.
+ * Should be the same result as with legacy or local transforms on their own.
*
* @author adavis
*/
-public abstract class AbstractTransformClient implements InitializingBean
+@Deprecated
+public class LegacyLocalRenditionTest extends AbstractRenditionTest
{
- protected NodeService nodeService;
-
- public void setNodeService(NodeService nodeService)
+ @BeforeClass
+ public static void before()
{
- this.nodeService = nodeService;
+ AbstractRenditionIntegrationTest.before();
+ legacyLocal();
}
- @Override
- public void afterPropertiesSet() throws Exception
+ @AfterClass
+ public static void after()
{
- PropertyCheck.mandatory(this, "nodeService", nodeService);
+ AbstractRenditionIntegrationTest.after();
}
}
diff --git a/src/test/java/org/alfresco/repo/rendition2/LegacyRenditionTest.java b/src/test/java/org/alfresco/repo/rendition2/LegacyRenditionTest.java
new file mode 100644
index 0000000000..0b82424607
--- /dev/null
+++ b/src/test/java/org/alfresco/repo/rendition2/LegacyRenditionTest.java
@@ -0,0 +1,52 @@
+/*
+ * #%L
+ * Alfresco Repository
+ * %%
+ * Copyright (C) 2005 - 2018 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 .
+ * #L%
+ */
+package org.alfresco.repo.rendition2;
+
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+
+/**
+ * Repeats quick file rendition tests with local transforms disabled but legacy transformers enabled.
+ * The Transform Service does not exist for the Community edition.
+ * Should be the same result as with local transforms.
+ *
+ * @author adavis
+ */
+public class LegacyRenditionTest extends AbstractRenditionTest
+{
+ @BeforeClass
+ public static void before()
+ {
+ AbstractRenditionIntegrationTest.before();
+ legacy();
+ }
+
+ @AfterClass
+ public static void after()
+ {
+ AbstractRenditionIntegrationTest.after();
+ }
+}
diff --git a/src/test/java/org/alfresco/repo/rendition2/LegacyTransformClientIntegrationTest.java b/src/test/java/org/alfresco/repo/rendition2/LegacyTransformClientIntegrationTest.java
new file mode 100644
index 0000000000..adbb50fd6d
--- /dev/null
+++ b/src/test/java/org/alfresco/repo/rendition2/LegacyTransformClientIntegrationTest.java
@@ -0,0 +1,61 @@
+/*
+ * #%L
+ * Alfresco Repository
+ * %%
+ * Copyright (C) 2005 - 2018 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 .
+ * #L%
+ */
+package org.alfresco.repo.rendition2;
+
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.springframework.beans.factory.annotation.Autowired;
+
+/**
+ * Integration tests for {@link LegacyTransformClient}
+ */
+@Deprecated
+public class LegacyTransformClientIntegrationTest extends LocalTransformClientIntegrationTest
+{
+ @Autowired
+ protected TransformClient legacyTransformClient;
+
+ @BeforeClass
+ public static void before()
+ {
+ AbstractRenditionIntegrationTest.before();
+ legacy();
+ }
+
+ @AfterClass
+ public static void after()
+ {
+ AbstractRenditionIntegrationTest.after();
+ }
+
+ @Before
+ public void setUp() throws Exception
+ {
+ super.setUp();
+ transformClient = legacyTransformClient;
+ }
+}
diff --git a/src/test/java/org/alfresco/repo/rendition2/LegacyTransformServiceRegistryIntegrationTest.java b/src/test/java/org/alfresco/repo/rendition2/LegacyTransformServiceRegistryIntegrationTest.java
new file mode 100644
index 0000000000..5bc1eceacd
--- /dev/null
+++ b/src/test/java/org/alfresco/repo/rendition2/LegacyTransformServiceRegistryIntegrationTest.java
@@ -0,0 +1,66 @@
+/*
+ * #%L
+ * Alfresco Repository
+ * %%
+ * Copyright (C) 2005 - 2018 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 .
+ * #L%
+ */
+package org.alfresco.repo.rendition2;
+
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.springframework.beans.factory.annotation.Autowired;
+
+/**
+ * Integration tests for {@link LegacyTransformServiceRegistry}
+ */
+@Deprecated
+public class LegacyTransformServiceRegistryIntegrationTest extends LocalTransformServiceRegistryIntegrationTest
+{
+ @Autowired
+ private LegacyTransformServiceRegistry legacyTransformServiceRegistry;
+
+ @Before
+ public void setUp() throws Exception
+ {
+ super.setUp();
+ transformServiceRegistry = legacyTransformServiceRegistry;
+ }
+
+ @BeforeClass
+ public static void before()
+ {
+ AbstractRenditionIntegrationTest.before();
+ legacy();
+ }
+
+ @AfterClass
+ public static void after()
+ {
+ AbstractRenditionIntegrationTest.after();
+ }
+
+ protected void setEnabled(boolean enabled)
+ {
+ legacyTransformServiceRegistry.setEnabled(enabled);
+ }
+}
diff --git a/src/test/java/org/alfresco/repo/rendition2/LocalRenditionTest.java b/src/test/java/org/alfresco/repo/rendition2/LocalRenditionTest.java
new file mode 100644
index 0000000000..6337e6832e
--- /dev/null
+++ b/src/test/java/org/alfresco/repo/rendition2/LocalRenditionTest.java
@@ -0,0 +1,64 @@
+/*
+ * #%L
+ * Alfresco Repository
+ * %%
+ * Copyright (C) 2005 - 2018 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 .
+ * #L%
+ */
+package org.alfresco.repo.rendition2;
+
+import org.alfresco.util.testing.category.DebugTests;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+/**
+ * Repeats quick file rendition tests with local transforms enabled but legacy transformers disabled.
+ * The Transform Service does not exist for the Community edition.
+ * Should be the same result as with legacy transforms only.
+ *
+ * @author adavis
+ */
+public class LocalRenditionTest extends AbstractRenditionTest
+{
+ @BeforeClass
+ public static void before()
+ {
+ AbstractRenditionIntegrationTest.before();
+ local();
+ }
+
+ @AfterClass
+ public static void after()
+ {
+ AbstractRenditionIntegrationTest.after();
+ }
+
+ // TODO this method will be removed when Local transformers support all 196 renditions supported by legacy
+ @Override
+ @Category(DebugTests.class)
+ @Test
+ public void testAllSourceExtensions() throws Exception
+ {
+ internalTestAllSourceExtensions(57, 0);
+ }
+}
diff --git a/src/test/java/org/alfresco/repo/rendition2/LegacyLocalTransformClientIntegrationTest.java b/src/test/java/org/alfresco/repo/rendition2/LocalTransformClientIntegrationTest.java
similarity index 56%
rename from src/test/java/org/alfresco/repo/rendition2/LegacyLocalTransformClientIntegrationTest.java
rename to src/test/java/org/alfresco/repo/rendition2/LocalTransformClientIntegrationTest.java
index fa64ea0788..8d603ac43d 100644
--- a/src/test/java/org/alfresco/repo/rendition2/LegacyLocalTransformClientIntegrationTest.java
+++ b/src/test/java/org/alfresco/repo/rendition2/LocalTransformClientIntegrationTest.java
@@ -30,107 +30,129 @@ import org.alfresco.service.cmr.repository.ChildAssociationRef;
import org.alfresco.service.cmr.repository.ContentData;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.datatype.DefaultTypeConverter;
+import org.junit.AfterClass;
import org.junit.Before;
+import org.junit.BeforeClass;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
import static org.alfresco.model.ContentModel.PROP_CONTENT;
/**
- * Integration tests for {@link LegacyLocalTransformClient}
+ * Integration tests for {@link LocalTransformClient}
*/
-public class LegacyLocalTransformClientIntegrationTest extends AbstractRenditionIntegrationTest
+public class LocalTransformClientIntegrationTest extends AbstractRenditionIntegrationTest
{
+ @Autowired
+ protected TransformClient localTransformClient;
+
+ protected TransformClient transformClient;
+
+ @BeforeClass
+ public static void before()
+ {
+ AbstractRenditionIntegrationTest.before();
+ local();
+ }
+
+ @AfterClass
+ public static void after()
+ {
+ // Strict MimetypeCheck property cleanup
+ System.clearProperty("transformer.strict.mimetype.check");
+ // Retry on DifferentMimetype property cleanup
+ System.clearProperty("content.transformer.retryOn.different.mimetype");
+ AbstractRenditionIntegrationTest.after();
+ }
+
@Before
public void setUp() throws Exception
{
super.setUp();
AuthenticationUtil.setRunAsUser(AuthenticationUtil.getAdminUserName());
- }
-
- // PDF transformation
-
- @Test
- public void testLocalRenderPdfToJpegMedium() throws Exception
- {
- localCheckRendition("quick.pdf", "medium", true);
+ transformClient = localTransformClient;
}
@Test
- public void testLocalRenderPdfToDoclib() throws Exception
+ public void testLocalRenderPagesToJpeg() throws Exception
{
- localCheckRendition("quick.pdf", "doclib", true);
+ legacyTransformServiceRegistry.setEnabled(false);
+ new RenditionDefinition2Impl("pagesToJpeg", "image/jpeg", new HashMap<>(), renditionDefinitionRegistry2 );
+ try
+ {
+ checkClientRendition("quick2009.pages", "pagesToJpeg", true);
+ }
+ finally
+ {
+ // Remove rendition even if check throws an exception to not interfere with other tests
+ renditionDefinitionRegistry2.unregister("pagesToJpeg");
+ }
}
- @Test
- public void testLocalRenderPdfJpegImgpreview() throws Exception
- {
- localCheckRendition("quick.pdf", "imgpreview", true);
- }
-
- @Test
- public void testLocalRenderPdfPngAvatar() throws Exception
- {
- localCheckRendition("quick.pdf", "avatar", true);
- }
-
- @Test
- public void testLocalRenderPdfPngAvatar32() throws Exception
- {
- localCheckRendition("quick.pdf", "avatar32", true);
- }
-
- @Test
- public void testLocalRenderPdfFlashWebpreview() throws Exception
- {
- localCheckRendition("quick.pdf", "webpreview", false);
- }
-
- // DOCX transformation
-
@Test
public void testLocalRenderDocxJpegMedium() throws Exception
{
- localCheckRendition("quick.docx", "medium", true);
+ checkClientRendition("quick.docx", "medium", true);
}
@Test
public void testLocalRenderDocxDoclib() throws Exception
{
- localCheckRendition("quick.docx", "doclib", true);
+ checkClientRendition("quick.docx", "doclib", true);
}
@Test
public void testLocalRenderDocxJpegImgpreview() throws Exception
{
- localCheckRendition("quick.docx", "imgpreview", true);
+ checkClientRendition("quick.docx", "imgpreview", true);
}
@Test
public void testLocalRenderDocxPngAvatar() throws Exception
{
- localCheckRendition("quick.docx", "avatar", true);
+ checkClientRendition("quick.docx", "avatar", true);
}
@Test
public void testLocalRenderDocxPngAvatar32() throws Exception
{
- localCheckRendition("quick.docx", "avatar32", true);
+ checkClientRendition("quick.docx", "avatar32", true);
}
@Test
public void testLocalRenderDocxFlashWebpreview() throws Exception
{
- localCheckRendition("quick.docx", "webpreview", false);
+ checkClientRendition("quick.docx", "webpreview", false);
}
@Test
public void testLocalRenderDocxPdf() throws Exception
{
- localCheckRendition("quick.docx", "pdf", false);
+ checkClientRendition("quick.docx", "pdf", false);
}
- private void localCheckRendition(String testFileName, String renditionDefinitionName, boolean expectedToPass) throws InterruptedException
+ @Test
+ public void testRetryOnDifferentMimetype() throws Exception
+ {
+ boolean expectedToPass = true;
+ if(!transformClient.getClass().isInstance(LocalTransformClient.class))
+ expectedToPass = false;
+
+ // File is actually an image masked as docx
+ checkClientRendition("quick-differentMimetype.docx", "pdf", expectedToPass);
+ }
+
+ @Test
+ public void testNonWhitelistedStrictMimetype() throws Exception
+ {
+ checkClientRendition("quickMaskedHtml.jpeg", "avatar32", false);
+ }
+
+ protected void checkClientRendition(String testFileName, String renditionDefinitionName, boolean expectedToPass) throws InterruptedException
{
if (expectedToPass)
{
@@ -143,11 +165,12 @@ public class LegacyLocalTransformClientIntegrationTest extends AbstractRendition
{
RenditionDefinition2 renditionDefinition =
renditionDefinitionRegistry2.getRenditionDefinition(renditionDefinitionName);
- transformClient.transform(
- sourceNode,
- renditionDefinition,
- AuthenticationUtil.getAdminUserName(),
- sourceContentHashCode);
+ String contentUrl = contentData.getContentUrl();
+ String sourceMimetype = contentData.getMimetype();
+ long size = contentData.getSize();
+ String adminUserName = AuthenticationUtil.getAdminUserName();
+ transformClient.checkSupported(sourceNode, renditionDefinition, sourceMimetype, size, contentUrl);
+ transformClient.transform(sourceNode, renditionDefinition, adminUserName, sourceContentHashCode);
return null;
});
ChildAssociationRef childAssociationRef = null;
diff --git a/src/test/java/org/alfresco/repo/rendition2/LegacyLocalTransformServiceRegistryTest.java b/src/test/java/org/alfresco/repo/rendition2/LocalTransformServiceRegistryIntegrationTest.java
similarity index 79%
rename from src/test/java/org/alfresco/repo/rendition2/LegacyLocalTransformServiceRegistryTest.java
rename to src/test/java/org/alfresco/repo/rendition2/LocalTransformServiceRegistryIntegrationTest.java
index bbded0270e..fe0a2d39f4 100644
--- a/src/test/java/org/alfresco/repo/rendition2/LegacyLocalTransformServiceRegistryTest.java
+++ b/src/test/java/org/alfresco/repo/rendition2/LocalTransformServiceRegistryIntegrationTest.java
@@ -25,9 +25,12 @@
*/
package org.alfresco.repo.rendition2;
-import com.sun.star.auth.InvalidArgumentException;
+import org.alfresco.repo.content.transform.LocalTransformServiceRegistry;
+import org.alfresco.transform.client.model.config.TransformServiceRegistry;
+import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.Before;
+import org.junit.BeforeClass;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
@@ -38,28 +41,46 @@ import static org.alfresco.repo.content.MimetypeMap.MIMETYPE_OPENXML_WORDPROCESS
import static org.alfresco.repo.content.MimetypeMap.MIMETYPE_PDF;
/**
- * Integration tests for {@link LegacyLocalTransformServiceRegistry}
+ * Integration tests for {@link LocalTransformServiceRegistry}
*/
-public class LegacyLocalTransformServiceRegistryTest extends AbstractRenditionIntegrationTest
+public class LocalTransformServiceRegistryIntegrationTest extends AbstractRenditionIntegrationTest
{
- private static final String RENDITION_NAME = "pdf";
-
@Autowired
- private LegacyLocalTransformServiceRegistry transformServiceRegistry;
+ private LocalTransformServiceRegistry localTransformServiceRegistry;
- @Autowired
- private RenditionDefinitionRegistry2 renditionDefinitionRegistry2;
+ protected TransformServiceRegistry transformServiceRegistry;
private Map options;
+ @BeforeClass
+ public static void before()
+ {
+ AbstractRenditionIntegrationTest.before();
+ local();
+ }
+
+ @AfterClass
+ public static void after()
+ {
+ AbstractRenditionIntegrationTest.after();
+ }
+
@Before
public void setUp() throws Exception
{
super.setUp();
+ transformServiceRegistry = localTransformServiceRegistry;
+
RenditionDefinition2 definition2 = renditionDefinitionRegistry2.getRenditionDefinition(RENDITION_NAME);
options = definition2.getTransformOptions();
}
+ protected void setEnabled(boolean enabled)
+ {
+ localTransformServiceRegistry.setEnabled(enabled);
+ }
+ private static final String RENDITION_NAME = "pdf";
+
@Test
public void testIsSupported()
{
@@ -71,7 +92,7 @@ public class LegacyLocalTransformServiceRegistryTest extends AbstractRenditionIn
// Bad Source
Assert.assertFalse(transformServiceRegistry.isSupported("docxBad", 1234, MIMETYPE_PDF, options, RENDITION_NAME));
// Bad Target
- Assert.assertFalse(transformServiceRegistry.isSupported(MIMETYPE_OPENXML_WORDPROCESSING, 1234, "pdfBad", options, RENDITION_NAME));
+ Assert.assertFalse(transformServiceRegistry.isSupported(MIMETYPE_OPENXML_WORDPROCESSING, 1234, "pdfBad", options, "pdfBad"));
// Good MaxSize docx max size is 768K
Assert.assertTrue(transformServiceRegistry.isSupported(MIMETYPE_OPENXML_WORDPROCESSING, 768L*1024, MIMETYPE_PDF, options, RENDITION_NAME));
@@ -89,7 +110,7 @@ public class LegacyLocalTransformServiceRegistryTest extends AbstractRenditionIn
Assert.assertTrue(transformServiceRegistry.isSupported(MIMETYPE_OPENXML_WORDPROCESSING, 1234, MIMETYPE_PDF, options, "custom"));
}
- @Test(expected = IllegalArgumentException.class)
+ @Test
public void testBadOptions()
{
// Source, Target and Props are in dictionary.properties
@@ -105,12 +126,12 @@ public class LegacyLocalTransformServiceRegistryTest extends AbstractRenditionIn
Assert.assertTrue(transformServiceRegistry.isSupported(MIMETYPE_OPENXML_WORDPROCESSING, 1234, MIMETYPE_PDF, options, RENDITION_NAME));
try
{
- transformServiceRegistry.setEnabled(false);
+ setEnabled(false);
Assert.assertFalse(transformServiceRegistry.isSupported(MIMETYPE_OPENXML_WORDPROCESSING, 1234, MIMETYPE_PDF, options, RENDITION_NAME));
}
finally
{
- transformServiceRegistry.setEnabled(true);
+ setEnabled(true);
}
Assert.assertTrue(transformServiceRegistry.isSupported(MIMETYPE_OPENXML_WORDPROCESSING, 1234, MIMETYPE_PDF, options, RENDITION_NAME));
}
diff --git a/src/test/java/org/alfresco/repo/rendition2/NoLocalTransformRenditionTest.java b/src/test/java/org/alfresco/repo/rendition2/NoneRenditionTest.java
similarity index 88%
rename from src/test/java/org/alfresco/repo/rendition2/NoLocalTransformRenditionTest.java
rename to src/test/java/org/alfresco/repo/rendition2/NoneRenditionTest.java
index 5954f46658..e6541fe950 100644
--- a/src/test/java/org/alfresco/repo/rendition2/NoLocalTransformRenditionTest.java
+++ b/src/test/java/org/alfresco/repo/rendition2/NoneRenditionTest.java
@@ -32,27 +32,26 @@ import org.junit.Test;
import org.junit.experimental.categories.Category;
/**
- * Disables local transform and repeats the RenditionTests
+ * Repeats quick file rendition tests with local transforms and legacy transformers disabled.
+ * The Transform Service does not exist for the Community edition.
*
* @author adavis
*/
-public class NoLocalTransformRenditionTest extends RenditionTest
+public class NoneRenditionTest extends AbstractRenditionTest
{
@BeforeClass
public static void before()
{
AbstractRenditionIntegrationTest.before();
- System.setProperty("local.transform.service.enabled", "false");
+ none();
}
@AfterClass
public static void after()
{
AbstractRenditionIntegrationTest.after();
- System.clearProperty("local.transform.service.enabled");
}
-
@Test
@Override
public void testTasRestApiRenditions() throws Exception
diff --git a/src/test/java/org/alfresco/repo/rendition2/RenditionService2IntegrationTest.java b/src/test/java/org/alfresco/repo/rendition2/RenditionService2IntegrationTest.java
index 8b538bd47d..016f099a08 100644
--- a/src/test/java/org/alfresco/repo/rendition2/RenditionService2IntegrationTest.java
+++ b/src/test/java/org/alfresco/repo/rendition2/RenditionService2IntegrationTest.java
@@ -36,6 +36,9 @@ import org.alfresco.service.cmr.repository.datatype.DefaultTypeConverter;
import org.alfresco.service.cmr.security.PermissionService;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
import org.junit.Test;
import java.util.List;
@@ -48,6 +51,13 @@ import static org.junit.Assert.assertNotEquals;
*/
public class RenditionService2IntegrationTest extends AbstractRenditionIntegrationTest
{
+ @BeforeClass
+ public static void before()
+ {
+ AbstractRenditionIntegrationTest.before();
+ legacyLocal();
+ }
+
// PDF transformation
@Test
diff --git a/src/test/java/org/alfresco/transform/client/model/config/LocalTransformServiceRegistryConfigTest.java b/src/test/java/org/alfresco/transform/client/model/config/LocalTransformServiceRegistryConfigTest.java
new file mode 100644
index 0000000000..443216e3fe
--- /dev/null
+++ b/src/test/java/org/alfresco/transform/client/model/config/LocalTransformServiceRegistryConfigTest.java
@@ -0,0 +1,490 @@
+/*
+ * #%L
+ * Alfresco Repository
+ * %%
+ * Copyright (C) 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 .
+ * #L%
+ */
+package org.alfresco.transform.client.model.config;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.alfresco.repo.content.MimetypeMap;
+import org.alfresco.repo.content.transform.LocalTransformServiceRegistry;
+import org.alfresco.repo.content.transform.TransformerDebug;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.quartz.CronExpression;
+import org.quartz.Scheduler;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+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.
+ */
+public class LocalTransformServiceRegistryConfigTest extends TransformServiceRegistryConfigTest
+{
+ private class TestLocalTransformServiceRegistry extends LocalTransformServiceRegistry
+ {
+ private boolean lastReadSucceed = false;
+ private boolean mockSuccessReadingRemoteConfig = true;
+
+ public synchronized boolean getMockSuccessReadingRemoteConfig()
+ {
+ return mockSuccessReadingRemoteConfig;
+ }
+
+ public synchronized void setMockSuccessReadingRemoteConfig(boolean mockSuccessReadingRemoteConfig)
+ {
+ System.out.println("\n"+getMs()+": set next mock read to "+(mockSuccessReadingRemoteConfig ? "success" : "failure"));
+ this.mockSuccessReadingRemoteConfig = mockSuccessReadingRemoteConfig;
+ }
+
+ @Override
+ protected String getBaseUrlIfTesting(String name, String baseUrl)
+ {
+ return baseUrl == null
+ ? getProperty(LOCAL_TRANSFORM +name+URL, null)
+ : baseUrl;
+ }
+
+ @Override
+ protected TransformServiceRegistryImpl.Data readConfig() throws IOException
+ {
+ readConfigCount++;
+ data = createData();
+ boolean mockSuccessReadingRemoteConfig = getMockSuccessReadingRemoteConfig();
+ lastReadSucceed = mockSuccessReadingRemoteConfig;
+ setSuccessReadingRemoteConfig(data, mockSuccessReadingRemoteConfig);
+ System.out.println(getMs() + "readConfig() success="+mockSuccessReadingRemoteConfig+" reads="+readConfigCount);
+ return data;
+ }
+
+ public Data assertDataChanged(Data data, String msg)
+ {
+ // If the data changes, there has been a read
+ System.out.println(getMs()+msg);
+ assertNotEquals("The configuration data should have changed: "+msg, this.data, data);
+ return this.data;
+ }
+
+ public Data assertDataUnchanged(Data data, String msg)
+ {
+ // If the data changes, there has been a read
+ System.out.println(getMs()+msg);
+ assertEquals("The configuration data should be the same: "+msg, this.data, data);
+ return this.data;
+ }
+ }
+
+ protected TestLocalTransformServiceRegistry registry;
+
+ private Properties properties = new Properties();
+
+ @Mock private TransformerDebug transformerDebug;
+ @Mock private MimetypeMap mimetypeMap;
+
+ 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";
+
+ private static Log log = LogFactory.getLog(LocalTransformServiceRegistry.class);
+
+ private Map> imagemagickSupportedTransformation;
+ private Map> tikaSupportedTransformation;
+ private Map> pdfRendererSupportedTransformation;
+ private Map> libreofficeSupportedTransformation;
+ private Map> officeToImageViaPdfSupportedTransformation;
+
+ private TransformServiceRegistryImpl.Data data;
+ private int readConfigCount;
+ private long startMs;
+
+ @Before
+ public void setUp() throws Exception
+ {
+ MockitoAnnotations.initMocks(this);
+ initTestData();
+
+ super.setUp();
+ }
+
+ protected LocalTransformServiceRegistry buildTransformServiceRegistryImpl() throws Exception
+ {
+ registry = new TestLocalTransformServiceRegistry();
+ registry.setJsonObjectMapper(JSON_OBJECT_MAPPER);
+ registry.setProperties(properties);
+ registry.setTransformerDebug(transformerDebug);
+ registry.setMimetypeService(mimetypeMap);
+ registry.setPipelineConfigDir("");
+ registry.setCronExpression(new CronExpression("* * * * * ? 2099")); // not for a long time.
+ registry.setInitialAndOnErrorCronExpression(new CronExpression("* * * * * ? 2099")); // not for a long time.
+ return registry;
+ }
+
+ private String getMs()
+ {
+ 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()
+ {
+ // Need to have at least one supportedSourceAndTargetList element per transformer and there are 3.
+ return 4+3;
+ }
+
+ /**
+ * Reads and loads localTransforms from LOCAL_TRANSFORM_SERVICE_CONFIG config file.
+ * @return List list of local transformers.
+ */
+ private List retrieveLocalTransformList()
+ {
+ try {
+ CombinedConfig combinedConfig = new CombinedConfig(log);
+ combinedConfig.addLocalConfig(LOCAL_TRANSFORM_SERVICE_CONFIG);
+ return combinedConfig.getTransforms();
+ } catch (IOException e) {
+ log.error("Could not read LocalTransform config file");
+ fail();
+ }
+ return null;
+ }
+
+ /**
+ * Initialize source and target test data for each transformer
+ */
+ private void initTestData()
+ {
+ // Add JVM properties
+ System.setProperty(LOCAL_TRANSFORM + "pdfrenderer" + URL, "http://localhost:8090/");
+ System.setProperty(LOCAL_TRANSFORM + "imagemagick" + URL, "http://localhost:8091/");
+ System.setProperty(LOCAL_TRANSFORM + "libreoffice" + URL, "http://localhost:8092/");
+ System.setProperty(LOCAL_TRANSFORM + "tika" + URL, "http://localhost:8093/");
+
+ // Add alfresco-global properties
+ properties.setProperty(LOCAL_TRANSFORM + "pdfrenderer" + URL, "http://localhost:8090/");
+ properties.setProperty(LOCAL_TRANSFORM + "imagemagick" + URL, "http://localhost:8091/");
+ properties.setProperty(LOCAL_TRANSFORM + "libreoffice" + URL, "http://localhost:8092/");
+ properties.setProperty(LOCAL_TRANSFORM + "tika" + URL, "http://localhost:8093/");
+
+ // ImageMagick supported Source and Target List:
+ imagemagickSupportedTransformation = new HashMap<>();
+ List targetMimetype = new ArrayList<>();
+ targetMimetype.add("image/gif");
+ targetMimetype.add("image/tiff");
+ imagemagickSupportedTransformation.put("image/tiff", targetMimetype);
+ targetMimetype.add("image/png");
+ targetMimetype.add("image/jpeg");
+ imagemagickSupportedTransformation.put("image/gif", targetMimetype);
+ imagemagickSupportedTransformation.put("image/jpeg", targetMimetype);
+ imagemagickSupportedTransformation.put("image/png", targetMimetype);
+
+ // Tika Supported Source and Target List:
+ targetMimetype = new ArrayList<>();
+ tikaSupportedTransformation = new HashMap<>();
+ targetMimetype.add("text/plain");
+ tikaSupportedTransformation.put("application/pdf", targetMimetype);
+ tikaSupportedTransformation.put("application/msword", targetMimetype);
+ tikaSupportedTransformation.put("application/vnd.ms-excel", targetMimetype);
+ tikaSupportedTransformation.put("application/vnd.ms-powerpoint", targetMimetype);
+ tikaSupportedTransformation.put("application/vnd.openxmlformats-officedocument.wordprocessingml.document", targetMimetype);
+ tikaSupportedTransformation.put("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", targetMimetype);
+ tikaSupportedTransformation.put("application/vnd.openxmlformats-officedocument.presentationml.presentation", targetMimetype);
+ tikaSupportedTransformation.put("application/vnd.ms-outlook", targetMimetype);
+
+ // Libre Office Source and Target List:
+ targetMimetype = new ArrayList<>();
+ libreofficeSupportedTransformation = new HashMap<>();
+ targetMimetype.add("application/pdf");
+ libreofficeSupportedTransformation.put("application/vnd.ms-excel", targetMimetype);
+ libreofficeSupportedTransformation.put("application/vnd.ms-powerpoint", targetMimetype);
+ libreofficeSupportedTransformation.put("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", targetMimetype);
+ libreofficeSupportedTransformation.put("application/vnd.openxmlformats-officedocument.presentationml.presentation", targetMimetype);
+ libreofficeSupportedTransformation.put("application/vnd.ms-outlook", targetMimetype);
+ targetMimetype.add("application/msword");
+ libreofficeSupportedTransformation.put("application/msword", targetMimetype);
+ libreofficeSupportedTransformation.put("application/vnd.openxmlformats-officedocument.wordprocessingml.document", targetMimetype);
+
+ // Pdf Renderer Source and Target List:
+ targetMimetype = new ArrayList<>();
+ pdfRendererSupportedTransformation = new HashMap<>();
+ targetMimetype.add("image/png");
+ pdfRendererSupportedTransformation.put("application/pdf", targetMimetype);
+
+ // Office to Image via Pdf Pipeline Transformer Source and Target List:
+ targetMimetype = new ArrayList<>();
+ officeToImageViaPdfSupportedTransformation = new HashMap<>();
+ targetMimetype.add("image/gif");
+ targetMimetype.add("image/tiff");
+ targetMimetype.add("image/png");
+ targetMimetype.add("image/jpeg");
+ officeToImageViaPdfSupportedTransformation.put("application/msword", targetMimetype);
+ officeToImageViaPdfSupportedTransformation.put("application/vnd.ms-excel", targetMimetype);
+ officeToImageViaPdfSupportedTransformation.put("application/vnd.ms-powerpoint", targetMimetype);
+ officeToImageViaPdfSupportedTransformation.put("application/vnd.openxmlformats-officedocument.wordprocessingml.document", targetMimetype);
+ officeToImageViaPdfSupportedTransformation.put("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", targetMimetype);
+ officeToImageViaPdfSupportedTransformation.put("application/vnd.openxmlformats-officedocument.presentationml.presentation", targetMimetype);
+ officeToImageViaPdfSupportedTransformation.put("application/vnd.ms-outlook", targetMimetype);
+ }
+
+ protected String getBaseUrl(Transformer transformer)
+ {
+ return LOCAL_TRANSFORM+transformer.getTransformerName()+".url";
+ }
+
+ @Test
+ public void testReadWriteJson() throws IOException
+ {
+ // Override super method so it passes, as there is nothing more to be gained for LocalTransforms.
+ }
+
+ @Test
+ public void testReadJsonConfig()
+ {
+ List transformerList = retrieveLocalTransformList();
+ // Assert expected size of the transformers.
+ assertNotNull("Transformer list is null.", transformerList);
+ assertEquals("Unexpected number of transformers retrieved", 5, transformerList.size());
+
+ // Assert proper transformers are loaded
+ List listOfExpectedTransformersName= new ArrayList<>();
+ listOfExpectedTransformersName.add("imagemagick");
+ listOfExpectedTransformersName.add("tika");
+ listOfExpectedTransformersName.add("pdfrenderer");
+ listOfExpectedTransformersName.add("libreoffice");
+ listOfExpectedTransformersName.add("officeToImageViaPdf");
+
+ for (CombinedConfig.TransformAndItsOrigin t : transformerList)
+ {
+ assertTrue(t.transform.getTransformerName() + " should be an expected local transformer.", listOfExpectedTransformersName.contains(t.transform.getTransformerName()));
+ listOfExpectedTransformersName.remove(t.transform.getTransformerName());
+
+ switch (t.transform.getTransformerName())
+ {
+ case "imagemagick":
+ assertEquals(t.transform.getTransformerName() + " incorrect number of supported transform", 14, t.transform.getSupportedSourceAndTargetList().size());
+ assertEquals( t.transform.getTransformerName() + "incorrect number of transform options", 6, t.transform.getTransformOptions().size());
+ assertNull(t.transform.getTransformerName() + " expected to not be a transformer pipeline", t.transform.getTransformerPipeline());
+
+ //Test supportedSourceAndTargetList
+ for ( SupportedSourceAndTarget ssat: t.transform.getSupportedSourceAndTargetList())
+ {
+ assertTrue(ssat.getSourceMediaType() + " not expected to be a supported transform source.", imagemagickSupportedTransformation.containsKey(ssat.getSourceMediaType()));
+ assertTrue(ssat.getTargetMediaType() + " not expected to be a supported transform target for " + ssat.getSourceMediaType(), imagemagickSupportedTransformation.get(ssat.getSourceMediaType()).contains(ssat.getTargetMediaType()));
+ }
+ break;
+
+ case "tika":
+ assertEquals(t.transform.getTransformerName() + " incorrect number of supported transform", 8, t.transform.getSupportedSourceAndTargetList().size());
+ assertEquals( t.transform.getTransformerName() + "incorrect number of transform options", 5, t.transform.getTransformOptions().size());
+ assertNull(t.transform.getTransformerName() + " expected to not be a transformer pipeline", t.transform.getTransformerPipeline());
+
+ //Test supportedSourceAndTargetList
+ for ( SupportedSourceAndTarget ssat: t.transform.getSupportedSourceAndTargetList())
+ {
+ assertTrue(ssat.getSourceMediaType() + " not expected to be a supported transform source.", tikaSupportedTransformation.containsKey(ssat.getSourceMediaType()));
+ assertTrue(ssat.getTargetMediaType() + " not expected to be a supported transform target for " + ssat.getSourceMediaType(), tikaSupportedTransformation.get(ssat.getSourceMediaType()).contains(ssat.getTargetMediaType()));
+ }
+ break;
+
+ case "pdfrenderer":
+ assertEquals(t.transform.getTransformerName() + " incorrect number of supported transform", 1, t.transform.getSupportedSourceAndTargetList().size());
+ assertEquals( t.transform.getTransformerName() + "incorrect number of transform options", 5, t.transform.getTransformOptions().size());
+ assertNull(t.transform.getTransformerName() + " expected to not be a transformer pipeline", t.transform.getTransformerPipeline());
+
+ //Test supportedSourceAndTargetList
+ for ( SupportedSourceAndTarget ssat: t.transform.getSupportedSourceAndTargetList())
+ {
+ assertTrue(ssat.getSourceMediaType() + " not expected to be a supported transform source.", pdfRendererSupportedTransformation.containsKey(ssat.getSourceMediaType()));
+ assertTrue(ssat.getTargetMediaType() + " not expected to be a supported transform target for " + ssat.getSourceMediaType(), pdfRendererSupportedTransformation.get(ssat.getSourceMediaType()).contains(ssat.getTargetMediaType()));
+ }
+ break;
+
+ case "libreoffice":
+ assertEquals(t.transform.getTransformerName() + " incorrect number of supported transform", 9, t.transform.getSupportedSourceAndTargetList().size());
+ assertNull( t.transform.getTransformerName() + "incorrect number of transform options", t.transform.getTransformOptions());
+ assertNull(t.transform.getTransformerName() + " expected to not be a transformer pipeline", t.transform.getTransformerPipeline());
+
+ //Test supportedSourceAndTargetList
+ for ( SupportedSourceAndTarget ssat: t.transform.getSupportedSourceAndTargetList())
+ {
+ assertTrue(ssat.getSourceMediaType() + " not expected to be a supported transform source.", libreofficeSupportedTransformation.containsKey(ssat.getSourceMediaType()));
+ assertTrue(ssat.getTargetMediaType() + " not expected to be a supported transform target for " + ssat.getSourceMediaType(), libreofficeSupportedTransformation.get(ssat.getSourceMediaType()).contains(ssat.getTargetMediaType()));
+ }
+ break;
+
+ case "officeToImageViaPdf":
+ assertEquals(t.transform.getTransformerName() + " incorrect number of supported transform", 28, t.transform.getSupportedSourceAndTargetList().size());
+ assertEquals( t.transform.getTransformerName() + "incorrect number of transform options", 2, t.transform.getTransformOptions().size());
+ assertNotNull(t.transform.getTransformerName() + " expected to be a transformer pipeline", t.transform.getTransformerPipeline());
+
+ //Test supportedSourceAndTargetList
+ for ( SupportedSourceAndTarget ssat: t.transform.getSupportedSourceAndTargetList())
+ {
+ assertTrue(ssat.getSourceMediaType() + " not expected to be a supported transform source.", officeToImageViaPdfSupportedTransformation.containsKey(ssat.getSourceMediaType()));
+ assertTrue(ssat.getTargetMediaType() + " not expected to be a supported transform target for " + ssat.getSourceMediaType(), officeToImageViaPdfSupportedTransformation.get(ssat.getSourceMediaType()).contains(ssat.getTargetMediaType()));
+ }
+ break;
+ }
+ }
+ assertEquals("Transformer expected but not found in config file", 0, listOfExpectedTransformersName.size());
+ }
+
+ @Test
+ public void testReadTransformProperties()
+ {
+ List transformerList = retrieveLocalTransformList();
+ assertNotNull("Transformer list is null.", transformerList);
+ for (CombinedConfig.TransformAndItsOrigin t : transformerList)
+ {
+ if(t.transform.getTransformerPipeline() == null)
+ {
+ assertNotNull(t.transform.getTransformerName()+ " JVM property not set.", System.getProperty(LOCAL_TRANSFORM + t.transform.getTransformerName() + URL));
+ }
+ }
+ assertEquals("Unexpected pdfrenderer JVM property value", "http://localhost:8090/", System.getProperty(LOCAL_TRANSFORM + "pdfrenderer" + URL));
+ assertEquals("Unexpected imagemagick JVM property value", "http://localhost:8091/", System.getProperty(LOCAL_TRANSFORM + "imagemagick" + URL));
+ assertEquals("Unexpected libreoffice JVM property value", "http://localhost:8092/", System.getProperty(LOCAL_TRANSFORM + "libreoffice" + URL));
+ assertEquals("Unexpected tika JVM property value", "http://localhost:8093/", System.getProperty(LOCAL_TRANSFORM + "tika" + URL));
+
+ for (CombinedConfig.TransformAndItsOrigin t : transformerList)
+ {
+ if(t.transform.getTransformerPipeline() == null)
+ {
+ assertNotNull(t.transform.getTransformerName()+ " alfresco-global property not set.", properties.getProperty(LOCAL_TRANSFORM + t.transform.getTransformerName() + URL));
+ }
+ }
+ assertEquals("Unexpected pdfrenderer alfresco-global property value", "http://localhost:8090/", properties.getProperty(LOCAL_TRANSFORM + "pdfrenderer" + URL));
+ assertEquals("Unexpected imagemagick alfresco-global property value", "http://localhost:8091/", properties.getProperty(LOCAL_TRANSFORM + "imagemagick" + URL));
+ assertEquals("Unexpected libreoffice alfresco-global property value", "http://localhost:8092/", properties.getProperty(LOCAL_TRANSFORM + "libreoffice" + URL));
+ assertEquals("Unexpected tika alfresco-global property value", "http://localhost:8093/", properties.getProperty(LOCAL_TRANSFORM + "tika" + URL));
+ }
+
+ @Test
+ public void testAdditionAndRemovalOfTEngines() throws Exception
+ {
+ CronExpression origCronExpression = registry.getCronExpression();
+ CronExpression origInitialAndOnErrorCronExpression = registry.getInitialAndOnErrorCronExpression();
+
+ String origPipelineConfigDir = registry.getPipelineConfigDir();
+ Scheduler origScheduler = registry.getScheduler();
+
+ if (origScheduler != null)
+ {
+ origScheduler.clear();
+ }
+
+ try
+ {
+ TransformServiceRegistryImpl.Data prevData;
+ data = null;
+ readConfigCount = 0;
+
+ registry.setScheduler(null);
+ registry.setInitialAndOnErrorCronExpression(new CronExpression(("0/2 * * ? * * *"))); // every 2 seconds rather than 10 seconds
+ registry.setCronExpression(new CronExpression(("0/4 * * ? * * *"))); // every 4 seconds rather than 10 mins
+
+ // Sleep until a 6 second boundary, in order to make testing clearer.
+ // It avoids having to work out schedule offsets and extra quick runs that can otherwise take place.
+ Thread.sleep(4000-System.currentTimeMillis()%4000);
+ startMs = System.currentTimeMillis();
+ registry.setMockSuccessReadingRemoteConfig(false);
+ registry.afterPropertiesSet();
+
+ Thread.sleep(1000); // 1 seconds
+ data = registry.assertDataChanged(data, "There should have been a read after a few milliseconds that fails");
+
+ Thread.sleep(2000); // 3 seconds
+ data = registry.assertDataChanged(data, "There should have been a read after 2 seconds that fails");
+
+ Thread.sleep(2000); // 5 seconds
+ data = registry.assertDataChanged(data, "There should have been a read after 4 seconds that fails");
+
+ Thread.sleep(2000); // 7 seconds
+ data = registry.assertDataChanged(data, "There should have been a read after 6 seconds that fails");
+
+ // Should switch to normal 4s schedule after the next read, so the read at 12 seconds will be on that schedule.
+ // It is always possible that another quick one gets scheduled almost straight away after the next read.
+ registry.setMockSuccessReadingRemoteConfig(true);
+ Thread.sleep(2000); // 9 seconds
+ data = registry.assertDataChanged(data, "There should have been a read after 8 seconds that succeeds");
+
+ Thread.sleep(2000); // 11 seconds
+ data = registry.assertDataUnchanged(data, "There really should not have been a read until 12 seconds");
+
+ Thread.sleep(2000); // 13 seconds
+ data = registry.assertDataChanged(data, "There should have been a read after 12 seconds that succeeds");
+
+ // Should switch back to initial/error schedule after failure
+ registry.setMockSuccessReadingRemoteConfig(false);
+ Thread.sleep(4000); // 17 seconds
+ data = registry.assertDataChanged(data, "There should have been a read after 16 seconds that fails");
+
+ Thread.sleep(2000); // 19 seconds
+ data = registry.assertDataChanged(data, "There should have been a read after 18 seconds");
+ }
+ finally
+ {
+ registry.setMockSuccessReadingRemoteConfig(true);
+
+ // Reset scheduler properties just in case another tests needs them in future.
+ // We don't start the scheduler with registry.afterPropertiesSet() as this is
+ // really just mocked up version of the registry.
+ registry.setCronExpression(origCronExpression);
+ registry.setInitialAndOnErrorCronExpression(origInitialAndOnErrorCronExpression);
+ registry.setPipelineConfigDir(origPipelineConfigDir);
+ registry.setScheduler(null);
+ }
+ }
+}
diff --git a/src/main/java/org/alfresco/transform/client/model/config/TransformBuilder.java b/src/test/java/org/alfresco/transform/client/model/config/TransformBuilder.java
similarity index 67%
rename from src/main/java/org/alfresco/transform/client/model/config/TransformBuilder.java
rename to src/test/java/org/alfresco/transform/client/model/config/TransformBuilder.java
index 024620fd88..a9d9316df9 100644
--- a/src/main/java/org/alfresco/transform/client/model/config/TransformBuilder.java
+++ b/src/test/java/org/alfresco/transform/client/model/config/TransformBuilder.java
@@ -29,12 +29,12 @@ import java.util.ArrayList;
import java.util.List;
/**
- * Helper class that builds a {@link Transformer} given the source and target extensions and a pipeline of Transformers
- * for creating intermediary content, or a set of failover transformers.
+ * Helper class that builds a {@link Transformer} given the source and target types and a pipeline of Transformers
+ * for creating intermediary content.
*/
public class TransformBuilder
{
- public Transformer buildPipeLine(String name, String version, List sourceAndTargetList,
+ public Transformer buildPipeLine(String name, List sourceAndTargetList,
List transformerList)
{
List options = new ArrayList<>(transformerList.size());
@@ -47,13 +47,6 @@ public class TransformBuilder
options.add(new TransformOptionGroup(t.isRequired(), t.getTransformer().getTransformOptions()));
}
});
- return new Transformer(name, version, options, sourceAndTargetList);
+ return new Transformer(name, options, sourceAndTargetList);
}
-
- // TODO Commented out for now as it is unclear what the Transform service will support in terms of failover transformations.
- // Note: The use of a list of Transformers rather than ChildTransformers, as the supplied actual options would have
- // to match one or more of the transformer's options. Matching one or more options is not currently
- // implemented by the TransformServiceRegistry
- // public Transformer buildFailover(String name, String version, List sourceAndTargetList,
- // List transformerList)
}
diff --git a/src/test/java/org/alfresco/transform/client/model/config/TransformServiceRegistryImplTest.java b/src/test/java/org/alfresco/transform/client/model/config/TransformServiceRegistryConfigTest.java
similarity index 69%
rename from src/test/java/org/alfresco/transform/client/model/config/TransformServiceRegistryImplTest.java
rename to src/test/java/org/alfresco/transform/client/model/config/TransformServiceRegistryConfigTest.java
index febf322d00..a1d4cb25eb 100644
--- a/src/test/java/org/alfresco/transform/client/model/config/TransformServiceRegistryImplTest.java
+++ b/src/test/java/org/alfresco/transform/client/model/config/TransformServiceRegistryConfigTest.java
@@ -2,7 +2,7 @@
* #%L
* Alfresco Repository
* %%
- * Copyright (C) 2005 - 2018 Alfresco Software Limited
+ * 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
@@ -26,6 +26,10 @@
package org.alfresco.transform.client.model.config;
import com.fasterxml.jackson.databind.ObjectMapper;
+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;
@@ -35,7 +39,6 @@ import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
-import java.io.InputStreamReader;
import java.io.Reader;
import java.util.Arrays;
import java.util.Collections;
@@ -50,83 +53,57 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
-public class TransformServiceRegistryImplTest
+/**
+ * Test the config received from the Transform Service about what it supports.
+ */
+public class TransformServiceRegistryConfigTest
{
- public static final String GIF = "gif";
- public static final String JPEG = "jpeg";
- public static final String PNG = "png";
- public static final String TIFF = "tiff";
- public static final String PDF = "pdf";
- public static final String DOC = "doc";
- public static final String XLS = "xls";
- public static final String PPT = "ppt";
- public static final String DOCX = "docx";
- public static final String XLSX = "xlsx";
- public static final String PPTX = "pptx";
- public static final String MSG = "msg";
- public static final String TXT = "txt";
+ private static Log log = LogFactory.getLog(TransformServiceRegistryConfigTest.class);
- public static final String GIF_MIMETYPE = "image/gif";
- public static final String JPEG_MIMETYPE = "image/jpeg";
- public static final String PNG_MIMETYPE = "image/png";
- public static final String TIFF_MIMETYPE = "image/tiff";
- public static final String PDF_MIMETYPE = "application/pdf";
- public static final String DOC_MIMETYPE = "application/msword";
- public static final String XLS_MIMETYPE = "application/vnd.ms-excel";
- public static final String PPT_MIMETYPE = "application/vnd.ms-powerpoint";
- public static final String DOCX_MIMETYPE = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
- public static final String XLSX_MIMETYPE = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
- public static final String PPTX_MIMETYPE = "application/vnd.openxmlformats-officedocument.presentationml.presentation";
- public static final String MSG_MIMETYPE = "application/vnd.ms-outlook";
- public static final String TXT_MIMETYPE = "text/plain";
+ public static final String GIF = "image/gif";
+ public static final String JPEG = "image/jpeg";
+ public static final String PNG = "image/png";
+ public static final String TIFF = "image/tiff";
+ public static final String PDF = "application/pdf";
+ public static final String DOC = "application/msword";
+ public static final String XLS = "application/vnd.ms-excel";
+ public static final String PPT = "application/vnd.ms-powerpoint";
+ public static final String MSG = "application/vnd.ms-outlook";
+ public static final String TXT = "text/plain";
+
+ 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 String TRANSFORM_SERVICE_CONFIG = "alfresco/transform-service-config.json";
public static final ObjectMapper JSON_OBJECT_MAPPER = new ObjectMapper();
private TransformServiceRegistryImpl registry;
- private TransformBuilder builder;
- private Transformer transformer;
- private ExtensionMap extensionMap;
+ protected TransformBuilder builder;
+ protected Transformer transformer;
@Before
public void setUp() throws Exception
{
- extensionMap = new ExtensionMap()
- {
- private Map map = new HashMap<>();
+ registry = buildTransformServiceRegistryImpl();
+ builder = new TransformBuilder();
+ LogManager.getLogger(TransformServiceRegistryConfigTest.class).setLevel(Level.DEBUG);
+ }
+ protected TransformServiceRegistryImpl buildTransformServiceRegistryImpl() throws Exception
+ {
+ TransformServiceRegistryImpl registry = new TransformServiceRegistryImpl()
+ {
+ @Override
+ protected Data readConfig() throws IOException
{
- map.put(GIF, GIF_MIMETYPE);
- map.put(JPEG, JPEG_MIMETYPE);
- map.put(PNG, PNG_MIMETYPE);
- map.put(TIFF, TIFF_MIMETYPE);
- map.put(PDF, PDF_MIMETYPE);
- map.put(DOC, DOC_MIMETYPE);
- map.put(XLS, XLS_MIMETYPE);
- map.put(PPT, PPT_MIMETYPE);
- map.put(DOCX, DOCX_MIMETYPE);
- map.put(XLSX, XLSX_MIMETYPE);
- map.put(PPTX, PPTX_MIMETYPE);
- map.put(MSG, MSG_MIMETYPE);
- map.put(TXT, TXT_MIMETYPE);
+ return createData(); // Empty config
}
@Override
- public String toMimetype(String extension)
+ protected Log getLog()
{
- return map.get(extension);
+ return log;
}
};
-
- registry = buildTransformServiceRegistryImpl();
-
- builder = new TransformBuilder();
- }
-
- private TransformServiceRegistryImpl buildTransformServiceRegistryImpl()
- {
- TransformServiceRegistryImpl registry = new TransformServiceRegistryImpl();
- registry.setExtensionMap(extensionMap);
registry.setJsonObjectMapper(JSON_OBJECT_MAPPER);
return registry;
}
@@ -137,6 +114,16 @@ public class TransformServiceRegistryImplTest
// shut down
}
+ protected String getTransformServiceConfig()
+ {
+ return TRANSFORM_SERVICE_CONFIG;
+ }
+
+ protected String getTransformServiceConfigPipeline()
+ {
+ return TRANSFORM_SERVICE_CONFIG_PIPELINE;
+ }
+
private void assertAddToPossibleOptions(TransformOptionGroup transformOptionGroup, String actualOptionNames, String expectedNames, String expectedRequired)
{
Map actualOptions = buildActualOptions(actualOptionNames);
@@ -186,55 +173,72 @@ public class TransformServiceRegistryImplTest
}
}
- private void assertTransformOptions(List transformOptions)
+ private void assertTransformOptions(List transformOptions) throws Exception
{
- transformer = new Transformer("name", "1",
+ transformer = new Transformer("name",
transformOptions,
Arrays.asList(
new SupportedSourceAndTarget(DOC, TXT, -1),
new SupportedSourceAndTarget(XLS, TXT, 1024000)));
registry = buildTransformServiceRegistryImpl();
- registry.register(transformer);
+ registry.register(registry.getData(), transformer, getBaseUrl(transformer), getClass().getName());
- assertTrue(registry.isSupported(XLS_MIMETYPE, 1024, TXT_MIMETYPE, Collections.emptyMap(), null));
- assertTrue(registry.isSupported(XLS_MIMETYPE, 1024000, TXT_MIMETYPE, null, null));
- assertFalse(registry.isSupported(XLS_MIMETYPE, 1024001, TXT_MIMETYPE, Collections.emptyMap(), null));
- assertTrue(registry.isSupported(DOC_MIMETYPE, 1024001, TXT_MIMETYPE, null, null));
+ assertTrue(registry.isSupported(XLS, 1024, TXT, Collections.emptyMap(), null));
+ assertTrue(registry.isSupported(XLS, 1024000, TXT, null, null));
+ assertFalse(registry.isSupported(XLS, 1024001, TXT, Collections.emptyMap(), null));
+ assertTrue(registry.isSupported(DOC, 1024001, TXT, null, null));
}
- private void assertSupported(String sourceExt, long sourceSizeInBytes, String targetExt,
- Map actualOptions, String unsupportedMsg)
+ protected String getBaseUrl(Transformer transformer)
{
- assertSupported(sourceExt, sourceSizeInBytes, targetExt, actualOptions, unsupportedMsg, transformer);
+ return null;
}
- private void assertSupported(String sourceExt, long sourceSizeInBytes, String targetExt,
+ private void assertTransformerName(String sourceMimetype, long sourceSizeInBytes, String targetMimetype,
+ Map actualOptions, String expectedTransformerName,
+ Transformer... transformers) throws Exception
+ {
+ buildAndPopulateRegistry(transformers);
+ String transformerName = registry.getTransformerName(sourceMimetype, sourceSizeInBytes, targetMimetype, actualOptions, null);
+ assertEquals(sourceMimetype+" to "+targetMimetype+" should have returned "+expectedTransformerName, expectedTransformerName, transformerName);
+ }
+
+ private void assertSupported(String sourceMimetype, long sourceSizeInBytes, String targetMimetype,
+ Map actualOptions, String unsupportedMsg) throws Exception
+ {
+ assertSupported(sourceMimetype, sourceSizeInBytes, targetMimetype, actualOptions, unsupportedMsg, transformer);
+ }
+
+ private void assertSupported(String sourceMimetype, long sourceSizeInBytes, String targetMimetype,
Map actualOptions, String unsupportedMsg,
- Transformer... transformers)
+ Transformer... transformers) throws Exception
+ {
+ buildAndPopulateRegistry(transformers);
+ assertSupported(sourceMimetype, sourceSizeInBytes, targetMimetype, actualOptions, null, unsupportedMsg);
+ }
+
+ private void buildAndPopulateRegistry(Transformer[] transformers) throws Exception
{
registry = buildTransformServiceRegistryImpl();
for (Transformer transformer : transformers)
{
- registry.register(transformer);
+ registry.register(registry.getData(), transformer, getBaseUrl(transformer), getClass().getName());
}
- assertSupported(sourceExt, sourceSizeInBytes, targetExt, actualOptions, null, unsupportedMsg);
}
- private void assertSupported(String sourceExt, long sourceSizeInBytes, String targetExt,
- Map actualOptions, String transformName,
+ private void assertSupported(String sourceMimetype, long sourceSizeInBytes, String targetMimetype,
+ Map actualOptions, String renditionName,
String unsupportedMsg)
{
- String sourceMimetype = extensionMap.toMimetype(sourceExt);
- String targetMimetype = extensionMap.toMimetype(targetExt);
- boolean supported = registry.isSupported(sourceMimetype, sourceSizeInBytes, targetMimetype, actualOptions, transformName);
+ boolean supported = registry.isSupported(sourceMimetype, sourceSizeInBytes, targetMimetype, actualOptions, renditionName);
if (unsupportedMsg == null || unsupportedMsg.isEmpty())
{
- assertTrue(sourceExt+" to "+targetExt+" should be SUPPORTED", supported);
+ assertTrue(sourceMimetype+" to "+targetMimetype+" should be SUPPORTED", supported);
}
else
{
- assertFalse(sourceExt+" to "+targetExt+" should NOT be supported", supported);
+ assertFalse(sourceMimetype+" to "+targetMimetype+" should NOT be supported", supported);
}
}
@@ -249,10 +253,17 @@ public class TransformServiceRegistryImplTest
return actualOptions;
}
+ private void register(String path) throws IOException
+ {
+ CombinedConfig combinedConfig = new CombinedConfig(log);
+ combinedConfig.addLocalConfig(path);
+ combinedConfig.register(registry.getData(), registry);
+ }
+
@Test
public void testReadWriteJson() throws IOException
{
- Transformer libreOffice = new Transformer("libreOffice", "1",
+ Transformer libreoffice = new Transformer("libreoffice",
null, // there are no options
Arrays.asList(
new SupportedSourceAndTarget(DOC, PDF, -1),
@@ -260,7 +271,7 @@ public class TransformServiceRegistryImplTest
new SupportedSourceAndTarget(PPT, PDF, -1),
new SupportedSourceAndTarget(MSG, PDF, -1)));
- Transformer pdfRenderer = new Transformer("pdfRenderer", "1",
+ Transformer pdfrenderer = new Transformer("pdfrenderer",
Arrays.asList(
new TransformOptionValue(false, "page"),
new TransformOptionValue(false, "width"),
@@ -270,7 +281,7 @@ public class TransformServiceRegistryImplTest
Arrays.asList(
new SupportedSourceAndTarget(PDF, PNG, -1)));
- Transformer tika = new Transformer("tika", "1",
+ Transformer tika = new Transformer("tika",
Arrays.asList(
new TransformOptionValue(false, "transform"),
new TransformOptionValue(false, "includeContents"),
@@ -284,7 +295,7 @@ public class TransformServiceRegistryImplTest
new SupportedSourceAndTarget(PPT, TXT, -1),
new SupportedSourceAndTarget(MSG, TXT, -1)));
- Transformer imageMagick = new Transformer("imageMagick", "1",
+ Transformer imagemagick = new Transformer("imagemagick",
Arrays.asList(
new TransformOptionValue(false, "alphaRemove"),
new TransformOptionValue(false, "autoOrient"),
@@ -322,7 +333,7 @@ public class TransformServiceRegistryImplTest
new SupportedSourceAndTarget(TIFF, PNG, -1),
new SupportedSourceAndTarget(TIFF, TIFF, -1)));
- Transformer officeToImage = builder.buildPipeLine("officeToImageViaPdf", "1",
+ Transformer officeToImage = builder.buildPipeLine("transformer1",
Arrays.asList(
new SupportedSourceAndTarget(DOC, GIF, -1),
new SupportedSourceAndTarget(DOC, JPEG, -1),
@@ -341,11 +352,11 @@ public class TransformServiceRegistryImplTest
new SupportedSourceAndTarget(MSG, PNG, -1),
new SupportedSourceAndTarget(MSG, TIFF, -1)),
Arrays.asList(
- new ChildTransformer(false, libreOffice), // to pdf
- new ChildTransformer(false, pdfRenderer), // to png
- new ChildTransformer(true, imageMagick))); // to other image formats
+ new ChildTransformer(false, libreoffice), // to pdf
+ new ChildTransformer(false, pdfrenderer), // to png
+ new ChildTransformer(true, imagemagick))); // to other image formats
- List transformers1 = Arrays.asList(libreOffice, tika, pdfRenderer, imageMagick, officeToImage);
+ List transformers1 = Arrays.asList(libreoffice, tika, pdfrenderer, imagemagick, officeToImage);
File tempFile = File.createTempFile("test", ".json");
ObjectMapper objectMapper = new ObjectMapper();
@@ -353,7 +364,7 @@ public class TransformServiceRegistryImplTest
try (Reader reader = new BufferedReader(new FileReader(tempFile)))
{
- registry.register(reader);
+ registry.register(registry.getData(), reader, getClass().getName());
// Check the count of transforms supported
assertEquals("The number of UNIQUE source to target mimetypes transforms has changed. Config change?",
42, countSupportedTransforms(true));
@@ -367,104 +378,102 @@ public class TransformServiceRegistryImplTest
assertSupported(PDF, 1234, PNG, null, null, ""); // pdfrenderer
assertSupported(JPEG,1234, GIF, null, null, ""); // imagemagick
assertSupported(MSG, 1234, TXT, null, null, ""); // tika
- assertSupported(MSG, 1234, GIF, null, null, ""); // officeToImageViaPdf
- assertSupported(DOC, 1234, PNG, null, null, ""); // officeToImageViaPdf
+ assertSupported(MSG, 1234, GIF, null, null, ""); // transformer1 (officeToImageViaPdf)
+ assertSupported(DOC, 1234, PNG, null, null, ""); // transformer1 (officeToImageViaPdf)
}
}
@Test
public void testJsonConfig() throws IOException
{
- try (Reader reader = new BufferedReader(new InputStreamReader(getClass().getClassLoader().
- getResourceAsStream(TRANSFORM_SERVICE_CONFIG))))
- {
- registry.register(reader);
+ register(getTransformServiceConfig());
- // Check the count of transforms supported
- assertEquals("The number of UNIQUE source to target mimetypes transforms has changed. Config change?",
- 63, countSupportedTransforms(true));
- assertEquals("The number of source to target mimetypes transforms has changed. " +
- "There may be multiple transformers for the same combination. Config change?",
- 63, countSupportedTransforms(false));
+ // Check the count of transforms supported
+ assertEquals("The number of UNIQUE source to target mimetypes transforms has changed. Config change?",
+ 60, countSupportedTransforms(true));
+ assertEquals("The number of source to target mimetypes transforms has changed. " +
+ "There may be multiple transformers for the same combination. Config change?",
+ 60, countSupportedTransforms(false));
- // Check a supported transform for each transformer.
- assertSupported(DOC, 1234, PDF, null, null, ""); // libreoffice
- assertSupported(DOC, 1234, PDF, null, null, ""); // libreoffice
- assertSupported(PDF, 1234, PNG, null, null, ""); // pdfrenderer
- assertSupported(JPEG,1234, GIF, null, null, ""); // imagemagick
- assertSupported(MSG, 1234, TXT, null, null, ""); // tika
- assertSupported(MSG, 1234, GIF, null, null, ""); // officeToImageViaPdf
+ // Check a supported transform for each transformer.
+ assertSupported(DOC, 1234, PDF, null, null, ""); // libreoffice
+ assertSupported(DOC, 1234, PDF, null, null, ""); // libreoffice
+ assertSupported(PDF, 1234, PNG, null, null, ""); // pdfrenderer
+ assertSupported(JPEG,1234, GIF, null, null, ""); // imagemagick
+ assertSupported(MSG, 1234, TXT, null, null, ""); // tika
+ assertSupported(MSG, 1234, GIF, null, null, ""); // officeToImageViaPdf
- Map invalidPdfOptions = new HashMap<>();
- invalidPdfOptions.put("allowEnlargement", "false");
- assertSupported(DOC, 1234, PDF, invalidPdfOptions, null, "Invalid as there is a extra option");
- }
+ Map 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
{
- try (Reader reader = new BufferedReader(new InputStreamReader(getClass().getClassLoader().
- getResourceAsStream("alfresco/transform-service-config-test1.json"))))
- {
- registry.register(reader);
+ register(getTransformServiceConfigPipeline());
- // Check the count of transforms supported
- assertEquals("The number of UNIQUE source to target mimetypes transforms has changed. Config change?",
- 4, countSupportedTransforms(true));
- assertEquals("The number of source to target mimetypes transforms has changed. " +
- "There may be multiple transformers for the same combination. Config change?",
- 4, countSupportedTransforms(false));
+ // 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));
- ConcurrentMap> transformer =
- registry.transformers.get("officeToImageViaPdf");
+ ConcurrentMap> transformer =
+ registry.getData().transformers.get("officeToImageViaPdf");
- // Check required and optional default correctly
- ConcurrentMap> transformsToWord =
- registry.transformers.get("application/msword");
- List supportedTransforms = transformsToWord.get("image/gif");
- TransformServiceRegistryImpl.SupportedTransform supportedTransform = supportedTransforms.get(0);
+ // Check required and optional default correctly
+ ConcurrentMap> transformsToWord =
+ registry.getData().transformers.get(DOC);
+ List supportedTransforms = transformsToWord.get(GIF);
+ TransformServiceRegistryImpl.SupportedTransform supportedTransform = supportedTransforms.get(0);
- TransformOptionGroup imageMagick = (TransformOptionGroup)supportedTransform.transformOptions.transformOptions.get(0);
- TransformOptionGroup pdf = (TransformOptionGroup)supportedTransform.transformOptions.transformOptions.get(1);
+ TransformOptionGroup imagemagick = (TransformOptionGroup)supportedTransform.transformOptions.transformOptions.get(0);
+ TransformOptionGroup pdf = (TransformOptionGroup)supportedTransform.transformOptions.transformOptions.get(1);
- TransformOptionValue alphaRemove = (TransformOptionValue)imageMagick.transformOptions.get(0);
- TransformOptionGroup crop = (TransformOptionGroup)imageMagick.transformOptions.get(4);
- TransformOptionValue cropGravity = (TransformOptionValue)crop.transformOptions.get(0);
- TransformOptionValue cropWidth = (TransformOptionValue)crop.transformOptions.get(1);
+ TransformOptionValue alphaRemove = (TransformOptionValue)imagemagick.transformOptions.get(0);
+ TransformOptionGroup crop = (TransformOptionGroup)imagemagick.transformOptions.get(4);
+ TransformOptionValue cropGravity = (TransformOptionValue)crop.transformOptions.get(0);
+ TransformOptionValue cropWidth = (TransformOptionValue)crop.transformOptions.get(1);
- assertTrue("The holding group should be required", supportedTransform.transformOptions.isRequired());
- assertTrue("imageMagick should be required as it is 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());
+ assertTrue("The holding group should be required", supportedTransform.transformOptions.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, null, null, "");
- assertSupported(DOC,1234, PNG, null, null, "");
- assertSupported(DOC,1234, JPEG, null, null, "");
- assertSupported(DOC,1234, TIFF, null, null, "");
+ // Check a supported transform for each transformer.
+ assertSupported(DOC,1234, GIF, null, null, "");
+ assertSupported(DOC,1234, PNG, null, null, "");
+ assertSupported(DOC,1234, JPEG, null, null, "");
+ assertSupported(DOC,1234, TIFF, null, null, "");
- Map 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, "");
- }
+ Map 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, "");
+ }
+
+ protected int getExpectedTransformsForTestJsonPipeline()
+ {
+ return 4;
}
private int countSupportedTransforms(boolean unique)
{
int count = 0;
int uniqueCount = 0;
- for (ConcurrentMap> targetMap : registry.transformers.values())
+ for (ConcurrentMap> targetMap : registry.getData().transformers.values())
{
for (List supportedTransforms : targetMap.values())
{
@@ -610,7 +619,7 @@ public class TransformServiceRegistryImplTest
}
@Test
- public void testNoActualOptions()
+ public void testNoActualOptions() throws Exception
{
assertTransformOptions(Arrays.asList(
new TransformOptionValue(false, "option1"),
@@ -618,16 +627,16 @@ public class TransformServiceRegistryImplTest
}
@Test
- public void testNoTrasformOptions()
+ public void testNoTrasformOptions() throws Exception
{
assertTransformOptions(Collections.emptyList());
assertTransformOptions(null);
}
@Test
- public void testSupported()
+ public void testSupported() throws Exception
{
- transformer = new Transformer("name", "1",
+ transformer = new Transformer("name",
Arrays.asList(
new TransformOptionValue(false, "page"),
new TransformOptionValue(false, "width"),
@@ -653,7 +662,7 @@ public class TransformServiceRegistryImplTest
public void testCache()
{
// Note: transformNames are an alias for a set of actualOptions and the target mimetpe. The source mimetype may change.
- transformer = new Transformer("name", "1",
+ transformer = new Transformer("name",
Arrays.asList(
new TransformOptionValue(false, "page"),
new TransformOptionValue(false, "width"),
@@ -662,23 +671,55 @@ public class TransformServiceRegistryImplTest
new SupportedSourceAndTarget(DOC, GIF, 102400),
new SupportedSourceAndTarget(MSG, GIF, -1)));
- registry.register(transformer);
+ registry.register(registry.getData(), transformer, getBaseUrl(transformer), getClass().getName());
assertSupported(DOC, 1024, GIF, null, "doclib", "");
assertSupported(MSG, 1024, GIF, null, "doclib", "");
- assertEquals(102400L, registry.getMaxSize(DOC_MIMETYPE, GIF_MIMETYPE, null, "doclib"));
- assertEquals(-1L, registry.getMaxSize(MSG_MIMETYPE, GIF_MIMETYPE, null, "doclib"));
+ assertEquals(102400L, registry.getMaxSize(DOC, GIF, null, "doclib"));
+ assertEquals(-1L, registry.getMaxSize(MSG, GIF, null, "doclib"));
// Change the cached value and try and check we are now using the cached value.
- registry.cachedMaxSizes.get("doclib").put(DOC_MIMETYPE, 1234L);
- assertEquals(1234L, registry.getMaxSize(DOC_MIMETYPE, GIF_MIMETYPE, null, "doclib"));
+ List supportedTransforms = registry.getData().cachedSupportedTransformList.get("doclib").get(DOC);
+ supportedTransforms.get(0).maxSourceSizeBytes = 1234L;
+ assertEquals(1234L, registry.getMaxSize(DOC, GIF, null, "doclib"));
}
@Test
- public void testMultipleTransformers()
+ public void testGetTransformerName() throws Exception
{
- Transformer transformer1 = new Transformer("transformer1", "1",
+ Transformer t1 = new Transformer("transformer1", null,
+ Arrays.asList(new SupportedSourceAndTarget(MSG, GIF, 100, 50)));
+ Transformer t2 = new Transformer("transformer2", null,
+ Arrays.asList(new SupportedSourceAndTarget(MSG, GIF, 200, 60)));
+ Transformer t3 = new Transformer("transformer3", null,
+ Arrays.asList(new SupportedSourceAndTarget(MSG, GIF, 200, 40)));
+ Transformer t4 = new Transformer("transformer4", null,
+ Arrays.asList(new SupportedSourceAndTarget(MSG, GIF, -1, 100)));
+ Transformer t5 = new Transformer("transformer5", null,
+ Arrays.asList(new SupportedSourceAndTarget(MSG, GIF, -1, 80)));
+
+ Map actualOptions = null;
+
+ // Select on size - priority is ignored
+ assertTransformerName(MSG, 100, GIF, actualOptions, "transformer1", t1, t2);
+ assertTransformerName(MSG, 150, GIF, actualOptions, "transformer2", t1, t2);
+ assertTransformerName(MSG, 250, GIF, actualOptions, null, t1, t2);
+ // Select on priority - t1, t2 and t4 are discarded.
+ // t3 is a higher priority and has a larger size than t1 and t2.
+ // Similar story fo t4 with t5.
+ assertTransformerName(MSG, 100, GIF, actualOptions, "transformer3", t1, t2, t3, t4, t5);
+ assertTransformerName(MSG, 200, GIF, actualOptions, "transformer3", t1, t2, t3, t4, t5);
+ // Select on size and priority, t1 and t2 discarded
+ assertTransformerName(MSG, 200, GIF, actualOptions, "transformer3", t1, t2, t3, t4);
+ assertTransformerName(MSG, 300, GIF, actualOptions, "transformer4", t1, t2, t3, t4);
+ assertTransformerName(MSG, 300, GIF, actualOptions, "transformer5", t1, t2, t3, t4, t5);
+ }
+
+ @Test
+ public void testMultipleTransformers() throws Exception
+ {
+ Transformer transformer1 = new Transformer("transformer1",
Arrays.asList(
new TransformOptionValue(false, "page"),
new TransformOptionValue(false, "width"),
@@ -688,7 +729,7 @@ public class TransformServiceRegistryImplTest
new SupportedSourceAndTarget(DOC, JPEG, -1),
new SupportedSourceAndTarget(MSG, GIF, -1)));
- Transformer transformer2 = new Transformer("transformer2", "1",
+ Transformer transformer2 = new Transformer("transformer2",
Arrays.asList(
new TransformOptionValue(false, "opt1"),
new TransformOptionValue(false, "opt2")),
@@ -696,7 +737,7 @@ public class TransformServiceRegistryImplTest
new SupportedSourceAndTarget(PDF, GIF, -1),
new SupportedSourceAndTarget(PPT, JPEG, -1)));
- Transformer transformer3 = new Transformer("transformer3", "1",
+ Transformer transformer3 = new Transformer("transformer3",
Arrays.asList(
new TransformOptionValue(false, "opt1")),
Arrays.asList(
@@ -711,7 +752,7 @@ public class TransformServiceRegistryImplTest
assertSupported(DOC, 102401, GIF, null, "source is too large", transformer1);
assertSupported(DOC, 102401, GIF, null, null, transformer1, transformer3);
- assertSupported(PDF, 1024, GIF, actualOptions, "Only transformer2 supports these mmetypes", transformer1);
+ assertSupported(PDF, 1024, GIF, actualOptions, "Only transformer2 supports these mimetypes", transformer1);
assertSupported(PDF, 1024, GIF, actualOptions, null, transformer1, transformer2);
assertSupported(PDF, 1024, GIF, actualOptions, null, transformer1, transformer2, transformer3);
@@ -723,15 +764,15 @@ public class TransformServiceRegistryImplTest
}
@Test
- public void testPipeline()
+ public void testPipeline() throws Exception
{
- Transformer transformer1 = new Transformer("transformer1", "1",
+ Transformer transformer1 = new Transformer("transformer1",
null, // there are no options
Arrays.asList(
new SupportedSourceAndTarget(DOC, PDF, -1),
new SupportedSourceAndTarget(MSG, PDF, -1)));
- Transformer transformer2 = new Transformer("transformer2", "1",
+ Transformer transformer2 = new Transformer("transformer2",
Arrays.asList(
new TransformOptionValue(false, "page"),
new TransformOptionValue(false, "width"),
@@ -764,7 +805,7 @@ public class TransformServiceRegistryImplTest
private void buildPipelineTransformer(Transformer transformer1, Transformer transformer2)
{
- transformer = builder.buildPipeLine("officeToImage", "1",
+ transformer = builder.buildPipeLine("transformer1",
Arrays.asList(
new SupportedSourceAndTarget(DOC, GIF, -1),
new SupportedSourceAndTarget(DOC, JPEG, -1),
@@ -773,14 +814,4 @@ public class TransformServiceRegistryImplTest
new ChildTransformer(false, transformer1),
new ChildTransformer(true, transformer2)));
}
-
- @Test(expected = IllegalArgumentException.class)
- public void textMissingMimetype()
- {
- transformer = new Transformer("name", "1",
- null, // there are no options
- Arrays.asList(
- new SupportedSourceAndTarget("rubbish", PDF, -1)));
- registry.register(transformer);
- }
}
\ No newline at end of file
diff --git a/src/test/resources/alfresco/local-transform-service-config-pipeline-test.json b/src/test/resources/alfresco/local-transform-service-config-pipeline-test.json
new file mode 100644
index 0000000000..cdafa97f24
--- /dev/null
+++ b/src/test/resources/alfresco/local-transform-service-config-pipeline-test.json
@@ -0,0 +1,77 @@
+{
+ "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": [
+ {
+ "transformerName": "imagemagick",
+ "supportedSourceAndTargetList": [
+ {"sourceMediaType": "image/tiff", "targetMediaType": "image/tiff"}
+ ],
+ "transformOptions": [
+ "imagemagickOptions"
+ ]
+ },
+ {
+ "transformerName": "pdfrenderer",
+ "supportedSourceAndTargetList": [
+ {"sourceMediaType": "application/pdf", "targetMediaType": "image/png" }
+ ],
+ "transformOptions": [
+ "pdfRendererOptions"
+ ]
+ },
+ {
+ "transformerName": "libreoffice",
+ "supportedSourceAndTargetList": [
+ {"sourceMediaType": "application/vnd.ms-outlook", "targetMediaType": "application/pdf"}
+ ]
+ },
+ {
+ "transformerName": "officeToImageViaPdf",
+ "transformerPipeline" : [
+ {"transformerName": "libreoffice", "targetMediaType": "application/pdf"},
+ {"transformerName": "pdfrenderer", "targetMediaType": "image/png"},
+ {"transformerName": "imagemagick"}
+ ],
+ "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"
+ ]
+ }
+ ]
+}
\ No newline at end of file
diff --git a/src/test/resources/alfresco/local-transform-service-config-test.json b/src/test/resources/alfresco/local-transform-service-config-test.json
new file mode 100644
index 0000000000..f78659b3fc
--- /dev/null
+++ b/src/test/resources/alfresco/local-transform-service-config-test.json
@@ -0,0 +1,154 @@
+{
+ "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": [
+ {
+ "transformerName": "imagemagick",
+ "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"
+ ]
+ },
+ {
+ "transformerName": "tika",
+ "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"
+ ]
+ },
+ {
+ "transformerName": "pdfrenderer",
+ "supportedSourceAndTargetList": [
+ {"sourceMediaType": "application/pdf", "targetMediaType": "image/png" }
+ ],
+ "transformOptions": [
+ "pdfRendererOptions"
+ ]
+ },
+ {
+ "transformerName": "libreoffice",
+ "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"}
+ ]
+ },
+ {
+ "transformerName": "officeToImageViaPdf",
+ "transformerPipeline" : [
+ {"transformerName": "libreoffice", "targetMediaType": "application/pdf"},
+ {"transformerName": "pdfrenderer", "targetMediaType": "image/png"},
+ {"transformerName": "imagemagick"}
+ ],
+ "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"
+ ]
+ }
+ ]
+}
\ No newline at end of file
diff --git a/src/test/resources/alfresco/transform-service-config-pipeline-test.json b/src/test/resources/alfresco/transform-service-config-pipeline-test.json
new file mode 100644
index 0000000000..aa45d4929e
--- /dev/null
+++ b/src/test/resources/alfresco/transform-service-config-pipeline-test.json
@@ -0,0 +1,47 @@
+{
+ "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"
+ ]
+ }
+ ]
+}
\ No newline at end of file
diff --git a/src/test/resources/alfresco/transform-service-config-test.json b/src/test/resources/alfresco/transform-service-config-test.json
new file mode 100644
index 0000000000..4590e35c1d
--- /dev/null
+++ b/src/test/resources/alfresco/transform-service-config-test.json
@@ -0,0 +1,144 @@
+{
+ "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"
+ ]
+ }
+ ]
+}
\ No newline at end of file
diff --git a/src/test/resources/alfresco/transform-service-config-test1.json b/src/test/resources/alfresco/transform-service-config-test1.json
deleted file mode 100644
index c3921c391d..0000000000
--- a/src/test/resources/alfresco/transform-service-config-test1.json
+++ /dev/null
@@ -1,49 +0,0 @@
-[
- {
- "name": "officeToImageViaPdf",
- "version": "1",
- "transformOptions": [
- {
- "group": {
- "required": true,
- "transformOptions": [
- {"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"}}
- ]}}
- ]}},{
- "group": {
- "transformOptions": [
- {"value": {"name": "page"}},
- {"value": {"name": "width"}},
- {"value": {"name": "height"}},
- {"value": {"name": "allowPdfEnlargement"}},
- {"value": {"name": "maintainPdfAspectRatio"}}
- ]
- }
- }
- ],
- "supportedSourceAndTargetList": [
- {"sourceExt": "doc", "targetExt": "gif" },
- {"sourceExt": "doc", "targetExt": "jpeg"},
- {"sourceExt": "doc", "targetExt": "png" },
- {"sourceExt": "doc", "targetExt": "tiff"}
- ]
- }
-]
\ No newline at end of file
diff --git a/src/test/resources/log4j.properties b/src/test/resources/log4j.properties
index e108d488dd..8a2e558c77 100644
--- a/src/test/resources/log4j.properties
+++ b/src/test/resources/log4j.properties
@@ -250,6 +250,7 @@ log4j.logger.org.alfresco.repo.security.authentication.identityservice=debug
log4j.logger.org.keycloak=debug
log4j.logger.org.alfresco.repo.content.transform.TransformerDebug=debug
+log4j.logger.org.alfresco.repo.content.transform.LocalTransform=debug
log4j.logger.org.alfresco.repo.rendition2=debug
-log4j.logger.org.alfresco.repo.rendition.RenditionServiceImpl=debug
+#log4j.logger.org.alfresco.repo.rendition.RenditionServiceImpl=debug
log4j.logger.org.alfresco.repo.rawevents=debug
\ No newline at end of file