Save point: [skip ci]

* pick up alfresco-t-engine-base in 5 base t-engines
* Switch over to using new base
* Moved files in 5 base t-engines so we can remove the -boot package in the next round of changes
This commit is contained in:
alandavis
2022-07-01 17:14:01 +01:00
parent 2e05eb71fb
commit c44ff5016a
373 changed files with 967 additions and 2119 deletions

View File

@@ -43,7 +43,7 @@ import org.springframework.context.event.EventListener;
import java.util.Arrays;
import java.util.List;
import static org.alfresco.transform.base.logging.StandardMessages.LICENCE;
import static org.alfresco.transform.base.logging.StandardMessages.COMMUNITY_LICENCE;
@SpringBootApplication
@EnableAutoConfiguration(exclude = { DataSourceAutoConfiguration.class})
@@ -51,9 +51,6 @@ public class Application
{
private static final Logger logger = LoggerFactory.getLogger(Application.class);
@Autowired(required = false)
private List<TransformEngine> transformEngines;
@Value("${container.name}")
private String containerName;
@@ -67,19 +64,4 @@ public class Application
{
SpringApplication.run(Application.class, args);
}
@EventListener(ApplicationReadyEvent.class)
public void startup()
{
logger.info("--------------------------------------------------------------------------------------------------------------------------------------------------------------");
Arrays.stream(LICENCE.split("\\n")).forEach(logger::info);
if (transformEngines != null) {
transformEngines.stream()
.map(transformEngine -> transformEngine.getStartupMessage())
.forEach(message -> Arrays.stream(message.split("\\n")).forEach(logger::info));
}
logger.info("--------------------------------------------------------------------------------------------------------------------------------------------------------------");
logger.info("Starting application components... Done");
}
}

View File

@@ -26,10 +26,17 @@
*/
package org.alfresco.transform.base;
import org.alfresco.transform.config.TransformConfig;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Map;
/**
* Interface to be implemented by transform specific code. The {@code transformerName} should match the transformerName
* in the {@link TransformConfig} returned by the {@link TransformEngine}. So that it is automatically picked up, it
* must exist in a package under {@code org.alfresco.transform} and have the Spring {@code @Component} annotation.
*/
public interface CustomTransformer
{
String getTransformerName();

View File

@@ -44,6 +44,8 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.TypeMismatchException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.event.EventListener;
import org.springframework.core.io.Resource;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
@@ -94,11 +96,11 @@ import static org.alfresco.transform.base.fs.FileManager.createTargetFileName;
import static org.alfresco.transform.base.fs.FileManager.deleteFile;
import static org.alfresco.transform.base.fs.FileManager.getFilenameFromContentDisposition;
import static org.alfresco.transform.base.fs.FileManager.save;
import static org.alfresco.transform.base.util.RequestParamMap.FILE;
import static org.alfresco.transform.base.util.RequestParamMap.SOURCE_ENCODING;
import static org.alfresco.transform.base.util.RequestParamMap.SOURCE_EXTENSION;
import static org.alfresco.transform.base.util.RequestParamMap.SOURCE_MIMETYPE;
import static org.alfresco.transform.base.util.RequestParamMap.TARGET_MIMETYPE;
import static org.alfresco.transform.common.RequestParamMap.FILE;
import static org.alfresco.transform.common.RequestParamMap.SOURCE_ENCODING;
import static org.alfresco.transform.common.RequestParamMap.SOURCE_EXTENSION;
import static org.alfresco.transform.common.RequestParamMap.SOURCE_MIMETYPE;
import static org.alfresco.transform.common.RequestParamMap.TARGET_MIMETYPE;
import static org.springframework.http.HttpStatus.BAD_REQUEST;
import static org.springframework.http.HttpStatus.CREATED;
import static org.springframework.http.HttpStatus.INTERNAL_SERVER_ERROR;
@@ -178,6 +180,22 @@ public class TransformController
}
}
@EventListener(ApplicationReadyEvent.class)
public void startup()
{
logger.info("--------------------------------------------------------------------------------------------------------------------------------------------------------------");
if (transformEngines != null)
{
transformEngines.stream()
.map(transformEngine -> transformEngine.getStartupMessage())
.forEach(message -> Arrays.stream(message.split("\\n")).forEach(logger::info));
}
logger.info("--------------------------------------------------------------------------------------------------------------------------------------------------------------");
logger.info("Starting application components... Done");
}
/**
* @return a string that may be used in client debug.
*/

View File

@@ -26,11 +26,14 @@
*/
package org.alfresco.transform.base;
import org.alfresco.transform.common.TransformConfigResourceReader;
import org.alfresco.transform.config.TransformConfig;
import org.alfresco.transform.base.probes.ProbeTestTransform;
/**
* The interface to the custom transform code applied on top of a base t-engine.
* Interface to be implemented by transform specific code. Provides information about the t-engine as a whole.
* Also see {@link CustomTransformer} which provides the code that performs transformation. There may be several
* in a single t-engine.
*/
public interface TransformEngine
{
@@ -45,7 +48,8 @@ public interface TransformEngine
String getStartupMessage();
/**
* @return a definition of what the t-engine supports. Normally read from a json Resource on the classpath.
* @return a definition of what the t-engine supports. Normally read from a json Resource on the classpath using a
* {@link TransformConfigResourceReader}.
*/
TransformConfig getTransformConfig();

View File

@@ -65,7 +65,7 @@ public class TransformRegistryImpl extends AbstractTransformRegistry
.sorted(Comparator.comparing(TransformEngine::getTransformEngineName))
.forEach(transformEngine -> {
TransformConfig transformConfig = transformEngine.getTransformConfig();
if (transformConfig != null)
if (transformConfig != null) // if not a wrapping TransformEngine like all-in-one
{
setCoreVersionOnSingleStepTransformers(transformConfig, coreVersion);
combinedTransformConfig.addTransformConfig(transformConfig,

View File

@@ -35,9 +35,6 @@ import java.util.Map;
import org.alfresco.transform.common.TransformException;
/**
*
*/
public abstract class AbstractCommandExecutor implements CommandExecutor
{
protected RuntimeExec transformCommand = createTransformCommand();
@@ -65,27 +62,4 @@ public abstract class AbstractCommandExecutor implements CommandExecutor
"Transformer failed to create an output file");
}
}
@Override
public String version()
{
if (checkCommand != null)
{
final ExecutionResult result = checkCommand.execute();
if (result.getExitValue() != 0 && result.getStdErr() != null && result.getStdErr().length() > 0)
{
throw new TransformException(INTERNAL_SERVER_ERROR.value(),
"Transformer version check exit code was not 0: \n" + result);
}
final String version = result.getStdOut().trim();
if (version.isEmpty())
{
throw new TransformException(INTERNAL_SERVER_ERROR.value(),
"Transformer version check failed to create any output");
}
return version;
}
return "Version not checked";
}
}

View File

@@ -37,14 +37,11 @@ import java.util.Map;
*
* @author Cezar Leahu
*/
public interface CommandExecutor extends Transformer
public interface CommandExecutor
{
void run(Map<String, String> properties, File targetFile, Long timeout);
String version();
default void run(String options, File sourceFile, File targetFile,
Long timeout)
default void run(String options, File sourceFile, File targetFile, Long timeout)
{
LogEntry.setOptions(options);
@@ -56,8 +53,7 @@ public interface CommandExecutor extends Transformer
run(properties, targetFile, timeout);
}
default void run(String options, File sourceFile, String pageRange, File targetFile,
Long timeout)
default void run(String options, File sourceFile, String pageRange, File targetFile, Long timeout)
{
LogEntry.setOptions(pageRange + (pageRange.isEmpty() ? "" : " ") + options);

View File

@@ -1,40 +0,0 @@
/*
* #%L
* Alfresco Transform Core
* %%
* Copyright (C) 2005 - 2022 Alfresco Software Limited
* %%
* This file is part of the Alfresco software.
* -
* If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms:
* -
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* -
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
* -
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
* #L%
*/
package org.alfresco.transform.base.executors;
import java.io.File;
/**
* Basic interface for executing transformations inside Java/JVM.
*
* @author Cezar Leahu
* @author adavis
*/
public interface JavaExecutor extends Transformer
{
void call(File sourceFile, File targetFile, String... args) throws Exception;
}

View File

@@ -1,130 +0,0 @@
package org.alfresco.transform.base.executors;
/*
* #%L
* Alfresco Transform Core
* %%
* Copyright (C) 2005 - 2022 Alfresco Software Limited
* %%
* This file is part of the Alfresco software.
* -
* If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms:
* -
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* -
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
* -
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
* #L%
*/
import org.alfresco.transform.common.TransformException;
import java.io.File;
import java.util.Map;
import static org.alfresco.transform.common.Mimetype.MIMETYPE_METADATA_EMBED;
import static org.alfresco.transform.common.Mimetype.MIMETYPE_METADATA_EXTRACT;
import static org.alfresco.transform.base.util.RequestParamMap.TRANSFORM_NAME_PARAMETER;
import static org.springframework.http.HttpStatus.BAD_REQUEST;
import static org.springframework.http.HttpStatus.INTERNAL_SERVER_ERROR;
/**
* Basic interface for executing transforms and metadata extract or embed actions.
*
* @author adavis
*/
public interface Transformer
{
/**
* @return A unique transformer id,
*
*/
String getTransformerId();
default void transform(String sourceMimetype, String targetMimetype, Map<String, String> transformOptions,
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
{
if (MIMETYPE_METADATA_EXTRACT.equals(targetMimetype))
{
extractMetadata(transformName, sourceMimetype, targetMimetype, transformOptions, sourceFile, targetFile);
}
else if (MIMETYPE_METADATA_EMBED.equals(targetMimetype))
{
embedMetadata(transformName, sourceMimetype, targetMimetype, transformOptions, sourceFile, targetFile);
}
else
{
transform(transformName, sourceMimetype, targetMimetype, transformOptions, sourceFile, targetFile);
}
}
catch (TransformException e)
{
throw e;
}
catch (IllegalArgumentException e)
{
throw new TransformException(BAD_REQUEST.value(), getMessage(e), e);
}
catch (Exception e)
{
throw new TransformException(INTERNAL_SERVER_ERROR.value(), getMessage(e), e);
}
if (!targetFile.exists())
{
throw new TransformException(INTERNAL_SERVER_ERROR.value(),
"Transformer failed to create an output file. Target file does not exist.");
}
if (sourceFile.length() > 0 && targetFile.length() == 0)
{
throw new TransformException(INTERNAL_SERVER_ERROR.value(),
"Transformer failed to create an output file. Target file is empty but source file was not empty.");
}
}
private static String getMessage(Exception e)
{
return e.getMessage() == null ? e.getClass().getSimpleName() : e.getMessage();
}
default void transform(String transformName, String sourceMimetype, String targetMimetype,
Map<String, String> transformOptions,
File sourceFile, File targetFile) throws Exception
{
}
default void extractMetadata(String transformName, String sourceMimetype, String targetMimetype,
Map<String, String> transformOptions,
File sourceFile, File targetFile) throws Exception
{
}
/**
* @deprecated The content repository has no non test embed metadata implementations.
* This code exists in case there are custom implementations, that need to be converted to T-Engines.
* It is simply a copy and paste from the content repository and has received limited testing.
*/
default void embedMetadata(String transformName, String sourceMimetype, String targetMimetype,
Map<String, String> transformOptions,
File sourceFile, File targetFile) throws Exception
{
}
}

View File

@@ -28,8 +28,16 @@ package org.alfresco.transform.base.logging;
public interface StandardMessages
{
String LICENCE =
String COMMUNITY_LICENCE =
"If the Alfresco software was purchased under a paid Alfresco license, the terms of the paid license agreement \n" +
"will prevail. Otherwise, the software is provided under terms of the GNU LGPL v3 license. \n" +
"See the license at http://www.gnu.org/licenses/lgpl-3.0.txt. or in /LICENSE.txt \n\n";
String ENTERPRISE_LICENCE =
"This image is only intended to be used with the Alfresco Enterprise Content Repository which is covered by\n" +
"https://www.alfresco.com/legal/agreements and https://www.alfresco.com/terms-use\n" +
"\n" +
"License rights for this program may be obtained from Alfresco Software, Ltd. pursuant to a written agreement\n" +
"and any use of this program without such an agreement is prohibited.\n" +
"\n";
}

View File

@@ -29,6 +29,7 @@ package org.alfresco.transform.base.metadataExtractors;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.alfresco.transform.base.CustomTransformer;
import org.alfresco.transform.common.TransformException;
import org.slf4j.Logger;
@@ -50,6 +51,8 @@ import java.util.Set;
import java.util.StringTokenizer;
import java.util.TreeMap;
import static org.alfresco.transform.base.metadataExtractors.AbstractMetadataExtractor.Type.EXTRACTOR;
/**
* Helper methods for metadata extract and embed.
* <p>
@@ -93,7 +96,7 @@ import java.util.TreeMap;
* @author Derek Hulley
* @author adavis
*/
public abstract class AbstractMetadataExtractor
public abstract class AbstractMetadataExtractor implements CustomTransformer
{
private static final String EXTRACT = "extract";
private static final String EMBED = "embed";
@@ -118,8 +121,16 @@ public abstract class AbstractMetadataExtractor
private ThreadLocal<Map<String, Set<String>>> extractMapping = new ThreadLocal<>();
private Map<String, Set<String>> embedMapping;
public AbstractMetadataExtractor(Logger logger)
public enum Type
{
EXTRACTOR, EMBEDDER
}
private final Type type;
public AbstractMetadataExtractor(Type type, Logger logger)
{
this.type = type;
this.logger = logger;
defaultExtractMapping = Collections.emptyMap();
embedMapping = Collections.emptyMap();
@@ -134,9 +145,22 @@ public abstract class AbstractMetadataExtractor
}
}
@Override
public String getTransformerName()
{
return getClass().getSimpleName();
}
public abstract Map<String, Serializable> extractMetadata(String sourceMimetype, Map<String, String> transformOptions,
File sourceFile) throws Exception;
public void embedMetadata(String sourceMimetype, Map<String, String> transformOptions,
String sourceEncoding, InputStream inputStream,
String targetEncoding, OutputStream outputStream) throws Exception
{
// TODO
throw new TransformException(500, "TODO embedMetadata");
}
public void embedMetadata(String sourceMimetype, String targetMimetype, Map<String, String> transformOptions,
File sourceFile, File targetFile) throws Exception
{
@@ -469,6 +493,21 @@ public abstract class AbstractMetadataExtractor
return true;
}
@Override
public void transform(String sourceMimetype, String sourceEncoding, InputStream inputStream,
String targetMimetype, String targetEncoding, OutputStream outputStream,
Map<String, String> transformOptions) throws Exception
{
if (type == EXTRACTOR)
{
extractMetadata(sourceMimetype, transformOptions, sourceEncoding, inputStream, targetEncoding, outputStream);
}
else
{
embedMetadata(sourceMimetype, transformOptions, sourceEncoding, inputStream, targetEncoding, outputStream);
}
}
public void extractMetadata(String sourceMimetype, Map<String, String> transformOptions,
String sourceEncoding, InputStream inputStream,
String targetEncoding, OutputStream outputStream) throws Exception

View File

@@ -1,41 +0,0 @@
/*
* #%L
* Alfresco Transform Core
* %%
* Copyright (C) 2005 - 2022 Alfresco Software Limited
* %%
* This file is part of the Alfresco software.
* -
* If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms:
* -
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* -
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
* -
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
* #L%
*/
package org.alfresco.transform.base.util;
/**
* Extends the list of transform options with historic request parameters or 'extra' parameters used in testing
* or communication in the all-in-one transformer.
*/
public interface RequestParamMap extends org.alfresco.transform.common.RequestParamMap
{
String TRANSFORM_NAME_PARAMETER = "alfresco.transform-name-parameter";
String FILE = "file";
String SOURCE_EXTENSION = "sourceExtension";
String SOURCE_MIMETYPE = "sourceMimetype";
String TARGET_MIMETYPE = "targetMimetype";
}