mirror of
https://github.com/Alfresco/alfresco-transform-core.git
synced 2025-07-31 17:38:33 +00:00
ACS-9835-Improve code quality in alfresco-transform-core (#1116)
This commit is contained in:
@@ -21,18 +21,17 @@
|
||||
*/
|
||||
package org.alfresco.transform.client.model;
|
||||
|
||||
import org.alfresco.transform.messages.TransformStack;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.transform.messages.TransformStack;
|
||||
|
||||
/**
|
||||
* Holds required contextual information.
|
||||
*
|
||||
* @author Denis Ungureanu
|
||||
* created on 10/01/2019
|
||||
* @author Denis Ungureanu created on 10/01/2019
|
||||
*/
|
||||
// This class is in the package org.alfresco.transform.messages in HxP because that is more readable, but in
|
||||
// org.alfresco.transform.client.model in Alfresco for backward compatibility.
|
||||
@@ -97,10 +96,10 @@ public class InternalContext implements Serializable
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the reply to destination name.
|
||||
* Note: replyToDestination is populated from jmsMessage replyTo field sent by T-Client
|
||||
* Sets the reply to destination name. Note: replyToDestination is populated from jmsMessage replyTo field sent by T-Client
|
||||
*
|
||||
* @param replyToDestination reply to destination name
|
||||
* @param replyToDestination
|
||||
* reply to destination name
|
||||
*/
|
||||
public void setReplyToDestination(String replyToDestination)
|
||||
{
|
||||
@@ -123,22 +122,23 @@ public class InternalContext implements Serializable
|
||||
}
|
||||
|
||||
public void setTransformRequestOptions(
|
||||
Map<String, String> transformRequestOptions)
|
||||
Map<String, String> transformRequestOptions)
|
||||
{
|
||||
this.transformRequestOptions = transformRequestOptions;
|
||||
}
|
||||
|
||||
@Override public String toString()
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return "InternalContext{" +
|
||||
"multiStep=" + multiStep +
|
||||
", attemptedRetries=" + attemptedRetries +
|
||||
", currentSourceMediaType='" + currentSourceMediaType + '\'' +
|
||||
", currentTargetMediaType='" + currentTargetMediaType + '\'' +
|
||||
", replyToDestination='" + replyToDestination + '\'' +
|
||||
", currentSourceSize=" + currentSourceSize +
|
||||
", transformRequestOptions=" + transformRequestOptions +
|
||||
'}';
|
||||
"multiStep=" + multiStep +
|
||||
", attemptedRetries=" + attemptedRetries +
|
||||
", currentSourceMediaType='" + currentSourceMediaType + '\'' +
|
||||
", currentTargetMediaType='" + currentTargetMediaType + '\'' +
|
||||
", replyToDestination='" + replyToDestination + '\'' +
|
||||
", currentSourceSize=" + currentSourceSize +
|
||||
", transformRequestOptions=" + transformRequestOptions +
|
||||
'}';
|
||||
}
|
||||
|
||||
// To avoid NPE checks, initialise expected bits of the structure
|
||||
@@ -153,7 +153,7 @@ public class InternalContext implements Serializable
|
||||
internalContext.setMultiStep(new MultiStep());
|
||||
}
|
||||
if (internalContext.getMultiStep().getTransformsToBeDone() == null ||
|
||||
internalContext.getMultiStep().getTransformsToBeDone().isEmpty()) // might be immutable
|
||||
internalContext.getMultiStep().getTransformsToBeDone().isEmpty()) // might be immutable
|
||||
{
|
||||
internalContext.getMultiStep().setTransformsToBeDone(new ArrayList<>());
|
||||
}
|
||||
@@ -166,11 +166,11 @@ public class InternalContext implements Serializable
|
||||
return internalContext == null
|
||||
? type + " InternalContext was null"
|
||||
: internalContext.getMultiStep() == null
|
||||
? type + " InternalContext did not have the MultiStep set"
|
||||
: internalContext.getMultiStep().getTransformsToBeDone() == null
|
||||
? type + " InternalContext did not have the TransformsToBeDone set"
|
||||
: internalContext.getMultiStep().getInitialRequestId() == null
|
||||
? type + " InternalContext did not have the InitialRequestId set"
|
||||
: TransformStack.checkStructure(internalContext, type);
|
||||
? type + " InternalContext did not have the MultiStep set"
|
||||
: internalContext.getMultiStep().getTransformsToBeDone() == null
|
||||
? type + " InternalContext did not have the TransformsToBeDone set"
|
||||
: internalContext.getMultiStep().getInitialRequestId() == null
|
||||
? type + " InternalContext did not have the InitialRequestId set"
|
||||
: TransformStack.checkStructure(internalContext, type);
|
||||
}
|
||||
}
|
||||
|
@@ -26,5 +26,4 @@ package org.alfresco.transform.client.model;
|
||||
*/
|
||||
@Deprecated
|
||||
public interface Mimetype extends org.alfresco.transform.common.Mimetype
|
||||
{
|
||||
}
|
||||
{}
|
||||
|
@@ -28,8 +28,7 @@ import java.util.List;
|
||||
/**
|
||||
* Holds required contextual information for a multi-step transform.
|
||||
*
|
||||
* @author Lucian Tuca
|
||||
* created on 19/12/2018
|
||||
* @author Lucian Tuca created on 19/12/2018
|
||||
*/
|
||||
// This class is in the package org.alfresco.transform.messages in HxP because that is more readable, but in
|
||||
// org.alfresco.transform.client.model in Alfresco for backward compatibility.
|
||||
@@ -71,14 +70,15 @@ public class MultiStep implements Serializable
|
||||
this.transformsToBeDone = transformsToBeDone;
|
||||
}
|
||||
|
||||
//endregion
|
||||
// endregion
|
||||
|
||||
@Override public String toString()
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return "MultiStep{" +
|
||||
"initialRequestId='" + initialRequestId + '\'' +
|
||||
", initialSourceMediaType='" + initialSourceMediaType + '\'' +
|
||||
", transformsToBeDone=" + transformsToBeDone +
|
||||
'}';
|
||||
"initialRequestId='" + initialRequestId + '\'' +
|
||||
", initialSourceMediaType='" + initialSourceMediaType + '\'' +
|
||||
", transformsToBeDone=" + transformsToBeDone +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
@@ -37,7 +37,7 @@ public class TransformReply implements Serializable
|
||||
private int schema;
|
||||
private InternalContext internalContext;
|
||||
|
||||
//region [Accessors]
|
||||
// region [Accessors]
|
||||
public String getRequestId()
|
||||
{
|
||||
return requestId;
|
||||
@@ -118,7 +118,7 @@ public class TransformReply implements Serializable
|
||||
this.internalContext = internalContext;
|
||||
}
|
||||
|
||||
//endregion
|
||||
// endregion
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o)
|
||||
@@ -137,18 +137,19 @@ public class TransformReply implements Serializable
|
||||
return Objects.hash(requestId);
|
||||
}
|
||||
|
||||
@Override public String toString()
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return "TransformReply{" +
|
||||
"requestId='" + requestId + '\'' +
|
||||
", status=" + status +
|
||||
", errorDetails='" + errorDetails + '\'' +
|
||||
", sourceReference='" + sourceReference + '\'' +
|
||||
", targetReference='" + targetReference + '\'' +
|
||||
", clientData='" + clientData + '\'' +
|
||||
", schema=" + schema +
|
||||
", internalContext=" + internalContext +
|
||||
'}';
|
||||
"requestId='" + requestId + '\'' +
|
||||
", status=" + status +
|
||||
", errorDetails='" + errorDetails + '\'' +
|
||||
", sourceReference='" + sourceReference + '\'' +
|
||||
", targetReference='" + targetReference + '\'' +
|
||||
", clientData='" + clientData + '\'' +
|
||||
", schema=" + schema +
|
||||
", internalContext=" + internalContext +
|
||||
'}';
|
||||
}
|
||||
|
||||
public static Builder builder()
|
||||
@@ -160,7 +161,8 @@ public class TransformReply implements Serializable
|
||||
{
|
||||
private final TransformReply reply = new TransformReply();
|
||||
|
||||
private Builder() {}
|
||||
private Builder()
|
||||
{}
|
||||
|
||||
public Builder withRequestId(final String requestId)
|
||||
{
|
||||
|
@@ -21,17 +21,17 @@
|
||||
*/
|
||||
package org.alfresco.transform.client.model;
|
||||
|
||||
import org.alfresco.transform.common.ExtensionService;
|
||||
import org.alfresco.transform.messages.TransformStack;
|
||||
import static org.alfresco.transform.messages.TransformStack.PIPELINE_FLAG;
|
||||
import static org.alfresco.transform.messages.TransformStack.levelBuilder;
|
||||
import static org.alfresco.transform.messages.TransformStack.setInitialTransformRequestOptions;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
import static org.alfresco.transform.messages.TransformStack.PIPELINE_FLAG;
|
||||
import static org.alfresco.transform.messages.TransformStack.levelBuilder;
|
||||
import static org.alfresco.transform.messages.TransformStack.setInitialTransformRequestOptions;
|
||||
import org.alfresco.transform.common.ExtensionService;
|
||||
import org.alfresco.transform.messages.TransformStack;
|
||||
|
||||
// This class is in the package org.alfresco.transform.messages in HxP because that is more readable, but in
|
||||
// org.alfresco.transform.client.model in Alfresco for backward compatibility.
|
||||
@@ -160,7 +160,7 @@ public class TransformRequest implements Serializable
|
||||
this.internalContext = internalContext;
|
||||
}
|
||||
|
||||
//endregion
|
||||
// endregion
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o)
|
||||
@@ -179,34 +179,32 @@ public class TransformRequest implements Serializable
|
||||
return Objects.hash(requestId);
|
||||
}
|
||||
|
||||
@Override public String toString()
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return "TransformRequest{" +
|
||||
"requestId='" + requestId + '\'' +
|
||||
", sourceReference='" + sourceReference + '\'' +
|
||||
", sourceMediaType='" + sourceMediaType + '\'' +
|
||||
", sourceSize=" + sourceSize +
|
||||
", sourceExtension='" + sourceExtension + '\'' +
|
||||
", targetMediaType='" + targetMediaType + '\'' +
|
||||
", targetExtension='" + targetExtension + '\'' +
|
||||
", clientData='" + clientData + '\'' +
|
||||
", schema=" + schema +
|
||||
", transformRequestOptions=" + transformRequestOptions +
|
||||
", internalContext=" + internalContext +
|
||||
'}';
|
||||
"requestId='" + requestId + '\'' +
|
||||
", sourceReference='" + sourceReference + '\'' +
|
||||
", sourceMediaType='" + sourceMediaType + '\'' +
|
||||
", sourceSize=" + sourceSize +
|
||||
", sourceExtension='" + sourceExtension + '\'' +
|
||||
", targetMediaType='" + targetMediaType + '\'' +
|
||||
", targetExtension='" + targetExtension + '\'' +
|
||||
", clientData='" + clientData + '\'' +
|
||||
", schema=" + schema +
|
||||
", transformRequestOptions=" + transformRequestOptions +
|
||||
", internalContext=" + internalContext +
|
||||
'}';
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets up the internal context structure when a client request is initially received by the router,
|
||||
* so that we don't have to keep checking if bits of it are initialised. Prior to making this call,
|
||||
* the id, sourceMimetypes, targetMimetype, transformRequestOptions and sourceReference should have
|
||||
* been set, if they are to be set.
|
||||
* Sets up the internal context structure when a client request is initially received by the router, so that we don't have to keep checking if bits of it are initialised. Prior to making this call, the id, sourceMimetypes, targetMimetype, transformRequestOptions and sourceReference should have been set, if they are to be set.
|
||||
*/
|
||||
public TransformRequest initialiseContextWhenReceivedByRouter()
|
||||
{
|
||||
setInternalContext(InternalContext.initialise(getInternalContext()));
|
||||
setTargetExtension(ExtensionService.getExtensionForTargetMimetype(getTargetMediaType(),
|
||||
getSourceMediaType()));
|
||||
getSourceMediaType()));
|
||||
getInternalContext().getMultiStep().setInitialRequestId(getRequestId());
|
||||
getInternalContext().getMultiStep().setInitialSourceMediaType(getSourceMediaType());
|
||||
getInternalContext().setTransformRequestOptions(getTransformRequestOptions());
|
||||
@@ -224,7 +222,8 @@ public class TransformRequest implements Serializable
|
||||
{
|
||||
private final TransformRequest request = new TransformRequest();
|
||||
|
||||
private Builder() {}
|
||||
private Builder()
|
||||
{}
|
||||
|
||||
public Builder withRequestId(final String requestId)
|
||||
{
|
||||
@@ -281,7 +280,7 @@ public class TransformRequest implements Serializable
|
||||
}
|
||||
|
||||
public Builder withTransformRequestOptions(
|
||||
final Map<String, String> transformRequestOptions)
|
||||
final Map<String, String> transformRequestOptions)
|
||||
{
|
||||
request.transformRequestOptions = transformRequestOptions;
|
||||
return this;
|
||||
@@ -297,7 +296,7 @@ public class TransformRequest implements Serializable
|
||||
{
|
||||
request.initialiseContextWhenReceivedByRouter();
|
||||
TransformStack.addTransformLevel(request.internalContext, levelBuilder(PIPELINE_FLAG)
|
||||
.withStep("dummyTransformerName", request.sourceMediaType, request.targetMediaType));
|
||||
.withStep("dummyTransformerName", request.sourceMediaType, request.targetMediaType));
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@@ -25,6 +25,5 @@ package org.alfresco.transform.client.util;
|
||||
* @deprecated will be removed in a future release when the deprecated alfresco-transform-model is removed.
|
||||
*/
|
||||
@Deprecated
|
||||
public interface RequestParamMap extends org.alfresco.transform.common.RequestParamMap
|
||||
{
|
||||
}
|
||||
public interface RequestParamMap extends org.alfresco.transform.common.RequestParamMap
|
||||
{}
|
||||
|
@@ -1,163 +1,159 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Transform Model
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2022 Alfresco Software Limited
|
||||
* %%
|
||||
* This program 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.
|
||||
*
|
||||
* This program 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 General Lesser Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Lesser Public
|
||||
* License along with this program. If not, see
|
||||
* <http://www.gnu.org/licenses/lgpl-3.0.html>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.transform.common;
|
||||
|
||||
import static org.alfresco.transform.common.Mimetype.MIMETYPE_DITA;
|
||||
import static org.alfresco.transform.common.Mimetype.MIMETYPE_EXCEL;
|
||||
import static org.alfresco.transform.common.Mimetype.MIMETYPE_IMAGE_SVG;
|
||||
import static org.alfresco.transform.common.Mimetype.MIMETYPE_IMAGE_XWD;
|
||||
import static org.alfresco.transform.common.Mimetype.MIMETYPE_OPENDOCUMENT_GRAPHICS;
|
||||
import static org.alfresco.transform.common.Mimetype.MIMETYPE_OPENDOCUMENT_PRESENTATION;
|
||||
import static org.alfresco.transform.common.Mimetype.MIMETYPE_OPENDOCUMENT_PRESENTATION_TEMPLATE;
|
||||
import static org.alfresco.transform.common.Mimetype.MIMETYPE_OPENDOCUMENT_SPREADSHEET;
|
||||
import static org.alfresco.transform.common.Mimetype.MIMETYPE_OPENDOCUMENT_SPREADSHEET_TEMPLATE;
|
||||
import static org.alfresco.transform.common.Mimetype.MIMETYPE_OPENDOCUMENT_TEXT;
|
||||
import static org.alfresco.transform.common.Mimetype.MIMETYPE_OPENDOCUMENT_TEXT_TEMPLATE;
|
||||
import static org.alfresco.transform.common.Mimetype.MIMETYPE_OPENOFFICE1_CALC;
|
||||
import static org.alfresco.transform.common.Mimetype.MIMETYPE_OPENOFFICE1_IMPRESS;
|
||||
import static org.alfresco.transform.common.Mimetype.MIMETYPE_OPENOFFICE1_WRITER;
|
||||
import static org.alfresco.transform.common.Mimetype.MIMETYPE_OPENXML_PRESENTATION;
|
||||
import static org.alfresco.transform.common.Mimetype.MIMETYPE_OPENXML_PRESENTATION_ADDIN;
|
||||
import static org.alfresco.transform.common.Mimetype.MIMETYPE_OPENXML_PRESENTATION_MACRO;
|
||||
import static org.alfresco.transform.common.Mimetype.MIMETYPE_OPENXML_PRESENTATION_SLIDE;
|
||||
import static org.alfresco.transform.common.Mimetype.MIMETYPE_OPENXML_PRESENTATION_SLIDESHOW;
|
||||
import static org.alfresco.transform.common.Mimetype.MIMETYPE_OPENXML_PRESENTATION_SLIDE_MACRO;
|
||||
import static org.alfresco.transform.common.Mimetype.MIMETYPE_OPENXML_PRESENTATION_TEMPLATE;
|
||||
import static org.alfresco.transform.common.Mimetype.MIMETYPE_OPENXML_PRESENTATION_TEMPLATE_MACRO;
|
||||
import static org.alfresco.transform.common.Mimetype.MIMETYPE_OPENXML_SPREADSHEET;
|
||||
import static org.alfresco.transform.common.Mimetype.MIMETYPE_OPENXML_SPREADSHEET_BINARY_MACRO;
|
||||
import static org.alfresco.transform.common.Mimetype.MIMETYPE_OPENXML_SPREADSHEET_MACRO;
|
||||
import static org.alfresco.transform.common.Mimetype.MIMETYPE_OPENXML_SPREADSHEET_TEMPLATE;
|
||||
import static org.alfresco.transform.common.Mimetype.MIMETYPE_OPENXML_SPREADSHEET_TEMPLATE_MACRO;
|
||||
import static org.alfresco.transform.common.Mimetype.MIMETYPE_OPENXML_WORDPROCESSING;
|
||||
import static org.alfresco.transform.common.Mimetype.MIMETYPE_OPENXML_WORDPROCESSING_MACRO;
|
||||
import static org.alfresco.transform.common.Mimetype.MIMETYPE_OPENXML_WORD_TEMPLATE;
|
||||
import static org.alfresco.transform.common.Mimetype.MIMETYPE_OPENXML_WORD_TEMPLATE_MACRO;
|
||||
import static org.alfresco.transform.common.Mimetype.MIMETYPE_OUTLOOK_MSG;
|
||||
import static org.alfresco.transform.common.Mimetype.MIMETYPE_PPT;
|
||||
import static org.alfresco.transform.common.Mimetype.MIMETYPE_VISIO;
|
||||
import static org.alfresco.transform.common.Mimetype.MIMETYPE_VISIO_2013;
|
||||
import static org.alfresco.transform.common.Mimetype.MIMETYPE_WORD;
|
||||
import static org.alfresco.transform.common.Mimetype.MIMETYPE_WORDPERFECT;
|
||||
import static org.alfresco.transform.common.Mimetype.MIMETYPE_TEXT_PLAIN;
|
||||
import static org.alfresco.transform.common.Mimetype.MIMETYPE_XHTML;
|
||||
import static org.alfresco.transform.common.TransformerDebug.MIMETYPE_METADATA_EMBED;
|
||||
import static org.alfresco.transform.common.TransformerDebug.MIMETYPE_METADATA_EXTRACT;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Provides mapping between mimtypes and file extensions, static and not configurable.
|
||||
* The correct extension is required for a small subset of transforms in pipelines which go through the
|
||||
* libreoffice transformer
|
||||
*/
|
||||
public class ExtensionService
|
||||
{
|
||||
private final static String MIMETYPE_TAB_SEPARATED_VALUES="text/tab-separated-values";
|
||||
private final static String MIMETYPE_CALC_TEMPLATE="application/vnd.sun.xml.calc.template";
|
||||
private final static String MIMETYPE_IMPRESS_TEMPLATE="application/vnd.sun.xml.impress.template";
|
||||
private final static String MIMETYPE_WRITER_TEMPLATE="application/vnd.sun.xml.writer.template";
|
||||
|
||||
private static final Map<String,String> mimetpeExtensions = Map.ofEntries(
|
||||
Map.entry(MIMETYPE_WORD, "doc"),
|
||||
Map.entry(MIMETYPE_OPENXML_WORDPROCESSING_MACRO, "docm"),
|
||||
Map.entry(MIMETYPE_OPENXML_WORDPROCESSING, "docx"),
|
||||
Map.entry(MIMETYPE_OPENXML_WORD_TEMPLATE_MACRO, "dotm"),
|
||||
Map.entry(MIMETYPE_OPENXML_WORD_TEMPLATE, "dotx"),
|
||||
Map.entry(MIMETYPE_OPENDOCUMENT_GRAPHICS, "odg"),
|
||||
Map.entry(MIMETYPE_OPENDOCUMENT_PRESENTATION, "odp"),
|
||||
Map.entry(MIMETYPE_OPENDOCUMENT_PRESENTATION_TEMPLATE, "otp"),
|
||||
Map.entry(MIMETYPE_OPENDOCUMENT_SPREADSHEET, "ods"),
|
||||
Map.entry(MIMETYPE_OPENDOCUMENT_SPREADSHEET_TEMPLATE, "ots"),
|
||||
Map.entry(MIMETYPE_OPENDOCUMENT_TEXT, "odt"),
|
||||
Map.entry(MIMETYPE_OPENDOCUMENT_TEXT_TEMPLATE, "ott"),
|
||||
Map.entry(MIMETYPE_OPENXML_PRESENTATION_TEMPLATE_MACRO, "potm"),
|
||||
Map.entry(MIMETYPE_OPENXML_PRESENTATION_TEMPLATE, "potx"),
|
||||
Map.entry(MIMETYPE_OPENXML_PRESENTATION_ADDIN, "ppam"),
|
||||
Map.entry(MIMETYPE_PPT, "ppt"),
|
||||
Map.entry(MIMETYPE_OPENXML_PRESENTATION_MACRO, "pptm"),
|
||||
Map.entry(MIMETYPE_OPENXML_PRESENTATION, "pptx"),
|
||||
Map.entry(MIMETYPE_OPENXML_PRESENTATION_SLIDE_MACRO, "sldm"),
|
||||
Map.entry(MIMETYPE_OPENXML_PRESENTATION_SLIDE, "sldx"),
|
||||
Map.entry(MIMETYPE_CALC_TEMPLATE, "stc"),
|
||||
Map.entry(MIMETYPE_IMPRESS_TEMPLATE, "sti"),
|
||||
Map.entry(MIMETYPE_WRITER_TEMPLATE, "stw"),
|
||||
Map.entry(MIMETYPE_TAB_SEPARATED_VALUES, "tsv"),
|
||||
Map.entry(MIMETYPE_OPENOFFICE1_CALC, "sxc"),
|
||||
Map.entry(MIMETYPE_OPENOFFICE1_IMPRESS, "sxi"),
|
||||
Map.entry(MIMETYPE_OPENOFFICE1_WRITER, "sxw"),
|
||||
Map.entry(MIMETYPE_VISIO, "vsd"),
|
||||
Map.entry(MIMETYPE_VISIO_2013, "vsdx"),
|
||||
Map.entry(MIMETYPE_WORDPERFECT, "wp"),
|
||||
Map.entry(MIMETYPE_EXCEL, "xls"),
|
||||
Map.entry(MIMETYPE_OPENXML_SPREADSHEET_BINARY_MACRO, "xlsb"),
|
||||
Map.entry(MIMETYPE_OPENXML_SPREADSHEET_MACRO, "xlsm"),
|
||||
Map.entry(MIMETYPE_OPENXML_SPREADSHEET, "xlsx"),
|
||||
Map.entry(MIMETYPE_OPENXML_SPREADSHEET_TEMPLATE_MACRO, "xltm"),
|
||||
Map.entry(MIMETYPE_OPENXML_PRESENTATION_SLIDESHOW, "ppsx"),
|
||||
Map.entry(MIMETYPE_OUTLOOK_MSG, "msg"),
|
||||
Map.entry(MIMETYPE_DITA, "dita"),
|
||||
Map.entry(MIMETYPE_OPENXML_SPREADSHEET_TEMPLATE, "xltx"),
|
||||
Map.entry(MIMETYPE_IMAGE_SVG, "svg"),
|
||||
Map.entry(MIMETYPE_TEXT_PLAIN, "txt"),
|
||||
Map.entry(MIMETYPE_XHTML, "xhtml"),
|
||||
Map.entry(MIMETYPE_IMAGE_XWD, "xwd")
|
||||
);
|
||||
|
||||
protected ExtensionService()
|
||||
{
|
||||
}
|
||||
|
||||
public static String getExtensionForTargetMimetype(String targetMimetype, String sourceMimetype)
|
||||
{
|
||||
if (targetMimetype == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return getExtensionForMimetype(MIMETYPE_METADATA_EMBED.equals(targetMimetype) ? sourceMimetype : targetMimetype);
|
||||
}
|
||||
|
||||
public static String getExtensionForMimetype(String mimetype)
|
||||
{
|
||||
if (mimetype == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
if (mimetpeExtensions.containsKey(mimetype))
|
||||
{
|
||||
return mimetpeExtensions.get(mimetype);
|
||||
}
|
||||
if (MIMETYPE_METADATA_EXTRACT.equals(mimetype))
|
||||
{
|
||||
return "json";
|
||||
}
|
||||
// else fall back to the original implementation
|
||||
return splitMimetype(mimetype);
|
||||
}
|
||||
|
||||
// Moved from Dispatcher. This fails to work in many cases, but we need to be backward compatible.
|
||||
private static String splitMimetype(final String mimetype)
|
||||
{
|
||||
final String[] parts = mimetype.split("[.\\-_|/]");
|
||||
return parts[parts.length - 1];
|
||||
}
|
||||
}
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Transform Model
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2022 Alfresco Software Limited
|
||||
* %%
|
||||
* This program 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.
|
||||
*
|
||||
* This program 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 General Lesser Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Lesser Public
|
||||
* License along with this program. If not, see
|
||||
* <http://www.gnu.org/licenses/lgpl-3.0.html>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.transform.common;
|
||||
|
||||
import static org.alfresco.transform.common.Mimetype.MIMETYPE_DITA;
|
||||
import static org.alfresco.transform.common.Mimetype.MIMETYPE_EXCEL;
|
||||
import static org.alfresco.transform.common.Mimetype.MIMETYPE_IMAGE_SVG;
|
||||
import static org.alfresco.transform.common.Mimetype.MIMETYPE_IMAGE_XWD;
|
||||
import static org.alfresco.transform.common.Mimetype.MIMETYPE_OPENDOCUMENT_GRAPHICS;
|
||||
import static org.alfresco.transform.common.Mimetype.MIMETYPE_OPENDOCUMENT_PRESENTATION;
|
||||
import static org.alfresco.transform.common.Mimetype.MIMETYPE_OPENDOCUMENT_PRESENTATION_TEMPLATE;
|
||||
import static org.alfresco.transform.common.Mimetype.MIMETYPE_OPENDOCUMENT_SPREADSHEET;
|
||||
import static org.alfresco.transform.common.Mimetype.MIMETYPE_OPENDOCUMENT_SPREADSHEET_TEMPLATE;
|
||||
import static org.alfresco.transform.common.Mimetype.MIMETYPE_OPENDOCUMENT_TEXT;
|
||||
import static org.alfresco.transform.common.Mimetype.MIMETYPE_OPENDOCUMENT_TEXT_TEMPLATE;
|
||||
import static org.alfresco.transform.common.Mimetype.MIMETYPE_OPENOFFICE1_CALC;
|
||||
import static org.alfresco.transform.common.Mimetype.MIMETYPE_OPENOFFICE1_IMPRESS;
|
||||
import static org.alfresco.transform.common.Mimetype.MIMETYPE_OPENOFFICE1_WRITER;
|
||||
import static org.alfresco.transform.common.Mimetype.MIMETYPE_OPENXML_PRESENTATION;
|
||||
import static org.alfresco.transform.common.Mimetype.MIMETYPE_OPENXML_PRESENTATION_ADDIN;
|
||||
import static org.alfresco.transform.common.Mimetype.MIMETYPE_OPENXML_PRESENTATION_MACRO;
|
||||
import static org.alfresco.transform.common.Mimetype.MIMETYPE_OPENXML_PRESENTATION_SLIDE;
|
||||
import static org.alfresco.transform.common.Mimetype.MIMETYPE_OPENXML_PRESENTATION_SLIDESHOW;
|
||||
import static org.alfresco.transform.common.Mimetype.MIMETYPE_OPENXML_PRESENTATION_SLIDE_MACRO;
|
||||
import static org.alfresco.transform.common.Mimetype.MIMETYPE_OPENXML_PRESENTATION_TEMPLATE;
|
||||
import static org.alfresco.transform.common.Mimetype.MIMETYPE_OPENXML_PRESENTATION_TEMPLATE_MACRO;
|
||||
import static org.alfresco.transform.common.Mimetype.MIMETYPE_OPENXML_SPREADSHEET;
|
||||
import static org.alfresco.transform.common.Mimetype.MIMETYPE_OPENXML_SPREADSHEET_BINARY_MACRO;
|
||||
import static org.alfresco.transform.common.Mimetype.MIMETYPE_OPENXML_SPREADSHEET_MACRO;
|
||||
import static org.alfresco.transform.common.Mimetype.MIMETYPE_OPENXML_SPREADSHEET_TEMPLATE;
|
||||
import static org.alfresco.transform.common.Mimetype.MIMETYPE_OPENXML_SPREADSHEET_TEMPLATE_MACRO;
|
||||
import static org.alfresco.transform.common.Mimetype.MIMETYPE_OPENXML_WORDPROCESSING;
|
||||
import static org.alfresco.transform.common.Mimetype.MIMETYPE_OPENXML_WORDPROCESSING_MACRO;
|
||||
import static org.alfresco.transform.common.Mimetype.MIMETYPE_OPENXML_WORD_TEMPLATE;
|
||||
import static org.alfresco.transform.common.Mimetype.MIMETYPE_OPENXML_WORD_TEMPLATE_MACRO;
|
||||
import static org.alfresco.transform.common.Mimetype.MIMETYPE_OUTLOOK_MSG;
|
||||
import static org.alfresco.transform.common.Mimetype.MIMETYPE_PPT;
|
||||
import static org.alfresco.transform.common.Mimetype.MIMETYPE_TEXT_PLAIN;
|
||||
import static org.alfresco.transform.common.Mimetype.MIMETYPE_VISIO;
|
||||
import static org.alfresco.transform.common.Mimetype.MIMETYPE_VISIO_2013;
|
||||
import static org.alfresco.transform.common.Mimetype.MIMETYPE_WORD;
|
||||
import static org.alfresco.transform.common.Mimetype.MIMETYPE_WORDPERFECT;
|
||||
import static org.alfresco.transform.common.Mimetype.MIMETYPE_XHTML;
|
||||
import static org.alfresco.transform.common.TransformerDebug.MIMETYPE_METADATA_EMBED;
|
||||
import static org.alfresco.transform.common.TransformerDebug.MIMETYPE_METADATA_EXTRACT;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Provides mapping between mimtypes and file extensions, static and not configurable. The correct extension is required for a small subset of transforms in pipelines which go through the libreoffice transformer
|
||||
*/
|
||||
public class ExtensionService
|
||||
{
|
||||
private final static String MIMETYPE_TAB_SEPARATED_VALUES = "text/tab-separated-values";
|
||||
private final static String MIMETYPE_CALC_TEMPLATE = "application/vnd.sun.xml.calc.template";
|
||||
private final static String MIMETYPE_IMPRESS_TEMPLATE = "application/vnd.sun.xml.impress.template";
|
||||
private final static String MIMETYPE_WRITER_TEMPLATE = "application/vnd.sun.xml.writer.template";
|
||||
|
||||
private static final Map<String, String> mimetpeExtensions = Map.ofEntries(
|
||||
Map.entry(MIMETYPE_WORD, "doc"),
|
||||
Map.entry(MIMETYPE_OPENXML_WORDPROCESSING_MACRO, "docm"),
|
||||
Map.entry(MIMETYPE_OPENXML_WORDPROCESSING, "docx"),
|
||||
Map.entry(MIMETYPE_OPENXML_WORD_TEMPLATE_MACRO, "dotm"),
|
||||
Map.entry(MIMETYPE_OPENXML_WORD_TEMPLATE, "dotx"),
|
||||
Map.entry(MIMETYPE_OPENDOCUMENT_GRAPHICS, "odg"),
|
||||
Map.entry(MIMETYPE_OPENDOCUMENT_PRESENTATION, "odp"),
|
||||
Map.entry(MIMETYPE_OPENDOCUMENT_PRESENTATION_TEMPLATE, "otp"),
|
||||
Map.entry(MIMETYPE_OPENDOCUMENT_SPREADSHEET, "ods"),
|
||||
Map.entry(MIMETYPE_OPENDOCUMENT_SPREADSHEET_TEMPLATE, "ots"),
|
||||
Map.entry(MIMETYPE_OPENDOCUMENT_TEXT, "odt"),
|
||||
Map.entry(MIMETYPE_OPENDOCUMENT_TEXT_TEMPLATE, "ott"),
|
||||
Map.entry(MIMETYPE_OPENXML_PRESENTATION_TEMPLATE_MACRO, "potm"),
|
||||
Map.entry(MIMETYPE_OPENXML_PRESENTATION_TEMPLATE, "potx"),
|
||||
Map.entry(MIMETYPE_OPENXML_PRESENTATION_ADDIN, "ppam"),
|
||||
Map.entry(MIMETYPE_PPT, "ppt"),
|
||||
Map.entry(MIMETYPE_OPENXML_PRESENTATION_MACRO, "pptm"),
|
||||
Map.entry(MIMETYPE_OPENXML_PRESENTATION, "pptx"),
|
||||
Map.entry(MIMETYPE_OPENXML_PRESENTATION_SLIDE_MACRO, "sldm"),
|
||||
Map.entry(MIMETYPE_OPENXML_PRESENTATION_SLIDE, "sldx"),
|
||||
Map.entry(MIMETYPE_CALC_TEMPLATE, "stc"),
|
||||
Map.entry(MIMETYPE_IMPRESS_TEMPLATE, "sti"),
|
||||
Map.entry(MIMETYPE_WRITER_TEMPLATE, "stw"),
|
||||
Map.entry(MIMETYPE_TAB_SEPARATED_VALUES, "tsv"),
|
||||
Map.entry(MIMETYPE_OPENOFFICE1_CALC, "sxc"),
|
||||
Map.entry(MIMETYPE_OPENOFFICE1_IMPRESS, "sxi"),
|
||||
Map.entry(MIMETYPE_OPENOFFICE1_WRITER, "sxw"),
|
||||
Map.entry(MIMETYPE_VISIO, "vsd"),
|
||||
Map.entry(MIMETYPE_VISIO_2013, "vsdx"),
|
||||
Map.entry(MIMETYPE_WORDPERFECT, "wp"),
|
||||
Map.entry(MIMETYPE_EXCEL, "xls"),
|
||||
Map.entry(MIMETYPE_OPENXML_SPREADSHEET_BINARY_MACRO, "xlsb"),
|
||||
Map.entry(MIMETYPE_OPENXML_SPREADSHEET_MACRO, "xlsm"),
|
||||
Map.entry(MIMETYPE_OPENXML_SPREADSHEET, "xlsx"),
|
||||
Map.entry(MIMETYPE_OPENXML_SPREADSHEET_TEMPLATE_MACRO, "xltm"),
|
||||
Map.entry(MIMETYPE_OPENXML_PRESENTATION_SLIDESHOW, "ppsx"),
|
||||
Map.entry(MIMETYPE_OUTLOOK_MSG, "msg"),
|
||||
Map.entry(MIMETYPE_DITA, "dita"),
|
||||
Map.entry(MIMETYPE_OPENXML_SPREADSHEET_TEMPLATE, "xltx"),
|
||||
Map.entry(MIMETYPE_IMAGE_SVG, "svg"),
|
||||
Map.entry(MIMETYPE_TEXT_PLAIN, "txt"),
|
||||
Map.entry(MIMETYPE_XHTML, "xhtml"),
|
||||
Map.entry(MIMETYPE_IMAGE_XWD, "xwd"));
|
||||
|
||||
protected ExtensionService()
|
||||
{}
|
||||
|
||||
public static String getExtensionForTargetMimetype(String targetMimetype, String sourceMimetype)
|
||||
{
|
||||
if (targetMimetype == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return getExtensionForMimetype(MIMETYPE_METADATA_EMBED.equals(targetMimetype) ? sourceMimetype : targetMimetype);
|
||||
}
|
||||
|
||||
public static String getExtensionForMimetype(String mimetype)
|
||||
{
|
||||
if (mimetype == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
if (mimetpeExtensions.containsKey(mimetype))
|
||||
{
|
||||
return mimetpeExtensions.get(mimetype);
|
||||
}
|
||||
if (MIMETYPE_METADATA_EXTRACT.equals(mimetype))
|
||||
{
|
||||
return "json";
|
||||
}
|
||||
// else fall back to the original implementation
|
||||
return splitMimetype(mimetype);
|
||||
}
|
||||
|
||||
// Moved from Dispatcher. This fails to work in many cases, but we need to be backward compatible.
|
||||
private static String splitMimetype(final String mimetype)
|
||||
{
|
||||
final String[] parts = mimetype.split("[.\\-_|/]");
|
||||
return parts[parts.length - 1];
|
||||
}
|
||||
}
|
||||
|
@@ -25,10 +25,10 @@ import java.util.StringJoiner;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
* The client data supplied and echoed back to content repository (the client). May be modified to include
|
||||
* TransformerDebug.
|
||||
* The client data supplied and echoed back to content repository (the client). May be modified to include TransformerDebug.
|
||||
*/
|
||||
public class RepositoryClientData {
|
||||
public class RepositoryClientData
|
||||
{
|
||||
public static final String CLIENT_DATA_SEPARATOR = "\u23D0";
|
||||
public static final String DEBUG_SEPARATOR = "\u23D1";
|
||||
public static final String REPO_ID = "Repo";
|
||||
@@ -66,23 +66,29 @@ public class RepositoryClientData {
|
||||
return isRepositoryClientData() ? split[REQUEST_ID_INDEX] : "";
|
||||
}
|
||||
|
||||
public String getRenditionName() {
|
||||
public String getRenditionName()
|
||||
{
|
||||
return isRepositoryClientData() ? split[RENDITION_INDEX] : "";
|
||||
}
|
||||
|
||||
public void appendDebug(String message) {
|
||||
public void appendDebug(String message)
|
||||
{
|
||||
if (isDebugRequested())
|
||||
{
|
||||
split[DEBUG_INDEX] += DEBUG_SEPARATOR + message;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isDebugRequested() {
|
||||
public boolean isDebugRequested()
|
||||
{
|
||||
return isRepositoryClientData() && split[9].startsWith(DEBUG);
|
||||
}
|
||||
|
||||
@Override public String toString() {
|
||||
if (split == null) {
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
if (split == null)
|
||||
{
|
||||
return origClientData;
|
||||
}
|
||||
StringJoiner sj = new StringJoiner(CLIENT_DATA_SEPARATOR);
|
||||
@@ -90,7 +96,8 @@ public class RepositoryClientData {
|
||||
return sj.toString();
|
||||
}
|
||||
|
||||
public static Builder builder() {
|
||||
public static Builder builder()
|
||||
{
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
@@ -99,14 +106,13 @@ public class RepositoryClientData {
|
||||
private final RepositoryClientData clientData = new RepositoryClientData(emptyClientData());
|
||||
|
||||
private Builder()
|
||||
{
|
||||
}
|
||||
{}
|
||||
|
||||
private static String emptyClientData()
|
||||
{
|
||||
StringJoiner sj = new StringJoiner(CLIENT_DATA_SEPARATOR);
|
||||
sj.add(REPO_ID+"ACS1234");
|
||||
for (int i=0; i<EXPECTED_ELEMENTS-2; i++)
|
||||
sj.add(REPO_ID + "ACS1234");
|
||||
for (int i = 0; i < EXPECTED_ELEMENTS - 2; i++)
|
||||
{
|
||||
sj.add("");
|
||||
}
|
||||
@@ -116,7 +122,7 @@ public class RepositoryClientData {
|
||||
|
||||
public Builder withRepoId(final String version)
|
||||
{
|
||||
clientData.split[REPO_INDEX] = REPO_ID+version;
|
||||
clientData.split[REPO_INDEX] = REPO_ID + version;
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -134,13 +140,13 @@ public class RepositoryClientData {
|
||||
|
||||
public Builder withDebug()
|
||||
{
|
||||
clientData.split[DEBUG_INDEX]=DEBUG;
|
||||
clientData.split[DEBUG_INDEX] = DEBUG;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder withDebugMessage(final String message)
|
||||
{
|
||||
clientData.split[DEBUG_INDEX]=DEBUG+DEBUG_SEPARATOR+message;
|
||||
clientData.split[DEBUG_INDEX] = DEBUG + DEBUG_SEPARATOR + message;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@@ -21,15 +21,16 @@
|
||||
*/
|
||||
package org.alfresco.transform.common;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Map;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import org.alfresco.transform.client.model.InternalContext;
|
||||
import org.alfresco.transform.client.model.TransformReply;
|
||||
import org.alfresco.transform.client.model.TransformRequest;
|
||||
import org.alfresco.transform.messages.TransformStack;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Map;
|
||||
|
||||
public class TransformerDebug
|
||||
{
|
||||
@@ -43,7 +44,7 @@ public class TransformerDebug
|
||||
|
||||
public static final String MIMETYPE_METADATA_EMBED = "alfresco-metadata-embed";
|
||||
|
||||
private static final String TIMEOUT = "timeout";
|
||||
private static final String TIMEOUT = "timeout";
|
||||
|
||||
// For truncating long option values
|
||||
private static final int MAX_OPTION_VALUE = 60;
|
||||
@@ -65,9 +66,10 @@ public class TransformerDebug
|
||||
getMimetypeExt(step.getSourceMediaType()) +
|
||||
getTargetMimetypeExt(step.getTargetMediaType(), step.getSourceMediaType()) + ' ' +
|
||||
(isTopLevel || !isTRouter()
|
||||
? fileSize(request.getSourceSize()) + ' ' +
|
||||
getRenditionName(new RepositoryClientData(request.getClientData()).getRenditionName())
|
||||
: "") +
|
||||
? fileSize(request.getSourceSize()) + ' ' +
|
||||
getRenditionName(new RepositoryClientData(request.getClientData()).getRenditionName())
|
||||
: "")
|
||||
+
|
||||
step.getTransformerName();
|
||||
if (isDebugToBeReturned(repositoryClientData))
|
||||
{
|
||||
@@ -162,7 +164,6 @@ public class TransformerDebug
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void logOptions(String reference, Map<String, String> options)
|
||||
{
|
||||
if (logger.isDebugEnabled() && !isTRouter && options != null && !options.isEmpty())
|
||||
@@ -186,8 +187,8 @@ public class TransformerDebug
|
||||
int len = value.length();
|
||||
if (len > MAX_OPTION_VALUE)
|
||||
{
|
||||
value = value.substring(0, MAX_OPTION_VALUE-MAX_OPTION_DOTS.length()-MAX_OPTION_END_CHARS) +
|
||||
MAX_OPTION_DOTS +value.substring(len-MAX_OPTION_END_CHARS);
|
||||
value = value.substring(0, MAX_OPTION_VALUE - MAX_OPTION_DOTS.length() - MAX_OPTION_END_CHARS) +
|
||||
MAX_OPTION_DOTS + value.substring(len - MAX_OPTION_END_CHARS);
|
||||
}
|
||||
return getPaddedReference(reference) +
|
||||
" " + key + "=\"" + value.replaceAll("\"", "\\\"") + "\"";
|
||||
@@ -277,7 +278,7 @@ public class TransformerDebug
|
||||
else
|
||||
{
|
||||
sb.append(mimetypeExt);
|
||||
sb.append(spaces(4 - mimetypeExt.length())); // Pad to normal max ext (4)
|
||||
sb.append(spaces(4 - mimetypeExt.length())); // Pad to normal max ext (4)
|
||||
}
|
||||
sb.append(' ');
|
||||
return sb.toString();
|
||||
@@ -286,18 +287,18 @@ public class TransformerDebug
|
||||
private String getRenditionName(String renditionName)
|
||||
{
|
||||
return !renditionName.isEmpty()
|
||||
? "-- "+ replaceWithMetadataRenditionNameIfEmbedOrExtract(renditionName)+" -- "
|
||||
? "-- " + replaceWithMetadataRenditionNameIfEmbedOrExtract(renditionName) + " -- "
|
||||
: "";
|
||||
}
|
||||
|
||||
private static String replaceWithMetadataRenditionNameIfEmbedOrExtract(String renditionName)
|
||||
{
|
||||
String transformName = getTransformName(renditionName);
|
||||
return transformName.startsWith(MIMETYPE_METADATA_EXTRACT)
|
||||
return transformName.startsWith(MIMETYPE_METADATA_EXTRACT)
|
||||
? "metadataExtract"
|
||||
: transformName.startsWith(MIMETYPE_METADATA_EMBED)
|
||||
? "metadataEmbed"
|
||||
: renditionName;
|
||||
? "metadataEmbed"
|
||||
: renditionName;
|
||||
}
|
||||
|
||||
private static String getTransformName(String renditionName)
|
||||
@@ -332,9 +333,9 @@ public class TransformerDebug
|
||||
{
|
||||
return "1 byte";
|
||||
}
|
||||
final String[] units = new String[] { "bytes", "KB", "MB", "GB", "TB" };
|
||||
final String[] units = new String[]{"bytes", "KB", "MB", "GB", "TB"};
|
||||
long divider = 1;
|
||||
for(int i = 0; i < units.length-1; i++)
|
||||
for (int i = 0; i < units.length - 1; i++)
|
||||
{
|
||||
long nextDivider = divider * 1024;
|
||||
if (size < nextDivider)
|
||||
@@ -343,7 +344,7 @@ public class TransformerDebug
|
||||
}
|
||||
divider = nextDivider;
|
||||
}
|
||||
return fileSizeFormat(size, divider, units[units.length-1]);
|
||||
return fileSizeFormat(size, divider, units[units.length - 1]);
|
||||
}
|
||||
|
||||
private static String fileSizeFormat(long size, long divider, String unit)
|
||||
@@ -352,7 +353,7 @@ public class TransformerDebug
|
||||
int decimalPoint = (int) size % 10;
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(size/10);
|
||||
sb.append(size / 10);
|
||||
if (decimalPoint != 0)
|
||||
{
|
||||
sb.append(".");
|
||||
|
@@ -31,8 +31,7 @@ public abstract class AbstractTransformOption implements TransformOption
|
||||
private boolean required;
|
||||
|
||||
public AbstractTransformOption()
|
||||
{
|
||||
}
|
||||
{}
|
||||
|
||||
public AbstractTransformOption(boolean required)
|
||||
{
|
||||
@@ -54,8 +53,10 @@ public abstract class AbstractTransformOption implements TransformOption
|
||||
@Override
|
||||
public boolean equals(Object o)
|
||||
{
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
if (this == o)
|
||||
return true;
|
||||
if (o == null || getClass() != o.getClass())
|
||||
return false;
|
||||
AbstractTransformOption that = (AbstractTransformOption) o;
|
||||
return required == that.required;
|
||||
}
|
||||
@@ -70,7 +71,7 @@ public abstract class AbstractTransformOption implements TransformOption
|
||||
public String toString()
|
||||
{
|
||||
return "AbstractTransformOption{" +
|
||||
"required=" + required +
|
||||
'}';
|
||||
"required=" + required +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
@@ -22,7 +22,9 @@
|
||||
package org.alfresco.transform.config;
|
||||
|
||||
/**
|
||||
* Holds information to add new {@link SupportedSourceAndTarget} objects to an existing {@link Transformer}.<p><br>
|
||||
* Holds information to add new {@link SupportedSourceAndTarget} objects to an existing {@link Transformer}.
|
||||
* <p>
|
||||
* <br>
|
||||
*
|
||||
* <pre>
|
||||
* "addSupported": [
|
||||
|
@@ -22,8 +22,9 @@
|
||||
package org.alfresco.transform.config;
|
||||
|
||||
/**
|
||||
* Holds information to overriding existing {@link SupportedSourceAndTarget} objects with new {@code priority} and
|
||||
* {@code maxSourceSizeBytes} values.<p><br>
|
||||
* Holds information to overriding existing {@link SupportedSourceAndTarget} objects with new {@code priority} and {@code maxSourceSizeBytes} values.
|
||||
* <p>
|
||||
* <br>
|
||||
*
|
||||
* <pre>
|
||||
* "overrideSupported" : [
|
||||
|
@@ -22,7 +22,9 @@
|
||||
package org.alfresco.transform.config;
|
||||
|
||||
/**
|
||||
* Holds information about existing {@link SupportedSourceAndTarget} objects that should be removed.<p><br>
|
||||
* Holds information about existing {@link SupportedSourceAndTarget} objects that should be removed.
|
||||
* <p>
|
||||
* <br>
|
||||
*
|
||||
* <pre>
|
||||
* "removeSupported" : [
|
||||
@@ -39,8 +41,9 @@ public class RemoveSupported extends TransformerAndTypes
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return "{"+super.toString()+"}";
|
||||
return "{" + super.toString() + "}";
|
||||
}
|
||||
|
||||
public static Builder builder()
|
||||
{
|
||||
return new Builder();
|
||||
|
@@ -25,19 +25,20 @@ import java.util.Objects;
|
||||
import java.util.StringJoiner;
|
||||
|
||||
/**
|
||||
* Holds information to provide default {@code priority} and / or {@code maxSourceSizeBytes} defaults. In precedence
|
||||
* order from most specific to most general these are defined by combinations of {@code transformerName} and
|
||||
* {@code sourceMediaType}:<p><br>
|
||||
* Holds information to provide default {@code priority} and / or {@code maxSourceSizeBytes} defaults. In precedence order from most specific to most general these are defined by combinations of {@code transformerName} and {@code sourceMediaType}:
|
||||
* <p>
|
||||
* <br>
|
||||
* <ul>
|
||||
* <li><b>transformer and source media type default</b> {@code transformerName} + {@code sourceMediaType}</li>
|
||||
* <li><b>transformer default</b> {@code transformerName}</li>
|
||||
* <li><b>source media type default</b> {@code sourceMediaType}</li>
|
||||
* <li><b>system wide default</b> none</li>
|
||||
* </ul><br>
|
||||
* <li><b>transformer and source media type default</b> {@code transformerName} + {@code sourceMediaType}</li>
|
||||
* <li><b>transformer default</b> {@code transformerName}</li>
|
||||
* <li><b>source media type default</b> {@code sourceMediaType}</li>
|
||||
* <li><b>system wide default</b> none</li>
|
||||
* </ul>
|
||||
* <br>
|
||||
*
|
||||
* Both {@code maxSourceSizeBytes} and {@code priority} may be specified in a {@code "supportedDefaults"} element, but
|
||||
* if only one is specified it is only that value that is being defaulted at the level specified by the combination of
|
||||
* {@code transformerName} and {@code sourceMediaType}.<p><br>
|
||||
* Both {@code maxSourceSizeBytes} and {@code priority} may be specified in a {@code "supportedDefaults"} element, but if only one is specified it is only that value that is being defaulted at the level specified by the combination of {@code transformerName} and {@code sourceMediaType}.
|
||||
* <p>
|
||||
* <br>
|
||||
*
|
||||
* <pre>
|
||||
* "supportedDefaults" : [
|
||||
@@ -110,9 +111,11 @@ public class SupportedDefaults
|
||||
@Override
|
||||
public boolean equals(Object o)
|
||||
{
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
SupportedDefaults that = (SupportedDefaults)o;
|
||||
if (this == o)
|
||||
return true;
|
||||
if (o == null || getClass() != o.getClass())
|
||||
return false;
|
||||
SupportedDefaults that = (SupportedDefaults) o;
|
||||
return Objects.equals(transformerName, that.transformerName) &&
|
||||
Objects.equals(sourceMediaType, that.sourceMediaType) &&
|
||||
Objects.equals(maxSourceSizeBytes, that.maxSourceSizeBytes) &&
|
||||
@@ -129,10 +132,14 @@ public class SupportedDefaults
|
||||
public String toString()
|
||||
{
|
||||
StringJoiner sj = new StringJoiner(", ");
|
||||
if (transformerName != null) sj.add("\"transformerName\": \""+transformerName+'"');
|
||||
if (sourceMediaType != null) sj.add("\"sourceMediaType\": \""+sourceMediaType+'"');
|
||||
if (maxSourceSizeBytes != null) sj.add("\"maxSourceSizeBytes\": \""+maxSourceSizeBytes+'"');
|
||||
if (priority != null) sj.add("\"priority\": \""+priority+'"');
|
||||
if (transformerName != null)
|
||||
sj.add("\"transformerName\": \"" + transformerName + '"');
|
||||
if (sourceMediaType != null)
|
||||
sj.add("\"sourceMediaType\": \"" + sourceMediaType + '"');
|
||||
if (maxSourceSizeBytes != null)
|
||||
sj.add("\"maxSourceSizeBytes\": \"" + maxSourceSizeBytes + '"');
|
||||
if (priority != null)
|
||||
sj.add("\"priority\": \"" + priority + '"');
|
||||
return "{" + sj.toString() + "}";
|
||||
}
|
||||
|
||||
|
@@ -25,8 +25,7 @@ import java.util.Objects;
|
||||
import java.util.StringJoiner;
|
||||
|
||||
/**
|
||||
* Represents a single source and target combination supported by a transformer. Each combination has an optional
|
||||
* maximum size and priority.
|
||||
* Represents a single source and target combination supported by a transformer. Each combination has an optional maximum size and priority.
|
||||
*/
|
||||
public class SupportedSourceAndTarget extends Types
|
||||
{
|
||||
@@ -34,8 +33,7 @@ public class SupportedSourceAndTarget extends Types
|
||||
Integer priority = null;
|
||||
|
||||
public SupportedSourceAndTarget()
|
||||
{
|
||||
}
|
||||
{}
|
||||
|
||||
public Long getMaxSourceSizeBytes()
|
||||
{
|
||||
@@ -60,12 +58,15 @@ public class SupportedSourceAndTarget extends Types
|
||||
@Override
|
||||
public boolean equals(Object o)
|
||||
{
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
if (!super.equals(o)) return false;
|
||||
SupportedSourceAndTarget that = (SupportedSourceAndTarget)o;
|
||||
if (this == o)
|
||||
return true;
|
||||
if (o == null || getClass() != o.getClass())
|
||||
return false;
|
||||
if (!super.equals(o))
|
||||
return false;
|
||||
SupportedSourceAndTarget that = (SupportedSourceAndTarget) o;
|
||||
return Objects.equals(maxSourceSizeBytes, that.maxSourceSizeBytes) &&
|
||||
Objects.equals(priority, that.priority);
|
||||
Objects.equals(priority, that.priority);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -79,9 +80,12 @@ public class SupportedSourceAndTarget extends Types
|
||||
{
|
||||
StringJoiner sj = new StringJoiner(", ");
|
||||
String superToString = super.toString();
|
||||
if (superToString != null) sj.add(superToString);
|
||||
if (maxSourceSizeBytes != null) sj.add("\"maxSourceSizeBytes\": \""+maxSourceSizeBytes+'"');
|
||||
if (priority != null) sj.add("\"priority\": \""+priority+'"');
|
||||
if (superToString != null)
|
||||
sj.add(superToString);
|
||||
if (maxSourceSizeBytes != null)
|
||||
sj.add("\"maxSourceSizeBytes\": \"" + maxSourceSizeBytes + '"');
|
||||
if (priority != null)
|
||||
sj.add("\"priority\": \"" + priority + '"');
|
||||
return "{" + sj.toString() + "}";
|
||||
}
|
||||
|
||||
|
@@ -30,8 +30,7 @@ import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Transform Configuration with multiple {@link Transformer}s and {@link TransformOption}s.
|
||||
* It can be used for one or more Transformers.
|
||||
* Transform Configuration with multiple {@link Transformer}s and {@link TransformOption}s. It can be used for one or more Transformers.
|
||||
*/
|
||||
public class TransformConfig
|
||||
{
|
||||
@@ -122,10 +121,12 @@ public class TransformConfig
|
||||
@Override
|
||||
public boolean equals(Object o)
|
||||
{
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
if (this == o)
|
||||
return true;
|
||||
if (o == null || getClass() != o.getClass())
|
||||
return false;
|
||||
TransformConfig that = (TransformConfig) o;
|
||||
return transformOptions.equals(that.transformOptions) &&
|
||||
return transformOptions.equals(that.transformOptions) &&
|
||||
transformers.equals(that.transformers) &&
|
||||
removeTransformers.equals(that.removeTransformers) &&
|
||||
addSupported.equals(that.addSupported) &&
|
||||
@@ -145,9 +146,9 @@ public class TransformConfig
|
||||
public String toString()
|
||||
{
|
||||
return "TransformConfig{" +
|
||||
"transformOptions=" + transformOptions +
|
||||
", transformers=" + transformers +
|
||||
'}';
|
||||
"transformOptions=" + transformOptions +
|
||||
", transformers=" + transformers +
|
||||
'}';
|
||||
}
|
||||
|
||||
public static Builder builder()
|
||||
@@ -159,7 +160,8 @@ public class TransformConfig
|
||||
{
|
||||
private final TransformConfig transformConfig = new TransformConfig();
|
||||
|
||||
private Builder() {}
|
||||
private Builder()
|
||||
{}
|
||||
|
||||
public TransformConfig build()
|
||||
{
|
||||
|
@@ -28,9 +28,9 @@ import com.fasterxml.jackson.annotation.JsonTypeInfo;
|
||||
* Represents an individual transformer option or group of options that are required or optional (default).
|
||||
*/
|
||||
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME,
|
||||
include = JsonTypeInfo.As.WRAPPER_OBJECT)
|
||||
include = JsonTypeInfo.As.WRAPPER_OBJECT)
|
||||
@JsonSubTypes({@JsonSubTypes.Type(value = TransformOptionValue.class, name = "value"),
|
||||
@JsonSubTypes.Type(value = TransformOptionGroup.class, name = "group")})
|
||||
@JsonSubTypes.Type(value = TransformOptionGroup.class, name = "group")})
|
||||
public interface TransformOption
|
||||
{
|
||||
boolean isRequired();
|
||||
|
@@ -26,9 +26,7 @@ import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* 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.
|
||||
*
|
||||
* In a pipeline transformation, a group of options
|
||||
*/
|
||||
@@ -37,8 +35,7 @@ public class TransformOptionGroup extends AbstractTransformOption
|
||||
private Set<TransformOption> transformOptions = new HashSet<>();
|
||||
|
||||
public TransformOptionGroup()
|
||||
{
|
||||
}
|
||||
{}
|
||||
|
||||
public TransformOptionGroup(boolean required, Set<TransformOption> transformOptions)
|
||||
{
|
||||
@@ -59,9 +56,12 @@ public class TransformOptionGroup extends AbstractTransformOption
|
||||
@Override
|
||||
public boolean equals(Object o)
|
||||
{
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
if (!super.equals(o)) return false;
|
||||
if (this == o)
|
||||
return true;
|
||||
if (o == null || getClass() != o.getClass())
|
||||
return false;
|
||||
if (!super.equals(o))
|
||||
return false;
|
||||
TransformOptionGroup that = (TransformOptionGroup) o;
|
||||
return Objects.equals(transformOptions, that.transformOptions);
|
||||
}
|
||||
@@ -76,7 +76,7 @@ public class TransformOptionGroup extends AbstractTransformOption
|
||||
public String toString()
|
||||
{
|
||||
return "TransformOptionGroup{" +
|
||||
"transformOptions=" + transformOptions +
|
||||
'}';
|
||||
"transformOptions=" + transformOptions +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -31,8 +31,7 @@ public class TransformOptionValue extends AbstractTransformOption
|
||||
private String name;
|
||||
|
||||
public TransformOptionValue()
|
||||
{
|
||||
}
|
||||
{}
|
||||
|
||||
public TransformOptionValue(boolean required, String name)
|
||||
{
|
||||
@@ -53,9 +52,12 @@ public class TransformOptionValue extends AbstractTransformOption
|
||||
@Override
|
||||
public boolean equals(Object o)
|
||||
{
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
if (!super.equals(o)) return false;
|
||||
if (this == o)
|
||||
return true;
|
||||
if (o == null || getClass() != o.getClass())
|
||||
return false;
|
||||
if (!super.equals(o))
|
||||
return false;
|
||||
TransformOptionValue that = (TransformOptionValue) o;
|
||||
return Objects.equals(name, that.name);
|
||||
}
|
||||
@@ -70,7 +72,7 @@ public class TransformOptionValue extends AbstractTransformOption
|
||||
public String toString()
|
||||
{
|
||||
return "TransformOptionValue{" +
|
||||
"name='" + name + '\'' +
|
||||
'}';
|
||||
"name='" + name + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
@@ -24,8 +24,7 @@ package org.alfresco.transform.config;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* 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
|
||||
{
|
||||
@@ -33,8 +32,7 @@ public class TransformStep
|
||||
private String targetMediaType;
|
||||
|
||||
public TransformStep()
|
||||
{
|
||||
}
|
||||
{}
|
||||
|
||||
public TransformStep(String transformerName, String targetMediaType)
|
||||
{
|
||||
@@ -65,11 +63,13 @@ public class TransformStep
|
||||
@Override
|
||||
public boolean equals(Object o)
|
||||
{
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
if (this == o)
|
||||
return true;
|
||||
if (o == null || getClass() != o.getClass())
|
||||
return false;
|
||||
TransformStep that = (TransformStep) o;
|
||||
return Objects.equals(transformerName, that.transformerName) &&
|
||||
Objects.equals(targetMediaType, that.targetMediaType);
|
||||
Objects.equals(targetMediaType, that.targetMediaType);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -82,8 +82,8 @@ public class TransformStep
|
||||
public String toString()
|
||||
{
|
||||
return "TransformStep{" +
|
||||
"transformerName='" + transformerName + '\'' +
|
||||
", targetMediaType='" + targetMediaType + '\'' +
|
||||
'}';
|
||||
"transformerName='" + transformerName + '\'' +
|
||||
", targetMediaType='" + targetMediaType + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
@@ -21,37 +21,24 @@
|
||||
*/
|
||||
package org.alfresco.transform.config;
|
||||
|
||||
import org.alfresco.transform.registry.TransformServiceRegistry;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
import org.alfresco.transform.registry.TransformServiceRegistry;
|
||||
|
||||
/**
|
||||
* 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, a pipeline of multiple transformers or a list
|
||||
* of failover transforms. 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 service. As a result clients have a simple generic view of 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.
|
||||
* 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, a pipeline of multiple transformers or a list of failover transforms. 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 service. As a result clients have a simple generic view of 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.
|
||||
* <ul>
|
||||
* <li>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.</lI>
|
||||
* <li>transformOptions - a grouping of individual transformer transformOptions. The group may be optional and may
|
||||
* contain nested transformOptions.</li>
|
||||
* <li>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.</lI>
|
||||
* <li>transformOptions - a grouping of individual transformer transformOptions. The group may be optional and may contain nested transformOptions.</li>
|
||||
* </ul>
|
||||
* For local transforms, this structure is extended when defining a pipeline transform and failover transform.
|
||||
* <ul>
|
||||
* <li>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.</li>
|
||||
* <li>transformerFailover - an array of failover definitions used in case of a fail transformation to pass a document
|
||||
* to a sequence of transforms until one succeeds.</li>
|
||||
* <li>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.</li>
|
||||
* <li>transformerFailover - an array of failover definitions used in case of a fail transformation to pass a document to a sequence of transforms until one succeeds.</li>
|
||||
* <li>coreVersion - indicates the version of the T-Engine's base. See {@link CoreVersionDecorator} for more detail.</li>
|
||||
* </ul>
|
||||
*/
|
||||
@@ -65,11 +52,10 @@ public class Transformer
|
||||
private List<String> transformerFailover = new ArrayList<>();
|
||||
|
||||
public Transformer()
|
||||
{
|
||||
}
|
||||
{}
|
||||
|
||||
public Transformer(String transformerName, Set<String> transformOptions,
|
||||
Set<SupportedSourceAndTarget> supportedSourceAndTargetList)
|
||||
Set<SupportedSourceAndTarget> supportedSourceAndTargetList)
|
||||
{
|
||||
this.transformerName = transformerName;
|
||||
this.transformOptions = transformOptions;
|
||||
@@ -77,16 +63,16 @@ public class Transformer
|
||||
}
|
||||
|
||||
public Transformer(String transformerName, Set<String> transformOptions,
|
||||
Set<SupportedSourceAndTarget> supportedSourceAndTargetList,
|
||||
List<TransformStep> transformerPipeline)
|
||||
Set<SupportedSourceAndTarget> supportedSourceAndTargetList,
|
||||
List<TransformStep> transformerPipeline)
|
||||
{
|
||||
this(transformerName, transformOptions, supportedSourceAndTargetList);
|
||||
this.transformerPipeline = transformerPipeline;
|
||||
}
|
||||
|
||||
public Transformer(String transformerName, Set<String> transformOptions,
|
||||
Set<SupportedSourceAndTarget> supportedSourceAndTargetList,
|
||||
List<TransformStep> transformerPipeline, List<String> transformerFailover)
|
||||
Set<SupportedSourceAndTarget> supportedSourceAndTargetList,
|
||||
List<TransformStep> transformerPipeline, List<String> transformerFailover)
|
||||
{
|
||||
this(transformerName, transformOptions, supportedSourceAndTargetList, transformerPipeline);
|
||||
this.transformerFailover = transformerFailover;
|
||||
@@ -148,7 +134,7 @@ public class Transformer
|
||||
}
|
||||
|
||||
public void setSupportedSourceAndTargetList(
|
||||
Set<SupportedSourceAndTarget> supportedSourceAndTargetList)
|
||||
Set<SupportedSourceAndTarget> supportedSourceAndTargetList)
|
||||
{
|
||||
this.supportedSourceAndTargetList = supportedSourceAndTargetList == null ? new HashSet<>() : supportedSourceAndTargetList;
|
||||
}
|
||||
@@ -156,36 +142,38 @@ public class Transformer
|
||||
@Override
|
||||
public boolean equals(Object o)
|
||||
{
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
if (this == o)
|
||||
return true;
|
||||
if (o == null || getClass() != o.getClass())
|
||||
return false;
|
||||
Transformer that = (Transformer) o;
|
||||
return Objects.equals(transformerName, that.transformerName) &&
|
||||
Objects.equals(coreVersion, that.coreVersion) &&
|
||||
Objects.equals(transformerPipeline, that.transformerPipeline) &&
|
||||
Objects.equals(transformerFailover, that.transformerFailover) &&
|
||||
Objects.equals(transformOptions, that.transformOptions) &&
|
||||
Objects.equals(supportedSourceAndTargetList,
|
||||
that.supportedSourceAndTargetList);
|
||||
Objects.equals(coreVersion, that.coreVersion) &&
|
||||
Objects.equals(transformerPipeline, that.transformerPipeline) &&
|
||||
Objects.equals(transformerFailover, that.transformerFailover) &&
|
||||
Objects.equals(transformOptions, that.transformOptions) &&
|
||||
Objects.equals(supportedSourceAndTargetList,
|
||||
that.supportedSourceAndTargetList);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
return Objects.hash(transformerName, coreVersion, transformerPipeline, transformerFailover, transformOptions,
|
||||
supportedSourceAndTargetList);
|
||||
supportedSourceAndTargetList);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return "Transformer{" +
|
||||
"transformerName='" + transformerName + '\'' +
|
||||
", coreVersion=" + coreVersion +
|
||||
", transformerPipeline=" + transformerPipeline +
|
||||
", transformerFailover=" + transformerFailover +
|
||||
", transformOptions=" + transformOptions +
|
||||
", supportedSourceAndTargetList=" + supportedSourceAndTargetList +
|
||||
'}';
|
||||
"transformerName='" + transformerName + '\'' +
|
||||
", coreVersion=" + coreVersion +
|
||||
", transformerPipeline=" + transformerPipeline +
|
||||
", transformerFailover=" + transformerFailover +
|
||||
", transformOptions=" + transformOptions +
|
||||
", supportedSourceAndTargetList=" + supportedSourceAndTargetList +
|
||||
'}';
|
||||
}
|
||||
|
||||
public static Builder builder()
|
||||
@@ -197,7 +185,8 @@ public class Transformer
|
||||
{
|
||||
private final Transformer transformer = new Transformer();
|
||||
|
||||
private Builder() {}
|
||||
private Builder()
|
||||
{}
|
||||
|
||||
public Transformer build()
|
||||
{
|
||||
@@ -235,7 +224,7 @@ public class Transformer
|
||||
}
|
||||
|
||||
public Builder withSupportedSourceAndTargetList(
|
||||
final Set<SupportedSourceAndTarget> supportedSourceAndTargetList)
|
||||
final Set<SupportedSourceAndTarget> supportedSourceAndTargetList)
|
||||
{
|
||||
transformer.supportedSourceAndTargetList = supportedSourceAndTargetList;
|
||||
return this;
|
||||
|
@@ -25,14 +25,14 @@ import java.util.Objects;
|
||||
import java.util.StringJoiner;
|
||||
|
||||
/**
|
||||
* Base object with {@code transformerName}, {@code sourceMediaType}and {@code targetMediaType}.
|
||||
* Used to identify supported transforms.
|
||||
* Base object with {@code transformerName}, {@code sourceMediaType}and {@code targetMediaType}. Used to identify supported transforms.
|
||||
*/
|
||||
public abstract class TransformerAndTypes extends Types
|
||||
{
|
||||
String transformerName;
|
||||
|
||||
protected TransformerAndTypes() {}
|
||||
protected TransformerAndTypes()
|
||||
{}
|
||||
|
||||
public String getTransformerName()
|
||||
{
|
||||
@@ -47,11 +47,14 @@ public abstract class TransformerAndTypes extends Types
|
||||
@Override
|
||||
public boolean equals(Object o)
|
||||
{
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
if (!super.equals(o)) return false;
|
||||
if (this == o)
|
||||
return true;
|
||||
if (o == null || getClass() != o.getClass())
|
||||
return false;
|
||||
if (!super.equals(o))
|
||||
return false;
|
||||
TransformerAndTypes that = (TransformerAndTypes) o;
|
||||
return Objects.equals(transformerName, that.transformerName);
|
||||
return Objects.equals(transformerName, that.transformerName);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -65,8 +68,10 @@ public abstract class TransformerAndTypes extends Types
|
||||
{
|
||||
StringJoiner sj = new StringJoiner(", ");
|
||||
String superToString = super.toString();
|
||||
if (transformerName != null) sj.add("\"transformerName\": \""+transformerName+'"');
|
||||
if (superToString != null) sj.add(superToString);
|
||||
if (transformerName != null)
|
||||
sj.add("\"transformerName\": \"" + transformerName + '"');
|
||||
if (superToString != null)
|
||||
sj.add(superToString);
|
||||
return sj.toString();
|
||||
}
|
||||
|
||||
@@ -84,7 +89,7 @@ public abstract class TransformerAndTypes extends Types
|
||||
public B withTransformerName(final String transformerName)
|
||||
{
|
||||
t.transformerName = transformerName;
|
||||
return (B)this;
|
||||
return (B) this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -25,15 +25,15 @@ import java.util.Objects;
|
||||
import java.util.StringJoiner;
|
||||
|
||||
/**
|
||||
* Base object with {@code transformerName}, {@code sourceMediaType}, {@code targetMediaType},
|
||||
* {@code maxSourceSizeBytes} and {@code priority}.
|
||||
* Base object with {@code transformerName}, {@code sourceMediaType}, {@code targetMediaType}, {@code maxSourceSizeBytes} and {@code priority}.
|
||||
*/
|
||||
public abstract class TransformerTypesSizeAndPriority extends TransformerAndTypes
|
||||
{
|
||||
Long maxSourceSizeBytes = null;
|
||||
Integer priority = null;
|
||||
|
||||
protected TransformerTypesSizeAndPriority() {}
|
||||
protected TransformerTypesSizeAndPriority()
|
||||
{}
|
||||
|
||||
public Long getMaxSourceSizeBytes()
|
||||
{
|
||||
@@ -58,11 +58,14 @@ public abstract class TransformerTypesSizeAndPriority extends TransformerAndType
|
||||
@Override
|
||||
public boolean equals(Object o)
|
||||
{
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
if (!super.equals(o)) return false;
|
||||
TransformerTypesSizeAndPriority that = (TransformerTypesSizeAndPriority)o;
|
||||
return getMaxSourceSizeBytes().equals(that.getMaxSourceSizeBytes()) &&
|
||||
if (this == o)
|
||||
return true;
|
||||
if (o == null || getClass() != o.getClass())
|
||||
return false;
|
||||
if (!super.equals(o))
|
||||
return false;
|
||||
TransformerTypesSizeAndPriority that = (TransformerTypesSizeAndPriority) o;
|
||||
return getMaxSourceSizeBytes().equals(that.getMaxSourceSizeBytes()) &&
|
||||
getPriority() == that.getPriority();
|
||||
}
|
||||
|
||||
@@ -77,10 +80,13 @@ public abstract class TransformerTypesSizeAndPriority extends TransformerAndType
|
||||
{
|
||||
StringJoiner sj = new StringJoiner(", ");
|
||||
String superToString = super.toString();
|
||||
if (superToString != null) sj.add(superToString);
|
||||
if (maxSourceSizeBytes != null) sj.add("\"maxSourceSizeBytes\": \""+maxSourceSizeBytes+'"');
|
||||
if (priority != null) sj.add("\"priority\": \""+priority+'"');
|
||||
return "{"+sj.toString()+"}";
|
||||
if (superToString != null)
|
||||
sj.add(superToString);
|
||||
if (maxSourceSizeBytes != null)
|
||||
sj.add("\"maxSourceSizeBytes\": \"" + maxSourceSizeBytes + '"');
|
||||
if (priority != null)
|
||||
sj.add("\"priority\": \"" + priority + '"');
|
||||
return "{" + sj.toString() + "}";
|
||||
}
|
||||
|
||||
public static class Builder<B extends TransformerTypesSizeAndPriority.Builder, T extends TransformerTypesSizeAndPriority>
|
||||
@@ -97,13 +103,13 @@ public abstract class TransformerTypesSizeAndPriority extends TransformerAndType
|
||||
public B withMaxSourceSizeBytes(final long maxSourceSizeBytes)
|
||||
{
|
||||
t.setMaxSourceSizeBytes(maxSourceSizeBytes);
|
||||
return (B)this;
|
||||
return (B) this;
|
||||
}
|
||||
|
||||
public B withPriority(final int priority)
|
||||
{
|
||||
t.setPriority(priority);
|
||||
return (B)this;
|
||||
return (B) this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -25,15 +25,15 @@ import java.util.Objects;
|
||||
import java.util.StringJoiner;
|
||||
|
||||
/**
|
||||
* Base object with {@code sourceMediaType} and {@code targetMediaType}.
|
||||
* Used to identify supported transforms.
|
||||
* Base object with {@code sourceMediaType} and {@code targetMediaType}. Used to identify supported transforms.
|
||||
*/
|
||||
public class Types
|
||||
{
|
||||
String sourceMediaType;
|
||||
String targetMediaType;
|
||||
|
||||
protected Types() {}
|
||||
protected Types()
|
||||
{}
|
||||
|
||||
public String getSourceMediaType()
|
||||
{
|
||||
@@ -58,10 +58,12 @@ public class Types
|
||||
@Override
|
||||
public boolean equals(Object o)
|
||||
{
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
if (this == o)
|
||||
return true;
|
||||
if (o == null || getClass() != o.getClass())
|
||||
return false;
|
||||
Types that = (Types) o;
|
||||
return Objects.equals(sourceMediaType, that.sourceMediaType) &&
|
||||
return Objects.equals(sourceMediaType, that.sourceMediaType) &&
|
||||
Objects.equals(targetMediaType, that.targetMediaType);
|
||||
}
|
||||
|
||||
@@ -75,8 +77,10 @@ public class Types
|
||||
public String toString()
|
||||
{
|
||||
StringJoiner sj = new StringJoiner(", ");
|
||||
if (sourceMediaType != null) sj.add("\"sourceMediaType\": \""+sourceMediaType+'"');
|
||||
if (targetMediaType != null) sj.add("\"targetMediaType\": \""+targetMediaType+'"');
|
||||
if (sourceMediaType != null)
|
||||
sj.add("\"sourceMediaType\": \"" + sourceMediaType + '"');
|
||||
if (targetMediaType != null)
|
||||
sj.add("\"targetMediaType\": \"" + targetMediaType + '"');
|
||||
return sj.toString();
|
||||
}
|
||||
|
||||
@@ -91,19 +95,19 @@ public class Types
|
||||
|
||||
public T build()
|
||||
{
|
||||
return (T)t;
|
||||
return (T) t;
|
||||
}
|
||||
|
||||
public B withSourceMediaType(final String sourceMediaType)
|
||||
{
|
||||
t.sourceMediaType = sourceMediaType;
|
||||
return (B)this;
|
||||
return (B) this;
|
||||
}
|
||||
|
||||
public B withTargetMediaType(final String targetMediaType)
|
||||
{
|
||||
t.targetMediaType = targetMediaType;
|
||||
return (B)this;
|
||||
return (B) this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -21,10 +21,10 @@
|
||||
*/
|
||||
package org.alfresco.transform.config.reader;
|
||||
|
||||
import org.alfresco.transform.config.TransformConfig;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.alfresco.transform.config.TransformConfig;
|
||||
|
||||
public interface TransformConfigReader
|
||||
{
|
||||
TransformConfig load() throws IOException;
|
||||
|
@@ -28,8 +28,7 @@ import org.springframework.core.io.Resource;
|
||||
public class TransformConfigReaderFactory
|
||||
{
|
||||
private TransformConfigReaderFactory()
|
||||
{
|
||||
}
|
||||
{}
|
||||
|
||||
public static TransformConfigReader create(final Resource resource)
|
||||
{
|
||||
@@ -44,7 +43,7 @@ public class TransformConfigReaderFactory
|
||||
{
|
||||
case "properties":
|
||||
throw new UnsupportedOperationException(".properties configuration files are no longer " +
|
||||
"supported: " + fileName);
|
||||
"supported: " + fileName);
|
||||
case "yaml":
|
||||
case "yml":
|
||||
return new TransformConfigReaderYaml(resource);
|
||||
|
@@ -1,47 +1,47 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Transform Model
|
||||
* %%
|
||||
* Copyright (C) 2015 - 2022 Alfresco Software Limited
|
||||
* %%
|
||||
* This program 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.
|
||||
*
|
||||
* This program 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 General Lesser Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Lesser Public
|
||||
* License along with this program. If not, see
|
||||
* <http://www.gnu.org/licenses/lgpl-3.0.html>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.transform.config.reader;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.alfresco.transform.config.TransformConfig;
|
||||
import org.springframework.core.io.Resource;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
public class TransformConfigReaderJson implements TransformConfigReader
|
||||
{
|
||||
private static final ObjectMapper MAPPER= new ObjectMapper();
|
||||
|
||||
private final Resource resource;
|
||||
|
||||
TransformConfigReaderJson(final Resource resource)
|
||||
{
|
||||
this.resource = resource;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TransformConfig load() throws IOException
|
||||
{
|
||||
return MAPPER.readValue(resource.getInputStream(), TransformConfig.class);
|
||||
}
|
||||
}
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Transform Model
|
||||
* %%
|
||||
* Copyright (C) 2015 - 2022 Alfresco Software Limited
|
||||
* %%
|
||||
* This program 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.
|
||||
*
|
||||
* This program 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 General Lesser Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Lesser Public
|
||||
* License along with this program. If not, see
|
||||
* <http://www.gnu.org/licenses/lgpl-3.0.html>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.transform.config.reader;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.springframework.core.io.Resource;
|
||||
|
||||
import org.alfresco.transform.config.TransformConfig;
|
||||
|
||||
public class TransformConfigReaderJson implements TransformConfigReader
|
||||
{
|
||||
private static final ObjectMapper MAPPER = new ObjectMapper();
|
||||
|
||||
private final Resource resource;
|
||||
|
||||
TransformConfigReaderJson(final Resource resource)
|
||||
{
|
||||
this.resource = resource;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TransformConfig load() throws IOException
|
||||
{
|
||||
return MAPPER.readValue(resource.getInputStream(), TransformConfig.class);
|
||||
}
|
||||
}
|
||||
|
@@ -23,11 +23,11 @@ package org.alfresco.transform.config.reader;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.alfresco.transform.config.TransformConfig;
|
||||
import org.springframework.core.io.Resource;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
|
||||
import org.springframework.core.io.Resource;
|
||||
|
||||
import org.alfresco.transform.config.TransformConfig;
|
||||
|
||||
public class TransformConfigReaderYaml implements TransformConfigReader
|
||||
{
|
||||
|
@@ -26,27 +26,30 @@
|
||||
*/
|
||||
package org.alfresco.transform.config.reader;
|
||||
|
||||
import org.alfresco.transform.exceptions.TransformException;
|
||||
import org.alfresco.transform.config.TransformConfig;
|
||||
import static org.springframework.http.HttpStatus.INTERNAL_SERVER_ERROR;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.core.io.ResourceLoader;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import static org.springframework.http.HttpStatus.INTERNAL_SERVER_ERROR;
|
||||
import org.alfresco.transform.config.TransformConfig;
|
||||
import org.alfresco.transform.exceptions.TransformException;
|
||||
|
||||
/**
|
||||
* Reads {@link TransformConfig} from json or yaml files. Typically used by {@code TransformEngine.getTransformConfig()}.
|
||||
*
|
||||
* <pre>
|
||||
* transformConfigResourceReader.read("classpath:pdfrenderer_engine_config.json");
|
||||
* transformConfigResourceReader.read("classpath:pdfrenderer_engine_config.json");
|
||||
* </pre>
|
||||
*/
|
||||
@Component
|
||||
public class TransformConfigResourceReader
|
||||
{
|
||||
@Autowired ResourceLoader resourceLoader;
|
||||
@Autowired
|
||||
ResourceLoader resourceLoader;
|
||||
|
||||
public TransformConfig read(String resourcePath)
|
||||
{
|
||||
|
@@ -21,10 +21,11 @@
|
||||
*/
|
||||
package org.alfresco.transform.messages;
|
||||
|
||||
import org.alfresco.transform.client.model.TransformRequest;
|
||||
import org.springframework.validation.Errors;
|
||||
import org.springframework.validation.Validator;
|
||||
|
||||
import org.alfresco.transform.client.model.TransformRequest;
|
||||
|
||||
/**
|
||||
* TransformRequestValidator
|
||||
* <p>
|
||||
@@ -58,36 +59,36 @@ public class TransformRequestValidator implements Validator
|
||||
if (sourceSize == null || sourceSize <= 0)
|
||||
{
|
||||
errors.rejectValue("sourceSize", null,
|
||||
"sourceSize cannot be null or have its value smaller than 0");
|
||||
"sourceSize cannot be null or have its value smaller than 0");
|
||||
}
|
||||
String sourceMediaType = request.getSourceMediaType();
|
||||
if (sourceMediaType == null || sourceMediaType.isEmpty())
|
||||
{
|
||||
errors.rejectValue("sourceMediaType", null,
|
||||
"sourceMediaType cannot be null or empty");
|
||||
"sourceMediaType cannot be null or empty");
|
||||
}
|
||||
String targetMediaType = request.getTargetMediaType();
|
||||
if (targetMediaType == null || targetMediaType.isEmpty())
|
||||
{
|
||||
errors.rejectValue("targetMediaType", null,
|
||||
"targetMediaType cannot be null or empty");
|
||||
"targetMediaType cannot be null or empty");
|
||||
}
|
||||
String targetExtension = request.getTargetExtension();
|
||||
if (targetExtension == null || targetExtension.isEmpty())
|
||||
{
|
||||
errors.rejectValue("targetExtension", null,
|
||||
"targetExtension cannot be null or empty");
|
||||
"targetExtension cannot be null or empty");
|
||||
}
|
||||
String clientData = request.getClientData();
|
||||
if (clientData == null || clientData.isEmpty())
|
||||
{
|
||||
errors.rejectValue("clientData", String.valueOf(request.getSchema()),
|
||||
"clientData cannot be null or empty");
|
||||
"clientData cannot be null or empty");
|
||||
}
|
||||
if (request.getSchema() < 0)
|
||||
{
|
||||
errors.rejectValue("schema", String.valueOf(request.getSchema()),
|
||||
"schema cannot be less than 0");
|
||||
"schema cannot be less than 0");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -21,50 +21,40 @@
|
||||
*/
|
||||
package org.alfresco.transform.messages;
|
||||
|
||||
import org.alfresco.transform.client.model.InternalContext;
|
||||
import org.alfresco.transform.client.model.MultiStep;
|
||||
import org.alfresco.transform.client.model.TransformReply;
|
||||
import org.alfresco.transform.common.TransformerDebug;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.StringJoiner;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import org.alfresco.transform.client.model.InternalContext;
|
||||
import org.alfresco.transform.client.model.MultiStep;
|
||||
import org.alfresco.transform.client.model.TransformReply;
|
||||
import org.alfresco.transform.common.TransformerDebug;
|
||||
|
||||
/**
|
||||
* Represents the current state of a top level transform request in terms of its current nested call stack, which is
|
||||
* the current transform step being performed and what other transform steps are still to be executed in the current
|
||||
* level. This information is encoded in the {@link MultiStep} structure of the
|
||||
* internal context passed between T-Router and T-Engines. Ideally we would have changed the structure,
|
||||
* but for backward compatibility we are using the existing structure, which allows T-Engines that were developed
|
||||
* previously to be used unchanged.<p><br/>
|
||||
* Represents the current state of a top level transform request in terms of its current nested call stack, which is the current transform step being performed and what other transform steps are still to be executed in the current level. This information is encoded in the {@link MultiStep} structure of the internal context passed between T-Router and T-Engines. Ideally we would have changed the structure, but for backward compatibility we are using the existing structure, which allows T-Engines that were developed previously to be used unchanged.
|
||||
* <p>
|
||||
* <br/>
|
||||
*
|
||||
* Originally the T-Router only allowed pipeline and single step transforms, so it was possible to represent them as a
|
||||
* flat list. However the original design was of a nested structure. Pipelines are just one example, with failover
|
||||
* transforms being the other. To bring the T-Router up to the same level of functionality as the Repository, it too
|
||||
* needs to support nested transforms. <p><br/>
|
||||
* Originally the T-Router only allowed pipeline and single step transforms, so it was possible to represent them as a flat list. However the original design was of a nested structure. Pipelines are just one example, with failover transforms being the other. To bring the T-Router up to the same level of functionality as the Repository, it too needs to support nested transforms.
|
||||
* <p>
|
||||
* <br/>
|
||||
*
|
||||
* <li>@{code transformsToBeDone[0]} holds the original Transformer Request Options as a list of key values pairs.
|
||||
* Needed so that we don't lose values as we walk down the individual transform steps</li>
|
||||
* <li>@{code transformsToBeDone[1]} holds the original source reference so that we don't delete the original source
|
||||
* until the whole transform is known to be successful, so that a queue entry may be retried on failure.</li>
|
||||
* <li>@{code transformsToBeDone[0]} holds the original Transformer Request Options as a list of key values pairs. Needed so that we don't lose values as we walk down the individual transform steps</li>
|
||||
* <li>@{code transformsToBeDone[1]} holds the original source reference so that we don't delete the original source until the whole transform is known to be successful, so that a queue entry may be retried on failure.</li>
|
||||
* <li>@{code transformsToBeDone[2]} holds information about the top level transform</li>
|
||||
* <li>@{code transformsToBeDone[size()-1]} holds information about the most nested transform being processed</li>
|
||||
* <li>Each level contains a list of step transforms. Just one for a singe step transform or a list for pipeline and
|
||||
* failover transforms</li>
|
||||
* <li>When a step is processed it will result in the creation of another level if it is a pipeline or failover
|
||||
* transform</li>
|
||||
* <li>Each level contains a list of step transforms. Just one for a singe step transform or a list for pipeline and failover transforms</li>
|
||||
* <li>When a step is processed it will result in the creation of another level if it is a pipeline or failover transform</li>
|
||||
* <li>As steps are completed, they are removed</li>
|
||||
* <li>When there are no steps left in a level the level is removed</li>
|
||||
*
|
||||
* Each level is represented by a String with a pipeline or failover flag @{code 'P'|'F'} followed by a step counter
|
||||
* and start time used in debug, a retry count and a sequence of transform steps. Each step is made up of three parts:
|
||||
* @{code<transformerName>|<sourceMimetype>|<targetMimetype> . All fields are separated by a @code{'\u23D0'} character.
|
||||
* The last step in the sequence is the current transform being performed. The top level transform is a pipeline of
|
||||
* one step. Although the source and target mimetypes are always the same for failover transforms, they use the same
|
||||
* structure.
|
||||
* Each level is represented by a String with a pipeline or failover flag @{code 'P'|'F'} followed by a step counter and start time used in debug, a retry count and a sequence of transform steps. Each step is made up of three parts:
|
||||
*
|
||||
* @{code<transformerName>|<sourceMimetype>|<targetMimetype> . All fields are separated by a @code{'\u23D0'} character. The last step in the sequence is the current transform being performed. The top level transform is a pipeline of one step. Although the source and target mimetypes are always the same for failover transforms, they use the same structure.
|
||||
*/
|
||||
public class TransformStack
|
||||
{
|
||||
@@ -84,7 +74,7 @@ public class TransformStack
|
||||
private static final int RETRY_INDEX = 3;
|
||||
|
||||
private static final int FIELDS_IN_HEADER = 4; // flag | counter | retry
|
||||
private static final int FIELDS_PER_STEP = 3; // name | source | target
|
||||
private static final int FIELDS_PER_STEP = 3; // name | source | target
|
||||
|
||||
public static LevelBuilder levelBuilder(String flag)
|
||||
{
|
||||
@@ -116,7 +106,7 @@ public class TransformStack
|
||||
stringJoiner.add("1");
|
||||
stringJoiner.add("0");
|
||||
stringJoiner.add("0");
|
||||
for (int i=reverseOrderStepElements.size()-1; i>=0; i--)
|
||||
for (int i = reverseOrderStepElements.size() - 1; i >= 0; i--)
|
||||
{
|
||||
stringJoiner.add(reverseOrderStepElements.get(i));
|
||||
}
|
||||
@@ -150,11 +140,11 @@ public class TransformStack
|
||||
}
|
||||
|
||||
public static void setInitialTransformRequestOptions(InternalContext internalContext,
|
||||
Map<String, String> transformRequestOptions)
|
||||
Map<String, String> transformRequestOptions)
|
||||
{
|
||||
init(internalContext);
|
||||
StringJoiner sj = new StringJoiner(SEPARATOR);
|
||||
transformRequestOptions.forEach((key,value)-> sj.add(key).add(value));
|
||||
transformRequestOptions.forEach((key, value) -> sj.add(key).add(value));
|
||||
levels(internalContext).set(OPTIONS_LEVEL, sj.toString());
|
||||
}
|
||||
|
||||
@@ -170,13 +160,13 @@ public class TransformStack
|
||||
|
||||
// To avoid the case where split() discards the last value, when it is a zero length string, we add and remove
|
||||
// a space. None of the keys or value may be null.
|
||||
String[] split = (level(internalContext, OPTIONS_LEVEL)+' ').split(SEPARATOR_REGEX);
|
||||
String[] split = (level(internalContext, OPTIONS_LEVEL) + ' ').split(SEPARATOR_REGEX);
|
||||
String lastValue = split[split.length - 1];
|
||||
split[split.length-1] = lastValue.substring(0, lastValue.length()-1);
|
||||
split[split.length - 1] = lastValue.substring(0, lastValue.length() - 1);
|
||||
|
||||
for (int i = split.length-2; i >= 0; i-=2)
|
||||
for (int i = split.length - 2; i >= 0; i -= 2)
|
||||
{
|
||||
transformRequestOptions.put(split[i], split[i+1]);
|
||||
transformRequestOptions.put(split[i], split[i + 1]);
|
||||
}
|
||||
return transformRequestOptions;
|
||||
}
|
||||
@@ -198,7 +188,7 @@ public class TransformStack
|
||||
|
||||
private static void init(InternalContext internalContext)
|
||||
{
|
||||
while(levels(internalContext).size() < TOP_STACK_LEVEL)
|
||||
while (levels(internalContext).size() < TOP_STACK_LEVEL)
|
||||
{
|
||||
levels(internalContext).add(null);
|
||||
}
|
||||
@@ -220,9 +210,9 @@ public class TransformStack
|
||||
{
|
||||
|
||||
int levelsLeft = levels(internalContext).size() - TOP_STACK_LEVEL;
|
||||
return levelsLeft <= 0 || // there has been an error, so we have lost the stack
|
||||
return levelsLeft <= 0 || // there has been an error, so we have lost the stack
|
||||
levelsLeft == 1 && // on top level wrapper level
|
||||
isTransformLevelFinished(internalContext); // the one step has been processed (removed)
|
||||
isTransformLevelFinished(internalContext); // the one step has been processed (removed)
|
||||
|
||||
}
|
||||
|
||||
@@ -238,7 +228,7 @@ public class TransformStack
|
||||
|
||||
public static void incrementReference(InternalContext internalContext)
|
||||
{
|
||||
setHeaderField(internalContext, REFERENCE_INDEX, Integer.toString(getReferenceCounter(internalContext)+1));
|
||||
setHeaderField(internalContext, REFERENCE_INDEX, Integer.toString(getReferenceCounter(internalContext) + 1));
|
||||
}
|
||||
|
||||
public static void resetAttemptedRetries(InternalContext internalContext)
|
||||
@@ -253,7 +243,7 @@ public class TransformStack
|
||||
|
||||
public static void incrementAttemptedRetries(InternalContext internalContext)
|
||||
{
|
||||
setHeaderField(internalContext, RETRY_INDEX,getAttemptedRetries(internalContext)+1);
|
||||
setHeaderField(internalContext, RETRY_INDEX, getAttemptedRetries(internalContext) + 1);
|
||||
}
|
||||
|
||||
private static void setHeaderField(InternalContext internalContext, int index, long value)
|
||||
@@ -265,17 +255,17 @@ public class TransformStack
|
||||
{
|
||||
List<String> levels = levels(internalContext);
|
||||
int size = levels.size();
|
||||
String level = levels.get(size-1);
|
||||
String level = levels.get(size - 1);
|
||||
int j = indexOfField(level, index);
|
||||
int k = level.indexOf(SEPARATOR, j+1);
|
||||
levels.set(size-1, level.substring(0, j) + value + level.substring(k));
|
||||
int k = level.indexOf(SEPARATOR, j + 1);
|
||||
levels.set(size - 1, level.substring(0, j) + value + level.substring(k));
|
||||
}
|
||||
|
||||
public static String getReference(InternalContext internalContext)
|
||||
{
|
||||
StringJoiner ref = new StringJoiner(".");
|
||||
List<String> levels = levels(internalContext);
|
||||
for (int i=TOP_STACK_LEVEL; i<levels.size(); i++)
|
||||
for (int i = TOP_STACK_LEVEL; i < levels.size(); i++)
|
||||
{
|
||||
ref.add(getHeaderFieldString(levels.get(i), REFERENCE_INDEX));
|
||||
}
|
||||
@@ -284,7 +274,7 @@ public class TransformStack
|
||||
|
||||
public static void setReferenceInADummyTopLevelIfUnset(InternalContext internalContext, String reference)
|
||||
{
|
||||
if (!reference.isBlank() && getReference(internalContext).isBlank() ) // When top transform level not set
|
||||
if (!reference.isBlank() && getReference(internalContext).isBlank()) // When top transform level not set
|
||||
{
|
||||
init(internalContext);
|
||||
addTransformLevel(internalContext, levelBuilder(PIPELINE_FLAG));
|
||||
@@ -325,7 +315,7 @@ public class TransformStack
|
||||
public static void removeTransformLevel(InternalContext internalContext)
|
||||
{
|
||||
List<String> levels = levels(internalContext);
|
||||
levels.remove(levels.size()-1);
|
||||
levels.remove(levels.size() - 1);
|
||||
}
|
||||
|
||||
public static void removeRemainingTransformLevels(TransformReply reply, TransformerDebug transformerDebug)
|
||||
@@ -370,7 +360,7 @@ public class TransformStack
|
||||
|
||||
private static int getStepCount(InternalContext internalContext)
|
||||
{
|
||||
return (StringUtils.countMatches(currentLevel(internalContext), SEPARATOR)+1-FIELDS_IN_HEADER)/FIELDS_PER_STEP;
|
||||
return (StringUtils.countMatches(currentLevel(internalContext), SEPARATOR) + 1 - FIELDS_IN_HEADER) / FIELDS_PER_STEP;
|
||||
}
|
||||
|
||||
public static void removeSuccessfulStep(TransformReply reply, TransformerDebug transformerDebug)
|
||||
@@ -384,7 +374,7 @@ public class TransformStack
|
||||
}
|
||||
|
||||
private static void removeFinishedSteps(TransformReply reply, boolean successful,
|
||||
TransformerDebug transformerDebug)
|
||||
TransformerDebug transformerDebug)
|
||||
{
|
||||
TransformStack.removeStep(reply, successful, transformerDebug);
|
||||
|
||||
@@ -414,8 +404,8 @@ public class TransformStack
|
||||
// remove one step as it was a successful pipeline step or an unsuccessful failover step
|
||||
List<String> levels = levels(internalContext);
|
||||
int size = levels.size();
|
||||
String level = levels.get(size-1);
|
||||
levels.set(size-1, level.substring(0,
|
||||
String level = levels.get(size - 1);
|
||||
levels.set(size - 1, level.substring(0,
|
||||
(successfulFailoverStep || unsuccessfulPipelineStep ? indexOfLastStep(level) : indexOfNextStep(level)) - 1));
|
||||
|
||||
if (!isTransformLevelFinished(internalContext))
|
||||
@@ -426,12 +416,12 @@ public class TransformStack
|
||||
|
||||
private static int indexOfNextStep(String level)
|
||||
{
|
||||
int j = level.length()-1;
|
||||
int j = level.length() - 1;
|
||||
for (int i = FIELDS_PER_STEP; i >= 1 && j > 0; i--)
|
||||
{
|
||||
j = level.lastIndexOf(SEPARATOR, j-1);
|
||||
j = level.lastIndexOf(SEPARATOR, j - 1);
|
||||
}
|
||||
return j+1;
|
||||
return j + 1;
|
||||
}
|
||||
|
||||
private static int indexOfLastStep(String level)
|
||||
@@ -444,23 +434,23 @@ public class TransformStack
|
||||
int j = 0;
|
||||
for (int i = n; i >= 1; i--)
|
||||
{
|
||||
j = level.indexOf(SEPARATOR, j+1);
|
||||
j = level.indexOf(SEPARATOR, j + 1);
|
||||
}
|
||||
return j+1;
|
||||
return j + 1;
|
||||
}
|
||||
|
||||
public static String checkStructure(InternalContext internalContext, String type)
|
||||
{
|
||||
// A null value will have been replaced with an empty array, so no need to check for that.
|
||||
String errorMessage = levels(internalContext).size() < (TOP_STACK_LEVEL + 1)
|
||||
? type+" InternalContext did not have the Stack set"
|
||||
? type + " InternalContext did not have the Stack set"
|
||||
: !validTransformOptions(internalContext)
|
||||
? type+" InternalContext did not have the TransformOptions set correctly"
|
||||
: levels(internalContext).size() == 1
|
||||
? type+" InternalContext levels were not set"
|
||||
: !validLevels(levels(internalContext))
|
||||
? type+" InternalContext did not have levels set correctly"
|
||||
: null;
|
||||
? type + " InternalContext did not have the TransformOptions set correctly"
|
||||
: levels(internalContext).size() == 1
|
||||
? type + " InternalContext levels were not set"
|
||||
: !validLevels(levels(internalContext))
|
||||
? type + " InternalContext did not have levels set correctly"
|
||||
: null;
|
||||
return errorMessage;
|
||||
}
|
||||
|
||||
@@ -476,11 +466,11 @@ public class TransformStack
|
||||
return true;
|
||||
}
|
||||
String[] split = keysAndValues.split(SEPARATOR_REGEX);
|
||||
if (split.length%2 != 0)
|
||||
if (split.length % 2 != 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
for (int i = split.length-2; i >= 0; i-=2)
|
||||
for (int i = split.length - 2; i >= 0; i -= 2)
|
||||
{
|
||||
if (split[i].isEmpty())
|
||||
{
|
||||
@@ -492,7 +482,7 @@ public class TransformStack
|
||||
|
||||
private static boolean validLevels(List<String> levels)
|
||||
{
|
||||
for (int i=levels.size()-1; i >=TOP_STACK_LEVEL; i--)
|
||||
for (int i = levels.size() - 1; i >= TOP_STACK_LEVEL; i--)
|
||||
{
|
||||
String level = levels.get(i);
|
||||
if (!validLevel(level))
|
||||
@@ -510,18 +500,19 @@ public class TransformStack
|
||||
return false;
|
||||
}
|
||||
String[] split = level.split(SEPARATOR_REGEX);
|
||||
if (split.length < FIELDS_IN_HEADER+FIELDS_PER_STEP || // must be at least 1 step
|
||||
(split.length-FIELDS_IN_HEADER)%FIELDS_PER_STEP != 0 ||
|
||||
(!PIPELINE_FLAG.equals(split[FLAG_INDEX]) &&
|
||||
!FAILOVER_FLAG.equals(split[FLAG_INDEX])) ||
|
||||
!aValidReference(split[REFERENCE_INDEX]) ||
|
||||
!aPositiveLong(split[START_INDEX]) ||
|
||||
!aPositiveInt(split[RETRY_INDEX]))
|
||||
if (split.length < FIELDS_IN_HEADER + FIELDS_PER_STEP || // must be at least 1 step
|
||||
(split.length - FIELDS_IN_HEADER) % FIELDS_PER_STEP != 0 ||
|
||||
(!PIPELINE_FLAG.equals(split[FLAG_INDEX]) &&
|
||||
!FAILOVER_FLAG.equals(split[FLAG_INDEX]))
|
||||
||
|
||||
!aValidReference(split[REFERENCE_INDEX]) ||
|
||||
!aPositiveLong(split[START_INDEX]) ||
|
||||
!aPositiveInt(split[RETRY_INDEX]))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
for (int i=split.length-1; i>=FIELDS_IN_HEADER; i--)
|
||||
for (int i = split.length - 1; i >= FIELDS_IN_HEADER; i--)
|
||||
{
|
||||
if (split[i].isBlank())
|
||||
{
|
||||
|
@@ -21,35 +21,35 @@
|
||||
*/
|
||||
package org.alfresco.transform.registry;
|
||||
|
||||
import org.alfresco.transform.config.CoreFunction;
|
||||
import org.alfresco.transform.config.TransformOption;
|
||||
import org.alfresco.transform.config.Transformer;
|
||||
import static org.alfresco.transform.registry.TransformRegistryHelper.lookupTransformOptions;
|
||||
import static org.alfresco.transform.registry.TransformRegistryHelper.retrieveTransformListBySize;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.alfresco.transform.registry.TransformRegistryHelper.lookupTransformOptions;
|
||||
import static org.alfresco.transform.registry.TransformRegistryHelper.retrieveTransformListBySize;
|
||||
import org.alfresco.transform.config.CoreFunction;
|
||||
import org.alfresco.transform.config.TransformOption;
|
||||
import org.alfresco.transform.config.Transformer;
|
||||
|
||||
/**
|
||||
* Used to work out if a transformation is supported. Sub classes should implement {@link #getData()} to return an
|
||||
* instance of the {@link TransformCache} class. This allows sub classes to periodically replace the registry's data with newer
|
||||
* values. They may also extend the Data class to include extra fields and methods.
|
||||
* Used to work out if a transformation is supported. Sub classes should implement {@link #getData()} to return an instance of the {@link TransformCache} class. This allows sub classes to periodically replace the registry's data with newer values. They may also extend the Data class to include extra fields and methods.
|
||||
*/
|
||||
public abstract class AbstractTransformRegistry implements TransformServiceRegistry
|
||||
{
|
||||
/**
|
||||
* Logs an error message if there is an error in the configuration.
|
||||
*
|
||||
* @param msg to be logged.
|
||||
* @param msg
|
||||
* to be logged.
|
||||
*/
|
||||
protected abstract void logError(String msg);
|
||||
|
||||
/**
|
||||
* Logs a warning message if there is a problem in the configuration.
|
||||
*
|
||||
* @param msg to be logged.
|
||||
* @param msg
|
||||
* to be logged.
|
||||
*/
|
||||
protected void logWarn(String msg)
|
||||
{
|
||||
@@ -64,70 +64,71 @@ public abstract class AbstractTransformRegistry implements TransformServiceRegis
|
||||
public abstract TransformCache getData();
|
||||
|
||||
/**
|
||||
* Registers a single transformer. This is an internal method called by
|
||||
* {@link CombinedTransformConfig#registerCombinedTransformers(AbstractTransformRegistry)}.
|
||||
* Registers a single transformer. This is an internal method called by {@link CombinedTransformConfig#registerCombinedTransformers(AbstractTransformRegistry)}.
|
||||
*
|
||||
* @param transformer to be registered
|
||||
* @param transformOptions all the transform options
|
||||
* @param baseUrl where the config was be read from. Only needed when it is remote. Is null when local.
|
||||
* Does not need to be a URL. May just be a name.
|
||||
* @param readFrom debug message for log messages, indicating what type of config was read.
|
||||
* @param transformer
|
||||
* to be registered
|
||||
* @param transformOptions
|
||||
* all the transform options
|
||||
* @param baseUrl
|
||||
* where the config was be read from. Only needed when it is remote. Is null when local. Does not need to be a URL. May just be a name.
|
||||
* @param readFrom
|
||||
* debug message for log messages, indicating what type of config was read.
|
||||
*/
|
||||
protected void register(final Transformer transformer,
|
||||
final Map<String, Set<TransformOption>> transformOptions, final String baseUrl,
|
||||
final String readFrom)
|
||||
final Map<String, Set<TransformOption>> transformOptions, final String baseUrl,
|
||||
final String readFrom)
|
||||
{
|
||||
getData().incrementTransformerCount();
|
||||
transformer
|
||||
.getSupportedSourceAndTargetList()
|
||||
.forEach(e -> getData().appendTransform(e.getSourceMediaType(), e.getTargetMediaType(),
|
||||
new SupportedTransform(
|
||||
transformer.getTransformerName(),
|
||||
lookupTransformOptions(transformer.getTransformOptions(), transformOptions,
|
||||
readFrom, this::logError),
|
||||
e.getMaxSourceSizeBytes(),
|
||||
e.getPriority()),
|
||||
transformer.getTransformerName(),
|
||||
transformer.getCoreVersion()));
|
||||
.getSupportedSourceAndTargetList()
|
||||
.forEach(e -> getData().appendTransform(e.getSourceMediaType(), e.getTargetMediaType(),
|
||||
new SupportedTransform(
|
||||
transformer.getTransformerName(),
|
||||
lookupTransformOptions(transformer.getTransformOptions(), transformOptions,
|
||||
readFrom, this::logError),
|
||||
e.getMaxSourceSizeBytes(),
|
||||
e.getPriority()),
|
||||
transformer.getTransformerName(),
|
||||
transformer.getCoreVersion()));
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* 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.
|
||||
* @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.
|
||||
*/
|
||||
@Override
|
||||
public String findTransformerName(final String sourceMimetype, final long sourceSizeInBytes,
|
||||
final String targetMimetype, final Map<String, String> actualOptions,
|
||||
final String renditionName)
|
||||
final String targetMimetype, final Map<String, String> actualOptions,
|
||||
final String renditionName)
|
||||
{
|
||||
return retrieveTransformListBySize(getData(), sourceMimetype, targetMimetype, actualOptions,
|
||||
renditionName)
|
||||
.stream()
|
||||
.filter(t -> t.getMaxSourceSizeBytes() == -1 ||
|
||||
t.getMaxSourceSizeBytes() >= sourceSizeInBytes)
|
||||
.findFirst()
|
||||
.map(SupportedTransform::getName)
|
||||
.orElse(null);
|
||||
renditionName)
|
||||
.stream()
|
||||
.filter(t -> t.getMaxSourceSizeBytes() == -1 ||
|
||||
t.getMaxSourceSizeBytes() >= sourceSizeInBytes)
|
||||
.findFirst()
|
||||
.map(SupportedTransform::getName)
|
||||
.orElse(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long findMaxSize(final String sourceMimetype, final String targetMimetype,
|
||||
final Map<String, String> actualOptions, final String renditionName)
|
||||
final Map<String, String> actualOptions, final String renditionName)
|
||||
{
|
||||
final List<SupportedTransform> supportedTransforms = retrieveTransformListBySize(getData(),
|
||||
sourceMimetype, targetMimetype, actualOptions, renditionName);
|
||||
return supportedTransforms.isEmpty() ? 0 :
|
||||
supportedTransforms.get(supportedTransforms.size() - 1).getMaxSourceSizeBytes();
|
||||
sourceMimetype, targetMimetype, actualOptions, renditionName);
|
||||
return supportedTransforms.isEmpty() ? 0 : supportedTransforms.get(supportedTransforms.size() - 1).getMaxSourceSizeBytes();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -21,6 +21,20 @@
|
||||
*/
|
||||
package org.alfresco.transform.registry;
|
||||
|
||||
import static java.util.stream.Collectors.toSet;
|
||||
|
||||
import static org.alfresco.transform.config.CoreVersionDecorator.setCoreVersionOnMultiStepTransformers;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.StringJoiner;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.alfresco.transform.config.AddSupported;
|
||||
import org.alfresco.transform.config.OverrideSupported;
|
||||
import org.alfresco.transform.config.RemoveSupported;
|
||||
@@ -33,30 +47,16 @@ import org.alfresco.transform.config.Transformer;
|
||||
import org.alfresco.transform.config.TransformerAndTypes;
|
||||
import org.alfresco.transform.config.Types;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.StringJoiner;
|
||||
import java.util.TreeSet;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static java.util.stream.Collectors.toSet;
|
||||
import static org.alfresco.transform.config.CoreVersionDecorator.setCoreVersionOnMultiStepTransformers;
|
||||
|
||||
/**
|
||||
* This class combines one or more T-Engine config and local files and registers them as if they were all in one file.
|
||||
* Transform options are shared between all sources.<p><br>
|
||||
* This class combines one or more T-Engine config and local files and registers them as if they were all in one file. Transform options are shared between all sources.
|
||||
* <p>
|
||||
* <br>
|
||||
*
|
||||
* The caller should make calls to {@link #addTransformConfig(TransformConfig, String, String, AbstractTransformRegistry)}
|
||||
* followed by calls to {@link #combineTransformerConfig(AbstractTransformRegistry)} and then
|
||||
* {@link #registerCombinedTransformers(AbstractTransformRegistry)}.<p><br>
|
||||
* The caller should make calls to {@link #addTransformConfig(TransformConfig, String, String, AbstractTransformRegistry)} followed by calls to {@link #combineTransformerConfig(AbstractTransformRegistry)} and then {@link #registerCombinedTransformers(AbstractTransformRegistry)}.
|
||||
* <p>
|
||||
* <br>
|
||||
*
|
||||
* The helper method {@link #combineAndRegister(TransformConfig, String, String, AbstractTransformRegistry)} may be used
|
||||
* when there is only one config.
|
||||
* The helper method {@link #combineAndRegister(TransformConfig, String, String, AbstractTransformRegistry)} may be used when there is only one config.
|
||||
*
|
||||
* @author adavis
|
||||
*/
|
||||
@@ -73,7 +73,7 @@ public class CombinedTransformConfig
|
||||
private final Defaults defaults = new Defaults();
|
||||
|
||||
public static void combineAndRegister(TransformConfig transformConfig, String readFrom, String baseUrl,
|
||||
AbstractTransformRegistry registry)
|
||||
AbstractTransformRegistry registry)
|
||||
{
|
||||
CombinedTransformConfig combinedTransformConfig = new CombinedTransformConfig();
|
||||
combinedTransformConfig.addTransformConfig(transformConfig, readFrom, baseUrl, registry);
|
||||
@@ -94,7 +94,7 @@ public class CombinedTransformConfig
|
||||
}
|
||||
|
||||
public void addTransformConfig(TransformConfig transformConfig, String readFrom, String baseUrl,
|
||||
AbstractTransformRegistry registry)
|
||||
AbstractTransformRegistry registry)
|
||||
{
|
||||
removeTransformers(transformConfig.getRemoveTransformers(), readFrom, registry);
|
||||
supportedDefaults(transformConfig.getSupportedDefaults(), readFrom, registry);
|
||||
@@ -113,8 +113,7 @@ public class CombinedTransformConfig
|
||||
if (!removeTransformersSet.isEmpty())
|
||||
{
|
||||
Set<String> leftOver = new HashSet<>(removeTransformersSet);
|
||||
combinedTransformers.removeIf(combinedTransformer ->
|
||||
{
|
||||
combinedTransformers.removeIf(combinedTransformer -> {
|
||||
String transformerName = combinedTransformer.get().getTransformerName();
|
||||
if (removeTransformersSet.contains(transformerName))
|
||||
{
|
||||
@@ -124,7 +123,7 @@ public class CombinedTransformConfig
|
||||
return false;
|
||||
});
|
||||
|
||||
Set<String> quotedLeftOver = leftOver.stream().map(transformerName -> "\""+transformerName+'"').collect(toSet());
|
||||
Set<String> quotedLeftOver = leftOver.stream().map(transformerName -> "\"" + transformerName + '"').collect(toSet());
|
||||
logWarn(quotedLeftOver, readFrom, registry, "removeTransformers");
|
||||
}
|
||||
}
|
||||
@@ -136,9 +135,8 @@ public class CombinedTransformConfig
|
||||
Set<SupportedDefaults> leftOver = new HashSet<>(supportedDefaults);
|
||||
supportedDefaults.stream()
|
||||
.filter(supportedDefault -> supportedDefault.getMaxSourceSizeBytes() != null ||
|
||||
supportedDefault.getPriority() != null)
|
||||
.forEach(supportedDefault ->
|
||||
{
|
||||
supportedDefault.getPriority() != null)
|
||||
.forEach(supportedDefault -> {
|
||||
defaults.add(supportedDefault);
|
||||
leftOver.remove(supportedDefault);
|
||||
});
|
||||
@@ -156,8 +154,8 @@ public class CombinedTransformConfig
|
||||
Set<T> leftOver = new HashSet<>(tSet);
|
||||
tSet.stream()
|
||||
.filter(t -> t.getTransformerName() != null &&
|
||||
t.getSourceMediaType() != null &&
|
||||
t.getTargetMediaType() != null)
|
||||
t.getSourceMediaType() != null &&
|
||||
t.getTargetMediaType() != null)
|
||||
.forEach(t -> process.process(leftOver, t));
|
||||
|
||||
logWarn(leftOver, readFrom, registry, elementName);
|
||||
@@ -183,14 +181,11 @@ public class CombinedTransformConfig
|
||||
private void removeSupported(Set<RemoveSupported> removeSupportedSet, String readFrom, AbstractTransformRegistry registry)
|
||||
{
|
||||
processSupported(removeSupportedSet, readFrom, registry, "removeSupported",
|
||||
(leftOver, removeSupported) ->
|
||||
combinedTransformers.stream()
|
||||
(leftOver, removeSupported) -> combinedTransformers.stream()
|
||||
.map(Origin::get)
|
||||
.forEach(transformer ->
|
||||
{
|
||||
.forEach(transformer -> {
|
||||
if (transformer.getTransformerName().equals(removeSupported.getTransformerName()) &&
|
||||
transformer.getSupportedSourceAndTargetList().removeIf(supported ->
|
||||
supported.getSourceMediaType().equals(removeSupported.getSourceMediaType()) &&
|
||||
transformer.getSupportedSourceAndTargetList().removeIf(supported -> supported.getSourceMediaType().equals(removeSupported.getSourceMediaType()) &&
|
||||
supported.getTargetMediaType().equals(removeSupported.getTargetMediaType())))
|
||||
{
|
||||
leftOver.remove(removeSupported);
|
||||
@@ -201,61 +196,52 @@ public class CombinedTransformConfig
|
||||
private void addSupported(Set<AddSupported> addSupportedSet, String readFrom, AbstractTransformRegistry registry)
|
||||
{
|
||||
processSupported(addSupportedSet, readFrom, registry, "addSupported",
|
||||
(leftOver, addSupported) ->
|
||||
combinedTransformers.stream()
|
||||
.map(Origin::get)
|
||||
.filter(transformer -> transformer.getTransformerName().equals(addSupported.getTransformerName()))
|
||||
.forEach(transformerWithName ->
|
||||
{
|
||||
Set<SupportedSourceAndTarget> supportedSourceAndTargetList =
|
||||
transformerWithName.getSupportedSourceAndTargetList();
|
||||
SupportedSourceAndTarget existingSupported = getExistingSupported(
|
||||
supportedSourceAndTargetList,
|
||||
addSupported.getSourceMediaType(), addSupported.getTargetMediaType());
|
||||
if (existingSupported == null)
|
||||
{
|
||||
SupportedSourceAndTarget newSupportedSourceAndTarget = SupportedSourceAndTarget.builder()
|
||||
.withSourceMediaType(addSupported.getSourceMediaType())
|
||||
.withTargetMediaType(addSupported.getTargetMediaType())
|
||||
.withMaxSourceSizeBytes(addSupported.getMaxSourceSizeBytes())
|
||||
.withPriority(addSupported.getPriority())
|
||||
.build();
|
||||
supportedSourceAndTargetList.add(newSupportedSourceAndTarget);
|
||||
leftOver.remove(addSupported);
|
||||
}}));
|
||||
(leftOver, addSupported) -> combinedTransformers.stream()
|
||||
.map(Origin::get)
|
||||
.filter(transformer -> transformer.getTransformerName().equals(addSupported.getTransformerName()))
|
||||
.forEach(transformerWithName -> {
|
||||
Set<SupportedSourceAndTarget> supportedSourceAndTargetList = transformerWithName.getSupportedSourceAndTargetList();
|
||||
SupportedSourceAndTarget existingSupported = getExistingSupported(
|
||||
supportedSourceAndTargetList,
|
||||
addSupported.getSourceMediaType(), addSupported.getTargetMediaType());
|
||||
if (existingSupported == null)
|
||||
{
|
||||
SupportedSourceAndTarget newSupportedSourceAndTarget = SupportedSourceAndTarget.builder()
|
||||
.withSourceMediaType(addSupported.getSourceMediaType())
|
||||
.withTargetMediaType(addSupported.getTargetMediaType())
|
||||
.withMaxSourceSizeBytes(addSupported.getMaxSourceSizeBytes())
|
||||
.withPriority(addSupported.getPriority())
|
||||
.build();
|
||||
supportedSourceAndTargetList.add(newSupportedSourceAndTarget);
|
||||
leftOver.remove(addSupported);
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
private void overrideSupported(Set<OverrideSupported> overrideSupportedSet, String readFrom, AbstractTransformRegistry registry)
|
||||
{
|
||||
processSupported(overrideSupportedSet, readFrom, registry, "overrideSupported",
|
||||
(leftOver, overrideSupported) ->
|
||||
combinedTransformers.stream().
|
||||
map(Origin::get).
|
||||
filter(transformer -> transformer.getTransformerName().equals(overrideSupported.getTransformerName())).
|
||||
forEach(transformerWithName ->
|
||||
{
|
||||
Set<SupportedSourceAndTarget> supportedSourceAndTargetList =
|
||||
transformerWithName.getSupportedSourceAndTargetList();
|
||||
SupportedSourceAndTarget existingSupported = getExistingSupported(
|
||||
supportedSourceAndTargetList,
|
||||
overrideSupported.getSourceMediaType(), overrideSupported.getTargetMediaType());
|
||||
if (existingSupported != null)
|
||||
{
|
||||
supportedSourceAndTargetList.remove(existingSupported);
|
||||
existingSupported.setMaxSourceSizeBytes(overrideSupported.getMaxSourceSizeBytes());
|
||||
existingSupported.setPriority(overrideSupported.getPriority());
|
||||
supportedSourceAndTargetList.add(existingSupported);
|
||||
leftOver.remove(overrideSupported);
|
||||
}
|
||||
}));
|
||||
(leftOver, overrideSupported) -> combinedTransformers.stream().map(Origin::get).filter(transformer -> transformer.getTransformerName().equals(overrideSupported.getTransformerName())).forEach(transformerWithName -> {
|
||||
Set<SupportedSourceAndTarget> supportedSourceAndTargetList = transformerWithName.getSupportedSourceAndTargetList();
|
||||
SupportedSourceAndTarget existingSupported = getExistingSupported(
|
||||
supportedSourceAndTargetList,
|
||||
overrideSupported.getSourceMediaType(), overrideSupported.getTargetMediaType());
|
||||
if (existingSupported != null)
|
||||
{
|
||||
supportedSourceAndTargetList.remove(existingSupported);
|
||||
existingSupported.setMaxSourceSizeBytes(overrideSupported.getMaxSourceSizeBytes());
|
||||
existingSupported.setPriority(overrideSupported.getPriority());
|
||||
supportedSourceAndTargetList.add(existingSupported);
|
||||
leftOver.remove(overrideSupported);
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
private SupportedSourceAndTarget getExistingSupported(Set<SupportedSourceAndTarget> supportedSourceAndTargetList,
|
||||
String sourceMediaType, String targetMediaType)
|
||||
String sourceMediaType, String targetMediaType)
|
||||
{
|
||||
return supportedSourceAndTargetList.stream().filter(supported ->
|
||||
supported.getSourceMediaType().equals(sourceMediaType) &&
|
||||
supported.getTargetMediaType().equals(targetMediaType))
|
||||
return supportedSourceAndTargetList.stream().filter(supported -> supported.getSourceMediaType().equals(sourceMediaType) &&
|
||||
supported.getTargetMediaType().equals(targetMediaType))
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
}
|
||||
@@ -273,7 +259,7 @@ public class CombinedTransformConfig
|
||||
public TransformConfig buildTransformConfig()
|
||||
{
|
||||
List<Transformer> transformers = new ArrayList<>();
|
||||
combinedTransformers.forEach(ct->transformers.add(ct.get()));
|
||||
combinedTransformers.forEach(ct -> transformers.add(ct.get()));
|
||||
Set<SupportedDefaults> supportedDefaults = defaults.getSupportedDefaults();
|
||||
return TransformConfig
|
||||
.builder()
|
||||
@@ -285,21 +271,18 @@ public class CombinedTransformConfig
|
||||
|
||||
public void registerCombinedTransformers(AbstractTransformRegistry registry)
|
||||
{
|
||||
combinedTransformers.forEach(ct ->
|
||||
registry.register(ct.get(), combinedTransformOptions, ct.getBaseUrl(), ct.getReadFrom()));
|
||||
combinedTransformers.forEach(ct -> registry.register(ct.get(), combinedTransformOptions, ct.getBaseUrl(), ct.getReadFrom()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Discards transformers that are invalid (e.g. transformers that have both pipeline and failover sections). Calls
|
||||
* {@link #removeInvalidTransformer(int, List, AbstractTransformRegistry, Origin, Transformer, String, String,
|
||||
* boolean, boolean)} for each transform, so that individual invalid transforms or overridden
|
||||
* transforms may be discarded.
|
||||
* Discards transformers that are invalid (e.g. transformers that have both pipeline and failover sections). Calls {@link #removeInvalidTransformer(int, List, AbstractTransformRegistry, Origin, Transformer, String, String, boolean, boolean)} for each transform, so that individual invalid transforms or overridden transforms may be discarded.
|
||||
*
|
||||
* @param registry that will hold the transforms.
|
||||
* @param registry
|
||||
* that will hold the transforms.
|
||||
*/
|
||||
private void removeInvalidTransformers(AbstractTransformRegistry registry)
|
||||
{
|
||||
for (int i=0; i<combinedTransformers.size(); i++)
|
||||
for (int i = 0; i < combinedTransformers.size(); i++)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -350,39 +333,37 @@ public class CombinedTransformConfig
|
||||
}
|
||||
|
||||
/**
|
||||
* Discards a transformer that is
|
||||
* 1) invalid:
|
||||
* a) has no name
|
||||
* b) the pass through transformer name is specified in a T-Engine
|
||||
* c) specifies transform options that don't exist,
|
||||
* d) has the same name as another T-Engine transform (i.e. there should be no duplicate names from t-engines),
|
||||
* e) the pass through transformer name is specified in a pipeline file
|
||||
* f) a single step transform defined outside a t-engine without it being an override,
|
||||
* g) a pipeline or failover transform is being overridden by a single step transform. Invalid because we
|
||||
* don't know if a t-engine will be able to do it.
|
||||
* 2) an earlier transform with the same name (it is being overridden). If the overridden transform is from a
|
||||
* T-Engine and the overriding transform is not a pipeline or a failover, we also copy the {@code baseUrl}
|
||||
* from the overridden transform so that the original T-Engine will still be called.
|
||||
* Discards a transformer that is 1) invalid: a) has no name b) the pass through transformer name is specified in a T-Engine c) specifies transform options that don't exist, d) has the same name as another T-Engine transform (i.e. there should be no duplicate names from t-engines), e) the pass through transformer name is specified in a pipeline file f) a single step transform defined outside a t-engine without it being an override, g) a pipeline or failover transform is being overridden by a single step transform. Invalid because we don't know if a t-engine will be able to do it. 2) an earlier transform with the same name (it is being overridden). If the overridden transform is from a T-Engine and the overriding transform is not a pipeline or a failover, we also copy the {@code baseUrl} from the overridden transform so that the original T-Engine will still be called.
|
||||
*
|
||||
* @param i the current transform's index into combinedTransformers.
|
||||
* @param combinedTransformers the full list of transformers in the order they were read.
|
||||
* @param registry that wil hold the transforms.
|
||||
* @param transformAndItsOrigin the current combinedTransformers element.
|
||||
* @param transformer the current transformer.
|
||||
* @param name the current transformer's name.
|
||||
* @param readFrom where the current transformer was read from.
|
||||
* @param isPipeline if the current transform is a pipeline.
|
||||
* @param isFailover if the current transform is a failover.
|
||||
* @param i
|
||||
* the current transform's index into combinedTransformers.
|
||||
* @param combinedTransformers
|
||||
* the full list of transformers in the order they were read.
|
||||
* @param registry
|
||||
* that wil hold the transforms.
|
||||
* @param transformAndItsOrigin
|
||||
* the current combinedTransformers element.
|
||||
* @param transformer
|
||||
* the current transformer.
|
||||
* @param name
|
||||
* the current transformer's name.
|
||||
* @param readFrom
|
||||
* where the current transformer was read from.
|
||||
* @param isPipeline
|
||||
* if the current transform is a pipeline.
|
||||
* @param isFailover
|
||||
* if the current transform is a failover.
|
||||
*
|
||||
* @return the index of a transform to be removed. {@code -1} is returned if there should not be a remove.
|
||||
* @throws IllegalArgumentException if the current transform has a problem and should be removed.
|
||||
* @throws IllegalStateException if the current transform is dependent on config from another transform which
|
||||
* is currently unavailable.
|
||||
* @throws IllegalArgumentException
|
||||
* if the current transform has a problem and should be removed.
|
||||
* @throws IllegalStateException
|
||||
* if the current transform is dependent on config from another transform which is currently unavailable.
|
||||
*/
|
||||
private int removeInvalidTransformer(int i, List<Origin<Transformer>> combinedTransformers,
|
||||
AbstractTransformRegistry registry,
|
||||
Origin<Transformer> transformAndItsOrigin, Transformer transformer,
|
||||
String name, String readFrom, boolean isPipeline, boolean isFailover)
|
||||
AbstractTransformRegistry registry,
|
||||
Origin<Transformer> transformAndItsOrigin, Transformer transformer,
|
||||
String name, String readFrom, boolean isPipeline, boolean isFailover)
|
||||
{
|
||||
int indexToRemove = -1;
|
||||
|
||||
@@ -459,8 +440,7 @@ public class CombinedTransformConfig
|
||||
// so we can talk to its T-Engine
|
||||
String overriddenBaseUrl = overriddenTransformAndItsOrigin.getBaseUrl();
|
||||
Transformer overriddenTransformTransform = transformAndItsOrigin.get();
|
||||
Origin<Transformer> overridingTransform =
|
||||
new Origin<>(overriddenTransformTransform, overriddenBaseUrl, readFrom);
|
||||
Origin<Transformer> overridingTransform = new Origin<>(overriddenTransformTransform, overriddenBaseUrl, readFrom);
|
||||
combinedTransformers.set(i, overridingTransform);
|
||||
}
|
||||
indexToRemove = j;
|
||||
@@ -484,7 +464,7 @@ public class CombinedTransformConfig
|
||||
{
|
||||
// Lists are short (< 100) entries and this is not a frequent or time critical step, so walking the list
|
||||
// should be okay.
|
||||
for (int j = toIndex-1; j >=0; j--)
|
||||
for (int j = toIndex - 1; j >= 0; j--)
|
||||
{
|
||||
Origin<Transformer> transformAndItsOrigin = combinedTransformers.get(j);
|
||||
Transformer transformer = transformAndItsOrigin.get();
|
||||
@@ -509,10 +489,11 @@ public class CombinedTransformConfig
|
||||
}
|
||||
|
||||
/**
|
||||
* Sort transformers so there are no forward references, if that is possible.
|
||||
* Logs warning message for those that have missing step transformers and removes them.
|
||||
* @param registry used to log messages
|
||||
*/
|
||||
* Sort transformers so there are no forward references, if that is possible. Logs warning message for those that have missing step transformers and removes them.
|
||||
*
|
||||
* @param registry
|
||||
* used to log messages
|
||||
*/
|
||||
private void sortTransformers(AbstractTransformRegistry registry)
|
||||
{
|
||||
List<Origin<Transformer>> transformers = new ArrayList<>(combinedTransformers.size());
|
||||
@@ -552,8 +533,7 @@ public class CombinedTransformConfig
|
||||
combinedTransformers.clear();
|
||||
combinedTransformers.addAll(todo);
|
||||
todo.clear();
|
||||
}
|
||||
while (added && !combinedTransformers.isEmpty());
|
||||
} while (added && !combinedTransformers.isEmpty());
|
||||
|
||||
transformers.addAll(todo);
|
||||
|
||||
@@ -604,18 +584,15 @@ public class CombinedTransformConfig
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies priority and size defaults. Must be called before {@link #addWildcardSupportedSourceAndTarget(AbstractTransformRegistry)}
|
||||
* as it uses the priority value.
|
||||
* Applies priority and size defaults. Must be called before {@link #addWildcardSupportedSourceAndTarget(AbstractTransformRegistry)} as it uses the priority value.
|
||||
*/
|
||||
private void applyDefaults()
|
||||
{
|
||||
combinedTransformers.stream()
|
||||
.map(Origin::get)
|
||||
.forEach(transformer ->
|
||||
{
|
||||
.forEach(transformer -> {
|
||||
transformer.setSupportedSourceAndTargetList(
|
||||
transformer.getSupportedSourceAndTargetList().stream().map(supportedSourceAndTarget ->
|
||||
{
|
||||
transformer.getSupportedSourceAndTargetList().stream().map(supportedSourceAndTarget -> {
|
||||
Integer priority = supportedSourceAndTarget.getPriority();
|
||||
Long maxSourceSizeBytes = supportedSourceAndTarget.getMaxSourceSizeBytes();
|
||||
if (defaults.valuesUnset(priority, maxSourceSizeBytes))
|
||||
@@ -633,26 +610,19 @@ public class CombinedTransformConfig
|
||||
}
|
||||
|
||||
/**
|
||||
* When no supported source and target mimetypes have been defined in a failover or pipeline transformer
|
||||
* this method adds all possible values that make sense.
|
||||
* <lu>
|
||||
* <li>Failover - all the supported values from the step transformers</li>
|
||||
* <li>Pipeline - builds up supported source and target values. The list of source types and max sizes will come
|
||||
* from the initial step transformer that have a target mimetype that matches the first
|
||||
* intermediate mimetype. We then step through all intermediate transformers checking the next
|
||||
* intermediate type is supported. When we get to the last step transformer, it provides all the
|
||||
* target mimetypes based on the previous intermediate mimetype. Any combinations supported by
|
||||
* the first transformer are excluded.</li>
|
||||
* </lu>
|
||||
* @param registry used to log messages
|
||||
* When no supported source and target mimetypes have been defined in a failover or pipeline transformer this method adds all possible values that make sense. <lu>
|
||||
* <li>Failover - all the supported values from the step transformers</li>
|
||||
* <li>Pipeline - builds up supported source and target values. The list of source types and max sizes will come from the initial step transformer that have a target mimetype that matches the first intermediate mimetype. We then step through all intermediate transformers checking the next intermediate type is supported. When we get to the last step transformer, it provides all the target mimetypes based on the previous intermediate mimetype. Any combinations supported by the first transformer are excluded.</li> </lu>
|
||||
*
|
||||
* @param registry
|
||||
* used to log messages
|
||||
*/
|
||||
private void addWildcardSupportedSourceAndTarget(AbstractTransformRegistry registry)
|
||||
{
|
||||
Map<String, Transformer> transformers = new HashMap<>();
|
||||
combinedTransformers.forEach(ct -> transformers.put(ct.get().getTransformerName(), ct.get()));
|
||||
|
||||
combinedTransformers.forEach(transformAndItsOrigin ->
|
||||
{
|
||||
combinedTransformers.forEach(transformAndItsOrigin -> {
|
||||
Transformer transformer = transformAndItsOrigin.get();
|
||||
|
||||
// If there are no SupportedSourceAndTarget, then work out all the wildcard combinations.
|
||||
@@ -666,13 +636,12 @@ public class CombinedTransformConfig
|
||||
if (isFailover)
|
||||
{
|
||||
Set<SupportedSourceAndTarget> supportedSourceAndTargets = failover.stream().flatMap(
|
||||
name -> transformers.get(name).getSupportedSourceAndTargetList().stream()).
|
||||
collect(toSet());
|
||||
name -> transformers.get(name).getSupportedSourceAndTargetList().stream()).collect(toSet());
|
||||
|
||||
// The failover transform might not be picked if the priority is the same as the step transforms
|
||||
// so reduce it here by 1. In future we might want to specify the priority in the json, but for now
|
||||
// it should be okay.
|
||||
supportedSourceAndTargets.forEach(s->s.setPriority(s.getPriority()-1));
|
||||
supportedSourceAndTargets.forEach(s -> s.setPriority(s.getPriority() - 1));
|
||||
transformer.setSupportedSourceAndTargetList(supportedSourceAndTargets);
|
||||
errorReason = "the step transforms don't support any"; // only used if there are none
|
||||
}
|
||||
@@ -683,7 +652,7 @@ public class CombinedTransformConfig
|
||||
Set<String> firstTransformOptions = null;
|
||||
String firstTransformStepName = null;
|
||||
int numberOfSteps = pipeline.size();
|
||||
for (int stepIndex=0; stepIndex<numberOfSteps; stepIndex++)
|
||||
for (int stepIndex = 0; stepIndex < numberOfSteps; stepIndex++)
|
||||
{
|
||||
TransformStep step = pipeline.get(stepIndex);
|
||||
String name = step.getTransformerName();
|
||||
@@ -697,9 +666,7 @@ public class CombinedTransformConfig
|
||||
String stepTrg = step.getTargetMediaType();
|
||||
if (stepIndex == 0)
|
||||
{
|
||||
sourceMediaTypesAndMaxSizes = stepTransformer.getSupportedSourceAndTargetList().stream().
|
||||
filter(s -> stepTrg.equals(s.getTargetMediaType())).
|
||||
collect(toSet());
|
||||
sourceMediaTypesAndMaxSizes = stepTransformer.getSupportedSourceAndTargetList().stream().filter(s -> stepTrg.equals(s.getTargetMediaType())).collect(toSet());
|
||||
sourceMediaType = stepTrg;
|
||||
firstTransformOptions = stepTransformer.getTransformOptions();
|
||||
firstTransformStepName = name;
|
||||
@@ -713,7 +680,7 @@ public class CombinedTransformConfig
|
||||
else
|
||||
{
|
||||
final String src = sourceMediaType;
|
||||
if (stepIndex+1 == numberOfSteps) // if final step
|
||||
if (stepIndex + 1 == numberOfSteps) // if final step
|
||||
{
|
||||
if (stepTrg != null)
|
||||
{
|
||||
@@ -723,22 +690,12 @@ public class CombinedTransformConfig
|
||||
|
||||
// Create a cartesian product of sourceMediaType,MaxSourceSize and TargetMediaType where
|
||||
// the source matches the last intermediate.
|
||||
Set<SupportedSourceAndTarget> supportedSourceAndTargets = sourceMediaTypesAndMaxSizes.stream().
|
||||
flatMap(s -> stepTransformer.getSupportedSourceAndTargetList().stream().
|
||||
filter(st ->
|
||||
{
|
||||
String targetMimetype = st.getTargetMediaType();
|
||||
return st.getSourceMediaType().equals(src) &&
|
||||
!(MIMETYPE_METADATA_EXTRACT.equals(targetMimetype) ||
|
||||
MIMETYPE_METADATA_EMBED.equals(targetMimetype));
|
||||
}).
|
||||
map(Types::getTargetMediaType).
|
||||
map(trg -> SupportedSourceAndTarget.builder().
|
||||
withSourceMediaType(s.getSourceMediaType()).
|
||||
withMaxSourceSizeBytes(s.getMaxSourceSizeBytes()).
|
||||
withPriority(s.getPriority()).
|
||||
withTargetMediaType(trg).build())).
|
||||
collect(toSet());
|
||||
Set<SupportedSourceAndTarget> supportedSourceAndTargets = sourceMediaTypesAndMaxSizes.stream().flatMap(s -> stepTransformer.getSupportedSourceAndTargetList().stream().filter(st -> {
|
||||
String targetMimetype = st.getTargetMediaType();
|
||||
return st.getSourceMediaType().equals(src) &&
|
||||
!(MIMETYPE_METADATA_EXTRACT.equals(targetMimetype) ||
|
||||
MIMETYPE_METADATA_EMBED.equals(targetMimetype));
|
||||
}).map(Types::getTargetMediaType).map(trg -> SupportedSourceAndTarget.builder().withSourceMediaType(s.getSourceMediaType()).withMaxSourceSizeBytes(s.getMaxSourceSizeBytes()).withPriority(s.getPriority()).withTargetMediaType(trg).build())).collect(toSet());
|
||||
|
||||
if (supportedSourceAndTargets.isEmpty())
|
||||
{
|
||||
@@ -773,9 +730,8 @@ public class CombinedTransformConfig
|
||||
}
|
||||
|
||||
// Check source to target is supported (it normally is)
|
||||
if (stepTransformer.getSupportedSourceAndTargetList().stream().
|
||||
noneMatch(st -> st.getSourceMediaType().equals(src) &&
|
||||
st.getTargetMediaType().equals(stepTrg)))
|
||||
if (stepTransformer.getSupportedSourceAndTargetList().stream().noneMatch(st -> st.getSourceMediaType().equals(src) &&
|
||||
st.getTargetMediaType().equals(stepTrg)))
|
||||
{
|
||||
errorReason = "the step transformer " +
|
||||
transformerName(stepTransformer.getTransformerName()) + " does not support \"" +
|
||||
@@ -815,22 +771,23 @@ public class CombinedTransformConfig
|
||||
private Set<TransformOption> getTransformOptions(Set<String> transformOptionNames)
|
||||
{
|
||||
Set<TransformOption> transformOptions = new HashSet<>();
|
||||
transformOptionNames.forEach(name->transformOptions.addAll(combinedTransformOptions.get(name)));
|
||||
transformOptionNames.forEach(name -> transformOptions.addAll(combinedTransformOptions.get(name)));
|
||||
return transformOptions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes pipeline transformers if the step transformers cannot be chained together via the intermediary types
|
||||
* to produce the set of claimed source and target mimetypes.
|
||||
* @param registry used to log messages
|
||||
* Removes pipeline transformers if the step transformers cannot be chained together via the intermediary types to produce the set of claimed source and target mimetypes.
|
||||
*
|
||||
* @param registry
|
||||
* used to log messages
|
||||
*/
|
||||
private void removePipelinesWithUnsupportedTransforms(AbstractTransformRegistry registry)
|
||||
{
|
||||
Map<String, Transformer> transformersByName = combinedTransformers.stream()
|
||||
.map(Origin::get)
|
||||
.collect(Collectors.toMap(Transformer::getTransformerName, Function.identity()));
|
||||
.map(Origin::get)
|
||||
.collect(Collectors.toMap(Transformer::getTransformerName, Function.identity()));
|
||||
|
||||
for (int i=0; i<combinedTransformers.size(); i++)
|
||||
for (int i = 0; i < combinedTransformers.size(); i++)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -851,33 +808,34 @@ public class CombinedTransformConfig
|
||||
|
||||
List<String> unsupported = new ArrayList<>();
|
||||
transformer.getSupportedSourceAndTargetList()
|
||||
.forEach(supportedSourceAndTarget -> {
|
||||
String nextSource = supportedSourceAndTarget.getSourceMediaType();
|
||||
for (TransformStep step : pipeline)
|
||||
{
|
||||
String source = nextSource;
|
||||
String target = step.getTargetMediaType() == null
|
||||
? supportedSourceAndTarget.getTargetMediaType()
|
||||
: step.getTargetMediaType();
|
||||
|
||||
if (transformersByName.get(step.getTransformerName()).getSupportedSourceAndTargetList().stream()
|
||||
.noneMatch(stepsSupportedSourceAndTarget -> source.equals(stepsSupportedSourceAndTarget.getSourceMediaType())
|
||||
&& target.equals(stepsSupportedSourceAndTarget.getTargetMediaType())))
|
||||
.forEach(supportedSourceAndTarget -> {
|
||||
String nextSource = supportedSourceAndTarget.getSourceMediaType();
|
||||
for (TransformStep step : pipeline)
|
||||
{
|
||||
unsupported.add(supportedSourceAndTarget.getSourceMediaType()+"->"+supportedSourceAndTarget.getTargetMediaType());
|
||||
break;
|
||||
String source = nextSource;
|
||||
String target = step.getTargetMediaType() == null
|
||||
? supportedSourceAndTarget.getTargetMediaType()
|
||||
: step.getTargetMediaType();
|
||||
|
||||
if (transformersByName.get(step.getTransformerName()).getSupportedSourceAndTargetList().stream()
|
||||
.noneMatch(stepsSupportedSourceAndTarget -> source.equals(stepsSupportedSourceAndTarget.getSourceMediaType())
|
||||
&& target.equals(stepsSupportedSourceAndTarget.getTargetMediaType())))
|
||||
{
|
||||
unsupported.add(supportedSourceAndTarget.getSourceMediaType() + "->" + supportedSourceAndTarget.getTargetMediaType());
|
||||
break;
|
||||
}
|
||||
nextSource = target;
|
||||
}
|
||||
nextSource = target;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
if (!unsupported.isEmpty())
|
||||
{
|
||||
throw new IllegalStateException("Pipeline transformer " + transformerName(name) +
|
||||
" steps do not support ("+
|
||||
" steps do not support (" +
|
||||
unsupported.stream()
|
||||
.sorted()
|
||||
.collect(Collectors.joining(", "))+
|
||||
.sorted()
|
||||
.collect(Collectors.joining(", "))
|
||||
+
|
||||
") so will be ignored");
|
||||
}
|
||||
}
|
||||
@@ -903,7 +861,7 @@ public class CombinedTransformConfig
|
||||
return combinedTransformers.size();
|
||||
}
|
||||
|
||||
public Map<String,Origin<Transformer>> getTransformerByNameMap()
|
||||
public Map<String, Origin<Transformer>> getTransformerByNameMap()
|
||||
{
|
||||
return combinedTransformers.stream().collect(Collectors.toMap(origin -> origin.get().getTransformerName(), origin -> origin));
|
||||
}
|
||||
|
@@ -21,19 +21,17 @@
|
||||
*/
|
||||
package org.alfresco.transform.registry;
|
||||
|
||||
import org.alfresco.transform.config.SupportedDefaults;
|
||||
import static java.util.stream.Collectors.toSet;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static java.util.stream.Collectors.toSet;
|
||||
import org.alfresco.transform.config.SupportedDefaults;
|
||||
|
||||
/**
|
||||
* Maintains a list of defaults of {@code maxSourceSizeBytes} and {@code priority} keyed on
|
||||
* {@code transformerName} and {@code sourceMediaType} so that it can provide a lookup when we
|
||||
* join everything together in {@link CombinedTransformConfig#combineTransformerConfig(AbstractTransformRegistry)}.
|
||||
* Maintains a list of defaults of {@code maxSourceSizeBytes} and {@code priority} keyed on {@code transformerName} and {@code sourceMediaType} so that it can provide a lookup when we join everything together in {@link CombinedTransformConfig#combineTransformerConfig(AbstractTransformRegistry)}.
|
||||
*
|
||||
* @see SupportedDefaults
|
||||
*/
|
||||
@@ -49,8 +47,7 @@ class Defaults
|
||||
|
||||
public void add(SupportedDefaults supportedDefault)
|
||||
{
|
||||
TransformerAndSourceType key =
|
||||
new TransformerAndSourceType(supportedDefault.getTransformerName(), supportedDefault.getSourceMediaType());
|
||||
TransformerAndSourceType key = new TransformerAndSourceType(supportedDefault.getTransformerName(), supportedDefault.getSourceMediaType());
|
||||
Long maxSourceSizeBytes = supportedDefault.getMaxSourceSizeBytes();
|
||||
if (maxSourceSizeBytes != null)
|
||||
{
|
||||
@@ -84,7 +81,7 @@ class Defaults
|
||||
}
|
||||
|
||||
private <T> T getDefault(String transformerName, String sourceMediaType, T supportedSourceAndTargetValue,
|
||||
Map<TransformerAndSourceType, T> map)
|
||||
Map<TransformerAndSourceType, T> map)
|
||||
{
|
||||
if (supportedSourceAndTargetValue != null)
|
||||
{
|
||||
@@ -96,7 +93,7 @@ class Defaults
|
||||
// 2: source media type default
|
||||
// 3: system wide default
|
||||
TransformerAndSourceType key = new TransformerAndSourceType(transformerName, sourceMediaType);
|
||||
for (int i=0; ; i++)
|
||||
for (int i = 0;; i++)
|
||||
{
|
||||
T value = map.get(key);
|
||||
if (value != null)
|
||||
@@ -106,10 +103,16 @@ class Defaults
|
||||
|
||||
switch (i)
|
||||
{
|
||||
case 0:
|
||||
case 2: key.setSourceMediaType(null); break;
|
||||
case 1: key.setSourceMediaType(sourceMediaType); key.setTransformerName(null); break;
|
||||
default: throw new IllegalStateException("Should have found an entry with a null, null lookup");
|
||||
case 0:
|
||||
case 2:
|
||||
key.setSourceMediaType(null);
|
||||
break;
|
||||
case 1:
|
||||
key.setSourceMediaType(sourceMediaType);
|
||||
key.setTransformerName(null);
|
||||
break;
|
||||
default:
|
||||
throw new IllegalStateException("Should have found an entry with a null, null lookup");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -117,15 +120,13 @@ class Defaults
|
||||
public Set<SupportedDefaults> getSupportedDefaults()
|
||||
{
|
||||
return Stream.concat(maxSourceSizeBytesDefaults.keySet().stream(), priorityDefaults.keySet().stream())
|
||||
.filter(key ->
|
||||
{
|
||||
.filter(key -> {
|
||||
// Discard the entry added by clear()
|
||||
return !SYSTEM_WIDE_KEY.equals(key) ||
|
||||
!DEFAULT_MAX_SOURCE_SIZE_BYTES.equals(maxSourceSizeBytesDefaults.get(key)) ||
|
||||
!DEFAULT_PRIORITY.equals(priorityDefaults.get(key));
|
||||
!DEFAULT_MAX_SOURCE_SIZE_BYTES.equals(maxSourceSizeBytesDefaults.get(key)) ||
|
||||
!DEFAULT_PRIORITY.equals(priorityDefaults.get(key));
|
||||
})
|
||||
.map(key ->
|
||||
{
|
||||
.map(key -> {
|
||||
Long maxSourceSizeBytes = maxSourceSizeBytesDefaults.get(key);
|
||||
Integer priority = priorityDefaults.get(key);
|
||||
return SupportedDefaults.builder()
|
||||
|
@@ -22,9 +22,8 @@
|
||||
package org.alfresco.transform.registry;
|
||||
|
||||
/**
|
||||
* Wraps an object so that we know where it was read from. The equals() and hashcode() are that of the wrapped object
|
||||
* so it is still possible do set operations.
|
||||
*/
|
||||
* Wraps an object so that we know where it was read from. The equals() and hashcode() are that of the wrapped object so it is still possible do set operations.
|
||||
*/
|
||||
public class Origin<T>
|
||||
{
|
||||
final T t;
|
||||
@@ -42,6 +41,7 @@ public class Origin<T>
|
||||
{
|
||||
return t;
|
||||
}
|
||||
|
||||
public String getBaseUrl()
|
||||
{
|
||||
return baseUrl;
|
||||
@@ -52,4 +52,3 @@ public class Origin<T>
|
||||
return readFrom;
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -35,7 +35,7 @@ public class SupportedTransform
|
||||
private final int priority;
|
||||
|
||||
SupportedTransform(String name, Set<TransformOption> transformOptions,
|
||||
long maxSourceSizeBytes, int priority)
|
||||
long maxSourceSizeBytes, int priority)
|
||||
{
|
||||
// Logically the top level TransformOptionGroup is required, so that child options are optional or required
|
||||
// based on their own setting.
|
||||
@@ -68,13 +68,15 @@ public class SupportedTransform
|
||||
@Override
|
||||
public boolean equals(Object o)
|
||||
{
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
if (this == o)
|
||||
return true;
|
||||
if (o == null || getClass() != o.getClass())
|
||||
return false;
|
||||
SupportedTransform that = (SupportedTransform) o;
|
||||
return maxSourceSizeBytes == that.maxSourceSizeBytes &&
|
||||
priority == that.priority &&
|
||||
Objects.equals(transformOptions, that.transformOptions) &&
|
||||
Objects.equals(name, that.name);
|
||||
priority == that.priority &&
|
||||
Objects.equals(transformOptions, that.transformOptions) &&
|
||||
Objects.equals(name, that.name);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -89,4 +91,3 @@ public class SupportedTransform
|
||||
return name + ':' + maxSourceSizeBytes + ':' + priority;
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -31,8 +31,7 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
public class TransformCache
|
||||
{
|
||||
// Looks up supported transform routes given source to target media types.
|
||||
private final Map<String, Map<String, List<SupportedTransform>>> transforms =
|
||||
new ConcurrentHashMap<>();
|
||||
private final Map<String, Map<String, List<SupportedTransform>>> transforms = new ConcurrentHashMap<>();
|
||||
|
||||
// Looks up coreVersion given the transformer name
|
||||
private final Map<String, String> coreVersions = new ConcurrentHashMap<>();
|
||||
@@ -41,8 +40,7 @@ public class TransformCache
|
||||
// Looks up a sorted list of transform routes, for a rendition (if the name is supplied) and the source
|
||||
// media type. Unlike a lookup on the transforms map above, processing of the transform options and priorities
|
||||
// will have already been done if cached.
|
||||
private final Map<String, Map<String, List<SupportedTransform>>> cachedSupportedTransformList =
|
||||
new ConcurrentHashMap<>();
|
||||
private final Map<String, Map<String, List<SupportedTransform>>> cachedSupportedTransformList = new ConcurrentHashMap<>();
|
||||
|
||||
protected int transformerCount = 0;
|
||||
protected int transformCount = 0;
|
||||
@@ -53,13 +51,13 @@ public class TransformCache
|
||||
}
|
||||
|
||||
public void appendTransform(final String sourceMimetype,
|
||||
final String targetMimetype, final SupportedTransform transform,
|
||||
String transformerName, String coreVersion)
|
||||
final String targetMimetype, final SupportedTransform transform,
|
||||
String transformerName, String coreVersion)
|
||||
{
|
||||
transforms
|
||||
.computeIfAbsent(sourceMimetype, k -> new ConcurrentHashMap<>())
|
||||
.computeIfAbsent(targetMimetype, k -> new ArrayList<>())
|
||||
.add(transform);
|
||||
.computeIfAbsent(sourceMimetype, k -> new ConcurrentHashMap<>())
|
||||
.computeIfAbsent(targetMimetype, k -> new ArrayList<>())
|
||||
.add(transform);
|
||||
coreVersions.put(transformerName, coreVersion == null ? "" : coreVersion);
|
||||
transformCount++;
|
||||
}
|
||||
@@ -75,27 +73,27 @@ public class TransformCache
|
||||
}
|
||||
|
||||
public void cache(final String renditionName, final String sourceMimetype,
|
||||
final List<SupportedTransform> transformListBySize)
|
||||
final List<SupportedTransform> transformListBySize)
|
||||
{
|
||||
cachedSupportedTransformList
|
||||
.get(renditionName)
|
||||
.put(sourceMimetype, transformListBySize);
|
||||
.get(renditionName)
|
||||
.put(sourceMimetype, transformListBySize);
|
||||
}
|
||||
|
||||
public List<SupportedTransform> retrieveCached(final String renditionName,
|
||||
final String sourceMimetype)
|
||||
final String sourceMimetype)
|
||||
{
|
||||
return cachedSupportedTransformList
|
||||
.computeIfAbsent(renditionName, k -> new ConcurrentHashMap<>())
|
||||
.get(sourceMimetype);
|
||||
.computeIfAbsent(renditionName, k -> new ConcurrentHashMap<>())
|
||||
.get(sourceMimetype);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return transformerCount == 0 && transformCount == 0
|
||||
? ""
|
||||
: "(transformers: " + transformerCount + " transforms: " + transformCount + ")";
|
||||
? ""
|
||||
: "(transformers: " + transformerCount + " transforms: " + transformCount + ")";
|
||||
}
|
||||
|
||||
public String getCoreVersion(String transformerName)
|
||||
|
@@ -21,33 +21,33 @@
|
||||
*/
|
||||
package org.alfresco.transform.registry;
|
||||
|
||||
import org.alfresco.transform.config.CoreFunction;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.transform.config.CoreFunction;
|
||||
|
||||
/**
|
||||
* Used by clients work out if a transformation is supported by a Transform Service.
|
||||
*/
|
||||
public interface TransformServiceRegistry
|
||||
{
|
||||
/**
|
||||
* Works out if the Transform Server should be able 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
|
||||
* Transformer objects registered with this class.
|
||||
* Works out if the Transform Server should be able 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 Transformer 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 transformName (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.
|
||||
* @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 transformName
|
||||
* (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.
|
||||
* @return {@code}true{@code} if it is supported.
|
||||
*/
|
||||
default boolean isSupported(final String sourceMimetype, final long sourceSizeInBytes,
|
||||
final String targetMimetype, final Map<String, String> actualOptions,
|
||||
final String transformName)
|
||||
final String targetMimetype, final Map<String, String> actualOptions,
|
||||
final String transformName)
|
||||
{
|
||||
long maxSize = findMaxSize(sourceMimetype, targetMimetype, actualOptions, transformName);
|
||||
return maxSize != 0 && (maxSize == -1L || maxSize >= sourceSizeInBytes);
|
||||
@@ -56,44 +56,44 @@ public interface TransformServiceRegistry
|
||||
/**
|
||||
* Returns the maximun size (in bytes) of the source content that can be transformed.
|
||||
*
|
||||
* @param sourceMimetype the mimetype of the source content
|
||||
* @param targetMimetype the mimetype of the target
|
||||
* @param actualOptions the actual name value pairs available that could be passed to the Transform Service.
|
||||
* @param transformName (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.
|
||||
* @return the maximum size (in bytes) of the source content that can be transformed. If {@code -1} there is no
|
||||
* limit, but if {@code 0} the transform is not supported.
|
||||
* @param sourceMimetype
|
||||
* the mimetype of the source content
|
||||
* @param targetMimetype
|
||||
* the mimetype of the target
|
||||
* @param actualOptions
|
||||
* the actual name value pairs available that could be passed to the Transform Service.
|
||||
* @param transformName
|
||||
* (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.
|
||||
* @return the maximum size (in bytes) of the source content that can be transformed. If {@code -1} there is no limit, but if {@code 0} the transform is not supported.
|
||||
*/
|
||||
long findMaxSize(String sourceMimetype, String targetMimetype, Map<String, String> actualOptions,
|
||||
String transformName);
|
||||
String transformName);
|
||||
|
||||
/**
|
||||
* 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 Transformer objects registered with this class.
|
||||
* 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 Transformer 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.
|
||||
* @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.
|
||||
* @return the name of the transformer or {@code}null{@code} if not set or there is no supported transformer.
|
||||
*/
|
||||
String findTransformerName(String sourceMimetype, long sourceSizeInBytes, String targetMimetype,
|
||||
Map<String, String> actualOptions, String renditionName);
|
||||
Map<String, String> actualOptions, String renditionName);
|
||||
|
||||
/**
|
||||
* Returns {@code true} if the {@code function} is supported by the named transformer. Not all transformers are
|
||||
* able to support all functionality, as newer features may have been introduced into the core t-engine code since
|
||||
* it was released. Normally used in conjunction with {@link #findTransformerName(String, long, String, Map, String)}
|
||||
* rather than {@link #isSupported(String, long, String, Map, String)}.
|
||||
* @param function to be checked.
|
||||
* @param transformerName name of the transformer.
|
||||
* Returns {@code true} if the {@code function} is supported by the named transformer. Not all transformers are able to support all functionality, as newer features may have been introduced into the core t-engine code since it was released. Normally used in conjunction with {@link #findTransformerName(String, long, String, Map, String)} rather than {@link #isSupported(String, long, String, Map, String)}.
|
||||
*
|
||||
* @param function
|
||||
* to be checked.
|
||||
* @param transformerName
|
||||
* name of the transformer.
|
||||
* @return {@code true} is supported, {@code false} otherwise.
|
||||
*/
|
||||
default boolean isSupported(CoreFunction function, String transformerName)
|
||||
|
@@ -21,13 +21,12 @@
|
||||
*/
|
||||
package org.alfresco.transform.registry;
|
||||
|
||||
import org.alfresco.transform.config.OverrideSupported;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import org.alfresco.transform.config.OverrideSupported;
|
||||
|
||||
/**
|
||||
* Key based using {@code transformerName} and {@code sourceMediaType} used as a key to lookup default values held in
|
||||
* {@link OverrideSupported} objects.
|
||||
* Key based using {@code transformerName} and {@code sourceMediaType} used as a key to lookup default values held in {@link OverrideSupported} objects.
|
||||
*/
|
||||
class TransformerAndSourceType
|
||||
{
|
||||
@@ -71,9 +70,9 @@ class TransformerAndSourceType
|
||||
{
|
||||
return false;
|
||||
}
|
||||
TransformerAndSourceType that = (TransformerAndSourceType)o;
|
||||
TransformerAndSourceType that = (TransformerAndSourceType) o;
|
||||
return Objects.equals(transformerName, that.transformerName) &&
|
||||
Objects.equals(sourceMediaType, that.sourceMediaType);
|
||||
Objects.equals(sourceMediaType, that.sourceMediaType);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -25,10 +25,7 @@ import org.alfresco.transform.config.Transformer;
|
||||
|
||||
public enum TransformerType
|
||||
{
|
||||
ENGINE_TRANSFORMER,
|
||||
PIPELINE_TRANSFORMER,
|
||||
FAILOVER_TRANSFORMER,
|
||||
UNSUPPORTED_TRANSFORMER;
|
||||
ENGINE_TRANSFORMER, PIPELINE_TRANSFORMER, FAILOVER_TRANSFORMER, UNSUPPORTED_TRANSFORMER;
|
||||
|
||||
public static TransformerType valueOf(Transformer transformer)
|
||||
{
|
||||
@@ -37,7 +34,7 @@ public enum TransformerType
|
||||
return null;
|
||||
}
|
||||
if ((transformer.getTransformerFailover() == null || transformer.getTransformerFailover().isEmpty()) &&
|
||||
(transformer.getTransformerPipeline() == null || transformer.getTransformerPipeline().isEmpty()))
|
||||
(transformer.getTransformerPipeline() == null || transformer.getTransformerPipeline().isEmpty()))
|
||||
{
|
||||
return ENGINE_TRANSFORMER;
|
||||
}
|
||||
@@ -52,4 +49,4 @@ public enum TransformerType
|
||||
|
||||
return UNSUPPORTED_TRANSFORMER;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -28,6 +28,5 @@ package org.alfresco.transform.router;
|
||||
public class ExtensionService extends org.alfresco.transform.common.ExtensionService
|
||||
{
|
||||
private ExtensionService()
|
||||
{
|
||||
}
|
||||
{}
|
||||
}
|
||||
|
@@ -21,17 +21,18 @@
|
||||
*/
|
||||
package org.alfresco.transform.common;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.StringJoiner;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import static org.alfresco.transform.common.RepositoryClientData.CLIENT_DATA_SEPARATOR;
|
||||
import static org.alfresco.transform.common.RepositoryClientData.DEBUG;
|
||||
import static org.alfresco.transform.common.RepositoryClientData.DEBUG_SEPARATOR;
|
||||
import static org.alfresco.transform.common.RepositoryClientData.REPO_ID;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import java.util.StringJoiner;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class RepositoryClientDataTest
|
||||
{
|
||||
@@ -41,11 +42,11 @@ public class RepositoryClientDataTest
|
||||
void AcsClientDataWithDebugTest()
|
||||
{
|
||||
repositoryClientData = RepositoryClientData.builder()
|
||||
.withRepoId("ACS1234")
|
||||
.withRenditionName("renditionName")
|
||||
.withRequestId("e123")
|
||||
.withDebug()
|
||||
.build();
|
||||
.withRepoId("ACS1234")
|
||||
.withRenditionName("renditionName")
|
||||
.withRequestId("e123")
|
||||
.withDebug()
|
||||
.build();
|
||||
String clientData = repositoryClientData.toString();
|
||||
|
||||
assertEquals("ACS1234", repositoryClientData.getAcsVersion());
|
||||
@@ -59,17 +60,17 @@ public class RepositoryClientDataTest
|
||||
void AcsClientDataWithoutDebugTest()
|
||||
{
|
||||
String clientData = new StringJoiner(CLIENT_DATA_SEPARATOR)
|
||||
.add(REPO_ID + "ACS1234")
|
||||
.add("1")
|
||||
.add("renditionName")
|
||||
.add("3")
|
||||
.add("4")
|
||||
.add("5")
|
||||
.add("54321")
|
||||
.add("7")
|
||||
.add("8")
|
||||
.add("9")
|
||||
.toString();
|
||||
.add(REPO_ID + "ACS1234")
|
||||
.add("1")
|
||||
.add("renditionName")
|
||||
.add("3")
|
||||
.add("4")
|
||||
.add("5")
|
||||
.add("54321")
|
||||
.add("7")
|
||||
.add("8")
|
||||
.add("9")
|
||||
.toString();
|
||||
repositoryClientData = new RepositoryClientData(clientData);
|
||||
|
||||
assertEquals("ACS1234", repositoryClientData.getAcsVersion());
|
||||
@@ -83,17 +84,17 @@ public class RepositoryClientDataTest
|
||||
void noLeadingRepoTest()
|
||||
{
|
||||
String clientData = new StringJoiner(CLIENT_DATA_SEPARATOR)
|
||||
.add("ACS1234")
|
||||
.add("1")
|
||||
.add("renditionName")
|
||||
.add("3")
|
||||
.add("4")
|
||||
.add("5")
|
||||
.add("54321")
|
||||
.add("7")
|
||||
.add("8")
|
||||
.add("9")
|
||||
.toString();
|
||||
.add("ACS1234")
|
||||
.add("1")
|
||||
.add("renditionName")
|
||||
.add("3")
|
||||
.add("4")
|
||||
.add("5")
|
||||
.add("54321")
|
||||
.add("7")
|
||||
.add("8")
|
||||
.add("9")
|
||||
.toString();
|
||||
repositoryClientData = new RepositoryClientData(clientData);
|
||||
|
||||
assertEquals("", repositoryClientData.getAcsVersion());
|
||||
@@ -107,16 +108,16 @@ public class RepositoryClientDataTest
|
||||
void tooFewElementsTest()
|
||||
{
|
||||
String clientData = new StringJoiner(CLIENT_DATA_SEPARATOR)
|
||||
.add(REPO_ID + "ACS1234")
|
||||
.add("1")
|
||||
.add("renditionName")
|
||||
.add("3")
|
||||
.add("4")
|
||||
.add("5")
|
||||
.add("54321")
|
||||
.add("7")
|
||||
.add("8")
|
||||
.toString();
|
||||
.add(REPO_ID + "ACS1234")
|
||||
.add("1")
|
||||
.add("renditionName")
|
||||
.add("3")
|
||||
.add("4")
|
||||
.add("5")
|
||||
.add("54321")
|
||||
.add("7")
|
||||
.add("8")
|
||||
.toString();
|
||||
repositoryClientData = new RepositoryClientData(clientData);
|
||||
|
||||
assertEquals("", repositoryClientData.getAcsVersion());
|
||||
@@ -130,18 +131,18 @@ public class RepositoryClientDataTest
|
||||
void tooManyElementsTest()
|
||||
{
|
||||
String clientData = new StringJoiner(CLIENT_DATA_SEPARATOR)
|
||||
.add(REPO_ID + "ACS1234")
|
||||
.add("1")
|
||||
.add("renditionName")
|
||||
.add("3")
|
||||
.add("4")
|
||||
.add("5")
|
||||
.add("54321")
|
||||
.add("7")
|
||||
.add("8")
|
||||
.add(DEBUG)
|
||||
.add("10")
|
||||
.toString();
|
||||
.add(REPO_ID + "ACS1234")
|
||||
.add("1")
|
||||
.add("renditionName")
|
||||
.add("3")
|
||||
.add("4")
|
||||
.add("5")
|
||||
.add("54321")
|
||||
.add("7")
|
||||
.add("8")
|
||||
.add(DEBUG)
|
||||
.add("10")
|
||||
.toString();
|
||||
repositoryClientData = new RepositoryClientData(clientData);
|
||||
assertEquals("", repositoryClientData.getAcsVersion());
|
||||
assertEquals("", repositoryClientData.getRenditionName());
|
||||
@@ -169,27 +170,27 @@ public class RepositoryClientDataTest
|
||||
void debugTest()
|
||||
{
|
||||
String clientData = new StringJoiner(CLIENT_DATA_SEPARATOR)
|
||||
.add(REPO_ID + "ACS1234")
|
||||
.add("1")
|
||||
.add("2")
|
||||
.add("3")
|
||||
.add("4")
|
||||
.add("5")
|
||||
.add("6")
|
||||
.add("7")
|
||||
.add("8")
|
||||
.add(DEBUG)
|
||||
.toString();
|
||||
.add(REPO_ID + "ACS1234")
|
||||
.add("1")
|
||||
.add("2")
|
||||
.add("3")
|
||||
.add("4")
|
||||
.add("5")
|
||||
.add("6")
|
||||
.add("7")
|
||||
.add("8")
|
||||
.add(DEBUG)
|
||||
.toString();
|
||||
repositoryClientData = new RepositoryClientData(clientData);
|
||||
|
||||
assertEquals(clientData, repositoryClientData.toString());
|
||||
|
||||
repositoryClientData.appendDebug("Some debug");
|
||||
assertEquals(clientData+DEBUG_SEPARATOR+"Some debug",
|
||||
repositoryClientData.toString());
|
||||
assertEquals(clientData + DEBUG_SEPARATOR + "Some debug",
|
||||
repositoryClientData.toString());
|
||||
|
||||
repositoryClientData.appendDebug("Some other debug");
|
||||
assertEquals(clientData+DEBUG_SEPARATOR+"Some debug"+DEBUG_SEPARATOR+"Some other debug",
|
||||
repositoryClientData.toString());
|
||||
assertEquals(clientData + DEBUG_SEPARATOR + "Some debug" + DEBUG_SEPARATOR + "Some other debug",
|
||||
repositoryClientData.toString());
|
||||
}
|
||||
}
|
||||
|
@@ -21,30 +21,31 @@
|
||||
*/
|
||||
package org.alfresco.transform.common;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import static org.alfresco.transform.common.Mimetype.MIMETYPE_TEXT_PLAIN;
|
||||
import static org.alfresco.transform.common.Mimetype.MIMETYPE_WORD;
|
||||
import static org.alfresco.transform.common.RepositoryClientData.DEBUG_SEPARATOR;
|
||||
|
||||
import java.util.StringJoiner;
|
||||
|
||||
import ch.qos.logback.classic.Level;
|
||||
import ch.qos.logback.classic.Logger;
|
||||
import ch.qos.logback.classic.LoggerContext;
|
||||
import ch.qos.logback.classic.spi.ILoggingEvent;
|
||||
import ch.qos.logback.core.AppenderBase;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import org.alfresco.transform.client.model.InternalContext;
|
||||
import org.alfresco.transform.client.model.TransformReply;
|
||||
import org.alfresco.transform.client.model.TransformRequest;
|
||||
import org.alfresco.transform.messages.TransformStack;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.StringJoiner;
|
||||
|
||||
import static org.alfresco.transform.common.Mimetype.MIMETYPE_TEXT_PLAIN;
|
||||
import static org.alfresco.transform.common.Mimetype.MIMETYPE_WORD;
|
||||
import static org.alfresco.transform.common.RepositoryClientData.DEBUG_SEPARATOR;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import org.alfresco.transform.client.model.InternalContext;
|
||||
import org.alfresco.transform.client.model.TransformReply;
|
||||
import org.alfresco.transform.client.model.TransformRequest;
|
||||
import org.alfresco.transform.messages.TransformStack;
|
||||
|
||||
/**
|
||||
* Tests TransformerDebug. AbstractRouterTest in the t-router contains more complete end to end tests. The tests in this
|
||||
* class are a smoke test at the moment.
|
||||
* Tests TransformerDebug. AbstractRouterTest in the t-router contains more complete end to end tests. The tests in this class are a smoke test at the moment.
|
||||
*/
|
||||
class TransformerDebugTest
|
||||
{
|
||||
@@ -61,7 +62,7 @@ class TransformerDebugTest
|
||||
}
|
||||
|
||||
private void twoStepTransform(boolean isTRouter, boolean fail, Level logLevel, String renditionName,
|
||||
long sourceSize)
|
||||
long sourceSize)
|
||||
{
|
||||
transformerDebug.setIsTRouter(isTRouter);
|
||||
monitorLogs(logLevel);
|
||||
@@ -90,7 +91,7 @@ class TransformerDebugTest
|
||||
transformerDebug.logOptions(request);
|
||||
TransformStack.removeSuccessfulStep(reply, transformerDebug);
|
||||
|
||||
request.setTransformRequestOptions(ImmutableMap.of("k1", "v1", "k2","v2"));
|
||||
request.setTransformRequestOptions(ImmutableMap.of("k1", "v1", "k2", "v2"));
|
||||
transformerDebug.pushTransform(request);
|
||||
transformerDebug.logOptions(request);
|
||||
if (fail)
|
||||
@@ -107,16 +108,15 @@ class TransformerDebugTest
|
||||
|
||||
private void monitorLogs(Level logLevel)
|
||||
{
|
||||
Logger logger = (Logger)LoggerFactory.getLogger(TransformerDebug.class);
|
||||
AppenderBase<ILoggingEvent> logAppender = new AppenderBase<>()
|
||||
{
|
||||
Logger logger = (Logger) LoggerFactory.getLogger(TransformerDebug.class);
|
||||
AppenderBase<ILoggingEvent> logAppender = new AppenderBase<>() {
|
||||
@Override
|
||||
protected void append(ILoggingEvent iLoggingEvent)
|
||||
{
|
||||
transformerDebugOutput.add(iLoggingEvent.getMessage());
|
||||
}
|
||||
};
|
||||
logAppender.setContext((LoggerContext)LoggerFactory.getILoggerFactory());
|
||||
logAppender.setContext((LoggerContext) LoggerFactory.getILoggerFactory());
|
||||
logger.setLevel(logLevel);
|
||||
logger.addAppender(logAppender);
|
||||
logAppender.start();
|
||||
@@ -128,12 +128,12 @@ class TransformerDebugTest
|
||||
twoStepTransform(true, false, Level.DEBUG, "", 1234L);
|
||||
|
||||
Assertions.assertEquals("" +
|
||||
"1 txt pdf 1.2 KB wrapper\n" +
|
||||
"1.1 txt doc transformer1\n" +
|
||||
"1.2 doc pdf transformer2\n" +
|
||||
"1.2 k1=\"v1\"\n" +
|
||||
"1.2 k2=\"v2\"\n" +
|
||||
"1 Finished in -- ms",
|
||||
"1 txt pdf 1.2 KB wrapper\n" +
|
||||
"1.1 txt doc transformer1\n" +
|
||||
"1.2 doc pdf transformer2\n" +
|
||||
"1.2 k1=\"v1\"\n" +
|
||||
"1.2 k2=\"v2\"\n" +
|
||||
"1 Finished in -- ms",
|
||||
getTransformerDebugOutput());
|
||||
}
|
||||
|
||||
@@ -145,14 +145,14 @@ class TransformerDebugTest
|
||||
// With trace there are "Finished" lines for nested transforms, like a T-Engine's debug but still without
|
||||
// the size and rendition name
|
||||
Assertions.assertEquals("" +
|
||||
"1 txt pdf 1.2 KB wrapper\n" +
|
||||
"1.1 txt doc transformer1\n" +
|
||||
"1.1 Finished in -- ms\n" +
|
||||
"1.2 doc pdf transformer2\n" +
|
||||
"1.2 k1=\"v1\"\n" +
|
||||
"1.2 k2=\"v2\"\n" +
|
||||
"1.2 Finished in -- ms\n" +
|
||||
"1 Finished in -- ms",
|
||||
"1 txt pdf 1.2 KB wrapper\n" +
|
||||
"1.1 txt doc transformer1\n" +
|
||||
"1.1 Finished in -- ms\n" +
|
||||
"1.2 doc pdf transformer2\n" +
|
||||
"1.2 k1=\"v1\"\n" +
|
||||
"1.2 k2=\"v2\"\n" +
|
||||
"1.2 Finished in -- ms\n" +
|
||||
"1 Finished in -- ms",
|
||||
getTransformerDebugOutput());
|
||||
}
|
||||
|
||||
@@ -164,14 +164,14 @@ class TransformerDebugTest
|
||||
// Note the first and last lines would only ever be logged on the router, but the expected data includes
|
||||
// the extra "Finished" lines, sizes and renditions (if set in client data).
|
||||
Assertions.assertEquals("" +
|
||||
"1 txt pdf 1.2 KB wrapper\n" +
|
||||
"1.1 txt doc 1.2 KB transformer1\n" +
|
||||
"1.1 Finished in -- ms\n" +
|
||||
"1.2 doc pdf 1.2 KB transformer2\n" +
|
||||
"1.2 k1=\"v1\"\n" +
|
||||
"1.2 k2=\"v2\"\n" +
|
||||
"1.2 Finished in -- ms\n" +
|
||||
"1 Finished in -- ms",
|
||||
"1 txt pdf 1.2 KB wrapper\n" +
|
||||
"1.1 txt doc 1.2 KB transformer1\n" +
|
||||
"1.1 Finished in -- ms\n" +
|
||||
"1.2 doc pdf 1.2 KB transformer2\n" +
|
||||
"1.2 k1=\"v1\"\n" +
|
||||
"1.2 k2=\"v2\"\n" +
|
||||
"1.2 Finished in -- ms\n" +
|
||||
"1 Finished in -- ms",
|
||||
getTransformerDebugOutput());
|
||||
}
|
||||
|
||||
@@ -181,13 +181,13 @@ class TransformerDebugTest
|
||||
twoStepTransform(true, true, Level.DEBUG, "", 1234L);
|
||||
|
||||
Assertions.assertEquals("" +
|
||||
"1 txt pdf 1.2 KB wrapper\n" +
|
||||
"1.1 txt doc transformer1\n" +
|
||||
"1.2 doc pdf transformer2\n" +
|
||||
"1.2 k1=\"v1\"\n" +
|
||||
"1.2 k2=\"v2\"\n" +
|
||||
"1.2 Dummy error",
|
||||
getTransformerDebugOutput());
|
||||
"1 txt pdf 1.2 KB wrapper\n" +
|
||||
"1.1 txt doc transformer1\n" +
|
||||
"1.2 doc pdf transformer2\n" +
|
||||
"1.2 k1=\"v1\"\n" +
|
||||
"1.2 k2=\"v2\"\n" +
|
||||
"1.2 Dummy error",
|
||||
getTransformerDebugOutput());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -196,13 +196,13 @@ class TransformerDebugTest
|
||||
twoStepTransform(true, false, Level.DEBUG, "renditionName", 1234L);
|
||||
|
||||
Assertions.assertEquals("" +
|
||||
"1 txt pdf 1.2 KB -- renditionName -- wrapper\n" +
|
||||
"1.1 txt doc transformer1\n" +
|
||||
"1.2 doc pdf transformer2\n" +
|
||||
"1.2 k1=\"v1\"\n" +
|
||||
"1.2 k2=\"v2\"\n" +
|
||||
"1 Finished in -- ms",
|
||||
getTransformerDebugOutput());
|
||||
"1 txt pdf 1.2 KB -- renditionName -- wrapper\n" +
|
||||
"1.1 txt doc transformer1\n" +
|
||||
"1.2 doc pdf transformer2\n" +
|
||||
"1.2 k1=\"v1\"\n" +
|
||||
"1.2 k2=\"v2\"\n" +
|
||||
"1 Finished in -- ms",
|
||||
getTransformerDebugOutput());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -211,13 +211,13 @@ class TransformerDebugTest
|
||||
twoStepTransform(true, false, Level.DEBUG, "transform:alfresco-metadata-extract", 1234L);
|
||||
|
||||
Assertions.assertEquals("" +
|
||||
"1 txt pdf 1.2 KB -- metadataExtract -- wrapper\n" +
|
||||
"1.1 txt doc transformer1\n" +
|
||||
"1.2 doc pdf transformer2\n" +
|
||||
"1.2 k1=\"v1\"\n" +
|
||||
"1.2 k2=\"v2\"\n" +
|
||||
"1 Finished in -- ms",
|
||||
getTransformerDebugOutput());
|
||||
"1 txt pdf 1.2 KB -- metadataExtract -- wrapper\n" +
|
||||
"1.1 txt doc transformer1\n" +
|
||||
"1.2 doc pdf transformer2\n" +
|
||||
"1.2 k1=\"v1\"\n" +
|
||||
"1.2 k2=\"v2\"\n" +
|
||||
"1 Finished in -- ms",
|
||||
getTransformerDebugOutput());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -226,13 +226,13 @@ class TransformerDebugTest
|
||||
twoStepTransform(true, false, Level.DEBUG, "transform:alfresco-metadata-embed", 1234L);
|
||||
|
||||
Assertions.assertEquals("" +
|
||||
"1 txt pdf 1.2 KB -- metadataEmbed -- wrapper\n" +
|
||||
"1.1 txt doc transformer1\n" +
|
||||
"1.2 doc pdf transformer2\n" +
|
||||
"1.2 k1=\"v1\"\n" +
|
||||
"1.2 k2=\"v2\"\n" +
|
||||
"1 Finished in -- ms",
|
||||
getTransformerDebugOutput());
|
||||
"1 txt pdf 1.2 KB -- metadataEmbed -- wrapper\n" +
|
||||
"1.1 txt doc transformer1\n" +
|
||||
"1.2 doc pdf transformer2\n" +
|
||||
"1.2 k1=\"v1\"\n" +
|
||||
"1.2 k2=\"v2\"\n" +
|
||||
"1 Finished in -- ms",
|
||||
getTransformerDebugOutput());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -241,28 +241,28 @@ class TransformerDebugTest
|
||||
twoStepTransform(true, false, Level.DEBUG, "", 1);
|
||||
|
||||
Assertions.assertEquals("" +
|
||||
"1 txt pdf 1 byte wrapper\n" +
|
||||
"1.1 txt doc transformer1\n" +
|
||||
"1.2 doc pdf transformer2\n" +
|
||||
"1.2 k1=\"v1\"\n" +
|
||||
"1.2 k2=\"v2\"\n" +
|
||||
"1 Finished in -- ms",
|
||||
getTransformerDebugOutput());
|
||||
"1 txt pdf 1 byte wrapper\n" +
|
||||
"1.1 txt doc transformer1\n" +
|
||||
"1.2 doc pdf transformer2\n" +
|
||||
"1.2 k1=\"v1\"\n" +
|
||||
"1.2 k2=\"v2\"\n" +
|
||||
"1 Finished in -- ms",
|
||||
getTransformerDebugOutput());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSourceSize23TB()
|
||||
{
|
||||
twoStepTransform(true, false, Level.DEBUG, "", 23L*1024*1024*1024*1024);
|
||||
twoStepTransform(true, false, Level.DEBUG, "", 23L * 1024 * 1024 * 1024 * 1024);
|
||||
|
||||
Assertions.assertEquals("" +
|
||||
"1 txt pdf 23 TB wrapper\n" +
|
||||
"1.1 txt doc transformer1\n" +
|
||||
"1.2 doc pdf transformer2\n" +
|
||||
"1.2 k1=\"v1\"\n" +
|
||||
"1.2 k2=\"v2\"\n" +
|
||||
"1 Finished in -- ms",
|
||||
getTransformerDebugOutput());
|
||||
"1 txt pdf 23 TB wrapper\n" +
|
||||
"1.1 txt doc transformer1\n" +
|
||||
"1.2 doc pdf transformer2\n" +
|
||||
"1.2 k1=\"v1\"\n" +
|
||||
"1.2 k2=\"v2\"\n" +
|
||||
"1 Finished in -- ms",
|
||||
getTransformerDebugOutput());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -301,7 +301,7 @@ class TransformerDebugTest
|
||||
transformerDebug.logFailure(reply);
|
||||
|
||||
String expectedDebug = " T-Request was null - a major error";
|
||||
String expectedClientData = origClientData+DEBUG_SEPARATOR+expectedDebug;
|
||||
String expectedClientData = origClientData + DEBUG_SEPARATOR + expectedDebug;
|
||||
Assertions.assertEquals(expectedDebug, getTransformerDebugOutput());
|
||||
assertEquals(expectedClientData, reply.getClientData());
|
||||
}
|
||||
@@ -309,15 +309,15 @@ class TransformerDebugTest
|
||||
@Test
|
||||
void tesGetOptionAndValue()
|
||||
{
|
||||
String sixtyChars = "12345678 10 345678 20 345678 30 345678 40 345678 50 abcdefgh";
|
||||
String sixtyChars = "12345678 10 345678 20 345678 30 345678 40 345678 50 abcdefgh";
|
||||
String sixtyOneChars = "12345678 10 345678 20 345678 30 345678 40 345678 50 abcd12345";
|
||||
String expected = "12345678 10 345678 20 345678 30 345678 40 345678 50 ...12345";
|
||||
String expected = "12345678 10 345678 20 345678 30 345678 40 345678 50 ...12345";
|
||||
|
||||
assertEquals("ref key=\"value\"",
|
||||
transformerDebug.getOptionAndValue("ref", "key", "value"));
|
||||
assertEquals("ref key=\""+sixtyChars+"\"",
|
||||
assertEquals("ref key=\"" + sixtyChars + "\"",
|
||||
transformerDebug.getOptionAndValue("ref", "key", sixtyChars));
|
||||
assertEquals("ref key=\""+expected+"\"",
|
||||
assertEquals("ref key=\"" + expected + "\"",
|
||||
transformerDebug.getOptionAndValue("ref", "key", sixtyOneChars));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -21,10 +21,10 @@
|
||||
*/
|
||||
package org.alfresco.transform.config;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class CoreFunctionTest
|
||||
{
|
||||
@Test
|
||||
@@ -47,4 +47,4 @@ class CoreFunctionTest
|
||||
assertTrue(CoreFunction.DIRECT_ACCESS_URL.isSupported("2.6"));
|
||||
assertTrue(CoreFunction.DIRECT_ACCESS_URL.isSupported("999999"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,300 +1,283 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Transform Model
|
||||
* %%
|
||||
* Copyright (C) 2015 - 2022 Alfresco Software Limited
|
||||
* %%
|
||||
* This program 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.
|
||||
*
|
||||
* This program 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 General Lesser Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Lesser Public
|
||||
* License along with this program. If not, see
|
||||
* <http://www.gnu.org/licenses/lgpl-3.0.html>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.transform.config.reader;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import org.alfresco.transform.config.TransformConfig;
|
||||
import org.alfresco.transform.config.TransformOption;
|
||||
import org.alfresco.transform.config.TransformOptionGroup;
|
||||
import org.alfresco.transform.config.TransformOptionValue;
|
||||
import org.alfresco.transform.config.Transformer;
|
||||
import org.alfresco.transform.config.SupportedSourceAndTarget;
|
||||
import org.alfresco.transform.config.TransformStep;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
public class TransformConfigReaderJsonTest
|
||||
{
|
||||
@Test
|
||||
public void testEmptyRoutesFile() throws Exception
|
||||
{
|
||||
final Resource resource = new ClassPathResource("config/sample1.json");
|
||||
final TransformConfigReader loader = TransformConfigReaderFactory.create(resource);
|
||||
TransformConfig transformConfig = loader.load();
|
||||
final List<Transformer> transformers = transformConfig.getTransformers();
|
||||
|
||||
assertNotNull(transformers);
|
||||
assertEquals(Collections.emptyList(), transformers);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMixedRoutesFile() throws Exception
|
||||
{
|
||||
final List<Transformer> expected = prepareSample2();
|
||||
|
||||
final Resource resource = new ClassPathResource("config/sample2.json");
|
||||
final TransformConfigReader loader = TransformConfigReaderFactory.create(resource);
|
||||
|
||||
TransformConfig transformConfig = loader.load();
|
||||
final List<Transformer> transformers = transformConfig.getTransformers();
|
||||
|
||||
assertNotNull(transformers);
|
||||
assertEquals(expected.size(), transformers.size());
|
||||
assertTrue(expected.containsAll(transformers));
|
||||
}
|
||||
|
||||
private List<Transformer> prepareSample2()
|
||||
{
|
||||
return List.of(
|
||||
Transformer.builder()
|
||||
.withTransformerName("CORE_AIO")
|
||||
.withSupportedSourceAndTargetList(ImmutableSet.of(
|
||||
SupportedSourceAndTarget.builder()
|
||||
.withSourceMediaType("image/gif")
|
||||
.withTargetMediaType("image/gif")
|
||||
.build()
|
||||
))
|
||||
.withTransformOptions(ImmutableSet.of("imageMagickOptions"))
|
||||
.build(),
|
||||
Transformer.builder()
|
||||
.withTransformerName("IMAGEMAGICK")
|
||||
.withSupportedSourceAndTargetList(ImmutableSet.of(
|
||||
SupportedSourceAndTarget.builder()
|
||||
.withSourceMediaType("image/gif")
|
||||
.withTargetMediaType("image/gif")
|
||||
.build()
|
||||
))
|
||||
.withTransformOptions(ImmutableSet.of("imageMagickOptions"))
|
||||
.build(),
|
||||
Transformer.builder()
|
||||
.withTransformerName("CORE_AIO")
|
||||
.withSupportedSourceAndTargetList(ImmutableSet.of(
|
||||
SupportedSourceAndTarget.builder()
|
||||
.withSourceMediaType("application/msword")
|
||||
.withTargetMediaType("application/pdf")
|
||||
.withMaxSourceSizeBytes(18874368L)
|
||||
.build()
|
||||
))
|
||||
.build(),
|
||||
Transformer.builder()
|
||||
.withTransformerName("PDF_RENDERER")
|
||||
.withSupportedSourceAndTargetList(ImmutableSet.of(
|
||||
SupportedSourceAndTarget.builder()
|
||||
.withSourceMediaType("application/vnd.ms-powerpoint")
|
||||
.withTargetMediaType("application/pdf")
|
||||
.withPriority(55)
|
||||
.withMaxSourceSizeBytes(50331648L)
|
||||
.build()
|
||||
))
|
||||
.build(),
|
||||
Transformer.builder()
|
||||
.withTransformerName("CORE_AIO")
|
||||
.withSupportedSourceAndTargetList(ImmutableSet.of(
|
||||
SupportedSourceAndTarget.builder()
|
||||
.withSourceMediaType("text/plain")
|
||||
.withTargetMediaType("text/plain")
|
||||
.build(),
|
||||
SupportedSourceAndTarget.builder()
|
||||
.withSourceMediaType("text/mediawiki")
|
||||
.withTargetMediaType("text/plain")
|
||||
.build(),
|
||||
SupportedSourceAndTarget.builder()
|
||||
.withSourceMediaType("text/css")
|
||||
.withTargetMediaType("text/plain")
|
||||
.build(),
|
||||
SupportedSourceAndTarget.builder()
|
||||
.withSourceMediaType("text/csv")
|
||||
.withTargetMediaType("text/plain")
|
||||
.build(),
|
||||
SupportedSourceAndTarget.builder()
|
||||
.withSourceMediaType("text/xml")
|
||||
.withTargetMediaType("text/plain")
|
||||
.build(),
|
||||
SupportedSourceAndTarget.builder()
|
||||
.withSourceMediaType("text/html")
|
||||
.withTargetMediaType("text/plain")
|
||||
.build(),
|
||||
SupportedSourceAndTarget.builder()
|
||||
.withSourceMediaType("application/x-javascript")
|
||||
.withTargetMediaType("text/plain")
|
||||
.build(),
|
||||
SupportedSourceAndTarget.builder()
|
||||
.withSourceMediaType("application/dita+xml")
|
||||
.withTargetMediaType("text/plain")
|
||||
.build()
|
||||
))
|
||||
.withTransformOptions(ImmutableSet.of("stringOptions"))
|
||||
.build(),
|
||||
Transformer.builder()
|
||||
.withTransformerName("officeToImageViaPdf")
|
||||
.withTransformerPipeline(ImmutableList.of(
|
||||
new TransformStep("libreoffice", "application/pdf"),
|
||||
new TransformStep("pdfToImageViaPng", null)
|
||||
))
|
||||
.withTransformOptions(ImmutableSet.of(
|
||||
"pdfRendererOptions",
|
||||
"imageMagickOptions"
|
||||
))
|
||||
.build(),
|
||||
Transformer.builder()
|
||||
.withTransformerName("textToImageViaPdf")
|
||||
.withTransformerPipeline(ImmutableList.of(
|
||||
new TransformStep("libreoffice", "application/pdf"),
|
||||
new TransformStep("pdfToImageViaPng", null)
|
||||
))
|
||||
.withTransformOptions(ImmutableSet.of(
|
||||
"pdfRendererOptions",
|
||||
"imageMagickOptions"
|
||||
))
|
||||
.withSupportedSourceAndTargetList(ImmutableSet.of(
|
||||
SupportedSourceAndTarget.builder()
|
||||
.withSourceMediaType("text/plain")
|
||||
.withTargetMediaType("image/gif")
|
||||
.build(),
|
||||
SupportedSourceAndTarget.builder()
|
||||
.withSourceMediaType("text/plain")
|
||||
.withTargetMediaType("image/jpeg")
|
||||
.build(),
|
||||
SupportedSourceAndTarget.builder()
|
||||
.withSourceMediaType("text/plain")
|
||||
.withTargetMediaType("image/tiff")
|
||||
.build(),
|
||||
SupportedSourceAndTarget.builder()
|
||||
.withSourceMediaType("text/plain")
|
||||
.withTargetMediaType("image/png")
|
||||
.build(),
|
||||
SupportedSourceAndTarget.builder()
|
||||
.withSourceMediaType("text/csv")
|
||||
.withTargetMediaType("image/gif")
|
||||
.build(),
|
||||
SupportedSourceAndTarget.builder()
|
||||
.withSourceMediaType("text/csv")
|
||||
.withTargetMediaType("image/jpeg")
|
||||
.build(),
|
||||
SupportedSourceAndTarget.builder()
|
||||
.withSourceMediaType("text/csv")
|
||||
.withTargetMediaType("image/tiff")
|
||||
.build(),
|
||||
SupportedSourceAndTarget.builder()
|
||||
.withSourceMediaType("text/csv")
|
||||
.withTargetMediaType("image/png")
|
||||
.build(),
|
||||
SupportedSourceAndTarget.builder()
|
||||
.withSourceMediaType("text/xml")
|
||||
.withTargetMediaType("image/gif")
|
||||
.build(),
|
||||
SupportedSourceAndTarget.builder()
|
||||
.withSourceMediaType("text/xml")
|
||||
.withTargetMediaType("image/jpeg")
|
||||
.build(),
|
||||
SupportedSourceAndTarget.builder()
|
||||
.withSourceMediaType("text/xml")
|
||||
.withTargetMediaType("image/tiff")
|
||||
.build(),
|
||||
SupportedSourceAndTarget.builder()
|
||||
.withSourceMediaType("text/xml")
|
||||
.withTargetMediaType("image/png")
|
||||
.build()
|
||||
))
|
||||
.withTransformOptions(ImmutableSet.of(
|
||||
"pdfRendererOptions",
|
||||
"imageMagickOptions"
|
||||
))
|
||||
.build()
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRouteFileWithTransformOptions() throws Exception
|
||||
{
|
||||
final List<Transformer> expected = prepareSample5Transformers();
|
||||
Map<String, Set<TransformOption>> expectedOptions = prepareSample5Options();
|
||||
|
||||
final Resource resource = new ClassPathResource("config/sample5.json");
|
||||
final TransformConfigReader loader = TransformConfigReaderFactory.create(resource);
|
||||
|
||||
TransformConfig transformConfig = loader.load();
|
||||
final List<Transformer> transformers = transformConfig.getTransformers();
|
||||
Map<String, Set<TransformOption>> transformOptions = transformConfig.getTransformOptions();
|
||||
|
||||
assertNotNull(transformers);
|
||||
assertEquals(expected.size(), transformers.size());
|
||||
assertTrue(expected.containsAll(transformers));
|
||||
assertEquals(expectedOptions, transformOptions);
|
||||
}
|
||||
|
||||
private List<Transformer> prepareSample5Transformers()
|
||||
{
|
||||
return List.of(
|
||||
Transformer.builder()
|
||||
.withTransformerName("CORE_AIO")
|
||||
.withSupportedSourceAndTargetList(ImmutableSet.of(
|
||||
SupportedSourceAndTarget.builder()
|
||||
.withSourceMediaType("image/gif")
|
||||
.withTargetMediaType("image/gif")
|
||||
.build()
|
||||
))
|
||||
.withTransformOptions(ImmutableSet.of("imageMagickOptions"))
|
||||
.build()
|
||||
);
|
||||
}
|
||||
|
||||
public static Map<String, Set<TransformOption>> prepareSample5Options()
|
||||
{
|
||||
return ImmutableMap.of(
|
||||
"imageMagickOptions", ImmutableSet.of(
|
||||
new TransformOptionValue(false, "alphaRemove"),
|
||||
new TransformOptionValue(false, "autoOrient"),
|
||||
new TransformOptionValue(false, "startPage"),
|
||||
new TransformOptionValue(false, "endPage"),
|
||||
new TransformOptionGroup(false, ImmutableSet.of(
|
||||
new TransformOptionValue(false, "cropGravity"),
|
||||
new TransformOptionValue(false, "cropWidth"),
|
||||
new TransformOptionValue(false, "cropHeight"),
|
||||
new TransformOptionValue(false, "cropPercentage"),
|
||||
new TransformOptionValue(false, "cropXOffset"),
|
||||
new TransformOptionValue(false, "cropYOffset")
|
||||
)),
|
||||
new TransformOptionGroup(false, ImmutableSet.of(
|
||||
new TransformOptionValue(false, "thumbnail"),
|
||||
new TransformOptionValue(false, "resizeHeight"),
|
||||
new TransformOptionValue(false, "resizeWidth"),
|
||||
new TransformOptionValue(false, "resizePercentage"),
|
||||
new TransformOptionValue(false, "allowEnlargement"),
|
||||
new TransformOptionValue(false, "maintainAspectRatio")
|
||||
)))
|
||||
);
|
||||
}
|
||||
}
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Transform Model
|
||||
* %%
|
||||
* Copyright (C) 2015 - 2022 Alfresco Software Limited
|
||||
* %%
|
||||
* This program 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.
|
||||
*
|
||||
* This program 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 General Lesser Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Lesser Public
|
||||
* License along with this program. If not, see
|
||||
* <http://www.gnu.org/licenses/lgpl-3.0.html>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.transform.config.reader;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
|
||||
import org.alfresco.transform.config.SupportedSourceAndTarget;
|
||||
import org.alfresco.transform.config.TransformConfig;
|
||||
import org.alfresco.transform.config.TransformOption;
|
||||
import org.alfresco.transform.config.TransformOptionGroup;
|
||||
import org.alfresco.transform.config.TransformOptionValue;
|
||||
import org.alfresco.transform.config.TransformStep;
|
||||
import org.alfresco.transform.config.Transformer;
|
||||
|
||||
public class TransformConfigReaderJsonTest
|
||||
{
|
||||
@Test
|
||||
public void testEmptyRoutesFile() throws Exception
|
||||
{
|
||||
final Resource resource = new ClassPathResource("config/sample1.json");
|
||||
final TransformConfigReader loader = TransformConfigReaderFactory.create(resource);
|
||||
TransformConfig transformConfig = loader.load();
|
||||
final List<Transformer> transformers = transformConfig.getTransformers();
|
||||
|
||||
assertNotNull(transformers);
|
||||
assertEquals(Collections.emptyList(), transformers);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMixedRoutesFile() throws Exception
|
||||
{
|
||||
final List<Transformer> expected = prepareSample2();
|
||||
|
||||
final Resource resource = new ClassPathResource("config/sample2.json");
|
||||
final TransformConfigReader loader = TransformConfigReaderFactory.create(resource);
|
||||
|
||||
TransformConfig transformConfig = loader.load();
|
||||
final List<Transformer> transformers = transformConfig.getTransformers();
|
||||
|
||||
assertNotNull(transformers);
|
||||
assertEquals(expected.size(), transformers.size());
|
||||
assertTrue(expected.containsAll(transformers));
|
||||
}
|
||||
|
||||
private List<Transformer> prepareSample2()
|
||||
{
|
||||
return List.of(
|
||||
Transformer.builder()
|
||||
.withTransformerName("CORE_AIO")
|
||||
.withSupportedSourceAndTargetList(ImmutableSet.of(
|
||||
SupportedSourceAndTarget.builder()
|
||||
.withSourceMediaType("image/gif")
|
||||
.withTargetMediaType("image/gif")
|
||||
.build()))
|
||||
.withTransformOptions(ImmutableSet.of("imageMagickOptions"))
|
||||
.build(),
|
||||
Transformer.builder()
|
||||
.withTransformerName("IMAGEMAGICK")
|
||||
.withSupportedSourceAndTargetList(ImmutableSet.of(
|
||||
SupportedSourceAndTarget.builder()
|
||||
.withSourceMediaType("image/gif")
|
||||
.withTargetMediaType("image/gif")
|
||||
.build()))
|
||||
.withTransformOptions(ImmutableSet.of("imageMagickOptions"))
|
||||
.build(),
|
||||
Transformer.builder()
|
||||
.withTransformerName("CORE_AIO")
|
||||
.withSupportedSourceAndTargetList(ImmutableSet.of(
|
||||
SupportedSourceAndTarget.builder()
|
||||
.withSourceMediaType("application/msword")
|
||||
.withTargetMediaType("application/pdf")
|
||||
.withMaxSourceSizeBytes(18874368L)
|
||||
.build()))
|
||||
.build(),
|
||||
Transformer.builder()
|
||||
.withTransformerName("PDF_RENDERER")
|
||||
.withSupportedSourceAndTargetList(ImmutableSet.of(
|
||||
SupportedSourceAndTarget.builder()
|
||||
.withSourceMediaType("application/vnd.ms-powerpoint")
|
||||
.withTargetMediaType("application/pdf")
|
||||
.withPriority(55)
|
||||
.withMaxSourceSizeBytes(50331648L)
|
||||
.build()))
|
||||
.build(),
|
||||
Transformer.builder()
|
||||
.withTransformerName("CORE_AIO")
|
||||
.withSupportedSourceAndTargetList(ImmutableSet.of(
|
||||
SupportedSourceAndTarget.builder()
|
||||
.withSourceMediaType("text/plain")
|
||||
.withTargetMediaType("text/plain")
|
||||
.build(),
|
||||
SupportedSourceAndTarget.builder()
|
||||
.withSourceMediaType("text/mediawiki")
|
||||
.withTargetMediaType("text/plain")
|
||||
.build(),
|
||||
SupportedSourceAndTarget.builder()
|
||||
.withSourceMediaType("text/css")
|
||||
.withTargetMediaType("text/plain")
|
||||
.build(),
|
||||
SupportedSourceAndTarget.builder()
|
||||
.withSourceMediaType("text/csv")
|
||||
.withTargetMediaType("text/plain")
|
||||
.build(),
|
||||
SupportedSourceAndTarget.builder()
|
||||
.withSourceMediaType("text/xml")
|
||||
.withTargetMediaType("text/plain")
|
||||
.build(),
|
||||
SupportedSourceAndTarget.builder()
|
||||
.withSourceMediaType("text/html")
|
||||
.withTargetMediaType("text/plain")
|
||||
.build(),
|
||||
SupportedSourceAndTarget.builder()
|
||||
.withSourceMediaType("application/x-javascript")
|
||||
.withTargetMediaType("text/plain")
|
||||
.build(),
|
||||
SupportedSourceAndTarget.builder()
|
||||
.withSourceMediaType("application/dita+xml")
|
||||
.withTargetMediaType("text/plain")
|
||||
.build()))
|
||||
.withTransformOptions(ImmutableSet.of("stringOptions"))
|
||||
.build(),
|
||||
Transformer.builder()
|
||||
.withTransformerName("officeToImageViaPdf")
|
||||
.withTransformerPipeline(ImmutableList.of(
|
||||
new TransformStep("libreoffice", "application/pdf"),
|
||||
new TransformStep("pdfToImageViaPng", null)))
|
||||
.withTransformOptions(ImmutableSet.of(
|
||||
"pdfRendererOptions",
|
||||
"imageMagickOptions"))
|
||||
.build(),
|
||||
Transformer.builder()
|
||||
.withTransformerName("textToImageViaPdf")
|
||||
.withTransformerPipeline(ImmutableList.of(
|
||||
new TransformStep("libreoffice", "application/pdf"),
|
||||
new TransformStep("pdfToImageViaPng", null)))
|
||||
.withTransformOptions(ImmutableSet.of(
|
||||
"pdfRendererOptions",
|
||||
"imageMagickOptions"))
|
||||
.withSupportedSourceAndTargetList(ImmutableSet.of(
|
||||
SupportedSourceAndTarget.builder()
|
||||
.withSourceMediaType("text/plain")
|
||||
.withTargetMediaType("image/gif")
|
||||
.build(),
|
||||
SupportedSourceAndTarget.builder()
|
||||
.withSourceMediaType("text/plain")
|
||||
.withTargetMediaType("image/jpeg")
|
||||
.build(),
|
||||
SupportedSourceAndTarget.builder()
|
||||
.withSourceMediaType("text/plain")
|
||||
.withTargetMediaType("image/tiff")
|
||||
.build(),
|
||||
SupportedSourceAndTarget.builder()
|
||||
.withSourceMediaType("text/plain")
|
||||
.withTargetMediaType("image/png")
|
||||
.build(),
|
||||
SupportedSourceAndTarget.builder()
|
||||
.withSourceMediaType("text/csv")
|
||||
.withTargetMediaType("image/gif")
|
||||
.build(),
|
||||
SupportedSourceAndTarget.builder()
|
||||
.withSourceMediaType("text/csv")
|
||||
.withTargetMediaType("image/jpeg")
|
||||
.build(),
|
||||
SupportedSourceAndTarget.builder()
|
||||
.withSourceMediaType("text/csv")
|
||||
.withTargetMediaType("image/tiff")
|
||||
.build(),
|
||||
SupportedSourceAndTarget.builder()
|
||||
.withSourceMediaType("text/csv")
|
||||
.withTargetMediaType("image/png")
|
||||
.build(),
|
||||
SupportedSourceAndTarget.builder()
|
||||
.withSourceMediaType("text/xml")
|
||||
.withTargetMediaType("image/gif")
|
||||
.build(),
|
||||
SupportedSourceAndTarget.builder()
|
||||
.withSourceMediaType("text/xml")
|
||||
.withTargetMediaType("image/jpeg")
|
||||
.build(),
|
||||
SupportedSourceAndTarget.builder()
|
||||
.withSourceMediaType("text/xml")
|
||||
.withTargetMediaType("image/tiff")
|
||||
.build(),
|
||||
SupportedSourceAndTarget.builder()
|
||||
.withSourceMediaType("text/xml")
|
||||
.withTargetMediaType("image/png")
|
||||
.build()))
|
||||
.withTransformOptions(ImmutableSet.of(
|
||||
"pdfRendererOptions",
|
||||
"imageMagickOptions"))
|
||||
.build());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRouteFileWithTransformOptions() throws Exception
|
||||
{
|
||||
final List<Transformer> expected = prepareSample5Transformers();
|
||||
Map<String, Set<TransformOption>> expectedOptions = prepareSample5Options();
|
||||
|
||||
final Resource resource = new ClassPathResource("config/sample5.json");
|
||||
final TransformConfigReader loader = TransformConfigReaderFactory.create(resource);
|
||||
|
||||
TransformConfig transformConfig = loader.load();
|
||||
final List<Transformer> transformers = transformConfig.getTransformers();
|
||||
Map<String, Set<TransformOption>> transformOptions = transformConfig.getTransformOptions();
|
||||
|
||||
assertNotNull(transformers);
|
||||
assertEquals(expected.size(), transformers.size());
|
||||
assertTrue(expected.containsAll(transformers));
|
||||
assertEquals(expectedOptions, transformOptions);
|
||||
}
|
||||
|
||||
private List<Transformer> prepareSample5Transformers()
|
||||
{
|
||||
return List.of(
|
||||
Transformer.builder()
|
||||
.withTransformerName("CORE_AIO")
|
||||
.withSupportedSourceAndTargetList(ImmutableSet.of(
|
||||
SupportedSourceAndTarget.builder()
|
||||
.withSourceMediaType("image/gif")
|
||||
.withTargetMediaType("image/gif")
|
||||
.build()))
|
||||
.withTransformOptions(ImmutableSet.of("imageMagickOptions"))
|
||||
.build());
|
||||
}
|
||||
|
||||
public static Map<String, Set<TransformOption>> prepareSample5Options()
|
||||
{
|
||||
return ImmutableMap.of(
|
||||
"imageMagickOptions", ImmutableSet.of(
|
||||
new TransformOptionValue(false, "alphaRemove"),
|
||||
new TransformOptionValue(false, "autoOrient"),
|
||||
new TransformOptionValue(false, "startPage"),
|
||||
new TransformOptionValue(false, "endPage"),
|
||||
new TransformOptionGroup(false, ImmutableSet.of(
|
||||
new TransformOptionValue(false, "cropGravity"),
|
||||
new TransformOptionValue(false, "cropWidth"),
|
||||
new TransformOptionValue(false, "cropHeight"),
|
||||
new TransformOptionValue(false, "cropPercentage"),
|
||||
new TransformOptionValue(false, "cropXOffset"),
|
||||
new TransformOptionValue(false, "cropYOffset"))),
|
||||
new TransformOptionGroup(false, ImmutableSet.of(
|
||||
new TransformOptionValue(false, "thumbnail"),
|
||||
new TransformOptionValue(false, "resizeHeight"),
|
||||
new TransformOptionValue(false, "resizeWidth"),
|
||||
new TransformOptionValue(false, "resizePercentage"),
|
||||
new TransformOptionValue(false, "allowEnlargement"),
|
||||
new TransformOptionValue(false, "maintainAspectRatio")))));
|
||||
}
|
||||
}
|
||||
|
@@ -31,17 +31,17 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.alfresco.transform.config.TransformConfig;
|
||||
import org.alfresco.transform.config.TransformOption;
|
||||
import org.alfresco.transform.config.Transformer;
|
||||
import org.alfresco.transform.config.SupportedSourceAndTarget;
|
||||
import org.alfresco.transform.config.TransformStep;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import org.alfresco.transform.config.SupportedSourceAndTarget;
|
||||
import org.alfresco.transform.config.TransformConfig;
|
||||
import org.alfresco.transform.config.TransformOption;
|
||||
import org.alfresco.transform.config.TransformStep;
|
||||
import org.alfresco.transform.config.Transformer;
|
||||
|
||||
public class TransformConfigReaderYamlTest
|
||||
{
|
||||
@@ -55,8 +55,8 @@ public class TransformConfigReaderYamlTest
|
||||
assertNotNull(transformers);
|
||||
assertEquals(Collections.emptyList(), transformers);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@Test
|
||||
public void testMixedRoutesFile() throws Exception
|
||||
{
|
||||
final List<Transformer> expected = prepareSample4();
|
||||
@@ -79,167 +79,156 @@ public class TransformConfigReaderYamlTest
|
||||
{
|
||||
var result = new ArrayList<Transformer>();
|
||||
result.add(Transformer.builder()
|
||||
.withTransformerName("CORE_AIO")
|
||||
.withSupportedSourceAndTargetList(ImmutableSet.of(
|
||||
.withTransformerName("CORE_AIO")
|
||||
.withSupportedSourceAndTargetList(ImmutableSet.of(
|
||||
SupportedSourceAndTarget.builder()
|
||||
.withSourceMediaType("image/gif")
|
||||
.withTargetMediaType("image/gif")
|
||||
.build()
|
||||
))
|
||||
.withTransformOptions(ImmutableSet.of("imageMagickOptions"))
|
||||
.build());
|
||||
.withSourceMediaType("image/gif")
|
||||
.withTargetMediaType("image/gif")
|
||||
.build()))
|
||||
.withTransformOptions(ImmutableSet.of("imageMagickOptions"))
|
||||
.build());
|
||||
|
||||
result.add(Transformer.builder()
|
||||
.withTransformerName("IMAGEMAGICK")
|
||||
.withSupportedSourceAndTargetList(ImmutableSet.of(
|
||||
.withTransformerName("IMAGEMAGICK")
|
||||
.withSupportedSourceAndTargetList(ImmutableSet.of(
|
||||
SupportedSourceAndTarget.builder()
|
||||
.withSourceMediaType("image/gif")
|
||||
.withTargetMediaType("image/gif")
|
||||
.build()
|
||||
))
|
||||
.withTransformOptions(ImmutableSet.of("imageMagickOptions"))
|
||||
.build());
|
||||
.withSourceMediaType("image/gif")
|
||||
.withTargetMediaType("image/gif")
|
||||
.build()))
|
||||
.withTransformOptions(ImmutableSet.of("imageMagickOptions"))
|
||||
.build());
|
||||
|
||||
result.add(Transformer.builder()
|
||||
.withTransformerName("CORE_AIO")
|
||||
.withSupportedSourceAndTargetList(ImmutableSet.of(
|
||||
.withTransformerName("CORE_AIO")
|
||||
.withSupportedSourceAndTargetList(ImmutableSet.of(
|
||||
SupportedSourceAndTarget.builder()
|
||||
.withSourceMediaType("application/msword")
|
||||
.withTargetMediaType("application/pdf")
|
||||
.withMaxSourceSizeBytes(18874368L)
|
||||
.build()
|
||||
))
|
||||
.build());
|
||||
.withSourceMediaType("application/msword")
|
||||
.withTargetMediaType("application/pdf")
|
||||
.withMaxSourceSizeBytes(18874368L)
|
||||
.build()))
|
||||
.build());
|
||||
|
||||
result.add(Transformer.builder()
|
||||
.withTransformerName("PDF_RENDERER")
|
||||
.withSupportedSourceAndTargetList(ImmutableSet.of(
|
||||
.withTransformerName("PDF_RENDERER")
|
||||
.withSupportedSourceAndTargetList(ImmutableSet.of(
|
||||
SupportedSourceAndTarget.builder()
|
||||
.withSourceMediaType("application/vnd.ms-powerpoint")
|
||||
.withTargetMediaType("application/pdf")
|
||||
.withPriority(55)
|
||||
.withMaxSourceSizeBytes(50331648L)
|
||||
.build()
|
||||
))
|
||||
.build());
|
||||
.withSourceMediaType("application/vnd.ms-powerpoint")
|
||||
.withTargetMediaType("application/pdf")
|
||||
.withPriority(55)
|
||||
.withMaxSourceSizeBytes(50331648L)
|
||||
.build()))
|
||||
.build());
|
||||
|
||||
result.add(Transformer.builder()
|
||||
.withTransformerName("CORE_AIO")
|
||||
.withSupportedSourceAndTargetList(ImmutableSet.of(
|
||||
.withTransformerName("CORE_AIO")
|
||||
.withSupportedSourceAndTargetList(ImmutableSet.of(
|
||||
SupportedSourceAndTarget.builder()
|
||||
.withSourceMediaType("text/plain")
|
||||
.withTargetMediaType("text/plain")
|
||||
.build(),
|
||||
.withSourceMediaType("text/plain")
|
||||
.withTargetMediaType("text/plain")
|
||||
.build(),
|
||||
SupportedSourceAndTarget.builder()
|
||||
.withSourceMediaType("text/mediawiki")
|
||||
.withTargetMediaType("text/plain")
|
||||
.build(),
|
||||
.withSourceMediaType("text/mediawiki")
|
||||
.withTargetMediaType("text/plain")
|
||||
.build(),
|
||||
SupportedSourceAndTarget.builder()
|
||||
.withSourceMediaType("text/css")
|
||||
.withTargetMediaType("text/plain")
|
||||
.build(),
|
||||
.withSourceMediaType("text/css")
|
||||
.withTargetMediaType("text/plain")
|
||||
.build(),
|
||||
SupportedSourceAndTarget.builder()
|
||||
.withSourceMediaType("text/csv")
|
||||
.withTargetMediaType("text/plain")
|
||||
.build(),
|
||||
.withSourceMediaType("text/csv")
|
||||
.withTargetMediaType("text/plain")
|
||||
.build(),
|
||||
SupportedSourceAndTarget.builder()
|
||||
.withSourceMediaType("text/xml")
|
||||
.withTargetMediaType("text/plain")
|
||||
.build(),
|
||||
.withSourceMediaType("text/xml")
|
||||
.withTargetMediaType("text/plain")
|
||||
.build(),
|
||||
SupportedSourceAndTarget.builder()
|
||||
.withSourceMediaType("text/html")
|
||||
.withTargetMediaType("text/plain")
|
||||
.build(),
|
||||
.withSourceMediaType("text/html")
|
||||
.withTargetMediaType("text/plain")
|
||||
.build(),
|
||||
SupportedSourceAndTarget.builder()
|
||||
.withSourceMediaType("application/x-javascript")
|
||||
.withTargetMediaType("text/plain")
|
||||
.build(),
|
||||
.withSourceMediaType("application/x-javascript")
|
||||
.withTargetMediaType("text/plain")
|
||||
.build(),
|
||||
SupportedSourceAndTarget.builder()
|
||||
.withSourceMediaType("application/dita+xml")
|
||||
.withTargetMediaType("text/plain")
|
||||
.build()
|
||||
))
|
||||
.withTransformOptions(ImmutableSet.of("stringOptions"))
|
||||
.build());
|
||||
.withSourceMediaType("application/dita+xml")
|
||||
.withTargetMediaType("text/plain")
|
||||
.build()))
|
||||
.withTransformOptions(ImmutableSet.of("stringOptions"))
|
||||
.build());
|
||||
|
||||
result.add(Transformer.builder()
|
||||
.withTransformerName("officeToImageViaPdf")
|
||||
.withTransformerPipeline(ImmutableList.of(
|
||||
.withTransformerName("officeToImageViaPdf")
|
||||
.withTransformerPipeline(ImmutableList.of(
|
||||
new TransformStep("libreoffice", "application/pdf"),
|
||||
new TransformStep("pdfToImageViaPng", null)
|
||||
))
|
||||
.withTransformOptions(ImmutableSet.of(
|
||||
new TransformStep("pdfToImageViaPng", null)))
|
||||
.withTransformOptions(ImmutableSet.of(
|
||||
"pdfRendererOptions",
|
||||
"imageMagickOptions"
|
||||
))
|
||||
.build());
|
||||
|
||||
"imageMagickOptions"))
|
||||
.build());
|
||||
|
||||
result.add(Transformer.builder()
|
||||
.withTransformerName("textToImageViaPdf")
|
||||
.withTransformerPipeline(ImmutableList.of(
|
||||
.withTransformerName("textToImageViaPdf")
|
||||
.withTransformerPipeline(ImmutableList.of(
|
||||
new TransformStep("libreoffice", "application/pdf"),
|
||||
new TransformStep("pdfToImageViaPng", null)
|
||||
))
|
||||
.withTransformOptions(ImmutableSet.of(
|
||||
new TransformStep("pdfToImageViaPng", null)))
|
||||
.withTransformOptions(ImmutableSet.of(
|
||||
"pdfRendererOptions",
|
||||
"imageMagickOptions"
|
||||
))
|
||||
.withSupportedSourceAndTargetList(ImmutableSet.of(
|
||||
"imageMagickOptions"))
|
||||
.withSupportedSourceAndTargetList(ImmutableSet.of(
|
||||
SupportedSourceAndTarget.builder()
|
||||
.withSourceMediaType("text/plain")
|
||||
.withTargetMediaType("image/gif")
|
||||
.build(),
|
||||
.withSourceMediaType("text/plain")
|
||||
.withTargetMediaType("image/gif")
|
||||
.build(),
|
||||
SupportedSourceAndTarget.builder()
|
||||
.withSourceMediaType("text/plain")
|
||||
.withTargetMediaType("image/jpeg")
|
||||
.build(),
|
||||
.withSourceMediaType("text/plain")
|
||||
.withTargetMediaType("image/jpeg")
|
||||
.build(),
|
||||
SupportedSourceAndTarget.builder()
|
||||
.withSourceMediaType("text/plain")
|
||||
.withTargetMediaType("image/tiff")
|
||||
.build(),
|
||||
.withSourceMediaType("text/plain")
|
||||
.withTargetMediaType("image/tiff")
|
||||
.build(),
|
||||
SupportedSourceAndTarget.builder()
|
||||
.withSourceMediaType("text/plain")
|
||||
.withTargetMediaType("image/png")
|
||||
.build(),
|
||||
.withSourceMediaType("text/plain")
|
||||
.withTargetMediaType("image/png")
|
||||
.build(),
|
||||
SupportedSourceAndTarget.builder()
|
||||
.withSourceMediaType("text/csv")
|
||||
.withTargetMediaType("image/gif")
|
||||
.build(),
|
||||
.withSourceMediaType("text/csv")
|
||||
.withTargetMediaType("image/gif")
|
||||
.build(),
|
||||
SupportedSourceAndTarget.builder()
|
||||
.withSourceMediaType("text/csv")
|
||||
.withTargetMediaType("image/jpeg")
|
||||
.build(),
|
||||
.withSourceMediaType("text/csv")
|
||||
.withTargetMediaType("image/jpeg")
|
||||
.build(),
|
||||
SupportedSourceAndTarget.builder()
|
||||
.withSourceMediaType("text/csv")
|
||||
.withTargetMediaType("image/tiff")
|
||||
.build(),
|
||||
.withSourceMediaType("text/csv")
|
||||
.withTargetMediaType("image/tiff")
|
||||
.build(),
|
||||
SupportedSourceAndTarget.builder()
|
||||
.withSourceMediaType("text/csv")
|
||||
.withTargetMediaType("image/png")
|
||||
.build(),
|
||||
.withSourceMediaType("text/csv")
|
||||
.withTargetMediaType("image/png")
|
||||
.build(),
|
||||
SupportedSourceAndTarget.builder()
|
||||
.withSourceMediaType("text/xml")
|
||||
.withTargetMediaType("image/gif")
|
||||
.build(),
|
||||
.withSourceMediaType("text/xml")
|
||||
.withTargetMediaType("image/gif")
|
||||
.build(),
|
||||
SupportedSourceAndTarget.builder()
|
||||
.withSourceMediaType("text/xml")
|
||||
.withTargetMediaType("image/jpeg")
|
||||
.build(),
|
||||
.withSourceMediaType("text/xml")
|
||||
.withTargetMediaType("image/jpeg")
|
||||
.build(),
|
||||
SupportedSourceAndTarget.builder()
|
||||
.withSourceMediaType("text/xml")
|
||||
.withTargetMediaType("image/tiff")
|
||||
.build(),
|
||||
.withSourceMediaType("text/xml")
|
||||
.withTargetMediaType("image/tiff")
|
||||
.build(),
|
||||
SupportedSourceAndTarget.builder()
|
||||
.withSourceMediaType("text/xml")
|
||||
.withTargetMediaType("image/png")
|
||||
.build()
|
||||
))
|
||||
.withTransformOptions(ImmutableSet.of(
|
||||
.withSourceMediaType("text/xml")
|
||||
.withTargetMediaType("image/png")
|
||||
.build()))
|
||||
.withTransformOptions(ImmutableSet.of(
|
||||
"pdfRendererOptions",
|
||||
"imageMagickOptions"
|
||||
))
|
||||
.build());
|
||||
|
||||
"imageMagickOptions"))
|
||||
.build());
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
@@ -21,19 +21,21 @@
|
||||
*/
|
||||
package org.alfresco.transform.messages;
|
||||
|
||||
import static org.alfresco.transform.common.Mimetype.MIMETYPE_IMAGE_PNG;
|
||||
import static org.alfresco.transform.common.Mimetype.MIMETYPE_PDF;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import static org.alfresco.transform.common.Mimetype.MIMETYPE_IMAGE_PNG;
|
||||
import static org.alfresco.transform.common.Mimetype.MIMETYPE_PDF;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import org.alfresco.transform.client.model.TransformRequest;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.validation.DirectFieldBindingResult;
|
||||
import org.springframework.validation.Errors;
|
||||
|
||||
import org.alfresco.transform.client.model.TransformRequest;
|
||||
|
||||
/**
|
||||
* TransformRequestValidatorTest
|
||||
* <p/>
|
||||
@@ -57,7 +59,7 @@ public class TransformRequestValidatorTest
|
||||
|
||||
assertEquals(1, errors.getAllErrors().size());
|
||||
assertEquals("request cannot be null",
|
||||
errors.getAllErrors().iterator().next().getDefaultMessage());
|
||||
errors.getAllErrors().iterator().next().getDefaultMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -70,7 +72,7 @@ public class TransformRequestValidatorTest
|
||||
|
||||
assertFalse(errors.getAllErrors().isEmpty());
|
||||
assertEquals("requestId cannot be null or empty",
|
||||
errors.getAllErrors().iterator().next().getDefaultMessage());
|
||||
errors.getAllErrors().iterator().next().getDefaultMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -85,7 +87,7 @@ public class TransformRequestValidatorTest
|
||||
|
||||
assertFalse(errors.getAllErrors().isEmpty());
|
||||
assertEquals("sourceSize cannot be null or have its value smaller than 0",
|
||||
errors.getAllErrors().iterator().next().getDefaultMessage());
|
||||
errors.getAllErrors().iterator().next().getDefaultMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -101,7 +103,7 @@ public class TransformRequestValidatorTest
|
||||
|
||||
assertFalse(errors.getAllErrors().isEmpty());
|
||||
assertEquals("sourceMediaType cannot be null or empty",
|
||||
errors.getAllErrors().iterator().next().getDefaultMessage());
|
||||
errors.getAllErrors().iterator().next().getDefaultMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -118,7 +120,7 @@ public class TransformRequestValidatorTest
|
||||
|
||||
assertFalse(errors.getAllErrors().isEmpty());
|
||||
assertEquals("targetMediaType cannot be null or empty",
|
||||
errors.getAllErrors().iterator().next().getDefaultMessage());
|
||||
errors.getAllErrors().iterator().next().getDefaultMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -136,7 +138,7 @@ public class TransformRequestValidatorTest
|
||||
|
||||
assertFalse(errors.getAllErrors().isEmpty());
|
||||
assertEquals("targetExtension cannot be null or empty",
|
||||
errors.getAllErrors().iterator().next().getDefaultMessage());
|
||||
errors.getAllErrors().iterator().next().getDefaultMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -155,7 +157,7 @@ public class TransformRequestValidatorTest
|
||||
|
||||
assertFalse(errors.getAllErrors().isEmpty());
|
||||
assertEquals("clientData cannot be null or empty",
|
||||
errors.getAllErrors().iterator().next().getDefaultMessage());
|
||||
errors.getAllErrors().iterator().next().getDefaultMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -176,7 +178,7 @@ public class TransformRequestValidatorTest
|
||||
|
||||
assertFalse(errors.getAllErrors().isEmpty());
|
||||
assertEquals("schema cannot be less than 0",
|
||||
errors.getAllErrors().iterator().next().getDefaultMessage());
|
||||
errors.getAllErrors().iterator().next().getDefaultMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@@ -21,16 +21,15 @@
|
||||
*/
|
||||
package org.alfresco.transform.messages;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import org.alfresco.transform.client.model.InternalContext;
|
||||
import org.alfresco.transform.client.model.MultiStep;
|
||||
import org.alfresco.transform.client.model.TransformReply;
|
||||
import org.alfresco.transform.common.TransformerDebug;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
|
||||
import static org.alfresco.transform.messages.TransformStack.OPTIONS_LEVEL;
|
||||
import static org.alfresco.transform.messages.TransformStack.SEPARATOR;
|
||||
import static org.alfresco.transform.messages.TransformStack.TOP_STACK_LEVEL;
|
||||
import static org.alfresco.transform.messages.TransformStack.getInitialSourceReference;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.util.ArrayList;
|
||||
@@ -38,14 +37,17 @@ import java.util.Arrays;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import static org.alfresco.transform.messages.TransformStack.OPTIONS_LEVEL;
|
||||
import static org.alfresco.transform.messages.TransformStack.SEPARATOR;
|
||||
import static org.alfresco.transform.messages.TransformStack.TOP_STACK_LEVEL;
|
||||
import static org.alfresco.transform.messages.TransformStack.getInitialSourceReference;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
import org.alfresco.transform.client.model.InternalContext;
|
||||
import org.alfresco.transform.client.model.MultiStep;
|
||||
import org.alfresco.transform.client.model.TransformReply;
|
||||
import org.alfresco.transform.common.TransformerDebug;
|
||||
|
||||
class TransformStackTest
|
||||
{
|
||||
@@ -401,7 +403,7 @@ class TransformStackTest
|
||||
TransformStack.Step step = TransformStack.currentStep(internalContext);
|
||||
String transformerName = step.getTransformerName();
|
||||
int depth = internalContext.getMultiStep().getTransformsToBeDone().size() - 2;
|
||||
System.out.println(transformStepCount + " ".substring(0, depth*2+1) + transformerName);
|
||||
System.out.println(transformStepCount + " ".substring(0, depth * 2 + 1) + transformerName);
|
||||
TransformStack.LevelBuilder nextLevel = TEST_LEVELS.get(transformerName);
|
||||
if (nextLevel == null)
|
||||
{
|
||||
@@ -491,15 +493,16 @@ class TransformStackTest
|
||||
TransformStack.addTransformLevel(internalContext, TEST_LEVELS.get("top"));
|
||||
|
||||
for (String value : Arrays.asList(
|
||||
"P" + SEPARATOR + "20" + SEPARATOR + START + SEPARATOR + "1" + STEP,
|
||||
"P" + SEPARATOR + "4" + SEPARATOR + "123" + SEPARATOR + "12" + STEP + STEP))
|
||||
"P" + SEPARATOR + "20" + SEPARATOR + START + SEPARATOR + "1" + STEP,
|
||||
"P" + SEPARATOR + "4" + SEPARATOR + "123" + SEPARATOR + "12" + STEP + STEP))
|
||||
{
|
||||
System.out.println("TransformLevel value: " + value);
|
||||
internalContext.getMultiStep().getTransformsToBeDone().set(TOP_STACK_LEVEL, value);
|
||||
Assertions.assertNull(TransformStack.checkStructure(internalContext, "T-Reply"));
|
||||
// call a getter just in case we have missed something
|
||||
TransformStack.currentStep(internalContext);
|
||||
};
|
||||
}
|
||||
;
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -508,12 +511,13 @@ class TransformStackTest
|
||||
TransformStack.addTransformLevel(internalContext, TEST_LEVELS.get("top"));
|
||||
|
||||
for (String value : Arrays.asList(
|
||||
"P" + SEPARATOR + "e20" + SEPARATOR + START + SEPARATOR + "1" + STEP))
|
||||
"P" + SEPARATOR + "e20" + SEPARATOR + START + SEPARATOR + "1" + STEP))
|
||||
{
|
||||
System.out.println("TransformLevel value: " + value);
|
||||
internalContext.getMultiStep().getTransformsToBeDone().set(TOP_STACK_LEVEL, value);
|
||||
Assertions.assertNull(TransformStack.checkStructure(internalContext, "T-Reply"));
|
||||
};
|
||||
}
|
||||
;
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -522,13 +526,14 @@ class TransformStackTest
|
||||
TransformStack.addTransformLevel(internalContext, TEST_LEVELS.get("top"));
|
||||
|
||||
for (String value : Arrays.asList(
|
||||
"P" + SEPARATOR + "x20" + SEPARATOR + START + SEPARATOR + "1" + STEP))
|
||||
"P" + SEPARATOR + "x20" + SEPARATOR + START + SEPARATOR + "1" + STEP))
|
||||
{
|
||||
System.out.println("TransformLevel value: " + value);
|
||||
internalContext.getMultiStep().getTransformsToBeDone().set(TOP_STACK_LEVEL, value);
|
||||
assertEquals("T-Reply InternalContext did not have levels set correctly",
|
||||
TransformStack.checkStructure(internalContext, "T-Reply"));
|
||||
};
|
||||
TransformStack.checkStructure(internalContext, "T-Reply"));
|
||||
}
|
||||
;
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -542,25 +547,25 @@ class TransformStackTest
|
||||
for (String value : Arrays.asList(
|
||||
null,
|
||||
"",
|
||||
"F" + SEPARATOR + "12" + SEPARATOR + START + SEPARATOR + "2",
|
||||
"F" + SEPARATOR + "-1" + SEPARATOR + START + SEPARATOR + "2" + STEP,
|
||||
"F" + SEPARATOR + "1" + SEPARATOR + "-3" + SEPARATOR + "2" + STEP,
|
||||
"F" + SEPARATOR + "1" + SEPARATOR + START + SEPARATOR + "-2" + STEP,
|
||||
"F" + SEPARATOR + "a" + SEPARATOR + START + SEPARATOR + "-2" + STEP,
|
||||
"F" + SEPARATOR + "1" + SEPARATOR + START + SEPARATOR + "b" + STEP,
|
||||
"P" + SEPARATOR + "0" + SEPARATOR + START + SEPARATOR + "12" + SEPARATOR + "name",
|
||||
"P" + SEPARATOR + "0" + SEPARATOR + START + SEPARATOR + "12" + SEPARATOR + "name" + SEPARATOR + "source",
|
||||
"P" + SEPARATOR + "0" + SEPARATOR + START + SEPARATOR + "12" + SEPARATOR + "name" + SEPARATOR + "source" + SEPARATOR + "",
|
||||
"P" + SEPARATOR + "0" + SEPARATOR + START + SEPARATOR + "12" + SEPARATOR + "name" + SEPARATOR + "" + SEPARATOR + "target",
|
||||
"F" + SEPARATOR + MAX_INT_PLUS_1 + SEPARATOR + START + SEPARATOR + "2" + STEP,
|
||||
"F" + SEPARATOR + "1" + SEPARATOR + MAX_LONG_PLUS_1 + SEPARATOR + "2" + STEP,
|
||||
"F" + SEPARATOR + "1" + SEPARATOR + START + SEPARATOR + MAX_INT_PLUS_1 + STEP
|
||||
))
|
||||
"F" + SEPARATOR + "12" + SEPARATOR + START + SEPARATOR + "2",
|
||||
"F" + SEPARATOR + "-1" + SEPARATOR + START + SEPARATOR + "2" + STEP,
|
||||
"F" + SEPARATOR + "1" + SEPARATOR + "-3" + SEPARATOR + "2" + STEP,
|
||||
"F" + SEPARATOR + "1" + SEPARATOR + START + SEPARATOR + "-2" + STEP,
|
||||
"F" + SEPARATOR + "a" + SEPARATOR + START + SEPARATOR + "-2" + STEP,
|
||||
"F" + SEPARATOR + "1" + SEPARATOR + START + SEPARATOR + "b" + STEP,
|
||||
"P" + SEPARATOR + "0" + SEPARATOR + START + SEPARATOR + "12" + SEPARATOR + "name",
|
||||
"P" + SEPARATOR + "0" + SEPARATOR + START + SEPARATOR + "12" + SEPARATOR + "name" + SEPARATOR + "source",
|
||||
"P" + SEPARATOR + "0" + SEPARATOR + START + SEPARATOR + "12" + SEPARATOR + "name" + SEPARATOR + "source" + SEPARATOR + "",
|
||||
"P" + SEPARATOR + "0" + SEPARATOR + START + SEPARATOR + "12" + SEPARATOR + "name" + SEPARATOR + "" + SEPARATOR + "target",
|
||||
"F" + SEPARATOR + MAX_INT_PLUS_1 + SEPARATOR + START + SEPARATOR + "2" + STEP,
|
||||
"F" + SEPARATOR + "1" + SEPARATOR + MAX_LONG_PLUS_1 + SEPARATOR + "2" + STEP,
|
||||
"F" + SEPARATOR + "1" + SEPARATOR + START + SEPARATOR + MAX_INT_PLUS_1 + STEP))
|
||||
{
|
||||
System.out.println("TransformLevel value: " + value);
|
||||
internalContext.getMultiStep().getTransformsToBeDone().set(TOP_STACK_LEVEL, value);
|
||||
assertEquals("T-Reply InternalContext did not have levels set correctly",
|
||||
TransformStack.checkStructure(internalContext, "T-Reply"));
|
||||
};
|
||||
}
|
||||
;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -21,26 +21,28 @@
|
||||
*/
|
||||
package org.alfresco.transform.registry;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import org.alfresco.transform.config.SupportedSourceAndTarget;
|
||||
import org.alfresco.transform.config.TransformConfig;
|
||||
import org.alfresco.transform.config.TransformStep;
|
||||
import org.alfresco.transform.config.Transformer;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static java.util.Collections.emptyList;
|
||||
import static java.util.Collections.emptyMap;
|
||||
import static java.util.Collections.emptySet;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import static java.util.Collections.emptyList;
|
||||
import static java.util.Collections.emptyMap;
|
||||
import static java.util.Collections.emptySet;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.alfresco.transform.config.SupportedSourceAndTarget;
|
||||
import org.alfresco.transform.config.TransformConfig;
|
||||
import org.alfresco.transform.config.TransformStep;
|
||||
import org.alfresco.transform.config.Transformer;
|
||||
|
||||
/**
|
||||
* Test the CombinedTransformConfig, extended by both T-Router and ACS repository.
|
||||
@@ -194,8 +196,7 @@ public class CombinedTransformConfigTest
|
||||
private static final String ROUTER_CONFIG_HAS_NO_BASE_URL = null;
|
||||
private static final String BASE_URL_B = "baseUrlB";
|
||||
|
||||
private final CombinedTransformConfig config = new CombinedTransformConfig()
|
||||
{
|
||||
private final CombinedTransformConfig config = new CombinedTransformConfig() {
|
||||
@Override
|
||||
protected boolean isPassThroughTransformName(String name)
|
||||
{
|
||||
@@ -210,8 +211,8 @@ public class CombinedTransformConfigTest
|
||||
private TransformConfig readTransformConfigFromResource(String filename) throws IOException
|
||||
{
|
||||
return objectMapper.readValue(
|
||||
getClass().getClassLoader().getResourceAsStream(filename),
|
||||
TransformConfig.class);
|
||||
getClass().getClassLoader().getResourceAsStream(filename),
|
||||
TransformConfig.class);
|
||||
}
|
||||
|
||||
private String expectedWildcardError(String errorReason)
|
||||
@@ -225,7 +226,7 @@ public class CombinedTransformConfigTest
|
||||
// tEngineTransformers). The override is expected to good unless an error message is provided.
|
||||
// A check is made at the end that A2D is possible and that A2B is not possible.
|
||||
private void assertOverride(List<Transformer> tEngineTransformers,
|
||||
List<Transformer> tRouterTransformers, String expectedError)
|
||||
List<Transformer> tRouterTransformers, String expectedError)
|
||||
{
|
||||
Transformer expectedTransformer = tRouterTransformers.isEmpty()
|
||||
? tEngineTransformers.get(tEngineTransformers.size() - 1)
|
||||
@@ -658,7 +659,7 @@ public class CombinedTransformConfigTest
|
||||
assertEquals("No supported source and target mimetypes could be added to the transformer \"5\" as " +
|
||||
"intermediate steps should have a target mimetype. Read from readFromB", registry.errorMessages.get(0));
|
||||
assertEquals("Transformer \"5\" has no supported source and target mimetypes, so will be ignored. "
|
||||
+ "Read from readFromB", registry.errorMessages.get(1));
|
||||
+ "Read from readFromB", registry.errorMessages.get(1));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -668,7 +669,7 @@ public class CombinedTransformConfigTest
|
||||
.withTransformerPipeline(List.of(
|
||||
new TransformStep("1", "mimetype/b"),
|
||||
new TransformStep("2", "mimetype/c"),
|
||||
new TransformStep("3", "mimetype/d"))) // the last step's mimetype should be null
|
||||
new TransformStep("3", "mimetype/d"))) // the last step's mimetype should be null
|
||||
.build();
|
||||
final TransformConfig transformConfig = TransformConfig.builder()
|
||||
.withTransformers(ImmutableList.of(
|
||||
@@ -683,9 +684,9 @@ public class CombinedTransformConfigTest
|
||||
|
||||
assertEquals(2, registry.errorMessages.size());
|
||||
assertEquals("No supported source and target mimetypes could be added to the transformer \"5\" as " +
|
||||
"the final step should not have a target mimetype. Read from readFromB", registry.errorMessages.get(0));
|
||||
"the final step should not have a target mimetype. Read from readFromB", registry.errorMessages.get(0));
|
||||
assertEquals("Transformer \"5\" has no supported source and target mimetypes, "
|
||||
+ "so will be ignored. Read from readFromB", registry.errorMessages.get(1));
|
||||
+ "so will be ignored. Read from readFromB", registry.errorMessages.get(1));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -747,10 +748,10 @@ public class CombinedTransformConfigTest
|
||||
.withTransformerPipeline(List.of(
|
||||
new TransformStep("2", "mimetype/c"),
|
||||
new TransformStep("3", null)))
|
||||
.withSupportedSourceAndTargetList(Set.of(
|
||||
SupportedSourceAndTarget.builder()
|
||||
.withSourceMediaType("mimetype/a")
|
||||
.withTargetMediaType("mimetype/d")
|
||||
.withSupportedSourceAndTargetList(Set.of(
|
||||
SupportedSourceAndTarget.builder()
|
||||
.withSourceMediaType("mimetype/a")
|
||||
.withTargetMediaType("mimetype/d")
|
||||
.build()))
|
||||
.build();
|
||||
final TransformConfig transformConfig = TransformConfig.builder()
|
||||
@@ -767,11 +768,11 @@ public class CombinedTransformConfigTest
|
||||
assertEquals(0, registry.errorMessages.size());
|
||||
assertEquals(3, config.buildTransformConfig().getTransformers().size());
|
||||
assertEquals("1", registry.findTransformerName("mimetype/a", -1,
|
||||
"mimetype/d", emptyMap(), null));
|
||||
"mimetype/d", emptyMap(), null));
|
||||
assertEquals("2", registry.findTransformerName("mimetype/a", -1,
|
||||
"mimetype/c", emptyMap(), null));
|
||||
"mimetype/c", emptyMap(), null));
|
||||
assertEquals("3", registry.findTransformerName("mimetype/c", -1,
|
||||
"mimetype/d", emptyMap(), null));
|
||||
"mimetype/d", emptyMap(), null));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -798,7 +799,7 @@ public class CombinedTransformConfigTest
|
||||
assertEquals(0, registry.errorMessages.size());
|
||||
assertEquals(3, config.buildTransformConfig().getTransformers().size());
|
||||
assertEquals("1", registry.findTransformerName("mimetype/a", -1,
|
||||
"mimetype/d", emptyMap(), null));
|
||||
"mimetype/d", emptyMap(), null));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -810,16 +811,15 @@ public class CombinedTransformConfigTest
|
||||
.withTransformerPipeline(List.of(
|
||||
new TransformStep("2", "mimetype/c"),
|
||||
new TransformStep("2", null)))
|
||||
.withSupportedSourceAndTargetList(Set.of(
|
||||
SupportedSourceAndTarget.builder()
|
||||
.withSourceMediaType("mimetype/a")
|
||||
.withTargetMediaType("mimetype/d")
|
||||
.build()
|
||||
))
|
||||
.withSupportedSourceAndTargetList(Set.of(
|
||||
SupportedSourceAndTarget.builder()
|
||||
.withSourceMediaType("mimetype/a")
|
||||
.withTargetMediaType("mimetype/d")
|
||||
.build()))
|
||||
.build();
|
||||
final TransformConfig transformConfig = TransformConfig.builder()
|
||||
.withTransformers(ImmutableList.of(
|
||||
TRANSFORMER2_B2C, // Does NOT support a->c so steps are invalid for a->d
|
||||
TRANSFORMER2_B2C, // Does NOT support a->c so steps are invalid for a->d
|
||||
TRANSFORMER3_C2D,
|
||||
pipeline))
|
||||
.build();
|
||||
@@ -833,9 +833,9 @@ public class CombinedTransformConfigTest
|
||||
assertEquals(expected, registry.errorMessages.get(0));
|
||||
assertEquals(2, config.buildTransformConfig().getTransformers().size());
|
||||
assertEquals("2", registry.findTransformerName("mimetype/b", -1,
|
||||
"mimetype/c", emptyMap(), null));
|
||||
"mimetype/c", emptyMap(), null));
|
||||
assertEquals("3", registry.findTransformerName("mimetype/c", -1,
|
||||
"mimetype/d", emptyMap(), null));
|
||||
"mimetype/d", emptyMap(), null));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -847,20 +847,19 @@ public class CombinedTransformConfigTest
|
||||
.withTransformerPipeline(List.of(
|
||||
new TransformStep("2", "mimetype/c"),
|
||||
new TransformStep("2", null)))
|
||||
.withSupportedSourceAndTargetList(Set.of(
|
||||
SupportedSourceAndTarget.builder()
|
||||
.withSourceMediaType("mimetype/a")
|
||||
.withTargetMediaType("mimetype/d")
|
||||
.withSupportedSourceAndTargetList(Set.of(
|
||||
SupportedSourceAndTarget.builder()
|
||||
.withSourceMediaType("mimetype/a")
|
||||
.withTargetMediaType("mimetype/d")
|
||||
.build(),
|
||||
SupportedSourceAndTarget.builder() // Always going to be invalid with these steps
|
||||
.withSourceMediaType("mimetype/x")
|
||||
.withTargetMediaType("mimetype/y")
|
||||
.build()
|
||||
))
|
||||
SupportedSourceAndTarget.builder() // Always going to be invalid with these steps
|
||||
.withSourceMediaType("mimetype/x")
|
||||
.withTargetMediaType("mimetype/y")
|
||||
.build()))
|
||||
.build();
|
||||
final TransformConfig transformConfig = TransformConfig.builder()
|
||||
.withTransformers(ImmutableList.of(
|
||||
TRANSFORMER2_B2C, // Does NOT support a->c so steps are invalid for a->d
|
||||
TRANSFORMER2_B2C, // Does NOT support a->c so steps are invalid for a->d
|
||||
TRANSFORMER3_C2D,
|
||||
pipeline))
|
||||
.build();
|
||||
@@ -886,7 +885,7 @@ public class CombinedTransformConfigTest
|
||||
.build();
|
||||
final TransformConfig transformConfig = TransformConfig.builder()
|
||||
.withTransformers(ImmutableList.of(
|
||||
TRANSFORMER2_B2X, // Does NOT support <anything>->c so steps are invalid
|
||||
TRANSFORMER2_B2X, // Does NOT support <anything>->c so steps are invalid
|
||||
TRANSFORMER3_C2D,
|
||||
pipeline))
|
||||
.build();
|
||||
@@ -897,11 +896,11 @@ public class CombinedTransformConfigTest
|
||||
|
||||
assertEquals(2, registry.errorMessages.size());
|
||||
assertEquals("No supported source and target mimetypes could be added to the transformer \"1\" as "
|
||||
+ "the first step transformer \"2\" does not support to \"mimetype/c\". Read from readFromB",
|
||||
registry.errorMessages.get(0));
|
||||
+ "the first step transformer \"2\" does not support to \"mimetype/c\". Read from readFromB",
|
||||
registry.errorMessages.get(0));
|
||||
assertEquals("Transformer \"1\" has no supported source and target mimetypes, so will be ignored. "
|
||||
+ "Read from readFromB",
|
||||
registry.errorMessages.get(1));
|
||||
+ "Read from readFromB",
|
||||
registry.errorMessages.get(1));
|
||||
assertEquals(2, config.buildTransformConfig().getTransformers().size());
|
||||
}
|
||||
|
||||
@@ -1028,9 +1027,9 @@ public class CombinedTransformConfigTest
|
||||
|
||||
assertEquals(2, registry.errorMessages.size());
|
||||
assertEquals(expectedWildcardError("the step transformer \"2\" does not support \"mimetype/b\" "
|
||||
+ "to \"mimetype/c\""), registry.errorMessages.get(0));
|
||||
+ "to \"mimetype/c\""), registry.errorMessages.get(0));
|
||||
assertEquals("Transformer \"4\" has no supported source and target mimetypes, so will be ignored. "
|
||||
+ "Read from readFromB", registry.errorMessages.get(1));
|
||||
+ "Read from readFromB", registry.errorMessages.get(1));
|
||||
|
||||
// The pipeline is removed, so 3 are expected
|
||||
assertEquals(3, config.buildTransformConfig().getTransformers().size());
|
||||
|
@@ -21,15 +21,15 @@
|
||||
*/
|
||||
package org.alfresco.transform.registry;
|
||||
|
||||
import org.alfresco.transform.config.TransformOption;
|
||||
import org.alfresco.transform.config.Transformer;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.alfresco.transform.config.TransformOption;
|
||||
import org.alfresco.transform.config.Transformer;
|
||||
|
||||
/**
|
||||
* Helper class for testing an {@link AbstractTransformRegistry}.
|
||||
*/
|
||||
@@ -69,8 +69,8 @@ public class FakeTransformRegistry extends AbstractTransformRegistry
|
||||
|
||||
@Override
|
||||
protected void register(final Transformer transformer,
|
||||
final Map<String, Set<TransformOption>> transformOptions, final String baseUrl,
|
||||
final String readFrom)
|
||||
final Map<String, Set<TransformOption>> transformOptions, final String baseUrl,
|
||||
final String readFrom)
|
||||
{
|
||||
super.register(transformer, transformOptions, baseUrl, readFrom);
|
||||
|
||||
|
@@ -21,26 +21,26 @@
|
||||
*/
|
||||
package org.alfresco.transform.registry;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import org.alfresco.transform.config.AddSupported;
|
||||
import org.alfresco.transform.config.SupportedDefaults;
|
||||
import org.alfresco.transform.config.OverrideSupported;
|
||||
import org.alfresco.transform.config.RemoveSupported;
|
||||
import org.alfresco.transform.config.SupportedSourceAndTarget;
|
||||
import org.alfresco.transform.config.TransformConfig;
|
||||
import org.alfresco.transform.config.Transformer;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.alfresco.transform.config.AddSupported;
|
||||
import org.alfresco.transform.config.OverrideSupported;
|
||||
import org.alfresco.transform.config.RemoveSupported;
|
||||
import org.alfresco.transform.config.SupportedDefaults;
|
||||
import org.alfresco.transform.config.SupportedSourceAndTarget;
|
||||
import org.alfresco.transform.config.TransformConfig;
|
||||
import org.alfresco.transform.config.Transformer;
|
||||
|
||||
/**
|
||||
* Tests the json elements: {@code removeTransformers}, {@code addSupported}, {@code removeSupported},
|
||||
* {@code overrideSupported} and {@code supportedDefaults}.
|
||||
* Tests the json elements: {@code removeTransformers}, {@code addSupported}, {@code removeSupported}, {@code overrideSupported} and {@code supportedDefaults}.
|
||||
*/
|
||||
public class OverrideTransformConfigTests
|
||||
{
|
||||
@@ -200,20 +200,20 @@ public class OverrideTransformConfigTests
|
||||
|
||||
final TransformConfig thirdConfig = TransformConfig.builder()
|
||||
.withSupportedDefaults(ImmutableSet.of(
|
||||
default_1A_200, // 0: transformer and source media type default
|
||||
default_2A__45, // 0: transformer and source media type default
|
||||
default_3_400, // 1: transformer default
|
||||
default_B_400, // 2: source media type default
|
||||
default_B_500, // 2: source media type default - overrides the previous value 400 defined in the same config
|
||||
default_1A_200, // 0: transformer and source media type default
|
||||
default_2A__45, // 0: transformer and source media type default
|
||||
default_3_400, // 1: transformer default
|
||||
default_B_400, // 2: source media type default
|
||||
default_B_500, // 2: source media type default - overrides the previous value 400 defined in the same config
|
||||
default__500_50, // 3: system wide default - totally overridden by the next lines.
|
||||
default__600, // 3: system wide default
|
||||
default___50, // 3: system wide default (combined with the other system default)
|
||||
default___45)) // 3: system wide default - overrides the value 45 defined in the same config
|
||||
default__600, // 3: system wide default
|
||||
default___50, // 3: system wide default (combined with the other system default)
|
||||
default___45)) // 3: system wide default - overrides the value 45 defined in the same config
|
||||
.build();
|
||||
|
||||
final TransformConfig fourthConfig = TransformConfig.builder()
|
||||
.withSupportedDefaults(ImmutableSet.of(
|
||||
SupportedDefaults.builder() // 3: system wide default
|
||||
SupportedDefaults.builder() // 3: system wide default
|
||||
.withMaxSourceSizeBytes(-1L)
|
||||
.withPriority(45)
|
||||
.build()))
|
||||
@@ -221,16 +221,15 @@ public class OverrideTransformConfigTests
|
||||
|
||||
final TransformConfig fifthConfig = TransformConfig.builder()
|
||||
.withSupportedDefaults(ImmutableSet.of(
|
||||
SupportedDefaults.builder() // 3: system wide default (reset to the default, so removed)
|
||||
SupportedDefaults.builder() // 3: system wide default (reset to the default, so removed)
|
||||
.withPriority(50)
|
||||
.build(),
|
||||
SupportedDefaults.builder() // Invalid as neither priority nor maxSourceSizeBytes are set
|
||||
SupportedDefaults.builder() // Invalid as neither priority nor maxSourceSizeBytes are set
|
||||
.withTransformerName("9")
|
||||
.withSourceMediaType("mimetype/z")
|
||||
.build()))
|
||||
.build();
|
||||
|
||||
|
||||
config.addTransformConfig(firstConfig, READ_FROM_A, BASE_URL_A, registry);
|
||||
TransformConfig resultConfig = config.buildTransformConfig();
|
||||
assertEquals(0, resultConfig.getSupportedDefaults().size());
|
||||
@@ -279,7 +278,7 @@ public class OverrideTransformConfigTests
|
||||
final TransformConfig secondConfig = TransformConfig.builder()
|
||||
.withRemoveSupported(ImmutableSet.of(
|
||||
RemoveSupported.builder()
|
||||
.withTransformerName("1") // c -> d does not exist
|
||||
.withTransformerName("1") // c -> d does not exist
|
||||
.withSourceMediaType("mimetype/c")
|
||||
.withTargetMediaType("mimetype/d")
|
||||
.build(),
|
||||
@@ -288,20 +287,20 @@ public class OverrideTransformConfigTests
|
||||
.withSourceMediaType("mimetype/a")
|
||||
.withTargetMediaType("mimetype/b")
|
||||
.build(),
|
||||
RemoveSupported.builder() // transformer does not exist
|
||||
RemoveSupported.builder() // transformer does not exist
|
||||
.withTransformerName("bad")
|
||||
.withSourceMediaType("mimetype/a")
|
||||
.withTargetMediaType("mimetype/d")
|
||||
.build(),
|
||||
RemoveSupported.builder() // transform name not set
|
||||
RemoveSupported.builder() // transform name not set
|
||||
.withSourceMediaType("mimetype/a")
|
||||
.withTargetMediaType("mimetype/d")
|
||||
.build(),
|
||||
RemoveSupported.builder() // source type not set
|
||||
RemoveSupported.builder() // source type not set
|
||||
.withTransformerName("1")
|
||||
.withTargetMediaType("mimetype/d")
|
||||
.build(),
|
||||
RemoveSupported.builder() // target type not set
|
||||
RemoveSupported.builder() // target type not set
|
||||
.withTransformerName("1")
|
||||
.withSourceMediaType("mimetype/a")
|
||||
.build()))
|
||||
@@ -334,7 +333,7 @@ public class OverrideTransformConfigTests
|
||||
.withSourceMediaType("mimetype/c")
|
||||
.withTargetMediaType("mimetype/d")
|
||||
.build(),
|
||||
AddSupported.builder() // duplicates original
|
||||
AddSupported.builder() // duplicates original
|
||||
.withTransformerName("1")
|
||||
.withSourceMediaType("mimetype/a")
|
||||
.withTargetMediaType("mimetype/b")
|
||||
@@ -347,20 +346,20 @@ public class OverrideTransformConfigTests
|
||||
.withPriority(44)
|
||||
.withMaxSourceSizeBytes(1234)
|
||||
.build(),
|
||||
AddSupported.builder() // transformer does not exist
|
||||
AddSupported.builder() // transformer does not exist
|
||||
.withTransformerName("bad")
|
||||
.withSourceMediaType("mimetype/a")
|
||||
.withTargetMediaType("mimetype/d")
|
||||
.build(),
|
||||
AddSupported.builder() // transform name not set
|
||||
AddSupported.builder() // transform name not set
|
||||
.withSourceMediaType("mimetype/a")
|
||||
.withTargetMediaType("mimetype/d")
|
||||
.build(),
|
||||
AddSupported.builder() // source type not set
|
||||
AddSupported.builder() // source type not set
|
||||
.withTransformerName("1")
|
||||
.withTargetMediaType("mimetype/d")
|
||||
.build(),
|
||||
AddSupported.builder() // target type not set
|
||||
AddSupported.builder() // target type not set
|
||||
.withTransformerName("1")
|
||||
.withSourceMediaType("mimetype/a")
|
||||
.build()))
|
||||
@@ -395,29 +394,29 @@ public class OverrideTransformConfigTests
|
||||
|
||||
final TransformConfig secondConfig = TransformConfig.builder()
|
||||
.withOverrideSupported(ImmutableSet.of(
|
||||
OverrideSupported.builder() // does not exist
|
||||
OverrideSupported.builder() // does not exist
|
||||
.withTransformerName("1")
|
||||
.withSourceMediaType("mimetype/c")
|
||||
.withTargetMediaType("mimetype/d")
|
||||
.build(),
|
||||
OverrideSupported.builder() // size default -> 200 and priority default -> 100
|
||||
OverrideSupported.builder() // size default -> 200 and priority default -> 100
|
||||
.withTransformerName("1")
|
||||
.withSourceMediaType("mimetype/a")
|
||||
.withTargetMediaType("mimetype/b")
|
||||
.withPriority(40)
|
||||
.build(),
|
||||
OverrideSupported.builder() // size 100 -> 200 and change priority to default
|
||||
OverrideSupported.builder() // size 100 -> 200 and change priority to default
|
||||
.withTransformerName("1")
|
||||
.withSourceMediaType("mimetype/x")
|
||||
.withTargetMediaType("mimetype/y")
|
||||
.withMaxSourceSizeBytes(200)
|
||||
.build(),
|
||||
OverrideSupported.builder() // transformer does not exist
|
||||
OverrideSupported.builder() // transformer does not exist
|
||||
.withTransformerName("bad")
|
||||
.withSourceMediaType("mimetype/a")
|
||||
.withTargetMediaType("mimetype/d")
|
||||
.build()))
|
||||
// OverrideSupported values with missing fields are defaults, so no test values here
|
||||
// OverrideSupported values with missing fields are defaults, so no test values here
|
||||
.build();
|
||||
|
||||
String expectedWarnMessage = "Unable to process \"overrideSupported\": [" +
|
||||
@@ -444,7 +443,7 @@ public class OverrideTransformConfigTests
|
||||
}
|
||||
|
||||
private void addTransformConfig(TransformConfig secondConfig, String expectedWarnMessage,
|
||||
Set<SupportedSourceAndTarget> expectedSupported, String expectedToString)
|
||||
Set<SupportedSourceAndTarget> expectedSupported, String expectedToString)
|
||||
{
|
||||
config.addTransformConfig(secondConfig, READ_FROM_B, BASE_URL_B, registry);
|
||||
TransformConfig resultConfig = config.buildTransformConfig();
|
||||
|
@@ -26,21 +26,24 @@
|
||||
*/
|
||||
package org.alfresco.transform.registry;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import org.alfresco.transform.exceptions.TransformException;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static java.util.Arrays.asList;
|
||||
import static java.util.Collections.emptySet;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
import static org.alfresco.transform.common.RequestParamMap.SOURCE_ENCODING;
|
||||
import static org.alfresco.transform.common.RequestParamMap.TIMEOUT;
|
||||
import static org.alfresco.transform.registry.TransformRegistryHelper.retrieveTransformListBySize;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import static java.util.Arrays.asList;
|
||||
import static java.util.Collections.emptySet;
|
||||
import static org.alfresco.transform.common.RequestParamMap.SOURCE_ENCODING;
|
||||
import static org.alfresco.transform.common.RequestParamMap.TIMEOUT;
|
||||
import static org.alfresco.transform.registry.TransformRegistryHelper.retrieveTransformListBySize;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.alfresco.transform.exceptions.TransformException;
|
||||
|
||||
public class TransformRegistryHelperTest
|
||||
{
|
||||
@@ -50,37 +53,37 @@ public class TransformRegistryHelperTest
|
||||
// This test was inspired by a failure to pick libreoffice over textToPdf despite the fact libreoffice has a
|
||||
// higher priority.
|
||||
SupportedTransform libreoffice = new SupportedTransform("libreoffice", emptySet(), -1, 50);
|
||||
SupportedTransform textToPdf = new SupportedTransform("textToPdf", emptySet(), 100,55);
|
||||
SupportedTransform textToPdf = new SupportedTransform("textToPdf", emptySet(), 100, 55);
|
||||
|
||||
assertOrder(asList(libreoffice, textToPdf), asList(libreoffice));
|
||||
assertOrder(asList(textToPdf, libreoffice), asList(libreoffice));
|
||||
|
||||
// * If multiple transforms with the same priority can support the same size, the one with the highest size
|
||||
// limit (or no limit) is used.
|
||||
// limit (or no limit) is used.
|
||||
// * Transforms with a higher priority (lower numerically) are used up to their size limit in preference to
|
||||
// lower priority transforms. These lower priority transforms will be used above that limit.
|
||||
// lower priority transforms. These lower priority transforms will be used above that limit.
|
||||
// * If there are multiple transforms with the same priority and size limit, the last one defined is used to
|
||||
// allow extensions to override standard transforms.
|
||||
// allow extensions to override standard transforms.
|
||||
// * In each of the above cases, it is possible for supplied transforms not to be returned from
|
||||
// retrieveTransformListBySize as they will never be used. However this method is currently only used
|
||||
// by (1) AbstractTransformRegistry.findTransformerName which filters out transformers that cannot support a
|
||||
// given size and then uses the lowest element and (2) AbstractTransformRegistry.findMaxSize and gets the last
|
||||
// element without filtering and returns its size limit. So there are opportunities to change the code so that
|
||||
// it does not actually have to remove transformers that will not be used.
|
||||
// retrieveTransformListBySize as they will never be used. However this method is currently only used
|
||||
// by (1) AbstractTransformRegistry.findTransformerName which filters out transformers that cannot support a
|
||||
// given size and then uses the lowest element and (2) AbstractTransformRegistry.findMaxSize and gets the last
|
||||
// element without filtering and returns its size limit. So there are opportunities to change the code so that
|
||||
// it does not actually have to remove transformers that will not be used.
|
||||
|
||||
// Test transforms
|
||||
SupportedTransform p45 = new SupportedTransform( "p45", emptySet(), -1, 45);
|
||||
SupportedTransform p50 = new SupportedTransform( "p50", emptySet(), -1, 50);
|
||||
SupportedTransform p55 = new SupportedTransform( "p55", emptySet(), -1, 55);
|
||||
SupportedTransform s100p45 = new SupportedTransform("s100p45", emptySet(), 100, 45);
|
||||
SupportedTransform s100p50 = new SupportedTransform("s100p50", emptySet(), 100, 50);
|
||||
SupportedTransform s100p55 = new SupportedTransform("s100p55", emptySet(), 100, 55);
|
||||
SupportedTransform s200p50 = new SupportedTransform("s200p50", emptySet(), 200, 50);
|
||||
SupportedTransform p45 = new SupportedTransform("p45", emptySet(), -1, 45);
|
||||
SupportedTransform p50 = new SupportedTransform("p50", emptySet(), -1, 50);
|
||||
SupportedTransform p55 = new SupportedTransform("p55", emptySet(), -1, 55);
|
||||
SupportedTransform s100p45 = new SupportedTransform("s100p45", emptySet(), 100, 45);
|
||||
SupportedTransform s100p50 = new SupportedTransform("s100p50", emptySet(), 100, 50);
|
||||
SupportedTransform s100p55 = new SupportedTransform("s100p55", emptySet(), 100, 55);
|
||||
SupportedTransform s200p50 = new SupportedTransform("s200p50", emptySet(), 200, 50);
|
||||
SupportedTransform s200p50b = new SupportedTransform("s200p50b", emptySet(), 200, 50);
|
||||
SupportedTransform s200p55 = new SupportedTransform("s200p55", emptySet(), 200, 55);
|
||||
SupportedTransform s300p45 = new SupportedTransform("s300p45", emptySet(), 300, 45);
|
||||
SupportedTransform s300p50 = new SupportedTransform("s300p50", emptySet(), 300, 50);
|
||||
SupportedTransform s300p55 = new SupportedTransform("s300p55", emptySet(), 300, 55);
|
||||
SupportedTransform s200p55 = new SupportedTransform("s200p55", emptySet(), 200, 55);
|
||||
SupportedTransform s300p45 = new SupportedTransform("s300p45", emptySet(), 300, 45);
|
||||
SupportedTransform s300p50 = new SupportedTransform("s300p50", emptySet(), 300, 50);
|
||||
SupportedTransform s300p55 = new SupportedTransform("s300p55", emptySet(), 300, 55);
|
||||
|
||||
// Just considers the priority
|
||||
assertOrder(asList(p50), asList(p50));
|
||||
@@ -125,8 +128,8 @@ public class TransformRegistryHelperTest
|
||||
{
|
||||
AtomicInteger transformerCount = new AtomicInteger(0);
|
||||
TransformCache data = new TransformCache();
|
||||
transformsInLoadOrder.forEach(t->data.appendTransform("text/plain", "application/pdf", t,
|
||||
"transformer"+transformerCount.getAndIncrement(), null));
|
||||
transformsInLoadOrder.forEach(t -> data.appendTransform("text/plain", "application/pdf", t,
|
||||
"transformer" + transformerCount.getAndIncrement(), null));
|
||||
|
||||
List<SupportedTransform> supportedTransforms = retrieveTransformListBySize(data,
|
||||
"text/plain", "application/pdf", null, null);
|
||||
@@ -160,8 +163,7 @@ public class TransformRegistryHelperTest
|
||||
// Similar to the method in AbstractTransformRegistry
|
||||
private long findMaxSize(List<SupportedTransform> supportedTransforms)
|
||||
{
|
||||
return supportedTransforms.isEmpty() ? 0 :
|
||||
supportedTransforms.get(supportedTransforms.size() - 1).getMaxSourceSizeBytes();
|
||||
return supportedTransforms.isEmpty() ? 0 : supportedTransforms.get(supportedTransforms.size() - 1).getMaxSourceSizeBytes();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -169,8 +171,7 @@ public class TransformRegistryHelperTest
|
||||
{
|
||||
TransformCache data = new TransformCache();
|
||||
|
||||
assertThrows(TransformException.class, () ->
|
||||
{
|
||||
assertThrows(TransformException.class, () -> {
|
||||
retrieveTransformListBySize(data, null, "application/pdf", null, null);
|
||||
});
|
||||
}
|
||||
@@ -180,8 +181,7 @@ public class TransformRegistryHelperTest
|
||||
{
|
||||
TransformCache data = new TransformCache();
|
||||
|
||||
assertThrows(TransformException.class, () ->
|
||||
{
|
||||
assertThrows(TransformException.class, () -> {
|
||||
retrieveTransformListBySize(data, "text/plain", null, null, null);
|
||||
});
|
||||
}
|
||||
@@ -192,10 +192,9 @@ public class TransformRegistryHelperTest
|
||||
// Almost identical to buildTransformListTargetMimeTypeNullErrorTest
|
||||
TransformCache data = new TransformCache();
|
||||
|
||||
assertThrows(TransformException.class, () ->
|
||||
{
|
||||
assertThrows(TransformException.class, () -> {
|
||||
retrieveTransformListBySize(data, "text/plain", null,
|
||||
new HashMap<>(ImmutableMap.of(TIMEOUT, "1234")), null);
|
||||
new HashMap<>(ImmutableMap.of(TIMEOUT, "1234")), null);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -205,10 +204,9 @@ public class TransformRegistryHelperTest
|
||||
// Almost identical to buildTransformListTargetMimeTypeNullErrorTest
|
||||
TransformCache data = new TransformCache();
|
||||
|
||||
assertThrows(TransformException.class, () ->
|
||||
{
|
||||
assertThrows(TransformException.class, () -> {
|
||||
retrieveTransformListBySize(data, "text/plain", null,
|
||||
new HashMap<>(ImmutableMap.of(SOURCE_ENCODING, "UTF-8")), null);
|
||||
new HashMap<>(ImmutableMap.of(SOURCE_ENCODING, "UTF-8")), null);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@@ -28,13 +28,15 @@ import static java.util.Collections.singletonList;
|
||||
import static java.util.Collections.singletonMap;
|
||||
import static java.util.function.Function.identity;
|
||||
import static java.util.stream.Collectors.toMap;
|
||||
import static org.alfresco.transform.registry.TransformRegistryHelper.addToPossibleTransformOptions;
|
||||
import static org.alfresco.transform.registry.TransformRegistryHelper.optionsMatch;
|
||||
|
||||
import static org.apache.commons.lang3.StringUtils.isBlank;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import static org.alfresco.transform.registry.TransformRegistryHelper.addToPossibleTransformOptions;
|
||||
import static org.alfresco.transform.registry.TransformRegistryHelper.optionsMatch;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
@@ -43,6 +45,10 @@ import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.alfresco.transform.config.CoreFunction;
|
||||
import org.alfresco.transform.config.SupportedSourceAndTarget;
|
||||
import org.alfresco.transform.config.TransformConfig;
|
||||
@@ -50,14 +56,9 @@ import org.alfresco.transform.config.TransformOption;
|
||||
import org.alfresco.transform.config.TransformOptionGroup;
|
||||
import org.alfresco.transform.config.TransformOptionValue;
|
||||
import org.alfresco.transform.config.Transformer;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
/**
|
||||
* Test the AbstractTransformRegistry, extended by both T-Engines and ACS repository, which need to
|
||||
* read JSON config to understand what is supported.
|
||||
* Test the AbstractTransformRegistry, extended by both T-Engines and ACS repository, which need to read JSON config to understand what is supported.
|
||||
*
|
||||
* @author adavis
|
||||
*/
|
||||
@@ -84,8 +85,7 @@ public class TransformRegistryModelTest
|
||||
|
||||
protected AbstractTransformRegistry buildTransformServiceRegistryImpl() throws Exception
|
||||
{
|
||||
return new AbstractTransformRegistry()
|
||||
{
|
||||
return new AbstractTransformRegistry() {
|
||||
private TransformCache data = new TransformCache();
|
||||
|
||||
@Override
|
||||
@@ -109,13 +109,13 @@ public class TransformRegistryModelTest
|
||||
}
|
||||
|
||||
private void assertAddToPossibleOptions(final TransformOptionGroup transformOptionGroup,
|
||||
final Set<String> actualOptionNames, final Set<String> expectedNameSet,
|
||||
final Set<String> expectedRequiredSet)
|
||||
final Set<String> actualOptionNames, final Set<String> expectedNameSet,
|
||||
final Set<String> expectedRequiredSet)
|
||||
{
|
||||
final Map<String, Boolean> possibleTransformOptions = new HashMap<>();
|
||||
|
||||
addToPossibleTransformOptions(possibleTransformOptions, transformOptionGroup, true,
|
||||
buildActualOptions(actualOptionNames));
|
||||
buildActualOptions(actualOptionNames));
|
||||
|
||||
assertEquals(expectedNameSet, possibleTransformOptions.keySet());
|
||||
|
||||
@@ -133,11 +133,11 @@ public class TransformRegistryModelTest
|
||||
|
||||
// transformOptionNames are upper case if required.
|
||||
private void assertOptionsMatch(final Set<String> actualOptionNames,
|
||||
final Set<String> transformOptionNames, final String unsupportedMsg)
|
||||
final Set<String> transformOptionNames, final String unsupportedMsg)
|
||||
{
|
||||
final Map<String, Boolean> transformOptions = transformOptionNames
|
||||
.stream()
|
||||
.collect(toMap(identity(), name -> name.toUpperCase().equals(name)));
|
||||
.stream()
|
||||
.collect(toMap(identity(), name -> name.toUpperCase().equals(name)));
|
||||
|
||||
boolean supported = optionsMatch(transformOptions, buildActualOptions(actualOptionNames));
|
||||
if (isBlank(unsupportedMsg))
|
||||
@@ -153,20 +153,20 @@ public class TransformRegistryModelTest
|
||||
private void assertTransformOptions(Set<TransformOption> setOfTransformOptions) throws Exception
|
||||
{
|
||||
final Transformer transformer = new Transformer("name", singleton("testOptions"), set(
|
||||
SupportedSourceAndTarget.builder()
|
||||
.withSourceMediaType(DOC)
|
||||
.withTargetMediaType(TXT)
|
||||
.build(),
|
||||
SupportedSourceAndTarget.builder()
|
||||
.withSourceMediaType(XLS)
|
||||
.withTargetMediaType(TXT)
|
||||
.withMaxSourceSizeBytes(1024000L)
|
||||
.build()));
|
||||
SupportedSourceAndTarget.builder()
|
||||
.withSourceMediaType(DOC)
|
||||
.withTargetMediaType(TXT)
|
||||
.build(),
|
||||
SupportedSourceAndTarget.builder()
|
||||
.withSourceMediaType(XLS)
|
||||
.withTargetMediaType(TXT)
|
||||
.withMaxSourceSizeBytes(1024000L)
|
||||
.build()));
|
||||
final TransformConfig transformConfig = TransformConfig
|
||||
.builder()
|
||||
.withTransformers(singletonList(transformer))
|
||||
.withTransformOptions(singletonMap("testOptions", setOfTransformOptions))
|
||||
.build();
|
||||
.builder()
|
||||
.withTransformers(singletonList(transformer))
|
||||
.withTransformOptions(singletonMap("testOptions", setOfTransformOptions))
|
||||
.build();
|
||||
|
||||
registry = buildTransformServiceRegistryImpl();
|
||||
CombinedTransformConfig.combineAndRegister(transformConfig, getClass().getName(), getBaseUrl(transformer), registry);
|
||||
@@ -183,30 +183,30 @@ public class TransformRegistryModelTest
|
||||
}
|
||||
|
||||
private void assertTransformerName(String sourceMimetype, long sourceSizeInBytes,
|
||||
String targetMimetype, Map<String, String> actualOptions, String expectedTransformerName,
|
||||
Transformer... transformers) throws Exception
|
||||
String targetMimetype, Map<String, String> actualOptions, String expectedTransformerName,
|
||||
Transformer... transformers) throws Exception
|
||||
{
|
||||
buildAndPopulateRegistry(transformers);
|
||||
String transformerName = registry.findTransformerName(sourceMimetype, sourceSizeInBytes,
|
||||
targetMimetype, actualOptions, null);
|
||||
targetMimetype, actualOptions, null);
|
||||
assertEquals(expectedTransformerName, transformerName);
|
||||
}
|
||||
|
||||
private void assertSupported(final Transformer transformer, final String sourceMimetype,
|
||||
final long sourceSizeInBytes, final String targetMimetype,
|
||||
final Map<String, String> actualOptions, final String unsupportedMsg) throws Exception
|
||||
final long sourceSizeInBytes, final String targetMimetype,
|
||||
final Map<String, String> actualOptions, final String unsupportedMsg) throws Exception
|
||||
{
|
||||
assertSupported(sourceMimetype, sourceSizeInBytes, targetMimetype, actualOptions,
|
||||
unsupportedMsg, transformer);
|
||||
unsupportedMsg, transformer);
|
||||
}
|
||||
|
||||
private void assertSupported(String sourceMimetype, long sourceSizeInBytes,
|
||||
String targetMimetype, Map<String, String> actualOptions, String unsupportedMsg,
|
||||
Transformer... transformers) throws Exception
|
||||
String targetMimetype, Map<String, String> actualOptions, String unsupportedMsg,
|
||||
Transformer... transformers) throws Exception
|
||||
{
|
||||
buildAndPopulateRegistry(transformers);
|
||||
assertSupported(sourceMimetype, sourceSizeInBytes, targetMimetype, actualOptions, null,
|
||||
unsupportedMsg);
|
||||
unsupportedMsg);
|
||||
}
|
||||
|
||||
private void buildAndPopulateRegistry(Transformer[] transformers) throws Exception
|
||||
@@ -220,11 +220,11 @@ public class TransformRegistryModelTest
|
||||
}
|
||||
|
||||
protected void assertSupported(String sourceMimetype, long sourceSizeInBytes,
|
||||
String targetMimetype, Map<String, String> actualOptions, String renditionName,
|
||||
String unsupportedMsg)
|
||||
String targetMimetype, Map<String, String> actualOptions, String renditionName,
|
||||
String unsupportedMsg)
|
||||
{
|
||||
boolean supported = registry.isSupported(sourceMimetype, sourceSizeInBytes, targetMimetype,
|
||||
actualOptions, renditionName);
|
||||
actualOptions, renditionName);
|
||||
if (unsupportedMsg == null || unsupportedMsg.isEmpty())
|
||||
{
|
||||
assertTrue(supported);
|
||||
@@ -238,151 +238,147 @@ public class TransformRegistryModelTest
|
||||
private static Map<String, String> buildActualOptions(final Set<String> optionNames)
|
||||
{
|
||||
return optionNames
|
||||
.stream()
|
||||
.collect(toMap(identity(), name -> "value for " + name));
|
||||
.stream()
|
||||
.collect(toMap(identity(), name -> "value for " + name));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOptionalGroups()
|
||||
{
|
||||
final TransformOptionGroup transformOptionGroup =
|
||||
new TransformOptionGroup(true, set(
|
||||
final TransformOptionGroup transformOptionGroup = new TransformOptionGroup(true, set(
|
||||
new TransformOptionValue(false, "1"),
|
||||
new TransformOptionValue(true, "2"),
|
||||
new TransformOptionGroup(false, set(
|
||||
new TransformOptionValue(false, "3.1"),
|
||||
new TransformOptionValue(false, "3.2"),
|
||||
new TransformOptionValue(false, "3.3"))),
|
||||
new TransformOptionValue(false, "3.1"),
|
||||
new TransformOptionValue(false, "3.2"),
|
||||
new TransformOptionValue(false, "3.3"))),
|
||||
new TransformOptionGroup(false, set( // OPTIONAL
|
||||
new TransformOptionValue(false, "4.1"),
|
||||
new TransformOptionValue(true, "4.2"),
|
||||
new TransformOptionValue(false, "4.3")))));
|
||||
new TransformOptionValue(false, "4.1"),
|
||||
new TransformOptionValue(true, "4.2"),
|
||||
new TransformOptionValue(false, "4.3")))));
|
||||
|
||||
assertAddToPossibleOptions(transformOptionGroup, emptySet(),
|
||||
set("1", "2"), set("2"));
|
||||
set("1", "2"), set("2"));
|
||||
assertAddToPossibleOptions(transformOptionGroup, set("1"),
|
||||
set("1", "2"), set("2"));
|
||||
set("1", "2"), set("2"));
|
||||
assertAddToPossibleOptions(transformOptionGroup, set("2"),
|
||||
set("1", "2"), set("2"));
|
||||
set("1", "2"), set("2"));
|
||||
assertAddToPossibleOptions(transformOptionGroup, set("2", "3.2"),
|
||||
set("1", "2", "3.1", "3.2", "3.3"), set("2"));
|
||||
set("1", "2", "3.1", "3.2", "3.3"), set("2"));
|
||||
assertAddToPossibleOptions(transformOptionGroup, set("2", "4.1"),
|
||||
set("1", "2", "4.1", "4.2", "4.3"), set("2", "4.2"));
|
||||
set("1", "2", "4.1", "4.2", "4.3"), set("2", "4.2"));
|
||||
assertAddToPossibleOptions(transformOptionGroup, set("2", "4.2"),
|
||||
set("1", "2", "4.1", "4.2", "4.3"), set("2", "4.2"));
|
||||
set("1", "2", "4.1", "4.2", "4.3"), set("2", "4.2"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRequiredGroup()
|
||||
{
|
||||
TransformOptionGroup transformOptionGroup =
|
||||
new TransformOptionGroup(true, set(
|
||||
TransformOptionGroup transformOptionGroup = new TransformOptionGroup(true, set(
|
||||
new TransformOptionValue(false, "1"),
|
||||
new TransformOptionValue(true, "2"),
|
||||
new TransformOptionGroup(false, set(
|
||||
new TransformOptionValue(false, "3.1"),
|
||||
new TransformOptionValue(false, "3.2"),
|
||||
new TransformOptionValue(false, "3.3"))),
|
||||
new TransformOptionValue(false, "3.1"),
|
||||
new TransformOptionValue(false, "3.2"),
|
||||
new TransformOptionValue(false, "3.3"))),
|
||||
new TransformOptionGroup(true, set(
|
||||
new TransformOptionValue(false, "4.1"),
|
||||
new TransformOptionValue(true, "4.2"),
|
||||
new TransformOptionValue(false, "4.3")))));
|
||||
new TransformOptionValue(false, "4.1"),
|
||||
new TransformOptionValue(true, "4.2"),
|
||||
new TransformOptionValue(false, "4.3")))));
|
||||
|
||||
assertAddToPossibleOptions(transformOptionGroup, emptySet(),
|
||||
set("1", "2", "4.1", "4.2", "4.3"), set("2", "4.2"));
|
||||
set("1", "2", "4.1", "4.2", "4.3"), set("2", "4.2"));
|
||||
assertAddToPossibleOptions(transformOptionGroup, set("1"),
|
||||
set("1", "2", "4.1", "4.2", "4.3"), set("2", "4.2"));
|
||||
set("1", "2", "4.1", "4.2", "4.3"), set("2", "4.2"));
|
||||
assertAddToPossibleOptions(transformOptionGroup, set("2", "3.2"),
|
||||
set("1", "2", "3.1", "3.2", "3.3", "4.1", "4.2", "4.3"), set("2", "4.2"));
|
||||
set("1", "2", "3.1", "3.2", "3.3", "4.1", "4.2", "4.3"), set("2", "4.2"));
|
||||
assertAddToPossibleOptions(transformOptionGroup, set("2", "4.1"),
|
||||
set("1", "2", "4.1", "4.2", "4.3"), set("2", "4.2"));
|
||||
set("1", "2", "4.1", "4.2", "4.3"), set("2", "4.2"));
|
||||
assertAddToPossibleOptions(transformOptionGroup, set("2", "4.2"),
|
||||
set("1", "2", "4.1", "4.2", "4.3"), set("2", "4.2"));
|
||||
set("1", "2", "4.1", "4.2", "4.3"), set("2", "4.2"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNestedGroups()
|
||||
{
|
||||
TransformOptionGroup transformOptionGroup =
|
||||
new TransformOptionGroup(false, set(
|
||||
TransformOptionGroup transformOptionGroup = new TransformOptionGroup(false, set(
|
||||
new TransformOptionGroup(false, set(
|
||||
new TransformOptionValue(false, "1"),
|
||||
new TransformOptionGroup(false, set(
|
||||
new TransformOptionValue(false, "1.2"),
|
||||
new TransformOptionValue(false, "1"),
|
||||
new TransformOptionGroup(false, set(
|
||||
new TransformOptionValue(false, "1.2.3"))))))),
|
||||
new TransformOptionValue(false, "1.2"),
|
||||
new TransformOptionGroup(false, set(
|
||||
new TransformOptionValue(false, "1.2.3"))))))),
|
||||
new TransformOptionGroup(false, set(
|
||||
new TransformOptionValue(false, "2"),
|
||||
new TransformOptionGroup(false, set(
|
||||
new TransformOptionValue(false, "2.2"),
|
||||
new TransformOptionValue(false, "2"),
|
||||
new TransformOptionGroup(false, set(
|
||||
new TransformOptionGroup(false, set(
|
||||
new TransformOptionValue(false, "2.2.1.2"))))))))),
|
||||
new TransformOptionValue(false, "2.2"),
|
||||
new TransformOptionGroup(false, set(
|
||||
new TransformOptionGroup(false, set(
|
||||
new TransformOptionValue(false, "2.2.1.2"))))))))),
|
||||
new TransformOptionGroup(false, set(
|
||||
new TransformOptionValue(true, "3"),
|
||||
new TransformOptionGroup(false, set(
|
||||
new TransformOptionValue(true, "3"),
|
||||
new TransformOptionGroup(false, set(
|
||||
new TransformOptionGroup(false, set(
|
||||
new TransformOptionValue(false, "3.1.1.2"))))))))),
|
||||
new TransformOptionGroup(false, set(
|
||||
new TransformOptionGroup(false, set(
|
||||
new TransformOptionValue(false, "3.1.1.2"))))))))),
|
||||
new TransformOptionGroup(false, set(
|
||||
new TransformOptionValue(false, "4"),
|
||||
new TransformOptionGroup(true, set(
|
||||
new TransformOptionGroup(false, set(
|
||||
new TransformOptionGroup(false, set(
|
||||
new TransformOptionValue(false, "4.1.1.2"))))))))),
|
||||
new TransformOptionGroup(false, set(
|
||||
new TransformOptionValue(false, "5"),
|
||||
new TransformOptionGroup(false, set(
|
||||
new TransformOptionValue(false, "4"),
|
||||
new TransformOptionGroup(true, set(
|
||||
new TransformOptionGroup(false, set(
|
||||
new TransformOptionValue(false, "5.1.1.2"))))))))),
|
||||
new TransformOptionGroup(false, set(
|
||||
new TransformOptionGroup(false, set(
|
||||
new TransformOptionValue(false, "4.1.1.2"))))))))),
|
||||
new TransformOptionGroup(false, set(
|
||||
new TransformOptionValue(false, "6"),
|
||||
new TransformOptionGroup(false, set(
|
||||
new TransformOptionValue(false, "5"),
|
||||
new TransformOptionGroup(false, set(
|
||||
new TransformOptionGroup(true, set(
|
||||
new TransformOptionValue(false, "6.1.1.2"))))))))),
|
||||
new TransformOptionGroup(true, set(
|
||||
new TransformOptionGroup(false, set(
|
||||
new TransformOptionValue(false, "5.1.1.2"))))))))),
|
||||
new TransformOptionGroup(false, set(
|
||||
new TransformOptionValue(false, "7"),
|
||||
new TransformOptionGroup(false, set(
|
||||
new TransformOptionValue(false, "6"),
|
||||
new TransformOptionGroup(false, set(
|
||||
new TransformOptionGroup(false, set(
|
||||
new TransformOptionValue(true, "7.1.1.2")))))))))
|
||||
));
|
||||
new TransformOptionGroup(false, set(
|
||||
new TransformOptionGroup(true, set(
|
||||
new TransformOptionValue(false, "6.1.1.2"))))))))),
|
||||
new TransformOptionGroup(false, set(
|
||||
new TransformOptionValue(false, "7"),
|
||||
new TransformOptionGroup(false, set(
|
||||
new TransformOptionGroup(false, set(
|
||||
new TransformOptionGroup(false, set(
|
||||
new TransformOptionValue(true, "7.1.1.2")))))))))));
|
||||
|
||||
assertAddToPossibleOptions(transformOptionGroup, emptySet(),
|
||||
emptySet(), emptySet());
|
||||
emptySet(), emptySet());
|
||||
assertAddToPossibleOptions(transformOptionGroup, set("1"),
|
||||
set("1"), emptySet());
|
||||
set("1"), emptySet());
|
||||
assertAddToPossibleOptions(transformOptionGroup, set("1", "7"),
|
||||
set("1", "7"), emptySet());
|
||||
set("1", "7"), emptySet());
|
||||
assertAddToPossibleOptions(transformOptionGroup, set("1", "7.1.1.2"),
|
||||
set("1", "7", "7.1.1.2"), set("7.1.1.2"));
|
||||
set("1", "7", "7.1.1.2"), set("7.1.1.2"));
|
||||
assertAddToPossibleOptions(transformOptionGroup, set("1", "6"),
|
||||
set("1", "6"), emptySet());
|
||||
set("1", "6"), emptySet());
|
||||
assertAddToPossibleOptions(transformOptionGroup, set("1", "6.1.1.2"),
|
||||
set("1", "6", "6.1.1.2"), emptySet());
|
||||
set("1", "6", "6.1.1.2"), emptySet());
|
||||
assertAddToPossibleOptions(transformOptionGroup, set("1", "5"),
|
||||
set("1", "5"), emptySet());
|
||||
set("1", "5"), emptySet());
|
||||
assertAddToPossibleOptions(transformOptionGroup, set("1", "5.1.1.2"),
|
||||
set("1", "5", "5.1.1.2"), emptySet());
|
||||
set("1", "5", "5.1.1.2"), emptySet());
|
||||
assertAddToPossibleOptions(transformOptionGroup, set("1", "4"),
|
||||
set("1", "4"), emptySet());
|
||||
set("1", "4"), emptySet());
|
||||
assertAddToPossibleOptions(transformOptionGroup, set("1", "4.1.1.2"),
|
||||
set("1", "4", "4.1.1.2"), emptySet());
|
||||
set("1", "4", "4.1.1.2"), emptySet());
|
||||
assertAddToPossibleOptions(transformOptionGroup, set("1", "3"),
|
||||
set("1", "3"), set("3"));
|
||||
set("1", "3"), set("3"));
|
||||
assertAddToPossibleOptions(transformOptionGroup, set("1", "3.1.1.2"),
|
||||
set("1", "3", "3.1.1.2"), set("3"));
|
||||
set("1", "3", "3.1.1.2"), set("3"));
|
||||
|
||||
assertAddToPossibleOptions(transformOptionGroup, set("2"),
|
||||
set("2"), emptySet());
|
||||
set("2"), emptySet());
|
||||
assertAddToPossibleOptions(transformOptionGroup, set("2", "2.2"),
|
||||
set("2", "2.2"), emptySet());
|
||||
set("2", "2.2"), emptySet());
|
||||
assertAddToPossibleOptions(transformOptionGroup, set("3"),
|
||||
set("3"), set("3"));
|
||||
set("3"), set("3"));
|
||||
assertAddToPossibleOptions(transformOptionGroup, set("3.1.1.2"),
|
||||
set("3", "3.1.1.2"), set("3"));
|
||||
set("3", "3.1.1.2"), set("3"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -397,7 +393,7 @@ public class TransformRegistryModelTest
|
||||
assertOptionsMatch(set("B", "d"), set("a", "B", "c"), "there is an extra option d");
|
||||
assertOptionsMatch(set("B", "c", "d"), set("a", "B", "c"), "there is an extra option d");
|
||||
assertOptionsMatch(set("d"), set("a", "B", "c"),
|
||||
"required option B is missing and there is an extra option d");
|
||||
"required option B is missing and there is an extra option d");
|
||||
|
||||
assertOptionsMatch(set("a"), set("a", "b", "c"), null);
|
||||
assertOptionsMatch(emptySet(), set("a", "b", "c"), null);
|
||||
@@ -408,8 +404,8 @@ public class TransformRegistryModelTest
|
||||
public void testNoActualOptions() throws Exception
|
||||
{
|
||||
assertTransformOptions(set(
|
||||
new TransformOptionValue(false, "option1"),
|
||||
new TransformOptionValue(false, "option2")));
|
||||
new TransformOptionValue(false, "option1"),
|
||||
new TransformOptionValue(false, "option2")));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -423,38 +419,38 @@ public class TransformRegistryModelTest
|
||||
public void testSupported() throws Exception
|
||||
{
|
||||
mapOfTransformOptions.put("options1", set(
|
||||
new TransformOptionValue(false, "page"),
|
||||
new TransformOptionValue(false, "width"),
|
||||
new TransformOptionValue(false, "height")));
|
||||
new TransformOptionValue(false, "page"),
|
||||
new TransformOptionValue(false, "width"),
|
||||
new TransformOptionValue(false, "height")));
|
||||
final Transformer transformer = new Transformer("name", singleton("options1"), set(
|
||||
SupportedSourceAndTarget.builder()
|
||||
.withSourceMediaType(DOC)
|
||||
.withTargetMediaType(GIF)
|
||||
.withMaxSourceSizeBytes(102400L)
|
||||
.build(),
|
||||
SupportedSourceAndTarget.builder()
|
||||
.withSourceMediaType(DOC)
|
||||
.withTargetMediaType(JPEG)
|
||||
.build(),
|
||||
SupportedSourceAndTarget.builder()
|
||||
.withSourceMediaType(MSG)
|
||||
.withTargetMediaType(GIF)
|
||||
.build()));
|
||||
SupportedSourceAndTarget.builder()
|
||||
.withSourceMediaType(DOC)
|
||||
.withTargetMediaType(GIF)
|
||||
.withMaxSourceSizeBytes(102400L)
|
||||
.build(),
|
||||
SupportedSourceAndTarget.builder()
|
||||
.withSourceMediaType(DOC)
|
||||
.withTargetMediaType(JPEG)
|
||||
.build(),
|
||||
SupportedSourceAndTarget.builder()
|
||||
.withSourceMediaType(MSG)
|
||||
.withTargetMediaType(GIF)
|
||||
.build()));
|
||||
|
||||
assertSupported(transformer, DOC, 1024, GIF, emptyMap(), null);
|
||||
assertSupported(transformer, DOC, 102400, GIF, emptyMap(), null);
|
||||
assertSupported(transformer, DOC, 102401, GIF, emptyMap(), "source is too large");
|
||||
assertSupported(transformer, DOC, 1024, JPEG, emptyMap(), null);
|
||||
assertSupported(transformer, GIF, 1024, DOC, emptyMap(),
|
||||
GIF + " is not a source of this transformer");
|
||||
GIF + " is not a source of this transformer");
|
||||
assertSupported(transformer, MSG, 1024, GIF, emptyMap(), null);
|
||||
assertSupported(transformer, MSG, 1024, JPEG, emptyMap(),
|
||||
MSG + " to " + JPEG + " is not supported by this transformer");
|
||||
MSG + " to " + JPEG + " is not supported by this transformer");
|
||||
|
||||
assertSupported(transformer, DOC, 1024, GIF, buildActualOptions(set("page", "width")),
|
||||
null);
|
||||
null);
|
||||
assertSupported(transformer, DOC, 1024, GIF,
|
||||
buildActualOptions(set("page", "width", "startPage")), "startPage is not an option");
|
||||
buildActualOptions(set("page", "width", "startPage")), "startPage is not an option");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -463,20 +459,20 @@ public class TransformRegistryModelTest
|
||||
public void testCache()
|
||||
{
|
||||
mapOfTransformOptions.put("options1", set(
|
||||
new TransformOptionValue(false, "page"),
|
||||
new TransformOptionValue(false, "width"),
|
||||
new TransformOptionValue(false, "height")));
|
||||
new TransformOptionValue(false, "page"),
|
||||
new TransformOptionValue(false, "width"),
|
||||
new TransformOptionValue(false, "height")));
|
||||
|
||||
final Transformer transformer = new Transformer("name", singleton("options1"), set(
|
||||
SupportedSourceAndTarget.builder()
|
||||
.withSourceMediaType(DOC)
|
||||
.withTargetMediaType(GIF)
|
||||
.withMaxSourceSizeBytes(102400L)
|
||||
.build(),
|
||||
SupportedSourceAndTarget.builder()
|
||||
.withSourceMediaType(MSG)
|
||||
.withTargetMediaType(GIF)
|
||||
.build()));
|
||||
SupportedSourceAndTarget.builder()
|
||||
.withSourceMediaType(DOC)
|
||||
.withTargetMediaType(GIF)
|
||||
.withMaxSourceSizeBytes(102400L)
|
||||
.build(),
|
||||
SupportedSourceAndTarget.builder()
|
||||
.withSourceMediaType(MSG)
|
||||
.withTargetMediaType(GIF)
|
||||
.build()));
|
||||
|
||||
TransformConfig transformConfig = TransformConfig.builder()
|
||||
.withTransformers(Collections.singletonList(transformer))
|
||||
@@ -492,7 +488,7 @@ public class TransformRegistryModelTest
|
||||
|
||||
// check we are now using the cached value.
|
||||
final SupportedTransform cachedSupportedTransform = new SupportedTransform("name1",
|
||||
emptySet(), 999999L, 0);
|
||||
emptySet(), 999999L, 0);
|
||||
|
||||
registry.getData()
|
||||
.retrieveCached("doclib", DOC)
|
||||
@@ -504,15 +500,15 @@ public class TransformRegistryModelTest
|
||||
public void testTransformCacheGetTransforms() // Used in the Alfresco Repo tests
|
||||
{
|
||||
TransformConfig transformConfig = TransformConfig.builder()
|
||||
.withTransformers(ImmutableList.of(new Transformer("transformer1", emptySet(), set(
|
||||
SupportedSourceAndTarget.builder()
|
||||
.withSourceMediaType(GIF)
|
||||
.withTargetMediaType(PDF)
|
||||
.build(),
|
||||
SupportedSourceAndTarget.builder()
|
||||
.withSourceMediaType(GIF)
|
||||
.withTargetMediaType(JPEG)
|
||||
.build()))))
|
||||
.withTransformers(ImmutableList.of(new Transformer("transformer1", emptySet(), set(
|
||||
SupportedSourceAndTarget.builder()
|
||||
.withSourceMediaType(GIF)
|
||||
.withTargetMediaType(PDF)
|
||||
.build(),
|
||||
SupportedSourceAndTarget.builder()
|
||||
.withSourceMediaType(GIF)
|
||||
.withTargetMediaType(JPEG)
|
||||
.build()))))
|
||||
.build();
|
||||
|
||||
assertEquals(0, registry.getData().getTransforms().size());
|
||||
@@ -539,8 +535,8 @@ public class TransformRegistryModelTest
|
||||
assertTransformerName(MSG, 150, GIF, emptyMap(), "transformer2", t1, t2);
|
||||
assertTransformerName(MSG, 250, GIF, emptyMap(), 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.
|
||||
// t3 is a higher priority and has a larger size than t1 and t2.
|
||||
// Similar story fo t4 with t5.
|
||||
assertTransformerName(MSG, 100, GIF, emptyMap(), "transformer3", t1, t2, t3, t4, t5);
|
||||
assertTransformerName(MSG, 200, GIF, emptyMap(), "transformer3", t1, t2, t3, t4, t5);
|
||||
// Select on size and priority, t1 and t2 discarded
|
||||
@@ -550,7 +546,7 @@ public class TransformRegistryModelTest
|
||||
}
|
||||
|
||||
private Transformer newTransformer(String transformerName, String sourceMediaType, String targetMediaType,
|
||||
long maxSourceSizeBytes, int priority)
|
||||
long maxSourceSizeBytes, int priority)
|
||||
{
|
||||
return Transformer.builder().withTransformerName(transformerName)
|
||||
.withSupportedSourceAndTargetList(ImmutableSet.of(
|
||||
@@ -567,68 +563,68 @@ public class TransformRegistryModelTest
|
||||
public void testMultipleTransformers() throws Exception
|
||||
{
|
||||
mapOfTransformOptions.put("options1", set(
|
||||
new TransformOptionValue(false, "page"),
|
||||
new TransformOptionValue(false, "width"),
|
||||
new TransformOptionValue(false, "height")));
|
||||
new TransformOptionValue(false, "page"),
|
||||
new TransformOptionValue(false, "width"),
|
||||
new TransformOptionValue(false, "height")));
|
||||
mapOfTransformOptions.put("options2", set(
|
||||
new TransformOptionValue(false, "opt1"),
|
||||
new TransformOptionValue(false, "opt2")));
|
||||
new TransformOptionValue(false, "opt1"),
|
||||
new TransformOptionValue(false, "opt2")));
|
||||
mapOfTransformOptions.put("options3", new HashSet<>(singletonList(
|
||||
new TransformOptionValue(false, "opt1"))));
|
||||
new TransformOptionValue(false, "opt1"))));
|
||||
|
||||
Transformer transformer1 = new Transformer("transformer1", singleton("options1"), set(
|
||||
SupportedSourceAndTarget.builder()
|
||||
.withSourceMediaType(DOC)
|
||||
.withTargetMediaType(GIF)
|
||||
.withMaxSourceSizeBytes(102400L)
|
||||
.build(),
|
||||
SupportedSourceAndTarget.builder()
|
||||
.withSourceMediaType(DOC)
|
||||
.withTargetMediaType(JPEG)
|
||||
.build(),
|
||||
SupportedSourceAndTarget.builder()
|
||||
.withSourceMediaType(MSG)
|
||||
.withTargetMediaType(GIF)
|
||||
.build()));
|
||||
SupportedSourceAndTarget.builder()
|
||||
.withSourceMediaType(DOC)
|
||||
.withTargetMediaType(GIF)
|
||||
.withMaxSourceSizeBytes(102400L)
|
||||
.build(),
|
||||
SupportedSourceAndTarget.builder()
|
||||
.withSourceMediaType(DOC)
|
||||
.withTargetMediaType(JPEG)
|
||||
.build(),
|
||||
SupportedSourceAndTarget.builder()
|
||||
.withSourceMediaType(MSG)
|
||||
.withTargetMediaType(GIF)
|
||||
.build()));
|
||||
|
||||
Transformer transformer2 = new Transformer("transformer2", singleton("options2"), set(
|
||||
SupportedSourceAndTarget.builder()
|
||||
.withSourceMediaType(PDF)
|
||||
.withTargetMediaType(GIF)
|
||||
.build(),
|
||||
SupportedSourceAndTarget.builder()
|
||||
.withSourceMediaType(PPT)
|
||||
.withTargetMediaType(JPEG)
|
||||
.build()));
|
||||
SupportedSourceAndTarget.builder()
|
||||
.withSourceMediaType(PDF)
|
||||
.withTargetMediaType(GIF)
|
||||
.build(),
|
||||
SupportedSourceAndTarget.builder()
|
||||
.withSourceMediaType(PPT)
|
||||
.withTargetMediaType(JPEG)
|
||||
.build()));
|
||||
|
||||
Transformer transformer3 = new Transformer("transformer3", singleton("options3"),
|
||||
new HashSet(singletonList(SupportedSourceAndTarget.builder()
|
||||
.withSourceMediaType(DOC)
|
||||
.withTargetMediaType(GIF)
|
||||
.build())));
|
||||
new HashSet(singletonList(SupportedSourceAndTarget.builder()
|
||||
.withSourceMediaType(DOC)
|
||||
.withTargetMediaType(GIF)
|
||||
.build())));
|
||||
|
||||
assertSupported(DOC, 1024, GIF, emptyMap(), null, transformer1);
|
||||
assertSupported(DOC, 1024, GIF, emptyMap(), null, transformer1, transformer2);
|
||||
assertSupported(DOC, 1024, GIF, emptyMap(), null, transformer1, transformer2,
|
||||
transformer3);
|
||||
transformer3);
|
||||
|
||||
assertSupported(DOC, 102401, GIF, emptyMap(), "source is too large", transformer1);
|
||||
assertSupported(DOC, 102401, GIF, emptyMap(), null, transformer1, transformer3);
|
||||
|
||||
assertSupported(PDF, 1024, GIF, emptyMap(), "Only transformer2 supports these mimetypes",
|
||||
transformer1);
|
||||
transformer1);
|
||||
assertSupported(PDF, 1024, GIF, emptyMap(), null, transformer1, transformer2);
|
||||
assertSupported(PDF, 1024, GIF, emptyMap(), null, transformer1, transformer2,
|
||||
transformer3);
|
||||
transformer3);
|
||||
|
||||
final Map<String, String> actualOptions = buildActualOptions(set("opt1"));
|
||||
assertSupported(PDF, 1024, GIF, actualOptions, "Only transformer2/4 supports these options",
|
||||
transformer1);
|
||||
transformer1);
|
||||
assertSupported(PDF, 1024, GIF, actualOptions, null, transformer1, transformer2);
|
||||
assertSupported(PDF, 1024, GIF, actualOptions, null, transformer1, transformer2,
|
||||
transformer3);
|
||||
transformer3);
|
||||
assertSupported(PDF, 1024, GIF, actualOptions,
|
||||
"transformer4 supports opt1 but not the source mimetype ", transformer1, transformer3);
|
||||
"transformer4 supports opt1 but not the source mimetype ", transformer1, transformer3);
|
||||
}
|
||||
|
||||
@SafeVarargs
|
||||
@@ -650,7 +646,7 @@ public class TransformRegistryModelTest
|
||||
t2.setCoreVersion("1.0");
|
||||
t3.setCoreVersion("2.5.7");
|
||||
|
||||
buildAndPopulateRegistry(new Transformer[] {t1, t2, t3});
|
||||
buildAndPopulateRegistry(new Transformer[]{t1, t2, t3});
|
||||
|
||||
assertTrue(registry.isSupported(CoreFunction.HTTP, "transformer1"));
|
||||
assertTrue(registry.isSupported(CoreFunction.HTTP, "transformer2"));
|
||||
|
Reference in New Issue
Block a user