REPO-4334 Move metadata extraction into T-Engines (#247)

* Metadata extract code added to T-Engines
* Required a refactor of duplicate code to avoid 3x more duplication:
        - try catches used to return return exit codes
        - calls to java libraries or commands to external processes
        - building of transform options in controllers, adaptors
* integration tests based on current extracts performed in the repo
* included extract code for libreoffice, and embed code even though not used out of the box any more. There may well be custom extracts using them that move to T-Engines
* removal of unused imports
* minor autoOrient / allowEnlargement bug fixes that were not included in Paddington on the T-Engine side.
This commit is contained in:
Alan Davis
2020-06-11 20:20:22 +01:00
committed by GitHub
parent ca394440bb
commit 06109dee75
158 changed files with 10288 additions and 1454 deletions

View File

@@ -2,7 +2,7 @@
* #%L
* Alfresco Transform Core
* %%
* Copyright (C) 2005 - 2019 Alfresco Software Limited
* Copyright (C) 2005 - 2020 Alfresco Software Limited
* %%
* This file is part of the Alfresco software.
* -
@@ -26,16 +26,15 @@
*/
package org.alfresco.transformer;
import static org.alfresco.transformer.util.Util.stringToBoolean;
import static org.alfresco.transformer.util.Util.stringToInteger;
import static org.springframework.http.HttpStatus.BAD_REQUEST;
import com.google.common.collect.ImmutableList;
import org.alfresco.transform.exceptions.TransformException;
import java.util.List;
import java.util.StringJoiner;
import org.alfresco.transform.exceptions.TransformException;
import com.google.common.collect.ImmutableList;
import static org.alfresco.transformer.util.Util.stringToBoolean;
import static org.alfresco.transformer.util.Util.stringToInteger;
import static org.springframework.http.HttpStatus.BAD_REQUEST;
/**
* ImageMagick options builder.
@@ -107,7 +106,7 @@ public final class ImageMagickOptionsBuilder
public ImageMagickOptionsBuilder withAutoOrient(final Boolean autoOrient)
{
this.autoOrient = autoOrient;
this.autoOrient = autoOrient == null ? true : autoOrient;
return this;
}
@@ -223,7 +222,7 @@ public final class ImageMagickOptionsBuilder
public ImageMagickOptionsBuilder withAllowEnlargement(final Boolean allowEnlargement)
{
this.allowEnlargement = allowEnlargement;
this.allowEnlargement = allowEnlargement == null ? true : allowEnlargement;
return this;
}

View File

@@ -26,15 +26,42 @@
*/
package org.alfresco.transformer.executors;
import org.alfresco.transform.exceptions.TransformException;
import org.alfresco.transformer.ImageMagickOptionsBuilder;
import java.io.File;
import java.util.HashMap;
import java.util.Map;
import static org.alfresco.transformer.util.RequestParamMap.ALLOW_ENLARGEMENT;
import static org.alfresco.transformer.util.RequestParamMap.ALPHA_REMOVE;
import static org.alfresco.transformer.util.RequestParamMap.AUTO_ORIENT;
import static org.alfresco.transformer.util.RequestParamMap.COMMAND_OPTIONS;
import static org.alfresco.transformer.util.RequestParamMap.CROP_GRAVITY;
import static org.alfresco.transformer.util.RequestParamMap.CROP_HEIGHT;
import static org.alfresco.transformer.util.RequestParamMap.CROP_PERCENTAGE;
import static org.alfresco.transformer.util.RequestParamMap.CROP_WIDTH;
import static org.alfresco.transformer.util.RequestParamMap.CROP_X_OFFSET;
import static org.alfresco.transformer.util.RequestParamMap.CROP_Y_OFFSET;
import static org.alfresco.transformer.util.RequestParamMap.END_PAGE;
import static org.alfresco.transformer.util.RequestParamMap.MAINTAIN_ASPECT_RATIO;
import static org.alfresco.transformer.util.RequestParamMap.RESIZE_HEIGHT;
import static org.alfresco.transformer.util.RequestParamMap.RESIZE_PERCENTAGE;
import static org.alfresco.transformer.util.RequestParamMap.RESIZE_WIDTH;
import static org.alfresco.transformer.util.RequestParamMap.START_PAGE;
import static org.alfresco.transformer.util.RequestParamMap.THUMBNAIL;
import static org.alfresco.transformer.util.RequestParamMap.TIMEOUT;
import static org.alfresco.transformer.util.Util.stringToInteger;
import static org.alfresco.transformer.util.Util.stringToLong;
/**
* CommandExecutor implementation for running ImageMagick transformations. It runs the
* transformation logic as a separate Shell process.
*/
public class ImageMagickCommandExecutor extends AbstractCommandExecutor
{
private static final String ID = "imagemagick";
private final String ROOT;
private final String DYN;
private final String EXE;
@@ -65,6 +92,12 @@ public class ImageMagickCommandExecutor extends AbstractCommandExecutor
super.checkCommand = createCheckCommand();
}
@Override
public String getTransformerId()
{
return ID;
}
public static final String LICENCE = "This transformer uses ImageMagick from ImageMagick Studio LLC. See the license at http://www.imagemagick.org/script/license.php or in /ImageMagick-license.txt";
@Override
@@ -111,4 +144,51 @@ public class ImageMagickCommandExecutor extends AbstractCommandExecutor
runtimeExec.setCommandsAndArguments(commandsAndArguments);
return runtimeExec;
}
@Override
public void transform(String transformName, String sourceMimetype, String targetMimetype,
Map<String, String> transformOptions,
File sourceFile, File targetFile) throws TransformException
{
final String options = ImageMagickOptionsBuilder
.builder()
.withStartPage(transformOptions.get(START_PAGE))
.withEndPage(transformOptions.get(END_PAGE))
.withAlphaRemove(transformOptions.get(ALPHA_REMOVE))
.withAutoOrient(transformOptions.get(AUTO_ORIENT))
.withCropGravity(transformOptions.get(CROP_GRAVITY))
.withCropWidth(transformOptions.get(CROP_WIDTH))
.withCropHeight(transformOptions.get(CROP_HEIGHT))
.withCropPercentage(transformOptions.get(CROP_PERCENTAGE))
.withCropXOffset(transformOptions.get(CROP_X_OFFSET))
.withCropYOffset(transformOptions.get(CROP_Y_OFFSET))
.withThumbnail(transformOptions.get(THUMBNAIL))
.withResizeWidth(transformOptions.get(RESIZE_WIDTH))
.withResizeHeight(transformOptions.get(RESIZE_HEIGHT))
.withResizePercentage(transformOptions.get(RESIZE_PERCENTAGE))
.withAllowEnlargement(transformOptions.get(ALLOW_ENLARGEMENT))
.withMaintainAspectRatio(transformOptions.get(MAINTAIN_ASPECT_RATIO))
.withCommandOptions(transformOptions.get(COMMAND_OPTIONS))
.build();
String pageRange = calculatePageRange(
stringToInteger(transformOptions.get(START_PAGE)),
stringToInteger(transformOptions.get(END_PAGE))
);
Long timeout = stringToLong(transformOptions.get(TIMEOUT));
run(options, sourceFile, pageRange, targetFile, timeout);
}
private static String calculatePageRange(Integer startPage, Integer endPage)
{
return startPage == null
? endPage == null
? ""
: "[" + endPage + ']'
: endPage == null || startPage.equals(endPage)
? "[" + startPage + ']'
: "[" + startPage + '-' + endPage + ']';
}
}