mirror of
https://github.com/Alfresco/alfresco-transform-core.git
synced 2025-08-14 17:58:27 +00:00
Merge branch 'master' into ATS-812_PoC_FFmpeg_skeleton
* master: (52 commits) [maven-release-plugin][skip ci] prepare for next development iteration [maven-release-plugin][skip ci] prepare release 2.5.7-A4 ACS-2587 Fix test failure ACS-2587 Include directAccessUrl in T-Config if supported (#539) ATS-864: fix dependabot ATS-864: Switch from fabric8 to docker mvn plugin (#436) ACS-2072 Enforce third party license compliance. [maven-release-plugin][skip ci] prepare for next development iteration [maven-release-plugin][skip ci] prepare release 2.5.7-A3 [trigger release] 2.5.7-A3 Bump activemq-client from 5.16.3 to 5.16.4 (#534) Bump maven-javadoc-plugin from 3.3.1 to 3.3.2 (#533) ATS-981 Avoid CVE-2022-23181 with spring-boot-starter-web 2.6.3 (#537) [maven-release-plugin][skip ci] prepare for next development iteration [maven-release-plugin][skip ci] prepare release 2.5.7-A2 [trigger release] 2.5.7-A2 ACS-2497 Rework httpTransformRequestUsingDirectAccessUrlTest so it can be used in AI and Aspose (#535) Bump docker-maven-plugin from 0.38.1 to 0.39.0 (#528) [maven-release-plugin][skip ci] prepare for next development iteration [maven-release-plugin][skip ci] prepare release 2.5.7-A1 ... # Conflicts: # .travis.yml # alfresco-transformer-base/src/main/java/org/alfresco/transformer/util/RequestParamMap.java Also bumped pom.xml version (for two ffmpeg folders) from 2.5.5-A2-SNAPSHOT to match others (2.5.7-A5-SNAPSHOT)
This commit is contained in:
@@ -1,15 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>org.alfresco</groupId>
|
||||
<artifactId>alfresco-transform-core</artifactId>
|
||||
<version>2.5.5-A2-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
<version>2.5.7-A5-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>alfresco-transformer-base</artifactId>
|
||||
<version>2.5.5-A2-SNAPSHOT</version>
|
||||
|
||||
<properties>
|
||||
<transformer.base.deploy.skip>false</transformer.base.deploy.skip>
|
||||
@@ -81,7 +80,6 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<version>3.2.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
|
@@ -33,11 +33,11 @@ import org.alfresco.transform.client.model.TransformRequestValidator;
|
||||
import org.alfresco.transform.client.model.config.TransformConfig;
|
||||
import org.alfresco.transform.client.registry.TransformServiceRegistry;
|
||||
import org.alfresco.transform.exceptions.TransformException;
|
||||
import org.alfresco.transform.router.TransformStack;
|
||||
import org.alfresco.transform.router.TransformerDebug;
|
||||
import org.alfresco.transformer.clients.AlfrescoSharedFileStoreClient;
|
||||
import org.alfresco.transformer.logging.LogEntry;
|
||||
import org.alfresco.transformer.model.FileRefResponse;
|
||||
import org.codehaus.plexus.util.FileUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -58,12 +58,20 @@ import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static java.util.stream.Collectors.joining;
|
||||
import static org.alfresco.transform.client.model.config.CoreVersionDecorator.setOrClearCoreVersion;
|
||||
import static org.alfresco.transform.client.util.RequestParamMap.DIRECT_ACCESS_URL;
|
||||
import static org.alfresco.transform.client.util.RequestParamMap.CONFIG_VERSION;
|
||||
import static org.alfresco.transform.client.util.RequestParamMap.CONFIG_VERSION_DEFAULT;
|
||||
import static org.alfresco.transform.client.util.RequestParamMap.ENDPOINT_TRANSFORM;
|
||||
import static org.alfresco.transform.client.util.RequestParamMap.ENDPOINT_TRANSFORM_CONFIG;
|
||||
import static org.alfresco.transformer.fs.FileManager.TempFileProvider.createTempFile;
|
||||
import static org.alfresco.transformer.fs.FileManager.buildFile;
|
||||
import static org.alfresco.transformer.fs.FileManager.createAttachment;
|
||||
@@ -126,7 +134,7 @@ public abstract class AbstractTransformerController implements TransformControll
|
||||
|
||||
// Request parameters that are not part of transform options
|
||||
public static final List<String> NON_TRANSFORM_OPTION_REQUEST_PARAMETERS = Arrays.asList(SOURCE_EXTENSION,
|
||||
TARGET_EXTENSION, TARGET_MIMETYPE, SOURCE_MIMETYPE, TEST_DELAY, TRANSFORM_NAME_PROPERTY);
|
||||
TARGET_EXTENSION, TARGET_MIMETYPE, SOURCE_MIMETYPE, TEST_DELAY, TRANSFORM_NAME_PROPERTY, DIRECT_ACCESS_URL);
|
||||
|
||||
@Autowired
|
||||
private AlfrescoSharedFileStoreClient alfrescoSharedFileStoreClient;
|
||||
@@ -140,27 +148,28 @@ public abstract class AbstractTransformerController implements TransformControll
|
||||
@Autowired
|
||||
private TransformerDebug transformerDebug;
|
||||
|
||||
@GetMapping(value = "/transform/config")
|
||||
public ResponseEntity<TransformConfig> info()
|
||||
@GetMapping(value = ENDPOINT_TRANSFORM_CONFIG)
|
||||
public ResponseEntity<TransformConfig> info(
|
||||
@RequestParam(value = CONFIG_VERSION, defaultValue = CONFIG_VERSION_DEFAULT) int configVersion)
|
||||
{
|
||||
logger.info("GET Transform Config.");
|
||||
final TransformConfig transformConfig =
|
||||
((TransformRegistryImpl) transformRegistry).getTransformConfig();
|
||||
logger.info("GET Transform Config version: " + configVersion);
|
||||
TransformConfig transformConfig = ((TransformRegistryImpl) transformRegistry).getTransformConfig();
|
||||
transformConfig = setOrClearCoreVersion(transformConfig, configVersion);
|
||||
return new ResponseEntity<>(transformConfig, OK);
|
||||
}
|
||||
|
||||
@PostMapping(value = "/transform", consumes = MULTIPART_FORM_DATA_VALUE)
|
||||
@PostMapping(value = ENDPOINT_TRANSFORM, consumes = MULTIPART_FORM_DATA_VALUE)
|
||||
public ResponseEntity<Resource> transform(HttpServletRequest request,
|
||||
@RequestParam(FILE) MultipartFile sourceMultipartFile,
|
||||
@RequestParam(value = FILE, required = false) MultipartFile sourceMultipartFile,
|
||||
@RequestParam(TARGET_EXTENSION) String targetExtension,
|
||||
@RequestParam(value = SOURCE_MIMETYPE, required = false) String sourceMimetype,
|
||||
@RequestParam(value = TARGET_MIMETYPE, required = false) String targetMimetype,
|
||||
@RequestParam Map<String, String> requestParameters,
|
||||
@RequestParam (value = TEST_DELAY, required = false) Long testDelay,
|
||||
@RequestParam(value = TEST_DELAY, required = false) Long testDelay,
|
||||
|
||||
// The TRANSFORM_NAME_PROPERTY param allows ACS legacy transformers to specify which transform to use,
|
||||
// It can be removed once legacy transformers are removed from ACS.
|
||||
@RequestParam (value = TRANSFORM_NAME_PROPERTY, required = false) String requestTransformName)
|
||||
@RequestParam(value = TRANSFORM_NAME_PROPERTY, required = false) String requestTransformName)
|
||||
{
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
@@ -168,10 +177,27 @@ public abstract class AbstractTransformerController implements TransformControll
|
||||
+ "targetExtension: '{}', requestParameters: {}", sourceMimetype, targetMimetype, targetExtension, requestParameters);
|
||||
}
|
||||
|
||||
final String targetFilename = createTargetFileName(
|
||||
sourceMultipartFile.getOriginalFilename(), targetExtension);
|
||||
final String directUrl = requestParameters.getOrDefault(DIRECT_ACCESS_URL, "");
|
||||
|
||||
File sourceFile;
|
||||
String sourceFilename;
|
||||
if (directUrl.isBlank())
|
||||
{
|
||||
if (sourceMultipartFile == null)
|
||||
{
|
||||
throw new TransformException(BAD_REQUEST.value(), "Required request part 'file' is not present");
|
||||
}
|
||||
sourceFile = createSourceFile(request, sourceMultipartFile);
|
||||
sourceFilename = sourceMultipartFile.getOriginalFilename();
|
||||
}
|
||||
else
|
||||
{
|
||||
sourceFile = getSourceFileFromDirectUrl(directUrl);
|
||||
sourceFilename = sourceFile.getName();
|
||||
}
|
||||
|
||||
final String targetFilename = createTargetFileName(sourceFilename, targetExtension);
|
||||
getProbeTestTransform().incrementTransformerCount();
|
||||
final File sourceFile = createSourceFile(request, sourceMultipartFile);
|
||||
final File targetFile = createTargetFile(request, targetFilename);
|
||||
|
||||
Map<String, String> transformOptions = getTransformOptions(requestParameters);
|
||||
@@ -186,6 +212,25 @@ public abstract class AbstractTransformerController implements TransformControll
|
||||
return body;
|
||||
}
|
||||
|
||||
private File getSourceFileFromDirectUrl(String directUrl)
|
||||
{
|
||||
File sourceFile = createTempFile("tmp", ".tmp");
|
||||
try
|
||||
{
|
||||
FileUtils.copyURLToFile(new URL(directUrl), sourceFile);
|
||||
}
|
||||
catch (IllegalArgumentException e)
|
||||
{
|
||||
throw new TransformException(BAD_REQUEST.value(), "Direct Access Url is invalid.", e);
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
throw new TransformException(BAD_REQUEST.value(), "Direct Access Url not found.", e);
|
||||
}
|
||||
|
||||
return sourceFile;
|
||||
}
|
||||
|
||||
protected Map<String, String> getTransformOptions(Map<String, String> requestParameters)
|
||||
{
|
||||
Map<String, String> transformOptions = new HashMap<>(requestParameters);
|
||||
@@ -204,7 +249,7 @@ public abstract class AbstractTransformerController implements TransformControll
|
||||
* @param timeout Transformation timeout
|
||||
* @return A transformation reply
|
||||
*/
|
||||
@PostMapping(value = "/transform", produces = APPLICATION_JSON_VALUE)
|
||||
@PostMapping(value = ENDPOINT_TRANSFORM, produces = APPLICATION_JSON_VALUE)
|
||||
@ResponseBody
|
||||
public ResponseEntity<TransformReply> transform(@RequestBody TransformRequest request,
|
||||
@RequestParam(value = "timeout", required = false) Long timeout)
|
||||
@@ -240,7 +285,15 @@ public abstract class AbstractTransformerController implements TransformControll
|
||||
File sourceFile;
|
||||
try
|
||||
{
|
||||
sourceFile = loadSourceFile(request.getSourceReference(), request.getSourceExtension());
|
||||
final String directUrl = request.getTransformRequestOptions().getOrDefault(DIRECT_ACCESS_URL, "");
|
||||
if (directUrl.isBlank())
|
||||
{
|
||||
sourceFile = loadSourceFile(request.getSourceReference(), request.getSourceExtension());
|
||||
}
|
||||
else
|
||||
{
|
||||
sourceFile = getSourceFileFromDirectUrl(directUrl);
|
||||
}
|
||||
}
|
||||
catch (TransformException e)
|
||||
{
|
||||
@@ -280,7 +333,7 @@ public abstract class AbstractTransformerController implements TransformControll
|
||||
{
|
||||
String targetMimetype = request.getTargetMediaType();
|
||||
String sourceMimetype = request.getSourceMediaType();
|
||||
Map<String, String> transformOptions = request.getTransformRequestOptions();
|
||||
Map<String, String> transformOptions = getTransformOptions(request.getTransformRequestOptions());
|
||||
transformerDebug.logOptions(request);
|
||||
String transformName = getTransformerName(sourceFile, sourceMimetype, targetMimetype, transformOptions);
|
||||
transformImpl(transformName, sourceMimetype, targetMimetype, transformOptions, sourceFile, targetFile);
|
||||
|
@@ -26,6 +26,7 @@
|
||||
package org.alfresco.transformer;
|
||||
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
import static org.alfresco.transform.client.model.config.CoreVersionDecorator.setCoreVersionOnSingleStepTransformers;
|
||||
import static org.springframework.http.HttpStatus.INTERNAL_SERVER_ERROR;
|
||||
|
||||
import java.io.IOException;
|
||||
@@ -61,6 +62,9 @@ public class TransformRegistryImpl extends AbstractTransformRegistry
|
||||
@Value("${transform.core.config.location:classpath:engine_config.json}")
|
||||
private String locationFromProperty;
|
||||
|
||||
@Value("${transform.core.version}")
|
||||
private String coreVersion;
|
||||
|
||||
private Resource engineConfig;
|
||||
|
||||
@PostConstruct
|
||||
@@ -82,7 +86,9 @@ public class TransformRegistryImpl extends AbstractTransformRegistry
|
||||
{
|
||||
try (Reader reader = new InputStreamReader(engineConfig.getInputStream(), UTF_8))
|
||||
{
|
||||
return jsonObjectMapper.readValue(reader, TransformConfig.class);
|
||||
TransformConfig transformConfig = jsonObjectMapper.readValue(reader, TransformConfig.class);
|
||||
setCoreVersionOnSingleStepTransformers(transformConfig, coreVersion);
|
||||
return transformConfig;
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
|
@@ -38,16 +38,17 @@ import org.springframework.web.client.RestTemplate;
|
||||
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
import static org.alfresco.transform.client.util.RequestParamMap.ENDPOINT_TRANSFORM;
|
||||
|
||||
@Configuration
|
||||
public class WebApplicationConfig implements WebMvcConfigurer
|
||||
{
|
||||
|
||||
@Override
|
||||
public void addInterceptors(InterceptorRegistry registry)
|
||||
{
|
||||
registry
|
||||
.addInterceptor(transformInterceptor())
|
||||
.addPathPatterns("/transform", "/live", "/ready");
|
||||
.addPathPatterns(ENDPOINT_TRANSFORM, "/live", "/ready");
|
||||
}
|
||||
|
||||
@Bean
|
||||
|
@@ -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.
|
||||
* -
|
||||
@@ -26,7 +26,11 @@
|
||||
*/
|
||||
package org.alfresco.transformer.util;
|
||||
|
||||
public interface RequestParamMap
|
||||
/**
|
||||
* 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.client.util.RequestParamMap
|
||||
{
|
||||
// This property can be sent by acs repository's legacy transformers to force a transform,
|
||||
// instead of letting this T-Engine determine it based on the request parameters.
|
||||
@@ -35,43 +39,14 @@ public interface RequestParamMap
|
||||
// See ATS-731.
|
||||
@Deprecated
|
||||
String TRANSFORM_NAME_PROPERTY = "transformName";
|
||||
|
||||
String TRANSFORM_NAME_PARAMETER = "alfresco.transform-name-parameter";
|
||||
String FILE = "file";
|
||||
|
||||
String SOURCE_ENCODING = "sourceEncoding";
|
||||
String FILE = "file";
|
||||
String SOURCE_EXTENSION = "sourceExtension";
|
||||
String SOURCE_MIMETYPE = "sourceMimetype";
|
||||
String TARGET_EXTENSION = "targetExtension";
|
||||
String TARGET_MIMETYPE = "targetMimetype";
|
||||
String TARGET_ENCODING = "targetEncoding";
|
||||
String TEST_DELAY = "testDelay";
|
||||
String PAGE_REQUEST_PARAM = "page";
|
||||
String WIDTH_REQUEST_PARAM = "width";
|
||||
String HEIGHT_REQUEST_PARAM = "height";
|
||||
String ALLOW_PDF_ENLARGEMENT = "allowPdfEnlargement";
|
||||
String MAINTAIN_PDF_ASPECT_RATIO = "maintainPdfAspectRatio";
|
||||
String START_PAGE = "startPage";
|
||||
String END_PAGE = "endPage";
|
||||
String ALPHA_REMOVE = "alphaRemove";
|
||||
String AUTO_ORIENT = "autoOrient";
|
||||
String CROP_GRAVITY = "cropGravity";
|
||||
String CROP_WIDTH = "cropWidth";
|
||||
String CROP_HEIGHT = "cropHeight";
|
||||
String CROP_PERCENTAGE = "cropPercentage";
|
||||
String CROP_X_OFFSET = "cropXOffset";
|
||||
String CROP_Y_OFFSET = "cropYOffset";
|
||||
String THUMBNAIL = "thumbnail";
|
||||
String RESIZE_WIDTH = "resizeWidth";
|
||||
String RESIZE_HEIGHT = "resizeHeight";
|
||||
String RESIZE_PERCENTAGE = "resizePercentage";
|
||||
String ALLOW_ENLARGEMENT = "allowEnlargement";
|
||||
String MAINTAIN_ASPECT_RATIO = "maintainAspectRatio";
|
||||
String COMMAND_OPTIONS = "commandOptions";
|
||||
String TIMEOUT = "timeout";
|
||||
String INCLUDE_CONTENTS = "includeContents";
|
||||
String NOT_EXTRACT_BOOKMARKS_TEXT = "notExtractBookmarksText";
|
||||
String PAGE_LIMIT = "pageLimit";
|
||||
|
||||
// TODO PoC for FFmpeg - effectively target options (note: if we need specific source options, may need extra set)
|
||||
String TIME_OFFSET = "timeOffset";
|
||||
@@ -79,4 +54,5 @@ public interface RequestParamMap
|
||||
String FRAMES_NUM = "framesNum";
|
||||
String FRAME_WIDTH = "frameWidth";
|
||||
String FRAME_HEIGHT = "frameHeight";
|
||||
|
||||
}
|
||||
|
@@ -36,6 +36,7 @@
|
||||
<div>
|
||||
<br/>
|
||||
<a href="/">Test Transformation</a>
|
||||
<a href="/transform/config?configVersion=9999">Transformer Config</a>
|
||||
</div>
|
||||
|
||||
</body>
|
||||
|
@@ -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.
|
||||
* -
|
||||
@@ -26,6 +26,8 @@
|
||||
*/
|
||||
package org.alfresco.transformer;
|
||||
|
||||
import static org.alfresco.transform.client.util.RequestParamMap.DIRECT_ACCESS_URL;
|
||||
import static org.alfresco.transform.client.util.RequestParamMap.ENDPOINT_TRANSFORM;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.springframework.http.HttpMethod.POST;
|
||||
import static org.springframework.http.MediaType.MULTIPART_FORM_DATA;
|
||||
@@ -89,9 +91,12 @@ public abstract class AbstractHttpRequestTest
|
||||
@Test
|
||||
public void noFileError()
|
||||
{
|
||||
// Transformer name is not part of the title as this is checked by another handler
|
||||
LinkedMultiValueMap<String, Object> parameters = new LinkedMultiValueMap<>();
|
||||
parameters.add("targetExtension", ".tmp");
|
||||
|
||||
assertTransformError(false,
|
||||
"Required request part 'file' is not present");
|
||||
getTransformerName() + " - Required request part 'file' is not present",
|
||||
parameters);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -103,10 +108,12 @@ public abstract class AbstractHttpRequestTest
|
||||
private void assertMissingParameter(String name)
|
||||
{
|
||||
assertTransformError(true,
|
||||
getTransformerName() + " - Request parameter '" + name + "' is missing");
|
||||
getTransformerName() + " - Request parameter '" + name + "' is missing", null);
|
||||
}
|
||||
|
||||
protected void assertTransformError(boolean addFile, String errorMessage)
|
||||
protected void assertTransformError(boolean addFile,
|
||||
String errorMessage,
|
||||
LinkedMultiValueMap<String, Object> additionalParams)
|
||||
{
|
||||
LinkedMultiValueMap<String, Object> parameters = new LinkedMultiValueMap<>();
|
||||
if (addFile)
|
||||
@@ -114,6 +121,11 @@ public abstract class AbstractHttpRequestTest
|
||||
parameters.add("file",
|
||||
new org.springframework.core.io.ClassPathResource("quick." + getSourceExtension()));
|
||||
}
|
||||
if (additionalParams != null)
|
||||
{
|
||||
parameters.addAll(additionalParams);
|
||||
}
|
||||
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.setContentType(MULTIPART_FORM_DATA);
|
||||
HttpEntity<LinkedMultiValueMap<String, Object>> entity = new HttpEntity<>(parameters,
|
||||
@@ -122,10 +134,25 @@ public abstract class AbstractHttpRequestTest
|
||||
sendTranformationRequest(entity, errorMessage);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void httpTransformRequestDirectAccessUrlNotFoundTest()
|
||||
{
|
||||
String directUrl = "https://expired/direct/access/url";
|
||||
|
||||
LinkedMultiValueMap<String, Object> parameters = new LinkedMultiValueMap<>();
|
||||
parameters.add("targetExtension", ".tmp");
|
||||
parameters.add(DIRECT_ACCESS_URL, directUrl);
|
||||
|
||||
assertTransformError(false,
|
||||
getTransformerName() + " - Direct Access Url not found.",
|
||||
parameters);
|
||||
|
||||
}
|
||||
|
||||
protected void sendTranformationRequest(
|
||||
final HttpEntity<LinkedMultiValueMap<String, Object>> entity, final String errorMessage)
|
||||
{
|
||||
final ResponseEntity<String> response = restTemplate.exchange("/transform", POST, entity,
|
||||
final ResponseEntity<String> response = restTemplate.exchange(ENDPOINT_TRANSFORM, POST, entity,
|
||||
String.class, "");
|
||||
assertEquals(errorMessage, getErrorMessage(response.getBody()));
|
||||
}
|
||||
|
@@ -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.
|
||||
* -
|
||||
@@ -102,8 +102,8 @@ public abstract class AbstractMetadataExtractsIT
|
||||
jsonObjectMapper.writerWithDefaultPrettyPrinter().writeValue(actualMetadataFile, actualMetadata);
|
||||
|
||||
Map<String, Serializable> expectedMetadata = readExpectedMetadata(metadataFilename, actualMetadataFile);
|
||||
assertEquals(expectedMetadata, actualMetadata,
|
||||
"The metadata did not match the expected value. It has been saved in "+actualMetadataFile.getAbsolutePath());
|
||||
assertEquals(expectedMetadata, actualMetadata,
|
||||
sourceFile+": The metadata did not match the expected value. It has been saved in "+actualMetadataFile.getAbsolutePath());
|
||||
actualMetadataFile.delete();
|
||||
}
|
||||
catch (Exception e)
|
||||
|
@@ -27,13 +27,21 @@
|
||||
package org.alfresco.transformer;
|
||||
|
||||
import static java.nio.file.StandardCopyOption.REPLACE_EXISTING;
|
||||
import static org.alfresco.transform.client.model.Mimetype.MIMETYPE_TEXT_PLAIN;
|
||||
import static org.alfresco.transform.client.util.RequestParamMap.DIRECT_ACCESS_URL;
|
||||
import static org.alfresco.transform.client.util.RequestParamMap.ENDPOINT_TRANSFORM;
|
||||
import static org.alfresco.transform.client.util.RequestParamMap.ENDPOINT_TRANSFORM_CONFIG_LATEST;
|
||||
import static org.alfresco.transform.client.util.RequestParamMap.ENDPOINT_TRANSFORM_CONFIG;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.springframework.http.HttpHeaders.ACCEPT;
|
||||
import static org.springframework.http.HttpHeaders.CONTENT_TYPE;
|
||||
import static org.springframework.http.HttpStatus.BAD_REQUEST;
|
||||
import static org.springframework.http.HttpStatus.CREATED;
|
||||
import static org.springframework.http.HttpStatus.INTERNAL_SERVER_ERROR;
|
||||
import static org.springframework.http.HttpStatus.OK;
|
||||
import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;
|
||||
@@ -52,6 +60,7 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.alfresco.transform.client.model.InternalContext;
|
||||
import org.alfresco.transform.client.model.TransformReply;
|
||||
@@ -65,16 +74,20 @@ import org.alfresco.transform.client.model.config.Transformer;
|
||||
import org.alfresco.transform.client.registry.TransformServiceRegistry;
|
||||
import org.alfresco.transform.router.TransformStack;
|
||||
import org.alfresco.transformer.clients.AlfrescoSharedFileStoreClient;
|
||||
import org.alfresco.transformer.model.FileRefEntity;
|
||||
import org.alfresco.transformer.model.FileRefResponse;
|
||||
import org.alfresco.transformer.probes.ProbeTestTransform;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||
import org.springframework.boot.test.mock.mockito.SpyBean;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.mock.web.MockMultipartFile;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
import org.springframework.test.web.servlet.ResultActions;
|
||||
import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder;
|
||||
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
|
||||
|
||||
@@ -103,6 +116,9 @@ public abstract class AbstractTransformerControllerTest
|
||||
@SpyBean
|
||||
protected TransformServiceRegistry transformRegistry;
|
||||
|
||||
@Value("${transform.core.version}")
|
||||
private String coreVersion;
|
||||
|
||||
protected String sourceExtension;
|
||||
protected String targetExtension;
|
||||
protected String sourceMimetype;
|
||||
@@ -196,7 +212,7 @@ public abstract class AbstractTransformerControllerTest
|
||||
" does not exist in the resources directory");
|
||||
}
|
||||
// added as part of ATS-702 to allow test resources to be read from the imported jar files to prevent test resource duplication
|
||||
if(testFileUrl!=null)
|
||||
if (testFileUrl!=null)
|
||||
{
|
||||
// Each use of the tempDir should result in a unique directory being used
|
||||
testFile = new File(tempDir, testFilename);
|
||||
@@ -207,9 +223,39 @@ public abstract class AbstractTransformerControllerTest
|
||||
}
|
||||
|
||||
protected MockHttpServletRequestBuilder mockMvcRequest(String url, MockMultipartFile sourceFile,
|
||||
String... params)
|
||||
{
|
||||
if (sourceFile == null)
|
||||
{
|
||||
return mockMvcRequestWithoutMockMultipartFile(url, params);
|
||||
}
|
||||
else
|
||||
{
|
||||
return mockMvcRequestWithMockMultipartFile(url, sourceFile, params);
|
||||
}
|
||||
}
|
||||
|
||||
private MockHttpServletRequestBuilder mockMvcRequestWithoutMockMultipartFile(String url,
|
||||
String... params)
|
||||
{
|
||||
MockHttpServletRequestBuilder builder = MockMvcRequestBuilders.multipart(ENDPOINT_TRANSFORM);
|
||||
|
||||
if (params.length % 2 != 0)
|
||||
{
|
||||
throw new IllegalArgumentException("each param should have a name and value.");
|
||||
}
|
||||
for (int i = 0; i < params.length; i += 2)
|
||||
{
|
||||
builder = builder.param(params[i], params[i + 1]);
|
||||
}
|
||||
|
||||
return builder;
|
||||
}
|
||||
|
||||
private MockHttpServletRequestBuilder mockMvcRequestWithMockMultipartFile(String url, MockMultipartFile sourceFile,
|
||||
String... params)
|
||||
{
|
||||
MockHttpServletRequestBuilder builder = MockMvcRequestBuilders.multipart("/transform").file(
|
||||
MockHttpServletRequestBuilder builder = MockMvcRequestBuilders.multipart(ENDPOINT_TRANSFORM).file(
|
||||
sourceFile);
|
||||
|
||||
if (params.length % 2 != 0)
|
||||
@@ -252,7 +298,7 @@ public abstract class AbstractTransformerControllerTest
|
||||
public void simpleTransformTest() throws Exception
|
||||
{
|
||||
mockMvc.perform(
|
||||
mockMvcRequest("/transform", sourceFile, "targetExtension", targetExtension))
|
||||
mockMvcRequest(ENDPOINT_TRANSFORM, sourceFile, "targetExtension", targetExtension))
|
||||
.andExpect(status().is(OK.value()))
|
||||
.andExpect(content().bytes(expectedTargetFileBytes))
|
||||
.andExpect(header().string("Content-Disposition",
|
||||
@@ -263,7 +309,7 @@ public abstract class AbstractTransformerControllerTest
|
||||
public void testDelayTest() throws Exception
|
||||
{
|
||||
long start = System.currentTimeMillis();
|
||||
mockMvc.perform(mockMvcRequest("/transform", sourceFile, "targetExtension", targetExtension,
|
||||
mockMvc.perform(mockMvcRequest(ENDPOINT_TRANSFORM, sourceFile, "targetExtension", targetExtension,
|
||||
"testDelay", "400"))
|
||||
.andExpect(status().is(OK.value()))
|
||||
.andExpect(content().bytes(expectedTargetFileBytes))
|
||||
@@ -278,7 +324,7 @@ public abstract class AbstractTransformerControllerTest
|
||||
@Test
|
||||
public void noTargetFileTest() throws Exception
|
||||
{
|
||||
mockMvc.perform(mockMvcRequest("/transform", sourceFile, "targetExtension", "xxx"))
|
||||
mockMvc.perform(mockMvcRequest(ENDPOINT_TRANSFORM, sourceFile, "targetExtension", "xxx"))
|
||||
.andExpect(status().is(INTERNAL_SERVER_ERROR.value()));
|
||||
}
|
||||
|
||||
@@ -290,7 +336,7 @@ public abstract class AbstractTransformerControllerTest
|
||||
expectedSourceFileBytes);
|
||||
|
||||
mockMvc.perform(
|
||||
mockMvcRequest("/transform", sourceFile, "targetExtension", targetExtension))
|
||||
mockMvcRequest(ENDPOINT_TRANSFORM, sourceFile, "targetExtension", targetExtension))
|
||||
.andExpect(status().is(OK.value()))
|
||||
.andExpect(content().bytes(expectedTargetFileBytes))
|
||||
.andExpect(header().string("Content-Disposition",
|
||||
@@ -305,7 +351,7 @@ public abstract class AbstractTransformerControllerTest
|
||||
expectedSourceFileBytes);
|
||||
|
||||
mockMvc.perform(
|
||||
mockMvcRequest("/transform", sourceFile, "targetExtension", targetExtension))
|
||||
mockMvcRequest(ENDPOINT_TRANSFORM, sourceFile, "targetExtension", targetExtension))
|
||||
.andExpect(status().is(OK.value()))
|
||||
.andExpect(content().bytes(expectedTargetFileBytes))
|
||||
.andExpect(header().string("Content-Disposition",
|
||||
@@ -319,7 +365,7 @@ public abstract class AbstractTransformerControllerTest
|
||||
sourceFile = new MockMultipartFile("file", "abc/", sourceMimetype, expectedSourceFileBytes);
|
||||
|
||||
mockMvc.perform(
|
||||
mockMvcRequest("/transform", sourceFile, "targetExtension", targetExtension))
|
||||
mockMvcRequest(ENDPOINT_TRANSFORM, sourceFile, "targetExtension", targetExtension))
|
||||
.andExpect(status().is(BAD_REQUEST.value()))
|
||||
.andExpect(status().reason(containsString("The source filename was not supplied")));
|
||||
}
|
||||
@@ -330,14 +376,14 @@ public abstract class AbstractTransformerControllerTest
|
||||
sourceFile = new MockMultipartFile("file", "", sourceMimetype, expectedSourceFileBytes);
|
||||
|
||||
mockMvc.perform(
|
||||
mockMvcRequest("/transform", sourceFile, "targetExtension", targetExtension))
|
||||
mockMvcRequest(ENDPOINT_TRANSFORM, sourceFile, "targetExtension", targetExtension))
|
||||
.andExpect(status().is(BAD_REQUEST.value()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void noTargetExtensionTest() throws Exception
|
||||
{
|
||||
mockMvc.perform(mockMvcRequest("/transform", sourceFile))
|
||||
mockMvc.perform(mockMvcRequest(ENDPOINT_TRANSFORM, sourceFile))
|
||||
.andExpect(status().is(BAD_REQUEST.value()))
|
||||
.andExpect(status().reason(
|
||||
containsString("Request parameter 'targetExtension' is missing")));
|
||||
@@ -382,7 +428,7 @@ public abstract class AbstractTransformerControllerTest
|
||||
String tr = objectMapper.writeValueAsString(transformRequest);
|
||||
String transformationReplyAsString = mockMvc
|
||||
.perform(MockMvcRequestBuilders
|
||||
.post("/transform")
|
||||
.post(ENDPOINT_TRANSFORM)
|
||||
.header(ACCEPT, APPLICATION_JSON_VALUE)
|
||||
.header(CONTENT_TYPE, APPLICATION_JSON_VALUE)
|
||||
.content(tr))
|
||||
@@ -411,12 +457,38 @@ public abstract class AbstractTransformerControllerTest
|
||||
TransformConfig expectedTransformConfig = objectMapper
|
||||
.readValue(getTestFile(getEngineConfigName(), true),
|
||||
TransformConfig.class);
|
||||
expectedTransformConfig.getTransformers().forEach(transformer -> {
|
||||
transformer.setCoreVersion(coreVersion);
|
||||
transformer.getTransformOptions().add(DIRECT_ACCESS_URL);
|
||||
});
|
||||
expectedTransformConfig.getTransformOptions().put(DIRECT_ACCESS_URL, Set.of(new TransformOptionValue(false, DIRECT_ACCESS_URL)));
|
||||
|
||||
ReflectionTestUtils.setField(transformRegistry, "engineConfig",
|
||||
new ClassPathResource(getEngineConfigName()));
|
||||
|
||||
String response = mockMvc
|
||||
.perform(MockMvcRequestBuilders.get("/transform/config"))
|
||||
.perform(MockMvcRequestBuilders.get(ENDPOINT_TRANSFORM_CONFIG_LATEST))
|
||||
.andExpect(status().is(OK.value()))
|
||||
.andExpect(header().string(CONTENT_TYPE, APPLICATION_JSON_VALUE))
|
||||
.andReturn().getResponse().getContentAsString();
|
||||
|
||||
TransformConfig transformConfig = objectMapper.readValue(response, TransformConfig.class);
|
||||
assertEquals(expectedTransformConfig, transformConfig);
|
||||
}
|
||||
|
||||
@Test
|
||||
// Test for case when T-Router or Repository is a version that does not expect it
|
||||
public void testGetTransformConfigInfoExcludingCoreVersion() throws Exception
|
||||
{
|
||||
TransformConfig expectedTransformConfig = objectMapper
|
||||
.readValue(getTestFile(getEngineConfigName(), true),
|
||||
TransformConfig.class);
|
||||
|
||||
ReflectionTestUtils.setField(transformRegistry, "engineConfig",
|
||||
new ClassPathResource(getEngineConfigName()));
|
||||
|
||||
String response = mockMvc
|
||||
.perform(MockMvcRequestBuilders.get(ENDPOINT_TRANSFORM_CONFIG))
|
||||
.andExpect(status().is(OK.value()))
|
||||
.andExpect(header().string(CONTENT_TYPE, APPLICATION_JSON_VALUE))
|
||||
.andReturn().getResponse().getContentAsString();
|
||||
@@ -434,7 +506,7 @@ public abstract class AbstractTransformerControllerTest
|
||||
new ClassPathResource("engine_config_with_duplicates.json"));
|
||||
|
||||
String response = mockMvc
|
||||
.perform(MockMvcRequestBuilders.get("/transform/config"))
|
||||
.perform(MockMvcRequestBuilders.get(ENDPOINT_TRANSFORM_CONFIG))
|
||||
.andExpect(status().is(OK.value()))
|
||||
.andExpect(header().string(CONTENT_TYPE, APPLICATION_JSON_VALUE))
|
||||
.andReturn().getResponse().getContentAsString();
|
||||
@@ -461,7 +533,7 @@ public abstract class AbstractTransformerControllerTest
|
||||
new ClassPathResource("engine_config_incomplete.json"));
|
||||
|
||||
String response = mockMvc
|
||||
.perform(MockMvcRequestBuilders.get("/transform/config"))
|
||||
.perform(MockMvcRequestBuilders.get(ENDPOINT_TRANSFORM_CONFIG))
|
||||
.andExpect(status().is(OK.value()))
|
||||
.andExpect(header().string(CONTENT_TYPE, APPLICATION_JSON_VALUE))
|
||||
.andReturn().getResponse().getContentAsString();
|
||||
@@ -484,7 +556,7 @@ public abstract class AbstractTransformerControllerTest
|
||||
new ClassPathResource("engine_config_no_transform_options.json"));
|
||||
|
||||
String response = mockMvc
|
||||
.perform(MockMvcRequestBuilders.get("/transform/config"))
|
||||
.perform(MockMvcRequestBuilders.get(ENDPOINT_TRANSFORM_CONFIG))
|
||||
.andExpect(status().is(OK.value()))
|
||||
.andExpect(header().string(CONTENT_TYPE, APPLICATION_JSON_VALUE))
|
||||
.andReturn().getResponse().getContentAsString();
|
||||
@@ -540,4 +612,64 @@ public abstract class AbstractTransformerControllerTest
|
||||
transformer.setSupportedSourceAndTargetList(supportedSourceAndTargetList);
|
||||
return transformer;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void queueTransformRequestUsingDirectAccessUrlTest() throws Exception
|
||||
{
|
||||
// Files
|
||||
String sourceFileRef = UUID.randomUUID().toString();
|
||||
File sourceFile = getTestFile("quick." + sourceExtension, true);
|
||||
String targetFileRef = UUID.randomUUID().toString();
|
||||
|
||||
TransformRequest transformRequest = createTransformRequest(sourceFileRef, sourceFile);
|
||||
Map<String, String> transformRequestOptions = transformRequest.getTransformRequestOptions();
|
||||
|
||||
String directUrl = "file://" + sourceFile.toPath();
|
||||
|
||||
transformRequestOptions.put(DIRECT_ACCESS_URL, directUrl);
|
||||
transformRequest.setTransformRequestOptions(transformRequestOptions);
|
||||
|
||||
when(alfrescoSharedFileStoreClient.saveFile(any()))
|
||||
.thenReturn(new FileRefResponse(new FileRefEntity(targetFileRef)));
|
||||
|
||||
// Update the Transformation Request with any specific params before sending it
|
||||
updateTransformRequestWithSpecificOptions(transformRequest);
|
||||
|
||||
// Serialize and call the transformer
|
||||
String tr = objectMapper.writeValueAsString(transformRequest);
|
||||
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);
|
||||
|
||||
// Assert the reply
|
||||
assertEquals(transformRequest.getRequestId(), transformReply.getRequestId());
|
||||
assertEquals(transformRequest.getClientData(), transformReply.getClientData());
|
||||
assertEquals(transformRequest.getSchema(), transformReply.getSchema());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void httpTransformRequestUsingDirectAccessUrlTest() throws Exception
|
||||
{
|
||||
File dauSourceFile = getTestFile("quick." + sourceExtension, true);
|
||||
String directUrl = "file://" + dauSourceFile.toPath();
|
||||
|
||||
ResultActions resultActions = mockMvc.perform(
|
||||
mockMvcRequest(ENDPOINT_TRANSFORM, null)
|
||||
.param("targetExtension", targetExtension)
|
||||
.param(DIRECT_ACCESS_URL, directUrl))
|
||||
.andExpect(status().is(OK.value()));
|
||||
|
||||
if (expectedTargetFileBytes != null)
|
||||
{
|
||||
resultActions.andExpect(content().bytes(expectedTargetFileBytes));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2015-2019 Alfresco Software, Ltd. All rights reserved.
|
||||
* Copyright 2015-2022 Alfresco Software, Ltd. All rights reserved.
|
||||
*
|
||||
* License rights for this program may be obtained from Alfresco Software, Ltd.
|
||||
* pursuant to a written agreement and any use of this program without such an
|
||||
@@ -8,6 +8,7 @@
|
||||
package org.alfresco.transformer;
|
||||
|
||||
import static java.util.Collections.emptyMap;
|
||||
import static org.alfresco.transform.client.util.RequestParamMap.ENDPOINT_TRANSFORM;
|
||||
import static org.springframework.http.MediaType.MULTIPART_FORM_DATA;
|
||||
|
||||
import java.util.Map;
|
||||
@@ -63,6 +64,6 @@ public class EngineClient
|
||||
|
||||
final HttpEntity<MultiValueMap<String, Object>> entity = new HttpEntity<>(body, headers);
|
||||
|
||||
return REST_TEMPLATE.postForEntity(engineUrl + "/transform", entity, Resource.class);
|
||||
return REST_TEMPLATE.postForEntity(engineUrl + ENDPOINT_TRANSFORM, entity, Resource.class);
|
||||
}
|
||||
}
|
||||
|
@@ -76,4 +76,10 @@ public class TestFileInfo
|
||||
{
|
||||
return new TestFileInfo(mimeType, extension, path, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return path;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user