Skip to content

Commit

Permalink
ACS-3118 Check the size of intermmitent results in a pipeline (#629)
Browse files Browse the repository at this point in the history
Set the size of a transform result in the Reply to the t-router.

Tidy up code: Avoid having to add the transformName to the transformOptions in the Controller class and then remove it in Transformer interface.
  • Loading branch information
alandavis authored May 31, 2022
1 parent 7a4d3c1 commit 60eb104
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,9 @@ public String version()
return getTransformerName() + " available";
}

// TODO ATS-713 Currently uses the Misc probeTest. The implementation will need to be changed such that the test can be selected based on the required transform
@Override
public ProbeTestTransform getProbeTestTransform()
{
// HtmlParserContentTransformer html -> text
// See the Javadoc on this method and Probes.md for the choice of these values.
return new ProbeTestTransform(this, "quick.html", "quick.txt",
119, 30, 150, 1024,
60 * 2 + 1, 60 * 2)
Expand Down Expand Up @@ -120,7 +117,6 @@ public void transformImpl(String transformName, String sourceMimetype, String ta
logger.debug("Performing transform with name '{}' using transformer with id '{}'.", transformName, transformer.getTransformerId());
}

transformOptions.put(TRANSFORM_NAME_PARAMETER, transformName);
transformer.transform(sourceMimetype, targetMimetype, transformOptions, sourceFile, targetFile);
transformer.transformExtractOrEmbed(transformName, sourceMimetype, targetMimetype, transformOptions, sourceFile, targetFile);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* #%L
* Alfresco Transform Core
* %%
* Copyright (C) 2005 - 2021 Alfresco Software Limited
* Copyright (C) 2005 - 2022 Alfresco Software Limited
* %%
* This file is part of the Alfresco software.
* -
Expand Down Expand Up @@ -184,9 +184,8 @@ public void testMiscHtml() throws Exception

Map<String, String> parameters = new HashMap<>();
parameters.put(SOURCE_ENCODING, "ISO-8859-1");
parameters.put(TRANSFORM_NAME_PARAMETER, "html");
Transformer transformer = aioTransformerRegistry.getByTransformName("html");
transformer.transform(SOURCE_MIMETYPE, TARGET_MIMETYPE, parameters, tmpS, tmpD);
transformer.transformExtractOrEmbed("html", SOURCE_MIMETYPE, TARGET_MIMETYPE, parameters, tmpS, tmpD);

assertEquals(expected, readFromFile(tmpD, "UTF-8"));
tmpS.delete();
Expand All @@ -198,9 +197,8 @@ public void testMiscHtml() throws Exception

tmpD = File.createTempFile("AlfrescoTestTarget_", ".txt");
parameters = new HashMap<>();
parameters.put(TRANSFORM_NAME_PARAMETER, "html");
parameters.put(SOURCE_ENCODING, "UTF-8");
transformer.transform(SOURCE_MIMETYPE, TARGET_MIMETYPE, parameters, tmpS, tmpD);
transformer.transformExtractOrEmbed("html", SOURCE_MIMETYPE, TARGET_MIMETYPE, parameters, tmpS, tmpD);
assertEquals(expected, readFromFile(tmpD, "UTF-8"));
tmpS.delete();
tmpD.delete();
Expand All @@ -211,9 +209,8 @@ public void testMiscHtml() throws Exception

tmpD = File.createTempFile("AlfrescoTestTarget_", ".txt");
parameters = new HashMap<>();
parameters.put(TRANSFORM_NAME_PARAMETER, "html");
parameters.put(SOURCE_ENCODING, "UTF-16");
transformer.transform(SOURCE_MIMETYPE, TARGET_MIMETYPE, parameters, tmpS, tmpD);
transformer.transformExtractOrEmbed("html", SOURCE_MIMETYPE, TARGET_MIMETYPE, parameters, tmpS, tmpD);
assertEquals(expected, readFromFile(tmpD, "UTF-8"));
tmpS.delete();
tmpD.delete();
Expand All @@ -237,9 +234,8 @@ public void testMiscHtml() throws Exception
tmpD = File.createTempFile("AlfrescoTestTarget_", ".txt");

parameters = new HashMap<>();
parameters.put(TRANSFORM_NAME_PARAMETER, "html");
parameters.put(SOURCE_ENCODING, "ISO-8859-1");
transformer.transform(SOURCE_MIMETYPE, TARGET_MIMETYPE, parameters, tmpS, tmpD);
transformer.transformExtractOrEmbed("html", SOURCE_MIMETYPE, TARGET_MIMETYPE, parameters, tmpS, tmpD);
assertEquals(expected, readFromFile(tmpD, "UTF-8"));
tmpS.delete();
tmpD.delete();
Expand Down Expand Up @@ -295,9 +291,8 @@ private void transformTextAndCheck(String text, String encoding, String checkTex
// Transform to PDF
Map<String, String> parameters = new HashMap<>();
parameters.put(PAGE_LIMIT, pageLimit);
parameters.put(TRANSFORM_NAME_PARAMETER, "textToPdf");
Transformer transformer = aioTransformerRegistry.getByTransformName("textToPdf");
transformer.transform("text/plain", "application/pdf", parameters, sourceFile, targetFile);
transformer.transformExtractOrEmbed("textToPdf", "text/plain", "application/pdf", parameters, sourceFile, targetFile);

// Read back in the PDF and check it
PDDocument doc = PDDocument.load(targetFile);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* #%L
* Alfresco Transform Core
* %%
* Copyright (C) 2005 - 2020 Alfresco Software Limited
* Copyright (C) 2005 - 2022 Alfresco Software Limited
* %%
* This file is part of the Alfresco software.
* -
Expand Down Expand Up @@ -126,6 +126,6 @@ protected String getTransformerName(final File sourceFile, final String sourceMi
public void transformImpl(String transformName, String sourceMimetype, String targetMimetype,
Map<String, String> transformOptions, File sourceFile, File targetFile)
{
commandExecutor.transform(sourceMimetype, targetMimetype, transformOptions, sourceFile, targetFile);
commandExecutor.transformExtractOrEmbed(transformName, sourceMimetype, targetMimetype, transformOptions, sourceFile, targetFile);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* #%L
* Alfresco Transform Core
* %%
* Copyright (C) 2005 - 2020 Alfresco Software Limited
* Copyright (C) 2005 - 2022 Alfresco Software Limited
* %%
* This file is part of the Alfresco software.
* -
Expand Down Expand Up @@ -128,6 +128,6 @@ protected String getTransformerName(final File sourceFile, final String sourceMi
public void transformImpl(String transformName, String sourceMimetype, String targetMimetype,
Map<String, String> transformOptions, File sourceFile, File targetFile)
{
javaExecutor.transform(sourceMimetype, targetMimetype, transformOptions, sourceFile, targetFile);
javaExecutor.transformExtractOrEmbed(transformName, sourceMimetype, targetMimetype, transformOptions, sourceFile, targetFile);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ protected void executeTransformCommand(File sourceFile, File targetFile)
public void transformImpl(String transformName, String sourceMimetype, String targetMimetype,
Map<String, String> transformOptions, File sourceFile, File targetFile)
{
transformOptions.put(TRANSFORM_NAME_PARAMETER, transformName);
transformer.transform(sourceMimetype, targetMimetype, transformOptions, sourceFile, targetFile);
transformer.transformExtractOrEmbed(transformName, sourceMimetype, targetMimetype, transformOptions, sourceFile, targetFile);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* #%L
* Alfresco Transform Core
* %%
* Copyright (C) 2005 - 2020 Alfresco Software Limited
* Copyright (C) 2005 - 2022 Alfresco Software Limited
* %%
* This file is part of the Alfresco software.
* -
Expand Down Expand Up @@ -113,6 +113,6 @@ protected String getTransformerName(final File sourceFile, final String sourceMi
public void transformImpl(String transformName, String sourceMimetype, String targetMimetype,
Map<String, String> transformOptions, File sourceFile, File targetFile)
{
commandExecutor.transform(sourceMimetype, targetMimetype, transformOptions, sourceFile, targetFile);
commandExecutor.transformExtractOrEmbed(transformName, sourceMimetype, targetMimetype, transformOptions, sourceFile, targetFile);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* #%L
* Alfresco Transform Core
* %%
* Copyright (C) 2005 - 2020 Alfresco Software Limited
* Copyright (C) 2005 - 2022 Alfresco Software Limited
* %%
* This file is part of the Alfresco software.
* -
Expand Down Expand Up @@ -40,7 +40,6 @@
import static org.alfresco.transformer.executors.Tika.PDF_BOX;
import static org.alfresco.transformer.util.MimetypeMap.MIMETYPE_PDF;
import static org.alfresco.transformer.util.MimetypeMap.MIMETYPE_TEXT_PLAIN;
import static org.alfresco.transformer.util.RequestParamMap.TRANSFORM_NAME_PARAMETER;

/**
* Controller for the Docker based Tika transformers.
Expand Down Expand Up @@ -107,7 +106,6 @@ protected void executeTransformCommand(File sourceFile, File targetFile)
public void transformImpl(String transformName, String sourceMimetype, String targetMimetype,
Map<String, String> transformOptions, File sourceFile, File targetFile)
{
transformOptions.put(TRANSFORM_NAME_PARAMETER, transformName);
javaExecutor.transform(sourceMimetype, targetMimetype, transformOptions, sourceFile, targetFile);
javaExecutor.transformExtractOrEmbed(transformName, sourceMimetype, targetMimetype, transformOptions, sourceFile, targetFile);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,7 @@ public ResponseEntity<TransformReply> transform(@RequestBody TransformRequest re
transformerDebug.logOptions(request);
String transformName = getTransformerName(sourceFile, sourceMimetype, targetMimetype, transformOptions);
transformImpl(transformName, sourceMimetype, targetMimetype, transformOptions, sourceFile, targetFile);
reply.getInternalContext().setCurrentSourceSize(targetFile.length());
}
catch (TransformException e)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* #%L
* Alfresco Transform Core
* %%
* Copyright (C) 2005 - 2020 Alfresco Software Limited
* Copyright (C) 2005 - 2022 Alfresco Software Limited
* %%
* This file is part of the Alfresco software.
* -
Expand Down Expand Up @@ -52,11 +52,17 @@ public interface Transformer
String getTransformerId();

default void transform(String sourceMimetype, String targetMimetype, Map<String, String> transformOptions,
File sourceFile, File targetFile) throws TransformException
File sourceFile, File targetFile) throws TransformException {
final String transformName = transformOptions.remove(TRANSFORM_NAME_PARAMETER);
transformExtractOrEmbed(transformName, sourceMimetype, targetMimetype, transformOptions, sourceFile, targetFile);
}

default void transformExtractOrEmbed(String transformName, String sourceMimetype, String targetMimetype,
Map<String, String> transformOptions,
File sourceFile, File targetFile) throws TransformException
{
try
{
final String transformName = transformOptions.remove(TRANSFORM_NAME_PARAMETER);
if (MIMETYPE_METADATA_EXTRACT.equals(targetMimetype))
{
extractMetadata(transformName, sourceMimetype, targetMimetype, transformOptions, sourceFile, targetFile);
Expand Down

0 comments on commit 60eb104

Please sign in to comment.