mirror of
https://github.com/Alfresco/alfresco-transform-core.git
synced 2025-08-07 17:48:35 +00:00
Merge branch 'master' into fix/mnt-20337_LO_6.1.6
This commit is contained in:
@@ -26,30 +26,52 @@
|
||||
*/
|
||||
package org.alfresco.transformer;
|
||||
|
||||
import io.micrometer.core.instrument.MeterRegistry;
|
||||
import static org.alfresco.transformer.logging.StandardMessages.LICENCE;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
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 io.micrometer.core.instrument.MeterRegistry;
|
||||
|
||||
@SpringBootApplication
|
||||
@EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class})
|
||||
@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() {
|
||||
MeterRegistryCustomizer<MeterRegistry> metricsCommonTags()
|
||||
{
|
||||
return registry -> registry.config().commonTags("containerName", containerName);
|
||||
}
|
||||
|
||||
|
||||
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("This transformer uses LibreOffice from The Document Foundation. See the license at https://www.libreoffice.org/download/license/ or in /libreoffice.txt");
|
||||
logger.info("-------------------------------------------------------------------------------------------------------------------------------------------------------");
|
||||
|
||||
logger.info("Starting application components... Done");
|
||||
}
|
||||
}
|
||||
|
@@ -30,11 +30,10 @@ import static org.alfresco.transformer.fs.FileManager.createAttachment;
|
||||
import static org.alfresco.transformer.fs.FileManager.createSourceFile;
|
||||
import static org.alfresco.transformer.fs.FileManager.createTargetFile;
|
||||
import static org.alfresco.transformer.fs.FileManager.createTargetFileName;
|
||||
import static org.alfresco.transformer.logging.StandardMessages.LICENCE;
|
||||
import static org.springframework.http.HttpStatus.OK;
|
||||
import static org.springframework.http.MediaType.MULTIPART_FORM_DATA_VALUE;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Arrays;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
@@ -46,7 +45,6 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
@@ -59,20 +57,20 @@ import org.springframework.web.multipart.MultipartFile;
|
||||
*
|
||||
* 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
|
||||
* 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
|
||||
@@ -81,15 +79,6 @@ public class LibreOfficeController extends AbstractTransformerController
|
||||
|
||||
@Autowired
|
||||
private LibreOfficeJavaExecutor javaExecutor;
|
||||
|
||||
@Autowired
|
||||
public LibreOfficeController()
|
||||
{
|
||||
logger.info("-------------------------------------------------------------------------------------------------------------------------------------------------------");
|
||||
Arrays.stream(LICENCE.split("\\n")).forEach(logger::info);
|
||||
logger.info("This transformer uses LibreOffice from The Document Foundation. See the license at https://www.libreoffice.org/download/license/ or in /libreoffice.txt");
|
||||
logger.info("-------------------------------------------------------------------------------------------------------------------------------------------------------");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTransformerName()
|
||||
@@ -108,7 +97,7 @@ public class LibreOfficeController extends AbstractTransformerController
|
||||
{
|
||||
// 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)
|
||||
11817, 1024, 150, 10240, 60 * 30 + 1, 60 * 15 + 20)
|
||||
{
|
||||
@Override
|
||||
protected void executeTransformCommand(File sourceFile, File targetFile)
|
||||
@@ -119,14 +108,15 @@ public class LibreOfficeController extends AbstractTransformerController
|
||||
}
|
||||
|
||||
//todo: the "timeout" request parameter is ignored; the timeout is preset at JodConverter creation
|
||||
@PostMapping(value = "/transform", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
||||
@PostMapping(value = "/transform", consumes = MULTIPART_FORM_DATA_VALUE)
|
||||
public ResponseEntity<Resource> transform(HttpServletRequest request,
|
||||
@RequestParam("file") MultipartFile sourceMultipartFile,
|
||||
@RequestParam("targetExtension") String targetExtension,
|
||||
@RequestParam(value = "timeout", required = false) Long timeout,
|
||||
@RequestParam(value = "testDelay", required = false) Long testDelay)
|
||||
@RequestParam("file") MultipartFile sourceMultipartFile,
|
||||
@RequestParam("targetExtension") String targetExtension,
|
||||
@RequestParam(value = "timeout", required = false) Long timeout,
|
||||
@RequestParam(value = "testDelay", required = false) Long testDelay)
|
||||
{
|
||||
String targetFilename = createTargetFileName(sourceMultipartFile.getOriginalFilename(), targetExtension);
|
||||
String targetFilename = createTargetFileName(sourceMultipartFile.getOriginalFilename(),
|
||||
targetExtension);
|
||||
getProbeTestTransform().incrementTransformerCount();
|
||||
File sourceFile = createSourceFile(request, sourceMultipartFile);
|
||||
File targetFile = createTargetFile(request, targetFilename);
|
||||
|
@@ -34,12 +34,14 @@ public interface JodConverter
|
||||
{
|
||||
/**
|
||||
* Gets the JodConverter OfficeManager.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
OfficeManager getOfficeManager();
|
||||
|
||||
/**
|
||||
* This method returns a boolean indicating whether the JodConverter connection to OOo is available.
|
||||
*
|
||||
* @return <code>true</code> if available, else <code>false</code>
|
||||
*/
|
||||
boolean isAvailable();
|
||||
|
@@ -128,7 +128,7 @@ public class JodConverterSharedInstance implements JodConverter
|
||||
StringTokenizer tokenizer = new StringTokenizer(s, ",");
|
||||
int tokenCount = tokenizer.countTokens();
|
||||
portNumbers = new int[tokenCount];
|
||||
for (int i = 0;tokenizer.hasMoreTokens();i++)
|
||||
for (int i = 0; tokenizer.hasMoreTokens(); i++)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -163,7 +163,8 @@ public class JodConverterSharedInstance implements JodConverter
|
||||
File tmp = new File(templateProfileDir);
|
||||
if (!tmp.isDirectory())
|
||||
{
|
||||
throw new AlfrescoRuntimeException("OpenOffice template profile directory "+templateProfileDir+" does not exist.");
|
||||
throw new AlfrescoRuntimeException(
|
||||
"OpenOffice template profile directory " + templateProfileDir + " does not exist.");
|
||||
}
|
||||
this.templateProfileDir = tmp;
|
||||
}
|
||||
@@ -176,7 +177,7 @@ public class JodConverterSharedInstance implements JodConverter
|
||||
|
||||
void setConnectTimeout(String connectTimeout)
|
||||
{
|
||||
this.connectTimeout = parseStringForLong(connectTimeout.trim());
|
||||
this.connectTimeout = parseStringForLong(connectTimeout.trim());
|
||||
}
|
||||
|
||||
void setEnabled(final String enabledStr)
|
||||
@@ -254,8 +255,8 @@ public class JodConverterSharedInstance implements JodConverter
|
||||
private int[] getPortNumbers()
|
||||
{
|
||||
return (enabled == null || !enabled) && deprecatedOooEnabled != null && deprecatedOooEnabled
|
||||
? deprecatedOooPortNumbers
|
||||
: portNumbers;
|
||||
? deprecatedOooPortNumbers
|
||||
: portNumbers;
|
||||
}
|
||||
|
||||
private Long parseStringForLong(String string)
|
||||
@@ -287,14 +288,15 @@ public class JodConverterSharedInstance implements JodConverter
|
||||
@PostConstruct
|
||||
public void afterPropertiesSet()
|
||||
{
|
||||
// isAvailable defaults to false afterPropertiesSet. It only becomes true on successful completion of this method.
|
||||
this.isAvailable = false;
|
||||
// isAvailable defaults to false afterPropertiesSet. It only becomes true on successful completion of this method.
|
||||
this.isAvailable = false;
|
||||
|
||||
int[] portNumbers = getPortNumbers();
|
||||
String officeHome = getOfficeHome();
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
logger.debug("JodConverter settings (null settings will be replaced by jodconverter defaults):");
|
||||
logger.debug(
|
||||
"JodConverter settings (null settings will be replaced by jodconverter defaults):");
|
||||
logger.debug(" officeHome = {}", officeHome);
|
||||
logger.debug(" enabled = {}", isEnabled());
|
||||
logger.debug(" portNumbers = {}", getString(portNumbers));
|
||||
@@ -390,7 +392,7 @@ public class JodConverterSharedInstance implements JodConverter
|
||||
StringBuilder portInfo = new StringBuilder();
|
||||
if (portNumbers != null)
|
||||
{
|
||||
for (int i = 0;i < portNumbers.length;i++)
|
||||
for (int i = 0; i < portNumbers.length; i++)
|
||||
{
|
||||
portInfo.append(portNumbers[i]);
|
||||
if (i < portNumbers.length - 1)
|
||||
@@ -404,78 +406,77 @@ public class JodConverterSharedInstance implements JodConverter
|
||||
|
||||
private void logAllSofficeFilesUnderOfficeHome()
|
||||
{
|
||||
if (!logger.isDebugEnabled())
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (!logger.isDebugEnabled())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
String officeHome = getOfficeHome();
|
||||
File requestedOfficeHome = new File(officeHome);
|
||||
String officeHome = getOfficeHome();
|
||||
File requestedOfficeHome = new File(officeHome);
|
||||
|
||||
logger.debug("Some information on soffice* files and their permissions");
|
||||
logger.debug("Some information on soffice* files and their permissions");
|
||||
|
||||
logFileInfo(requestedOfficeHome);
|
||||
logFileInfo(requestedOfficeHome);
|
||||
|
||||
for (File f : findSofficePrograms(requestedOfficeHome, new ArrayList<>(), 2))
|
||||
{
|
||||
logFileInfo(f);
|
||||
}
|
||||
}
|
||||
|
||||
private List<File> findSofficePrograms(File searchRoot, List<File> results, int maxRecursionDepth)
|
||||
{
|
||||
return this.findSofficePrograms(searchRoot, results, 0, maxRecursionDepth);
|
||||
for (File f : findSofficePrograms(requestedOfficeHome, new ArrayList<>(), 2))
|
||||
{
|
||||
logFileInfo(f);
|
||||
}
|
||||
}
|
||||
|
||||
private List<File> findSofficePrograms(File searchRoot, List<File> results,
|
||||
int currentRecursionDepth, int maxRecursionDepth)
|
||||
int maxRecursionDepth)
|
||||
{
|
||||
if (currentRecursionDepth >= maxRecursionDepth)
|
||||
{
|
||||
return results;
|
||||
}
|
||||
return this.findSofficePrograms(searchRoot, results, 0, maxRecursionDepth);
|
||||
}
|
||||
|
||||
File[] matchingFiles = searchRoot.listFiles((dir, name) -> name.startsWith("soffice"));
|
||||
private List<File> findSofficePrograms(File searchRoot, List<File> results,
|
||||
int currentRecursionDepth, int maxRecursionDepth)
|
||||
{
|
||||
if (currentRecursionDepth >= maxRecursionDepth)
|
||||
{
|
||||
return results;
|
||||
}
|
||||
|
||||
File[] matchingFiles = searchRoot.listFiles((dir, name) -> name.startsWith("soffice"));
|
||||
results.addAll(asList(matchingFiles));
|
||||
|
||||
for (File dir : requireNonNull(searchRoot.listFiles(File::isDirectory)))
|
||||
{
|
||||
findSofficePrograms(dir, results, currentRecursionDepth + 1, maxRecursionDepth);
|
||||
}
|
||||
{
|
||||
findSofficePrograms(dir, results, currentRecursionDepth + 1, maxRecursionDepth);
|
||||
}
|
||||
|
||||
return results;
|
||||
return results;
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs some information on the specified file, including name and r/w/x permissions.
|
||||
*
|
||||
* @param f the file to log.
|
||||
*/
|
||||
private void logFileInfo(File f)
|
||||
{
|
||||
if (!logger.isDebugEnabled())
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (!logger.isDebugEnabled())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
StringBuilder msg = new StringBuilder();
|
||||
msg.append(f).append(" ");
|
||||
if (f.exists())
|
||||
{
|
||||
if (f.canRead())
|
||||
{
|
||||
msg.append("(")
|
||||
.append(f.isDirectory() ? "d" : "-")
|
||||
.append(f.canRead() ? "r" : "-")
|
||||
.append(f.canWrite() ? "w" : "-")
|
||||
.append(f.canExecute() ? "x" : "-")
|
||||
.append(")");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
msg.append("does not exist");
|
||||
}
|
||||
logger.debug(msg.toString());
|
||||
StringBuilder msg = new StringBuilder();
|
||||
msg.append(f).append(" ");
|
||||
if (f.exists() && f.canRead())
|
||||
{
|
||||
msg.append("(")
|
||||
.append(f.isDirectory() ? "d" : "-")
|
||||
.append(f.canRead() ? "r" : "-")
|
||||
.append(f.canWrite() ? "w" : "-")
|
||||
.append(f.canExecute() ? "x" : "-")
|
||||
.append(")");
|
||||
}
|
||||
else
|
||||
{
|
||||
msg.append("does not exist");
|
||||
}
|
||||
logger.debug(msg.toString());
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -485,19 +486,19 @@ public class JodConverterSharedInstance implements JodConverter
|
||||
@PreDestroy
|
||||
public void destroy()
|
||||
{
|
||||
this.isAvailable = false;
|
||||
if (officeManager != null)
|
||||
{
|
||||
// If there is an OfficeException when stopping the officeManager below, then there is
|
||||
// little that can be done other than logging the exception and carrying on. The JodConverter-based
|
||||
// libraries will not be used in any case, as isAvailable is false.
|
||||
//
|
||||
// Any exception thrown out of this method will be logged and swallowed by Spring
|
||||
// (see javadoc for method declaration). Therefore there is no handling here for
|
||||
// exceptions from jodConverter.
|
||||
officeManager.stop();
|
||||
}
|
||||
}
|
||||
this.isAvailable = false;
|
||||
if (officeManager != null)
|
||||
{
|
||||
// If there is an OfficeException when stopping the officeManager below, then there is
|
||||
// little that can be done other than logging the exception and carrying on. The JodConverter-based
|
||||
// libraries will not be used in any case, as isAvailable is false.
|
||||
//
|
||||
// Any exception thrown out of this method will be logged and swallowed by Spring
|
||||
// (see javadoc for method declaration). Therefore there is no handling here for
|
||||
// exceptions from jodConverter.
|
||||
officeManager.stop();
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.content.JodConverterWorker#getOfficeManager()
|
||||
|
@@ -35,20 +35,20 @@ import java.io.IOException;
|
||||
import javax.annotation.PostConstruct;
|
||||
|
||||
import org.alfresco.transform.exceptions.TransformException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.apache.pdfbox.pdmodel.PDDocument;
|
||||
import org.apache.pdfbox.pdmodel.PDPage;
|
||||
import org.apache.pdfbox.pdmodel.PDPageContentStream;
|
||||
import org.artofsolving.jodconverter.OfficeDocumentConverter;
|
||||
import org.artofsolving.jodconverter.office.OfficeException;
|
||||
import org.artofsolving.jodconverter.office.OfficeManager;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.sun.star.task.ErrorCodeIOException;
|
||||
|
||||
/**
|
||||
* JavaExecutor implementation for running LibreOffice transformations. It loads the
|
||||
* JavaExecutor implementation for running LibreOffice transformations. It loads the
|
||||
* transformation logic in the same JVM (check the {@link JodConverter} implementation).
|
||||
*/
|
||||
@Component
|
||||
|
@@ -34,7 +34,15 @@ import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.doAnswer;
|
||||
import static org.mockito.Mockito.doThrow;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.springframework.http.HttpHeaders.ACCEPT;
|
||||
import static org.springframework.http.HttpHeaders.CONTENT_DISPOSITION;
|
||||
import static org.springframework.http.HttpHeaders.CONTENT_TYPE;
|
||||
import static org.springframework.http.HttpStatus.CREATED;
|
||||
import static org.springframework.http.HttpStatus.OK;
|
||||
import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;
|
||||
import static org.springframework.http.MediaType.IMAGE_PNG_VALUE;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
import static org.springframework.util.StringUtils.getFilenameExtension;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@@ -59,13 +67,10 @@ import org.springframework.boot.test.mock.mockito.SpyBean;
|
||||
import org.springframework.core.io.FileSystemResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.mock.web.MockMultipartFile;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* Test the LibreOfficeController without a server.
|
||||
@@ -94,15 +99,18 @@ public class LibreOfficeControllerTest extends AbstractTransformerControllerTest
|
||||
// The following is based on super.mockTransformCommand(...)
|
||||
// This is because LibreOffice used JodConverter rather than a RuntimeExec
|
||||
|
||||
expectedSourceFileBytes = Files.readAllBytes(getTestFile("quick." + sourceExtension, true).toPath());
|
||||
expectedTargetFileBytes = Files.readAllBytes(getTestFile("quick." + targetExtension, true).toPath());
|
||||
sourceFile = new MockMultipartFile("file", "quick." + sourceExtension, sourceMimetype, expectedSourceFileBytes);
|
||||
expectedSourceFileBytes = Files.readAllBytes(
|
||||
getTestFile("quick." + sourceExtension, true).toPath());
|
||||
expectedTargetFileBytes = Files.readAllBytes(
|
||||
getTestFile("quick." + targetExtension, true).toPath());
|
||||
sourceFile = new MockMultipartFile("file", "quick." + sourceExtension, sourceMimetype,
|
||||
expectedSourceFileBytes);
|
||||
|
||||
doAnswer(invocation ->
|
||||
{
|
||||
File sourceFile = invocation.getArgument(0);
|
||||
File targetFile = invocation.getArgument(1);
|
||||
String actualTargetExtension = StringUtils.getFilenameExtension(targetFile.getAbsolutePath());
|
||||
String actualTargetExtension = getFilenameExtension(targetFile.getAbsolutePath());
|
||||
|
||||
assertNotNull(sourceFile);
|
||||
assertNotNull(targetFile);
|
||||
@@ -119,7 +127,8 @@ public class LibreOfficeControllerTest extends AbstractTransformerControllerTest
|
||||
|
||||
// Check the supplied source file has not been changed.
|
||||
byte[] actualSourceFileBytes = Files.readAllBytes(sourceFile.toPath());
|
||||
assertTrue("Source file is not the same", Arrays.equals(expectedSourceFileBytes, actualSourceFileBytes));
|
||||
assertTrue("Source file is not the same",
|
||||
Arrays.equals(expectedSourceFileBytes, actualSourceFileBytes));
|
||||
|
||||
return null;
|
||||
}).when(javaExecutor).convert(any(), any());
|
||||
@@ -143,11 +152,14 @@ public class LibreOfficeControllerTest extends AbstractTransformerControllerTest
|
||||
{
|
||||
doThrow(OfficeException.class).when(javaExecutor).convert(any(), any());
|
||||
|
||||
mockMvc.perform(MockMvcRequestBuilders.multipart("/transform")
|
||||
.file(sourceFile)
|
||||
.param("targetExtension", "xxx"))
|
||||
.andExpect(status().is(400))
|
||||
.andExpect(status().reason(containsString("LibreOffice - LibreOffice server conversion failed:")));
|
||||
mockMvc
|
||||
.perform(MockMvcRequestBuilders
|
||||
.multipart("/transform")
|
||||
.file(sourceFile)
|
||||
.param("targetExtension", "xxx"))
|
||||
.andExpect(status().is(400))
|
||||
.andExpect(status().reason(
|
||||
containsString("LibreOffice - LibreOffice server conversion failed:")));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -156,7 +168,7 @@ public class LibreOfficeControllerTest extends AbstractTransformerControllerTest
|
||||
transformRequest.setSourceExtension("doc");
|
||||
transformRequest.setTargetExtension("pdf");
|
||||
transformRequest.setSourceMediaType("application/msword");
|
||||
transformRequest.setTargetMediaType(MediaType.IMAGE_PNG_VALUE);
|
||||
transformRequest.setTargetMediaType(IMAGE_PNG_VALUE);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -180,14 +192,13 @@ public class LibreOfficeControllerTest extends AbstractTransformerControllerTest
|
||||
|
||||
// HTTP Request
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.set(HttpHeaders.CONTENT_DISPOSITION,
|
||||
"attachment; filename=quick." + sourceExtension);
|
||||
headers.set(CONTENT_DISPOSITION, "attachment; filename=quick." + sourceExtension);
|
||||
ResponseEntity<Resource> response = new ResponseEntity<>(new FileSystemResource(
|
||||
sourceFile), headers, HttpStatus.OK);
|
||||
sourceFile), headers, OK);
|
||||
|
||||
when(alfrescoSharedFileStoreClient.retrieveFile(sourceFileRef)).thenReturn(response);
|
||||
when(alfrescoSharedFileStoreClient.saveFile(any())).thenReturn(
|
||||
new FileRefResponse(new FileRefEntity(targetFileRef)));
|
||||
when(alfrescoSharedFileStoreClient.saveFile(any()))
|
||||
.thenReturn(new FileRefResponse(new FileRefEntity(targetFileRef)));
|
||||
when(mockExecutionResult.getExitValue()).thenReturn(0);
|
||||
|
||||
// Update the Transformation Request with any specific params before sending it
|
||||
@@ -195,14 +206,14 @@ public class LibreOfficeControllerTest extends AbstractTransformerControllerTest
|
||||
|
||||
// Serialize and call the transformer
|
||||
String tr = objectMapper.writeValueAsString(transformRequest);
|
||||
String transformationReplyAsString = mockMvc.perform(
|
||||
MockMvcRequestBuilders.post("/transform")
|
||||
.header(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON_VALUE)
|
||||
.header(HttpHeaders.CONTENT_TYPE,
|
||||
MediaType.APPLICATION_JSON_VALUE).content(tr))
|
||||
.andExpect(
|
||||
status().is(HttpStatus.CREATED.value()))
|
||||
.andReturn().getResponse().getContentAsString();
|
||||
String transformationReplyAsString = mockMvc
|
||||
.perform(MockMvcRequestBuilders
|
||||
.post("/transform")
|
||||
.header(ACCEPT, APPLICATION_JSON_VALUE)
|
||||
.header(CONTENT_TYPE, APPLICATION_JSON_VALUE)
|
||||
.content(tr))
|
||||
.andExpect(status().is(CREATED.value()))
|
||||
.andReturn().getResponse().getContentAsString();
|
||||
|
||||
TransformReply transformReply = objectMapper.readValue(transformationReplyAsString,
|
||||
TransformReply.class);
|
||||
|
@@ -47,7 +47,8 @@ public class LibreOfficeQueueTransformServiceIT extends AbstractQueueTransformSe
|
||||
@Override
|
||||
protected TransformRequest buildRequest()
|
||||
{
|
||||
return TransformRequest.builder()
|
||||
return TransformRequest
|
||||
.builder()
|
||||
.withRequestId(UUID.randomUUID().toString())
|
||||
.withSourceMediaType(MIMETYPE_OPENXML_WORDPROCESSING)
|
||||
.withTargetMediaType(MIMETYPE_OPENXML_WORDPROCESSING)
|
||||
@@ -55,6 +56,7 @@ public class LibreOfficeQueueTransformServiceIT extends AbstractQueueTransformSe
|
||||
.withSchema(1)
|
||||
.withClientData("ACS")
|
||||
.withSourceReference(UUID.randomUUID().toString())
|
||||
.withSourceSize(32L).build();
|
||||
.withSourceSize(32L)
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user