mirror of
https://github.com/Alfresco/alfresco-transform-core.git
synced 2025-08-14 17:58:27 +00:00
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:
@@ -20,12 +20,12 @@
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.alfresco</groupId>
|
||||
<artifactId>alfresco-transformer-base</artifactId>
|
||||
<artifactId>alfresco-t-engine-base</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.alfresco</groupId>
|
||||
<artifactId>alfresco-transformer-base</artifactId>
|
||||
<artifactId>alfresco-t-engine-base</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<classifier>tests</classifier>
|
||||
<type>test-jar</type>
|
||||
|
@@ -1,80 +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.libreoffice;
|
||||
|
||||
import io.micrometer.core.instrument.MeterRegistry;
|
||||
import org.alfresco.transform.libreoffice.transformers.LibreOfficeJavaExecutor;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.actuate.autoconfigure.metrics.MeterRegistryCustomizer;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
||||
import org.springframework.boot.context.event.ApplicationReadyEvent;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.event.EventListener;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import static org.alfresco.transformer.logging.StandardMessages.LICENCE;
|
||||
|
||||
@SpringBootApplication
|
||||
@EnableAutoConfiguration(exclude = {DataSourceAutoConfiguration.class})
|
||||
public class Application
|
||||
{
|
||||
private static final Logger logger = LoggerFactory.getLogger(Application.class);
|
||||
|
||||
@Value("${container.name}")
|
||||
private String containerName;
|
||||
|
||||
@Bean
|
||||
MeterRegistryCustomizer<MeterRegistry> metricsCommonTags()
|
||||
{
|
||||
return registry -> registry.config().commonTags("containerName", containerName);
|
||||
}
|
||||
|
||||
// To run the LibreOffice T-Engine from the command line on a Mac, you generally need to
|
||||
// install LibreOffice and add: -Dtransform.core.libreoffice.path=/Applications/LibreOffice.app/Contents/
|
||||
// to the start up command.
|
||||
public static void main(String[] args)
|
||||
{
|
||||
SpringApplication.run(Application.class, args);
|
||||
}
|
||||
|
||||
@EventListener(ApplicationReadyEvent.class)
|
||||
public void startup()
|
||||
{
|
||||
logger.info("-------------------------------------------------------------------------------------------------------------------------------------------------------");
|
||||
Arrays.stream(LICENCE.split("\\n")).forEach(logger::info);
|
||||
logger.info(LibreOfficeJavaExecutor.LICENCE);
|
||||
logger.info("-------------------------------------------------------------------------------------------------------------------------------------------------------");
|
||||
|
||||
logger.info("Starting application components... Done");
|
||||
}
|
||||
}
|
@@ -1,134 +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.libreoffice;
|
||||
|
||||
import org.alfresco.transformer.AbstractTransformerController;
|
||||
import org.alfresco.transform.libreoffice.transformers.LibreOfficeJavaExecutor;
|
||||
import org.alfresco.transformer.probes.ProbeTestTransform;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Controller;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import java.io.File;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Controller for the Docker based LibreOffice transformer.
|
||||
*
|
||||
* Status Codes:
|
||||
*
|
||||
* 200 Success
|
||||
* 400 Bad Request: Request parameter <name> is missing (missing mandatory parameter)
|
||||
* 400 Bad Request: Request parameter <name> is of the wrong type
|
||||
* 400 Bad Request: Transformer exit code was not 0 (possible problem with the source file)
|
||||
* 400 Bad Request: The source filename was not supplied
|
||||
* 500 Internal Server Error: (no message with low level IO problems)
|
||||
* 500 Internal Server Error: The target filename was not supplied (should not happen as targetExtension is checked)
|
||||
* 500 Internal Server Error: Transformer version check exit code was not 0
|
||||
* 500 Internal Server Error: Transformer version check failed to create any output
|
||||
* 500 Internal Server Error: Could not read the target file
|
||||
* 500 Internal Server Error: The target filename was malformed (should not happen because of other checks)
|
||||
* 500 Internal Server Error: Transformer failed to create an output file (the exit code was 0, so there should be some content)
|
||||
* 500 Internal Server Error: Filename encoding error
|
||||
* 507 Insufficient Storage: Failed to store the source file
|
||||
*/
|
||||
@Controller
|
||||
public class LibreOfficeController extends AbstractTransformerController
|
||||
{
|
||||
private static final Logger logger = LoggerFactory.getLogger(LibreOfficeController.class);
|
||||
|
||||
@Value("${transform.core.libreoffice.path}")
|
||||
private String execPath;
|
||||
|
||||
@Value("${transform.core.libreoffice.maxTasksPerProcess}")
|
||||
private String maxTasksPerProcess;
|
||||
|
||||
@Value("${transform.core.libreoffice.timeout}")
|
||||
private String timeout;
|
||||
|
||||
@Value("${transform.core.libreoffice.portNumbers}")
|
||||
private String portNumbers;
|
||||
|
||||
@Value("${transform.core.libreoffice.templateProfileDir}")
|
||||
private String templateProfileDir;
|
||||
|
||||
@Value("${transform.core.libreoffice.isEnabled}")
|
||||
private String isEnabled;
|
||||
|
||||
LibreOfficeJavaExecutor javaExecutor;
|
||||
|
||||
@PostConstruct
|
||||
private void init()
|
||||
{
|
||||
javaExecutor = new LibreOfficeJavaExecutor(execPath, maxTasksPerProcess, timeout, portNumbers, templateProfileDir, isEnabled);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTransformerName()
|
||||
{
|
||||
return "LibreOffice";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String version()
|
||||
{
|
||||
return "LibreOffice available";
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProbeTestTransform getProbeTestTransform()
|
||||
{
|
||||
// See the Javadoc on this method and Probes.md for the choice of these values.
|
||||
return new ProbeTestTransform(this, "quick.doc", "quick.pdf",
|
||||
11817, 1024, 150, 10240, 60 * 30 + 1, 60 * 15 + 20)
|
||||
{
|
||||
@Override
|
||||
protected void executeTransformCommand(File sourceFile, File targetFile)
|
||||
{
|
||||
transformImpl(null, null, null, Collections.emptyMap(), sourceFile, targetFile);
|
||||
javaExecutor.call(sourceFile, targetFile);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getTransformerName(final File sourceFile, final String sourceMimetype,
|
||||
final String targetMimetype, final Map<String, String> transformOptions)
|
||||
{
|
||||
return null; // does not matter what value is returned, as it is not used because there is only one.
|
||||
}
|
||||
|
||||
@Override
|
||||
public void transformImpl(String transformName, String sourceMimetype, String targetMimetype,
|
||||
Map<String, String> transformOptions, File sourceFile, File targetFile)
|
||||
{
|
||||
javaExecutor.transformExtractOrEmbed(transformName, sourceMimetype, targetMimetype, transformOptions, sourceFile, targetFile);
|
||||
}
|
||||
}
|
@@ -14,7 +14,7 @@
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.alfresco</groupId>
|
||||
<artifactId>alfresco-transformer-base</artifactId>
|
||||
<artifactId>alfresco-t-engine-base</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* #%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.libreoffice;
|
||||
|
||||
import org.alfresco.transform.base.TransformEngine;
|
||||
import org.alfresco.transform.base.probes.ProbeTestTransform;
|
||||
import org.alfresco.transform.common.TransformConfigResourceReader;
|
||||
import org.alfresco.transform.config.TransformConfig;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import static org.alfresco.transform.base.logging.StandardMessages.COMMUNITY_LICENCE;
|
||||
import static org.alfresco.transform.common.Mimetype.MIMETYPE_PDF;
|
||||
import static org.alfresco.transform.common.Mimetype.MIMETYPE_WORD;
|
||||
|
||||
@Component
|
||||
public class LibreOfficeTransformEngine implements TransformEngine
|
||||
{
|
||||
@Autowired
|
||||
private TransformConfigResourceReader transformConfigResourceReader;
|
||||
|
||||
@Override
|
||||
public String getTransformEngineName()
|
||||
{
|
||||
return "0020-LibreOffice";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getStartupMessage()
|
||||
{
|
||||
return COMMUNITY_LICENCE +
|
||||
"This transformer uses LibreOffice from The Document Foundation. " +
|
||||
"See the license at https://www.libreoffice.org/download/license/ or in /libreoffice.txt";
|
||||
}
|
||||
|
||||
@Override
|
||||
public TransformConfig getTransformConfig()
|
||||
{
|
||||
|
||||
return transformConfigResourceReader.read("classpath:libreoffice_engine_config.json");
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProbeTestTransform getLivenessAndReadinessProbeTestTransform()
|
||||
{
|
||||
return new ProbeTestTransform("quick.doc", "quick.pdf",
|
||||
MIMETYPE_WORD, MIMETYPE_PDF, Collections.emptyMap(),
|
||||
11817, 1024, 150, 10240, 60 * 30 + 1, 60 * 15 + 20);
|
||||
}
|
||||
}
|
@@ -28,8 +28,8 @@ package org.alfresco.transform.libreoffice.transformers;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.sun.star.task.ErrorCodeIOException;
|
||||
import org.alfresco.transform.base.CustomTransformer;
|
||||
import org.alfresco.transform.common.TransformException;
|
||||
import org.alfresco.transformer.executors.JavaExecutor;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.pdfbox.pdmodel.PDDocument;
|
||||
import org.apache.pdfbox.pdmodel.PDPage;
|
||||
@@ -39,9 +39,14 @@ import org.artofsolving.jodconverter.office.OfficeException;
|
||||
import org.artofsolving.jodconverter.office.OfficeManager;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.io.Serializable;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -52,105 +57,92 @@ import static org.springframework.http.HttpStatus.INTERNAL_SERVER_ERROR;
|
||||
* JavaExecutor implementation for running LibreOffice transformations. It loads the
|
||||
* transformation logic in the same JVM (check the {@link JodConverter} implementation).
|
||||
*/
|
||||
public class LibreOfficeJavaExecutor implements JavaExecutor
|
||||
@Component
|
||||
public class LibreOfficeTransformer implements CustomTransformer
|
||||
{
|
||||
private static String ID = "libreoffice";
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(LibreOfficeJavaExecutor.class);
|
||||
private static final Logger logger = LoggerFactory.getLogger(LibreOfficeTransformer.class);
|
||||
|
||||
private static final int JODCONVERTER_TRANSFORMATION_ERROR_CODE = 3088;
|
||||
|
||||
private static String LIBREOFFICE_HOME;
|
||||
@Value("${transform.core.libreoffice.path}")
|
||||
private String path;
|
||||
@Value("${transform.core.libreoffice.maxTasksPerProcess}")
|
||||
private String maxTasksPerProcess;
|
||||
@Value("${transform.core.libreoffice.timeout}")
|
||||
private String timeout;
|
||||
@Value("${transform.core.libreoffice.portNumbers}")
|
||||
private String portNumbers;
|
||||
@Value("${transform.core.libreoffice.templateProfileDir}")
|
||||
private String templateProfileDir;
|
||||
@Value("${transform.core.libreoffice.isEnabled}")
|
||||
private String isEnabled;
|
||||
|
||||
private static String LIBREOFFICE_MAX_TASKS_PER_PROCESS;
|
||||
|
||||
private static String LIBREOFFICE_TIMEOUT;
|
||||
|
||||
private static String LIBREOFFICE_PORT_NUMBERS;
|
||||
|
||||
private static String LIBREOFFICE_TEMPLATE_PROFILE_DIR;
|
||||
|
||||
private static String LIBREOFFICE_IS_ENABLED;
|
||||
|
||||
public static final String LICENCE = "This transformer uses LibreOffice from The Document Foundation. See the license at https://www.libreoffice.org/download/license/ or in /libreoffice.txt";
|
||||
|
||||
private final JodConverter jodconverter;
|
||||
private JodConverter jodconverter;
|
||||
|
||||
private final ObjectMapper jsonObjectMapper = new ObjectMapper();
|
||||
|
||||
public LibreOfficeJavaExecutor(String path, String maxTasksPerProcess, String timeout, String portNumbers, String templateProfileDir, String isEnabled)
|
||||
@PostConstruct
|
||||
private void createJodConverter()
|
||||
{
|
||||
if (path == null || path.isEmpty())
|
||||
{
|
||||
throw new IllegalArgumentException("LibreOfficeJavaExecutor OFFICE_HOME cannot be null or empty");
|
||||
throw new IllegalArgumentException("LibreOfficeTransformer LIBREOFFICE_HOME cannot be null or empty");
|
||||
}
|
||||
LIBREOFFICE_HOME = path;
|
||||
|
||||
if(timeout == null || timeout.isEmpty() || !StringUtils.isNumeric(timeout))
|
||||
if (maxTasksPerProcess == null || maxTasksPerProcess.isEmpty() || !StringUtils.isNumeric(maxTasksPerProcess))
|
||||
{
|
||||
throw new IllegalArgumentException("LibreOfficeJavaExecutor TIMEOUT must have a numeric value");
|
||||
throw new IllegalArgumentException("LibreOfficeTransformer LIBREOFFICE_MAX_TASKS_PER_PROCESS must have a numeric value");
|
||||
}
|
||||
LIBREOFFICE_TIMEOUT = timeout;
|
||||
|
||||
if(maxTasksPerProcess == null || maxTasksPerProcess.isEmpty() || !StringUtils.isNumeric(maxTasksPerProcess))
|
||||
if (timeout == null || timeout.isEmpty() || !StringUtils.isNumeric(timeout))
|
||||
{
|
||||
throw new IllegalArgumentException("LibreOfficeJavaExecutor MAX_TASKS_PER_PROCESS must have a numeric value");
|
||||
}
|
||||
LIBREOFFICE_MAX_TASKS_PER_PROCESS = maxTasksPerProcess;
|
||||
|
||||
if(portNumbers == null || portNumbers.isEmpty())
|
||||
{
|
||||
throw new IllegalArgumentException("LibreOfficeJavaExecutor PORT variable cannot be null or empty");
|
||||
throw new IllegalArgumentException("LibreOfficeTransformer LIBREOFFICE_TIMEOUT must have a numeric value");
|
||||
}
|
||||
// value parsed and validated in JodConverterSharedInstance#parsePortNumbers(String s, String sys)
|
||||
LIBREOFFICE_PORT_NUMBERS = portNumbers;
|
||||
|
||||
if (portNumbers == null || portNumbers.isEmpty())
|
||||
{
|
||||
throw new IllegalArgumentException("LibreOfficeTransformer LIBREOFFICE_PORT_NUMBERS variable cannot be null or empty");
|
||||
}
|
||||
if (templateProfileDir == null)
|
||||
{
|
||||
throw new IllegalArgumentException("LibreOfficeJavaExecutor TEMPLATE_PROFILE_DIR variable cannot be null");
|
||||
throw new IllegalArgumentException("LibreOfficeTransformer LIBREOFFICE_TEMPLATE_PROFILE_DIR variable cannot be null");
|
||||
}
|
||||
LIBREOFFICE_TEMPLATE_PROFILE_DIR = templateProfileDir;
|
||||
|
||||
if(isEnabled == null || isEnabled.isEmpty() || !(isEnabled.equalsIgnoreCase("true")|| isEnabled.equalsIgnoreCase("false")))
|
||||
if (isEnabled == null || isEnabled.isEmpty() || !(isEnabled.equalsIgnoreCase("true")|| isEnabled.equalsIgnoreCase("false")))
|
||||
{
|
||||
throw new IllegalArgumentException("LibreOfficeJavaExecutor IS_ENABLED variable must be set to true/false");
|
||||
throw new IllegalArgumentException("LibreOfficeTransformer LIBREOFFICE_IS_ENABLED variable must be set to true/false");
|
||||
}
|
||||
LIBREOFFICE_IS_ENABLED = isEnabled;
|
||||
|
||||
jodconverter = createJodConverter();
|
||||
}
|
||||
|
||||
private static JodConverter createJodConverter()
|
||||
{
|
||||
final JodConverterSharedInstance jodconverter = new JodConverterSharedInstance();
|
||||
|
||||
jodconverter.setOfficeHome(LIBREOFFICE_HOME); // jodconverter.officeHome
|
||||
jodconverter.setMaxTasksPerProcess(LIBREOFFICE_MAX_TASKS_PER_PROCESS); // jodconverter.maxTasksPerProcess
|
||||
jodconverter.setTaskExecutionTimeout(LIBREOFFICE_TIMEOUT); // jodconverter.maxTaskExecutionTimeout
|
||||
jodconverter.setTaskQueueTimeout(LIBREOFFICE_TIMEOUT); // jodconverter.taskQueueTimeout
|
||||
jodconverter.setConnectTimeout(LIBREOFFICE_TIMEOUT); // jodconverter.connectTimeout
|
||||
jodconverter.setPortNumbers(LIBREOFFICE_PORT_NUMBERS); // jodconverter.portNumbers
|
||||
jodconverter.setTemplateProfileDir(LIBREOFFICE_TEMPLATE_PROFILE_DIR); // jodconverter.templateProfileDir
|
||||
jodconverter.setEnabled(LIBREOFFICE_IS_ENABLED); // jodconverter.enabled
|
||||
jodconverter.afterPropertiesSet();
|
||||
|
||||
return jodconverter;
|
||||
JodConverterSharedInstance sharedInstance = new JodConverterSharedInstance();
|
||||
jodconverter = sharedInstance;
|
||||
sharedInstance.setOfficeHome(path);
|
||||
sharedInstance.setMaxTasksPerProcess(maxTasksPerProcess);
|
||||
sharedInstance.setTaskExecutionTimeout(timeout);
|
||||
sharedInstance.setTaskQueueTimeout(timeout);
|
||||
sharedInstance.setConnectTimeout(timeout);
|
||||
sharedInstance.setPortNumbers(portNumbers);
|
||||
sharedInstance.setTemplateProfileDir(templateProfileDir);
|
||||
sharedInstance.setEnabled(isEnabled);
|
||||
sharedInstance.afterPropertiesSet();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTransformerId()
|
||||
public String getTransformerName()
|
||||
{
|
||||
return ID;
|
||||
return "libreoffice";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void transform(String sourceMimetype, String sourceEncoding, InputStream inputStream,
|
||||
String targetMimetype, String targetEncoding, OutputStream outputStream,
|
||||
Map<String, String> transformOptions) throws Exception
|
||||
{
|
||||
throw new TransformException(500, "TODO LibreOffice transform");
|
||||
}
|
||||
|
||||
public void transform(String transformName, String sourceMimetype, String targetMimetype, Map<String, String> transformOptions,
|
||||
File sourceFile, File targetFile)
|
||||
{
|
||||
call(sourceFile, targetFile);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void call(File sourceFile, File targetFile, String... args)
|
||||
{
|
||||
try
|
||||
@@ -229,7 +221,6 @@ public class LibreOfficeJavaExecutor implements JavaExecutor
|
||||
* 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.
|
||||
*/
|
||||
@Override
|
||||
public void extractMetadata(String transformName, String sourceMimetype, String targetMimetype,
|
||||
Map<String, String> transformOptions,
|
||||
File sourceFile, File targetFile)
|
@@ -3,8 +3,6 @@ queue:
|
||||
transform:
|
||||
core:
|
||||
version: @project.version@
|
||||
config:
|
||||
location: classpath:libreoffice_engine_config.json
|
||||
libreoffice:
|
||||
path: ${LIBREOFFICE_HOME:/opt/libreoffice7.2}
|
||||
maxTasksPerProcess: ${LIBREOFFICE_MAX_TASKS_PER_PROCESS:200}
|
@@ -28,9 +28,9 @@ package org.alfresco.transform.libreoffice;
|
||||
|
||||
import static org.alfresco.transform.common.Mimetype.MIMETYPE_PDF;
|
||||
import static org.alfresco.transform.common.RequestParamMap.ENDPOINT_TRANSFORM;
|
||||
import static org.alfresco.transformer.util.RequestParamMap.SOURCE_MIMETYPE;
|
||||
import static org.alfresco.transformer.util.RequestParamMap.TARGET_EXTENSION;
|
||||
import static org.alfresco.transformer.util.RequestParamMap.TARGET_MIMETYPE;
|
||||
import static org.alfresco.transform.common.RequestParamMap.SOURCE_MIMETYPE;
|
||||
import static org.alfresco.transform.common.RequestParamMap.TARGET_MIMETYPE;
|
||||
import static org.alfresco.transform.common.RequestParamMap.TARGET_EXTENSION;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
@@ -58,9 +58,9 @@ import javax.annotation.PostConstruct;
|
||||
|
||||
import org.alfresco.transform.client.model.TransformReply;
|
||||
import org.alfresco.transform.client.model.TransformRequest;
|
||||
import org.alfresco.transform.libreoffice.transformers.LibreOfficeTransformer;
|
||||
import org.alfresco.transformer.AbstractTransformerController;
|
||||
import org.alfresco.transformer.AbstractTransformerControllerTest;
|
||||
import org.alfresco.transform.libreoffice.transformers.LibreOfficeJavaExecutor;
|
||||
import org.alfresco.transformer.executors.RuntimeExec.ExecutionResult;
|
||||
import org.alfresco.transformer.model.FileRefEntity;
|
||||
import org.alfresco.transformer.model.FileRefResponse;
|
||||
@@ -114,12 +114,12 @@ public class LibreOfficeControllerTest extends AbstractTransformerControllerTest
|
||||
@Value("${transform.core.libreoffice.isEnabled}")
|
||||
private String isEnabled;
|
||||
|
||||
protected LibreOfficeJavaExecutor javaExecutor;
|
||||
protected LibreOfficeTransformer javaExecutor;
|
||||
|
||||
@PostConstruct
|
||||
private void init()
|
||||
{
|
||||
javaExecutor = Mockito.spy(new LibreOfficeJavaExecutor(execPath, maxTasksPerProcess, timeout, portNumbers, templateProfileDir, isEnabled));
|
||||
javaExecutor = Mockito.spy(new LibreOfficeTransformer(execPath, maxTasksPerProcess, timeout, portNumbers, templateProfileDir, isEnabled));
|
||||
}
|
||||
|
||||
@Autowired
|
||||
@@ -172,7 +172,7 @@ public class LibreOfficeControllerTest extends AbstractTransformerControllerTest
|
||||
}
|
||||
|
||||
|
||||
protected void setJavaExecutor(AbstractTransformerController controller, LibreOfficeJavaExecutor javaExecutor)
|
||||
protected void setJavaExecutor(AbstractTransformerController controller, LibreOfficeTransformer javaExecutor)
|
||||
{
|
||||
ReflectionTestUtils.setField(controller, "javaExecutor", javaExecutor);
|
||||
}
|
||||
@@ -314,14 +314,14 @@ public class LibreOfficeControllerTest extends AbstractTransformerControllerTest
|
||||
String errorMessage = "";
|
||||
try
|
||||
{
|
||||
new LibreOfficeJavaExecutor(execPath, "INVALID", timeout, portNumbers, templateProfileDir, isEnabled);
|
||||
new LibreOfficeTransformer(execPath, "INVALID", timeout, portNumbers, templateProfileDir, isEnabled);
|
||||
}
|
||||
catch (IllegalArgumentException e)
|
||||
{
|
||||
errorMessage = e.getMessage();
|
||||
}
|
||||
|
||||
assertEquals("LibreOfficeJavaExecutor MAX_TASKS_PER_PROCESS must have a numeric value", errorMessage);
|
||||
assertEquals("LibreOfficeTransformer MAX_TASKS_PER_PROCESS must have a numeric value", errorMessage);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -330,14 +330,14 @@ public class LibreOfficeControllerTest extends AbstractTransformerControllerTest
|
||||
String errorMessage = "";
|
||||
try
|
||||
{
|
||||
new LibreOfficeJavaExecutor(execPath, maxTasksPerProcess, "INVALID", portNumbers, templateProfileDir, isEnabled);
|
||||
new LibreOfficeTransformer(execPath, maxTasksPerProcess, "INVALID", portNumbers, templateProfileDir, isEnabled);
|
||||
}
|
||||
catch (IllegalArgumentException e)
|
||||
{
|
||||
errorMessage = e.getMessage();
|
||||
}
|
||||
|
||||
assertEquals("LibreOfficeJavaExecutor TIMEOUT must have a numeric value", errorMessage);
|
||||
assertEquals("LibreOfficeTransformer TIMEOUT must have a numeric value", errorMessage);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -346,14 +346,14 @@ public class LibreOfficeControllerTest extends AbstractTransformerControllerTest
|
||||
String errorMessage = "";
|
||||
try
|
||||
{
|
||||
new LibreOfficeJavaExecutor(execPath, maxTasksPerProcess, timeout, null, templateProfileDir, isEnabled);
|
||||
new LibreOfficeTransformer(execPath, maxTasksPerProcess, timeout, null, templateProfileDir, isEnabled);
|
||||
}
|
||||
catch (IllegalArgumentException e)
|
||||
{
|
||||
errorMessage = e.getMessage();
|
||||
}
|
||||
|
||||
assertEquals("LibreOfficeJavaExecutor PORT variable cannot be null or empty", errorMessage);
|
||||
assertEquals("LibreOfficeTransformer PORT variable cannot be null or empty", errorMessage);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -362,13 +362,13 @@ public class LibreOfficeControllerTest extends AbstractTransformerControllerTest
|
||||
String errorMessage = "";
|
||||
try
|
||||
{
|
||||
new LibreOfficeJavaExecutor(execPath, maxTasksPerProcess, timeout, portNumbers, templateProfileDir, "INVALID");
|
||||
new LibreOfficeTransformer(execPath, maxTasksPerProcess, timeout, portNumbers, templateProfileDir, "INVALID");
|
||||
}
|
||||
catch (IllegalArgumentException e)
|
||||
{
|
||||
errorMessage = e.getMessage();
|
||||
}
|
||||
|
||||
assertEquals("LibreOfficeJavaExecutor IS_ENABLED variable must be set to true/false", errorMessage);
|
||||
assertEquals("LibreOfficeTransformer IS_ENABLED variable must be set to true/false", errorMessage);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user