mirror of
https://github.com/Alfresco/alfresco-transform-core.git
synced 2025-08-14 17:58:27 +00:00
Save point: [skip ci]
* Testing the controller
This commit is contained in:
@@ -62,7 +62,7 @@ public class TransformRegistryImpl extends AbstractTransformRegistry
|
|||||||
@Value("${transform.core.config.location:classpath:engine_config.json}")
|
@Value("${transform.core.config.location:classpath:engine_config.json}")
|
||||||
private String locationFromProperty;
|
private String locationFromProperty;
|
||||||
|
|
||||||
@Value("${transform.core.version}")
|
@Autowired
|
||||||
private String coreVersion;
|
private String coreVersion;
|
||||||
|
|
||||||
private Resource engineConfig;
|
private Resource engineConfig;
|
||||||
|
@@ -114,7 +114,7 @@ public abstract class AbstractTransformerControllerTest
|
|||||||
@SpyBean
|
@SpyBean
|
||||||
protected TransformServiceRegistry transformRegistry;
|
protected TransformServiceRegistry transformRegistry;
|
||||||
|
|
||||||
@Value("${transform.core.version}")
|
@Autowired
|
||||||
private String coreVersion;
|
private String coreVersion;
|
||||||
|
|
||||||
protected String sourceExtension;
|
protected String sourceExtension;
|
||||||
|
@@ -27,7 +27,7 @@
|
|||||||
package org.alfresco.transform.coreaio;
|
package org.alfresco.transform.coreaio;
|
||||||
|
|
||||||
import org.alfresco.transform.base.TransformEngine;
|
import org.alfresco.transform.base.TransformEngine;
|
||||||
import org.alfresco.transform.base.probes.ProbeTestTransform;
|
import org.alfresco.transform.base.probes.ProbeTransform;
|
||||||
import org.alfresco.transform.config.TransformConfig;
|
import org.alfresco.transform.config.TransformConfig;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
@@ -76,9 +76,9 @@ public class AIOTransformEngine implements TransformEngine
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ProbeTestTransform getLivenessAndReadinessProbeTestTransform()
|
public ProbeTransform getProbeTransform()
|
||||||
{
|
{
|
||||||
return new ProbeTestTransform("quick.pdf", "quick.txt",
|
return new ProbeTransform("quick.pdf", "quick.txt",
|
||||||
MIMETYPE_PDF, MIMETYPE_TEXT_PLAIN, Collections.emptyMap(),
|
MIMETYPE_PDF, MIMETYPE_TEXT_PLAIN, Collections.emptyMap(),
|
||||||
60, 16, 400, 10240, 60 * 30 + 1, 60 * 15 + 20);
|
60, 16, 400, 10240, 60 * 30 + 1, 60 * 15 + 20);
|
||||||
}
|
}
|
||||||
|
@@ -46,7 +46,7 @@ import static org.junit.jupiter.api.Assertions.assertNull;
|
|||||||
*/
|
*/
|
||||||
public class AIOTest extends AbstractBaseTest
|
public class AIOTest extends AbstractBaseTest
|
||||||
{
|
{
|
||||||
@Value("${transform.core.version}")
|
@Autowired
|
||||||
private String coreVersion;
|
private String coreVersion;
|
||||||
|
|
||||||
//@Override
|
//@Override
|
||||||
|
@@ -74,6 +74,11 @@
|
|||||||
<artifactId>google-collections</artifactId>
|
<artifactId>google-collections</artifactId>
|
||||||
<version>1.0</version>
|
<version>1.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>ch.qos.logback</groupId>
|
||||||
|
<artifactId>logback-classic</artifactId>
|
||||||
|
<version>1.2.6</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
@@ -27,7 +27,7 @@
|
|||||||
package org.alfresco.transform.base;
|
package org.alfresco.transform.base;
|
||||||
|
|
||||||
import org.alfresco.transform.base.logging.LogEntry;
|
import org.alfresco.transform.base.logging.LogEntry;
|
||||||
import org.alfresco.transform.base.probes.ProbeTestTransform;
|
import org.alfresco.transform.base.probes.ProbeTransform;
|
||||||
import org.alfresco.transform.common.TransformException;
|
import org.alfresco.transform.common.TransformException;
|
||||||
import org.alfresco.transform.config.TransformConfig;
|
import org.alfresco.transform.config.TransformConfig;
|
||||||
import org.alfresco.transform.registry.TransformServiceRegistry;
|
import org.alfresco.transform.registry.TransformServiceRegistry;
|
||||||
@@ -66,11 +66,14 @@ import static java.text.MessageFormat.format;
|
|||||||
import static org.alfresco.transform.common.RequestParamMap.CONFIG_VERSION;
|
import static org.alfresco.transform.common.RequestParamMap.CONFIG_VERSION;
|
||||||
import static org.alfresco.transform.common.RequestParamMap.CONFIG_VERSION_DEFAULT;
|
import static org.alfresco.transform.common.RequestParamMap.CONFIG_VERSION_DEFAULT;
|
||||||
import static org.alfresco.transform.common.RequestParamMap.ENDPOINT_ERROR;
|
import static org.alfresco.transform.common.RequestParamMap.ENDPOINT_ERROR;
|
||||||
|
import static org.alfresco.transform.common.RequestParamMap.ENDPOINT_LIVE;
|
||||||
import static org.alfresco.transform.common.RequestParamMap.ENDPOINT_LOG;
|
import static org.alfresco.transform.common.RequestParamMap.ENDPOINT_LOG;
|
||||||
|
import static org.alfresco.transform.common.RequestParamMap.ENDPOINT_READY;
|
||||||
import static org.alfresco.transform.common.RequestParamMap.ENDPOINT_ROOT;
|
import static org.alfresco.transform.common.RequestParamMap.ENDPOINT_ROOT;
|
||||||
import static org.alfresco.transform.common.RequestParamMap.ENDPOINT_TEST;
|
import static org.alfresco.transform.common.RequestParamMap.ENDPOINT_TEST;
|
||||||
import static org.alfresco.transform.common.RequestParamMap.ENDPOINT_TRANSFORM;
|
import static org.alfresco.transform.common.RequestParamMap.ENDPOINT_TRANSFORM;
|
||||||
import static org.alfresco.transform.common.RequestParamMap.ENDPOINT_TRANSFORM_CONFIG;
|
import static org.alfresco.transform.common.RequestParamMap.ENDPOINT_TRANSFORM_CONFIG;
|
||||||
|
import static org.alfresco.transform.common.RequestParamMap.ENDPOINT_VERSION;
|
||||||
import static org.alfresco.transform.common.RequestParamMap.FILE;
|
import static org.alfresco.transform.common.RequestParamMap.FILE;
|
||||||
import static org.alfresco.transform.common.RequestParamMap.SOURCE_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_MIMETYPE;
|
||||||
@@ -93,17 +96,17 @@ public class TransformController
|
|||||||
private TransformServiceRegistry transformRegistry;
|
private TransformServiceRegistry transformRegistry;
|
||||||
@Autowired
|
@Autowired
|
||||||
private TransformHandler transformHandler;
|
private TransformHandler transformHandler;
|
||||||
@Value("${transform.core.version}")
|
@Autowired
|
||||||
private String coreVersion;
|
private String coreVersion;
|
||||||
|
|
||||||
private TransformEngine transformEngine;
|
TransformEngine transformEngine;
|
||||||
ProbeTestTransform probeTestTransform;
|
ProbeTransform probeTransform;
|
||||||
|
|
||||||
@PostConstruct
|
@PostConstruct
|
||||||
private void init()
|
private void init()
|
||||||
{
|
{
|
||||||
transformEngine = transformHandler.getTransformEngine();
|
transformEngine = transformHandler.getTransformEngine();
|
||||||
probeTestTransform = transformHandler.getProbeTestTransform();
|
probeTransform = transformHandler.getProbeTestTransform();
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventListener(ApplicationReadyEvent.class)
|
@EventListener(ApplicationReadyEvent.class)
|
||||||
@@ -122,7 +125,7 @@ public class TransformController
|
|||||||
/**
|
/**
|
||||||
* @return a string that may be used in client debug.
|
* @return a string that may be used in client debug.
|
||||||
*/
|
*/
|
||||||
@RequestMapping("/version")
|
@RequestMapping(ENDPOINT_VERSION)
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
public String version()
|
public String version()
|
||||||
{
|
{
|
||||||
@@ -167,21 +170,21 @@ public class TransformController
|
|||||||
/**
|
/**
|
||||||
* Kubernetes readiness probe.
|
* Kubernetes readiness probe.
|
||||||
*/
|
*/
|
||||||
@GetMapping("/ready")
|
@GetMapping(ENDPOINT_READY)
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
public String ready(HttpServletRequest request)
|
public String ready(HttpServletRequest request)
|
||||||
{
|
{
|
||||||
return probeTestTransform.doTransformOrNothing(request, false, this);
|
return probeTransform.doTransformOrNothing(request, false, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Kubernetes liveness probe.
|
* Kubernetes liveness probe.
|
||||||
*/
|
*/
|
||||||
@GetMapping("/live")
|
@GetMapping(ENDPOINT_LIVE)
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
public String live(HttpServletRequest request)
|
public String live(HttpServletRequest request)
|
||||||
{
|
{
|
||||||
return probeTestTransform.doTransformOrNothing(request, true, this);
|
return probeTransform.doTransformOrNothing(request, true, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping(value = ENDPOINT_TRANSFORM_CONFIG)
|
@GetMapping(value = ENDPOINT_TRANSFORM_CONFIG)
|
||||||
@@ -197,8 +200,8 @@ public class TransformController
|
|||||||
@PostMapping(value = ENDPOINT_TRANSFORM, consumes = MULTIPART_FORM_DATA_VALUE)
|
@PostMapping(value = ENDPOINT_TRANSFORM, consumes = MULTIPART_FORM_DATA_VALUE)
|
||||||
public ResponseEntity<StreamingResponseBody> transform(HttpServletRequest request,
|
public ResponseEntity<StreamingResponseBody> transform(HttpServletRequest request,
|
||||||
@RequestParam(value = FILE, required = false) MultipartFile sourceMultipartFile,
|
@RequestParam(value = FILE, required = false) MultipartFile sourceMultipartFile,
|
||||||
@RequestParam(value = SOURCE_MIMETYPE, required = false) String sourceMimetype,
|
@RequestParam(value = SOURCE_MIMETYPE, required = true) String sourceMimetype,
|
||||||
@RequestParam(value = TARGET_MIMETYPE, required = false) String targetMimetype,
|
@RequestParam(value = TARGET_MIMETYPE, required = true) String targetMimetype,
|
||||||
@RequestParam Map<String, String> requestParameters)
|
@RequestParam Map<String, String> requestParameters)
|
||||||
{
|
{
|
||||||
return transformHandler.handleHttpRequest(request, sourceMultipartFile, sourceMimetype,
|
return transformHandler.handleHttpRequest(request, sourceMultipartFile, sourceMimetype,
|
||||||
@@ -270,7 +273,7 @@ public class TransformController
|
|||||||
}
|
}
|
||||||
|
|
||||||
@ExceptionHandler(TransformException.class)
|
@ExceptionHandler(TransformException.class)
|
||||||
public ModelAndView transformExceptionWithMessage(HttpServletResponse response, TransformException e)
|
public ModelAndView handleTransformException(HttpServletResponse response, TransformException e)
|
||||||
throws IOException
|
throws IOException
|
||||||
{
|
{
|
||||||
final String message = e.getMessage();
|
final String message = e.getMessage();
|
||||||
@@ -278,7 +281,7 @@ public class TransformController
|
|||||||
|
|
||||||
logger.error(message);
|
logger.error(message);
|
||||||
long time = LogEntry.setStatusCodeAndMessage(statusCode, message);
|
long time = LogEntry.setStatusCodeAndMessage(statusCode, message);
|
||||||
probeTestTransform.recordTransformTime(time);
|
probeTransform.recordTransformTime(time);
|
||||||
response.sendError(statusCode, message);
|
response.sendError(statusCode, message);
|
||||||
|
|
||||||
ModelAndView mav = new ModelAndView();
|
ModelAndView mav = new ModelAndView();
|
||||||
|
@@ -26,7 +26,7 @@
|
|||||||
*/
|
*/
|
||||||
package org.alfresco.transform.base;
|
package org.alfresco.transform.base;
|
||||||
|
|
||||||
import org.alfresco.transform.base.probes.ProbeTestTransform;
|
import org.alfresco.transform.base.probes.ProbeTransform;
|
||||||
import org.alfresco.transform.common.TransformConfigResourceReader;
|
import org.alfresco.transform.common.TransformConfigResourceReader;
|
||||||
import org.alfresco.transform.config.TransformConfig;
|
import org.alfresco.transform.config.TransformConfig;
|
||||||
|
|
||||||
@@ -55,7 +55,7 @@ public interface TransformEngine
|
|||||||
TransformConfig getTransformConfig();
|
TransformConfig getTransformConfig();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return a ProbeTestTransform (will do a quick transform) for k8 liveness and readiness probes.
|
* @return a ProbeTransform (will do a quick transform) for k8 liveness and readiness probes.
|
||||||
*/
|
*/
|
||||||
ProbeTestTransform getLivenessAndReadinessProbeTestTransform();
|
ProbeTransform getProbeTransform();
|
||||||
}
|
}
|
||||||
|
@@ -30,7 +30,7 @@ import org.alfresco.transform.base.clients.AlfrescoSharedFileStoreClient;
|
|||||||
import org.alfresco.transform.base.fs.FileManager;
|
import org.alfresco.transform.base.fs.FileManager;
|
||||||
import org.alfresco.transform.base.logging.LogEntry;
|
import org.alfresco.transform.base.logging.LogEntry;
|
||||||
import org.alfresco.transform.base.model.FileRefResponse;
|
import org.alfresco.transform.base.model.FileRefResponse;
|
||||||
import org.alfresco.transform.base.probes.ProbeTestTransform;
|
import org.alfresco.transform.base.probes.ProbeTransform;
|
||||||
import org.alfresco.transform.base.util.OutputStreamLengthRecorder;
|
import org.alfresco.transform.base.util.OutputStreamLengthRecorder;
|
||||||
import org.alfresco.transform.client.model.InternalContext;
|
import org.alfresco.transform.client.model.InternalContext;
|
||||||
import org.alfresco.transform.client.model.TransformReply;
|
import org.alfresco.transform.client.model.TransformReply;
|
||||||
@@ -73,7 +73,6 @@ import java.util.concurrent.atomic.AtomicInteger;
|
|||||||
|
|
||||||
import static java.util.stream.Collectors.joining;
|
import static java.util.stream.Collectors.joining;
|
||||||
import static org.alfresco.transform.base.fs.FileManager.createTargetFile;
|
import static org.alfresco.transform.base.fs.FileManager.createTargetFile;
|
||||||
import static org.alfresco.transform.base.fs.FileManager.deleteFile;
|
|
||||||
import static org.alfresco.transform.base.fs.FileManager.getDirectAccessUrlInputStream;
|
import static org.alfresco.transform.base.fs.FileManager.getDirectAccessUrlInputStream;
|
||||||
import static org.alfresco.transform.common.RequestParamMap.DIRECT_ACCESS_URL;
|
import static org.alfresco.transform.common.RequestParamMap.DIRECT_ACCESS_URL;
|
||||||
import static org.alfresco.transform.common.RequestParamMap.SOURCE_ENCODING;
|
import static org.alfresco.transform.common.RequestParamMap.SOURCE_ENCODING;
|
||||||
@@ -112,7 +111,7 @@ public class TransformHandler
|
|||||||
|
|
||||||
private AtomicInteger httpRequestCount = new AtomicInteger(1);
|
private AtomicInteger httpRequestCount = new AtomicInteger(1);
|
||||||
private TransformEngine transformEngine;
|
private TransformEngine transformEngine;
|
||||||
private ProbeTestTransform probeTestTransform;
|
private ProbeTransform probeTransform;
|
||||||
private Map<String, CustomTransformer> customTransformersByName = new HashMap<>();
|
private Map<String, CustomTransformer> customTransformersByName = new HashMap<>();
|
||||||
|
|
||||||
@PostConstruct
|
@PostConstruct
|
||||||
@@ -147,7 +146,7 @@ public class TransformHandler
|
|||||||
{
|
{
|
||||||
if (transformEngine != null)
|
if (transformEngine != null)
|
||||||
{
|
{
|
||||||
probeTestTransform = transformEngine.getLivenessAndReadinessProbeTestTransform();
|
probeTransform = transformEngine.getProbeTransform();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -170,9 +169,9 @@ public class TransformHandler
|
|||||||
return transformEngine;
|
return transformEngine;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ProbeTestTransform getProbeTestTransform()
|
public ProbeTransform getProbeTestTransform()
|
||||||
{
|
{
|
||||||
return probeTestTransform;
|
return probeTransform;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ResponseEntity<StreamingResponseBody> handleHttpRequest(HttpServletRequest request,
|
public ResponseEntity<StreamingResponseBody> handleHttpRequest(HttpServletRequest request,
|
||||||
@@ -191,7 +190,7 @@ public class TransformHandler
|
|||||||
logger.debug("Processing request via HTTP endpoint. Params: sourceMimetype: '{}', targetMimetype: '{}', "
|
logger.debug("Processing request via HTTP endpoint. Params: sourceMimetype: '{}', targetMimetype: '{}', "
|
||||||
+ "requestParameters: {}", sourceMimetype, targetMimetype, requestParameters);
|
+ "requestParameters: {}", sourceMimetype, targetMimetype, requestParameters);
|
||||||
}
|
}
|
||||||
probeTestTransform.incrementTransformerCount();
|
probeTransform.incrementTransformerCount();
|
||||||
|
|
||||||
final String directUrl = requestParameters.getOrDefault(DIRECT_ACCESS_URL, "");
|
final String directUrl = requestParameters.getOrDefault(DIRECT_ACCESS_URL, "");
|
||||||
InputStream inputStream = new BufferedInputStream(directUrl.isBlank() ?
|
InputStream inputStream = new BufferedInputStream(directUrl.isBlank() ?
|
||||||
@@ -222,7 +221,7 @@ public class TransformHandler
|
|||||||
LogEntry.setTargetSize(outputStream.getLength());
|
LogEntry.setTargetSize(outputStream.getLength());
|
||||||
long time = LogEntry.setStatusCodeAndMessage(OK.value(), "Success");
|
long time = LogEntry.setStatusCodeAndMessage(OK.value(), "Success");
|
||||||
|
|
||||||
probeTestTransform.recordTransformTime(time);
|
probeTransform.recordTransformTime(time);
|
||||||
transformerDebug.popTransform(reference, time);
|
transformerDebug.popTransform(reference, time);
|
||||||
}
|
}
|
||||||
catch (TransformException e)
|
catch (TransformException e)
|
||||||
@@ -252,7 +251,7 @@ public class TransformHandler
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
logger.trace("Received {}, timeout {} ms", request, timeout);
|
logger.trace("Received {}, timeout {} ms", request, timeout);
|
||||||
probeTestTransform.incrementTransformerCount();
|
probeTransform.incrementTransformerCount();
|
||||||
checkTransformRequestValid(request, reply);
|
checkTransformRequestValid(request, reply);
|
||||||
inputStream = getInputStream(request, reply);
|
inputStream = getInputStream(request, reply);
|
||||||
String targetMimetype = request.getTargetMediaType();
|
String targetMimetype = request.getTargetMediaType();
|
||||||
@@ -300,7 +299,7 @@ public class TransformHandler
|
|||||||
deleteTmpFiles(transformManager);
|
deleteTmpFiles(transformManager);
|
||||||
closeInputStreamWithoutException(inputStream);
|
closeInputStreamWithoutException(inputStream);
|
||||||
|
|
||||||
probeTestTransform.recordTransformTime(System.currentTimeMillis()-start);
|
probeTransform.recordTransformTime(System.currentTimeMillis()-start);
|
||||||
transformerDebug.popTransform(reply);
|
transformerDebug.popTransform(reply);
|
||||||
|
|
||||||
logger.trace("Sending successful {}, timeout {} ms", reply, timeout);
|
logger.trace("Sending successful {}, timeout {} ms", reply, timeout);
|
||||||
|
@@ -50,7 +50,7 @@ public class TransformRegistryImpl extends AbstractTransformRegistry
|
|||||||
@Autowired(required = false)
|
@Autowired(required = false)
|
||||||
private List<TransformEngine> transformEngines;
|
private List<TransformEngine> transformEngines;
|
||||||
|
|
||||||
@Value("${transform.core.version}")
|
@Autowired
|
||||||
private String coreVersion;
|
private String coreVersion;
|
||||||
|
|
||||||
private TransformConfig transformConfigBeforeIncompleteTransformsAreRemoved;
|
private TransformConfig transformConfigBeforeIncompleteTransformsAreRemoved;
|
||||||
|
@@ -32,6 +32,8 @@ import org.alfresco.transform.base.clients.AlfrescoSharedFileStoreClient;
|
|||||||
import org.alfresco.transform.common.TransformerDebug;
|
import org.alfresco.transform.common.TransformerDebug;
|
||||||
import org.alfresco.transform.messages.TransformRequestValidator;
|
import org.alfresco.transform.messages.TransformRequestValidator;
|
||||||
import org.alfresco.transform.registry.TransformServiceRegistry;
|
import org.alfresco.transform.registry.TransformServiceRegistry;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.ComponentScan;
|
import org.springframework.context.annotation.ComponentScan;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
@@ -41,6 +43,7 @@ import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
|||||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||||
|
|
||||||
import static org.alfresco.transform.common.RequestParamMap.ENDPOINT_TRANSFORM;
|
import static org.alfresco.transform.common.RequestParamMap.ENDPOINT_TRANSFORM;
|
||||||
|
import static org.alfresco.transform.config.CoreFunction.standardizeCoreVersion;
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@ComponentScan(
|
@ComponentScan(
|
||||||
@@ -48,6 +51,9 @@ import static org.alfresco.transform.common.RequestParamMap.ENDPOINT_TRANSFORM;
|
|||||||
excludeFilters = @ComponentScan.Filter(type = FilterType.REGEX, pattern = ".*Test.*"))
|
excludeFilters = @ComponentScan.Filter(type = FilterType.REGEX, pattern = ".*Test.*"))
|
||||||
public class WebApplicationConfig implements WebMvcConfigurer
|
public class WebApplicationConfig implements WebMvcConfigurer
|
||||||
{
|
{
|
||||||
|
@Value("${transform.core.version}")
|
||||||
|
private String coreVersionString;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addInterceptors(InterceptorRegistry registry)
|
public void addInterceptors(InterceptorRegistry registry)
|
||||||
{
|
{
|
||||||
@@ -91,4 +97,10 @@ public class WebApplicationConfig implements WebMvcConfigurer
|
|||||||
{
|
{
|
||||||
return new TransformerDebug().setIsTEngine(true);
|
return new TransformerDebug().setIsTEngine(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public String coreVersion()
|
||||||
|
{
|
||||||
|
return standardizeCoreVersion(coreVersionString);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -48,7 +48,7 @@ import org.slf4j.LoggerFactory;
|
|||||||
public final class LogEntry
|
public final class LogEntry
|
||||||
{
|
{
|
||||||
private static final Logger logger = LoggerFactory.getLogger(LogEntry.class);
|
private static final Logger logger = LoggerFactory.getLogger(LogEntry.class);
|
||||||
// TODO allow ProbeTestTransform to find out if there are any transforms running longer than the max time.
|
// TODO allow ProbeTransform to find out if there are any transforms running longer than the max time.
|
||||||
|
|
||||||
private static final AtomicInteger count = new AtomicInteger(0);
|
private static final AtomicInteger count = new AtomicInteger(0);
|
||||||
private static final Deque<LogEntry> log = new ConcurrentLinkedDeque<>();
|
private static final Deque<LogEntry> log = new ConcurrentLinkedDeque<>();
|
||||||
|
@@ -81,9 +81,9 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||||||
* <li>livenessTransformPeriodSeconds The number of seconds between test transforms done for live probes</li>
|
* <li>livenessTransformPeriodSeconds The number of seconds between test transforms done for live probes</li>
|
||||||
* </ul>
|
* </ul>
|
||||||
*/
|
*/
|
||||||
public class ProbeTestTransform
|
public class ProbeTransform
|
||||||
{
|
{
|
||||||
private final Logger logger = LoggerFactory.getLogger(ProbeTestTransform.class);
|
private final Logger logger = LoggerFactory.getLogger(ProbeTransform.class);
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private TransformServiceRegistry transformRegistry;
|
private TransformServiceRegistry transformRegistry;
|
||||||
@@ -124,7 +124,7 @@ public class ProbeTestTransform
|
|||||||
return maxTime;
|
return maxTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ProbeTestTransform(String sourceFilename, String targetFilename,
|
public ProbeTransform(String sourceFilename, String targetFilename,
|
||||||
String sourceMimetype, String targetMimetype, Map<String, String> transformOptions,
|
String sourceMimetype, String targetMimetype, Map<String, String> transformOptions,
|
||||||
long expectedLength, long plusOrMinus, int livenessPercent, long maxTransforms, long maxTransformSeconds,
|
long expectedLength, long plusOrMinus, int livenessPercent, long maxTransforms, long maxTransformSeconds,
|
||||||
long livenessTransformPeriodSeconds)
|
long livenessTransformPeriodSeconds)
|
@@ -62,7 +62,7 @@ import java.util.Map;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.alfresco.transform.base.probes.ProbeTestTransform;
|
import org.alfresco.transform.base.probes.ProbeTransform;
|
||||||
import org.alfresco.transform.client.model.InternalContext;
|
import org.alfresco.transform.client.model.InternalContext;
|
||||||
import org.alfresco.transform.client.model.TransformReply;
|
import org.alfresco.transform.client.model.TransformReply;
|
||||||
import org.alfresco.transform.client.model.TransformRequest;
|
import org.alfresco.transform.client.model.TransformRequest;
|
||||||
@@ -124,7 +124,7 @@ public abstract class AbstractBaseTest
|
|||||||
@SpyBean
|
@SpyBean
|
||||||
protected TransformServiceRegistry transformRegistry;
|
protected TransformServiceRegistry transformRegistry;
|
||||||
|
|
||||||
@Value("${transform.core.version}")
|
@Autowired
|
||||||
private String coreVersion;
|
private String coreVersion;
|
||||||
|
|
||||||
protected String sourceExtension;
|
protected String sourceExtension;
|
||||||
@@ -152,9 +152,9 @@ public abstract class AbstractBaseTest
|
|||||||
String targetExtension, String sourceMimetype,
|
String targetExtension, String sourceMimetype,
|
||||||
boolean readTargetFileBytes) throws IOException;
|
boolean readTargetFileBytes) throws IOException;
|
||||||
|
|
||||||
protected ProbeTestTransform getProbeTestTransform()
|
protected ProbeTransform getProbeTestTransform()
|
||||||
{
|
{
|
||||||
return controller.probeTestTransform;
|
return controller.probeTransform;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract void updateTransformRequestWithSpecificOptions(TransformRequest transformRequest);
|
protected abstract void updateTransformRequestWithSpecificOptions(TransformRequest transformRequest);
|
||||||
@@ -364,8 +364,8 @@ public abstract class AbstractBaseTest
|
|||||||
@Test
|
@Test
|
||||||
public void calculateMaxTime() throws Exception
|
public void calculateMaxTime() throws Exception
|
||||||
{
|
{
|
||||||
ProbeTestTransform probeTestTransform = controller.probeTestTransform;
|
ProbeTransform probeTransform = controller.probeTransform;
|
||||||
probeTestTransform.setLivenessPercent(110);
|
probeTransform.setLivenessPercent(110);
|
||||||
|
|
||||||
long[][] values = new long[][]{
|
long[][] values = new long[][]{
|
||||||
{5000, 0, Long.MAX_VALUE}, // 1st transform is ignored
|
{5000, 0, Long.MAX_VALUE}, // 1st transform is ignored
|
||||||
@@ -384,9 +384,9 @@ public abstract class AbstractBaseTest
|
|||||||
long expectedNormalTime = v[1];
|
long expectedNormalTime = v[1];
|
||||||
long expectedMaxTime = v[2];
|
long expectedMaxTime = v[2];
|
||||||
|
|
||||||
probeTestTransform.calculateMaxTime(time, true);
|
probeTransform.calculateMaxTime(time, true);
|
||||||
assertEquals(expectedNormalTime, probeTestTransform.getNormalTime());
|
assertEquals(expectedNormalTime, probeTransform.getNormalTime());
|
||||||
assertEquals(expectedMaxTime, probeTestTransform.getMaxTime());
|
assertEquals(expectedMaxTime, probeTransform.getMaxTime());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,99 +0,0 @@
|
|||||||
/*
|
|
||||||
* #%L
|
|
||||||
* Alfresco Transform Core
|
|
||||||
* %%
|
|
||||||
* Copyright (C) 2005 - 2022 Alfresco Software Limited
|
|
||||||
* %%
|
|
||||||
* This file is part of the Alfresco software.
|
|
||||||
* -
|
|
||||||
* If the software was purchased under a paid Alfresco license, the terms of
|
|
||||||
* the paid license agreement will prevail. Otherwise, the software is
|
|
||||||
* provided under the following open source license terms:
|
|
||||||
* -
|
|
||||||
* Alfresco is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Lesser General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
* -
|
|
||||||
* Alfresco is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU Lesser General Public License for more details.
|
|
||||||
* -
|
|
||||||
* You should have received a copy of the GNU Lesser General Public License
|
|
||||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
* #L%
|
|
||||||
*/
|
|
||||||
package org.alfresco.transform.base;
|
|
||||||
|
|
||||||
import org.alfresco.transform.base.components.TestTransformEngineTwoTransformers;
|
|
||||||
import org.alfresco.transform.base.components.TestTransformerPdf2Png;
|
|
||||||
import org.alfresco.transform.base.components.TestTransformerTxT2Pdf;
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
|
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
|
||||||
import org.springframework.mock.web.MockMultipartFile;
|
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
|
||||||
import org.springframework.test.web.servlet.MockMvc;
|
|
||||||
import org.springframework.test.web.servlet.MvcResult;
|
|
||||||
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
|
|
||||||
|
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
|
|
||||||
import static org.alfresco.transform.common.Mimetype.MIMETYPE_IMAGE_PNG;
|
|
||||||
import static org.alfresco.transform.common.Mimetype.MIMETYPE_PDF;
|
|
||||||
import static org.alfresco.transform.common.Mimetype.MIMETYPE_TEXT_PLAIN;
|
|
||||||
import static org.alfresco.transform.common.RequestParamMap.ENDPOINT_TRANSFORM;
|
|
||||||
import static org.alfresco.transform.common.RequestParamMap.SOURCE_MIMETYPE;
|
|
||||||
import static org.alfresco.transform.common.RequestParamMap.TARGET_MIMETYPE;
|
|
||||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
|
|
||||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.header;
|
|
||||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.request;
|
|
||||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Testing base t-engine TransformController functionality.
|
|
||||||
*/
|
|
||||||
@AutoConfigureMockMvc
|
|
||||||
@SpringBootTest(classes={org.alfresco.transform.base.Application.class})
|
|
||||||
@ContextConfiguration(classes = {
|
|
||||||
TestTransformerTxT2Pdf.class,
|
|
||||||
TestTransformerPdf2Png.class,
|
|
||||||
TestTransformEngineTwoTransformers.class})
|
|
||||||
public class TransformControllerTestWithBasicConfig
|
|
||||||
{
|
|
||||||
@Autowired
|
|
||||||
protected MockMvc mockMvc;
|
|
||||||
|
|
||||||
private void assertGoodTransform(String originalValue, String expectedValue, String sourceMimetype, String targetMimetype,
|
|
||||||
String expectedTargetExtension) throws Exception
|
|
||||||
{
|
|
||||||
mockMvc.perform(
|
|
||||||
MockMvcRequestBuilders.multipart(ENDPOINT_TRANSFORM)
|
|
||||||
.file(new MockMultipartFile("file", null, sourceMimetype,
|
|
||||||
originalValue.getBytes(StandardCharsets.UTF_8)))
|
|
||||||
.param(SOURCE_MIMETYPE, sourceMimetype)
|
|
||||||
.param(TARGET_MIMETYPE, targetMimetype))
|
|
||||||
.andExpect(request().asyncStarted())
|
|
||||||
.andDo(MvcResult::getAsyncResult)
|
|
||||||
.andExpect(status().isOk())
|
|
||||||
.andExpect(header().string("Content-Disposition",
|
|
||||||
"attachment; filename*=UTF-8''transform." + expectedTargetExtension))
|
|
||||||
.andExpect(content().string(expectedValue));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void singleStepTransform() throws Exception
|
|
||||||
{
|
|
||||||
assertGoodTransform("Start", "Start -> TxT2Pdf()",
|
|
||||||
MIMETYPE_TEXT_PLAIN, MIMETYPE_PDF, "pdf");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void pipelineTransform() throws Exception
|
|
||||||
{
|
|
||||||
assertGoodTransform("Start", "Start -> TxT2Pdf() -> Pdf2Png()",
|
|
||||||
MIMETYPE_TEXT_PLAIN, MIMETYPE_IMAGE_PNG, "png");
|
|
||||||
}
|
|
||||||
}
|
|
@@ -0,0 +1,313 @@
|
|||||||
|
/*
|
||||||
|
* #%L
|
||||||
|
* Alfresco Transform Core
|
||||||
|
* %%
|
||||||
|
* Copyright (C) 2005 - 2022 Alfresco Software Limited
|
||||||
|
* %%
|
||||||
|
* This file is part of the Alfresco software.
|
||||||
|
* -
|
||||||
|
* If the software was purchased under a paid Alfresco license, the terms of
|
||||||
|
* the paid license agreement will prevail. Otherwise, the software is
|
||||||
|
* provided under the following open source license terms:
|
||||||
|
* -
|
||||||
|
* Alfresco is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
* -
|
||||||
|
* Alfresco is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
* -
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
* #L%
|
||||||
|
*/
|
||||||
|
package org.alfresco.transform.base;
|
||||||
|
|
||||||
|
import ch.qos.logback.classic.Level;
|
||||||
|
import ch.qos.logback.classic.Logger;
|
||||||
|
import ch.qos.logback.classic.LoggerContext;
|
||||||
|
import ch.qos.logback.classic.spi.ILoggingEvent;
|
||||||
|
import ch.qos.logback.core.AppenderBase;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import org.alfresco.transform.base.components.TestTransformEngineTwoTransformers;
|
||||||
|
import org.alfresco.transform.base.components.TestTransformerPdf2Png;
|
||||||
|
import org.alfresco.transform.base.components.TestTransformerTxT2Pdf;
|
||||||
|
import org.alfresco.transform.config.TransformConfig;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
import org.springframework.mock.web.MockMultipartFile;
|
||||||
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
|
import org.springframework.test.web.servlet.MockMvc;
|
||||||
|
import org.springframework.test.web.servlet.MvcResult;
|
||||||
|
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
|
||||||
|
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.util.StringJoiner;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import static org.alfresco.transform.common.Mimetype.MIMETYPE_PDF;
|
||||||
|
import static org.alfresco.transform.common.Mimetype.MIMETYPE_TEXT_PLAIN;
|
||||||
|
import static org.alfresco.transform.common.RequestParamMap.ENDPOINT_ERROR;
|
||||||
|
import static org.alfresco.transform.common.RequestParamMap.ENDPOINT_LIVE;
|
||||||
|
import static org.alfresco.transform.common.RequestParamMap.ENDPOINT_LOG;
|
||||||
|
import static org.alfresco.transform.common.RequestParamMap.ENDPOINT_READY;
|
||||||
|
import static org.alfresco.transform.common.RequestParamMap.ENDPOINT_ROOT;
|
||||||
|
import static org.alfresco.transform.common.RequestParamMap.ENDPOINT_TRANSFORM;
|
||||||
|
import static org.alfresco.transform.common.RequestParamMap.ENDPOINT_TRANSFORM_CONFIG;
|
||||||
|
import static org.alfresco.transform.common.RequestParamMap.ENDPOINT_TRANSFORM_CONFIG_LATEST;
|
||||||
|
import static org.alfresco.transform.common.RequestParamMap.ENDPOINT_VERSION;
|
||||||
|
import static org.alfresco.transform.common.RequestParamMap.FILE;
|
||||||
|
import static org.alfresco.transform.common.RequestParamMap.PAGE_REQUEST_PARAM;
|
||||||
|
import static org.alfresco.transform.common.RequestParamMap.SOURCE_MIMETYPE;
|
||||||
|
import static org.alfresco.transform.common.RequestParamMap.TARGET_MIMETYPE;
|
||||||
|
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.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
|
||||||
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.header;
|
||||||
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.request;
|
||||||
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Testing base t-engine TransformController functionality.
|
||||||
|
*/
|
||||||
|
@AutoConfigureMockMvc
|
||||||
|
@SpringBootTest(classes={org.alfresco.transform.base.Application.class})
|
||||||
|
@ContextConfiguration(classes = {
|
||||||
|
TestTransformEngineTwoTransformers.class,
|
||||||
|
TestTransformerTxT2Pdf.class,
|
||||||
|
TestTransformerPdf2Png.class})
|
||||||
|
public class TransformControllerWithSingleEngineTest
|
||||||
|
{
|
||||||
|
@Autowired
|
||||||
|
private MockMvc mockMvc;
|
||||||
|
@Autowired
|
||||||
|
private TransformController transformController;
|
||||||
|
@Autowired
|
||||||
|
protected ObjectMapper objectMapper;
|
||||||
|
@Autowired
|
||||||
|
private String coreVersion;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void initEngine() throws Exception
|
||||||
|
{
|
||||||
|
assertEquals(TestTransformEngineTwoTransformers.class.getSimpleName(),
|
||||||
|
transformController.transformEngine.getClass().getSimpleName());
|
||||||
|
assertNotNull(transformController.probeTransform);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void startupLogsIncludeEngineMessages() throws Exception
|
||||||
|
{
|
||||||
|
StringJoiner controllerLogMessages = getLogMessagesFor(TransformController.class);
|
||||||
|
|
||||||
|
transformController.startup();
|
||||||
|
|
||||||
|
assertEquals(
|
||||||
|
"--------------------------------------------------------------------------------------------------------------------------------------------------------------\n"
|
||||||
|
+ "Startup TwoTransformers\n"
|
||||||
|
+ "Line 2 TwoTransformers\n"
|
||||||
|
+ "Line 3\n"
|
||||||
|
+ "--------------------------------------------------------------------------------------------------------------------------------------------------------------\n"
|
||||||
|
+ "Starting application components... Done",
|
||||||
|
controllerLogMessages.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
private StringJoiner getLogMessagesFor(Class classBeingLogged)
|
||||||
|
{
|
||||||
|
StringJoiner logMessages = new StringJoiner("\n");
|
||||||
|
Logger logger = (Logger) LoggerFactory.getLogger(classBeingLogged);
|
||||||
|
AppenderBase<ILoggingEvent> logAppender = new AppenderBase<>()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
protected void append(ILoggingEvent iLoggingEvent)
|
||||||
|
{
|
||||||
|
logMessages.add(iLoggingEvent.getMessage());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
logAppender.setContext((LoggerContext)LoggerFactory.getILoggerFactory());
|
||||||
|
logger.setLevel(Level.DEBUG);
|
||||||
|
logger.addAppender(logAppender);
|
||||||
|
logAppender.start();
|
||||||
|
|
||||||
|
return logMessages;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void versionEndpointIncludesAvailable() throws Exception
|
||||||
|
{
|
||||||
|
mockMvc.perform(MockMvcRequestBuilders.get(ENDPOINT_VERSION))
|
||||||
|
.andExpect(status().isOk())
|
||||||
|
.andExpect(content().string("TwoTransformers "+coreVersion+" available"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testRootEndpointReturnsTestPage() throws Exception
|
||||||
|
{
|
||||||
|
mockMvc.perform(MockMvcRequestBuilders.get(ENDPOINT_ROOT))
|
||||||
|
.andExpect(status().isOk())
|
||||||
|
.andExpect(content().string(containsString("TwoTransformers Test Page")));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testErrorEndpointReturnsErrorPage() throws Exception
|
||||||
|
{
|
||||||
|
mockMvc.perform(MockMvcRequestBuilders.get(ENDPOINT_ERROR))
|
||||||
|
.andExpect(status().isOk())
|
||||||
|
.andExpect(content().string(containsString("TwoTransformers Error Page")));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testLogEndpointReturnsLogPage() throws Exception
|
||||||
|
{
|
||||||
|
mockMvc.perform(MockMvcRequestBuilders.get(ENDPOINT_LOG))
|
||||||
|
.andExpect(status().isOk())
|
||||||
|
.andExpect(content().string(containsString("TwoTransformers Log Entries")));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testReadyEndpointReturnsSuccessful() throws Exception
|
||||||
|
{
|
||||||
|
mockMvc.perform(MockMvcRequestBuilders.get(ENDPOINT_READY))
|
||||||
|
.andExpect(status().isOk())
|
||||||
|
.andExpect(content().string(containsString("Success - ")));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testLiveEndpointReturnsSuccessful() throws Exception
|
||||||
|
{
|
||||||
|
mockMvc.perform(MockMvcRequestBuilders.get(ENDPOINT_LIVE))
|
||||||
|
.andExpect(status().isOk())
|
||||||
|
.andExpect(content().string(containsString("Success - ")));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testConfigEndpointReturnsOriginalConfigFormat() throws Exception
|
||||||
|
{
|
||||||
|
// Includes Txt2PngViaPdf as Pdf2Jpg might exist in another t-engine
|
||||||
|
// coreValue is not set as this is the default version of config
|
||||||
|
// The transformer's options should not include directAccessUrl as this is the default version of config
|
||||||
|
assertConfig(ENDPOINT_TRANSFORM_CONFIG,
|
||||||
|
"Pdf2Png,null,imageOptions\n"
|
||||||
|
+ "TxT2Pdf,null,docOptions\n"
|
||||||
|
+ "Txt2JpgViaPdf,null,imageOptions\n"
|
||||||
|
+ "Txt2PngViaPdf,null,imageOptions",
|
||||||
|
"docOptions,imageOptions");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testConfigLatestEndpointReturnsCoreVersionAndDirectAccessUrlOption() throws Exception
|
||||||
|
{
|
||||||
|
assertConfig(ENDPOINT_TRANSFORM_CONFIG_LATEST,
|
||||||
|
"Pdf2Png,"+coreVersion+",directAccessUrl,imageOptions\n"
|
||||||
|
+ "TxT2Pdf,"+coreVersion+",directAccessUrl,docOptions\n"
|
||||||
|
+ "Txt2JpgViaPdf,null,imageOptions\n"
|
||||||
|
+ "Txt2PngViaPdf,"+coreVersion+",directAccessUrl,imageOptions",
|
||||||
|
"directAccessUrl,docOptions,imageOptions");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void assertConfig(String url, String expectedTransformers, String expectedOptions) throws Exception
|
||||||
|
{
|
||||||
|
TransformConfig config = objectMapper.readValue(
|
||||||
|
mockMvc.perform(MockMvcRequestBuilders.get(url))
|
||||||
|
.andExpect(status().isOk())
|
||||||
|
.andReturn()
|
||||||
|
.getResponse()
|
||||||
|
.getContentAsString(), TransformConfig.class);
|
||||||
|
|
||||||
|
// Gets a list of transformerNames,coreVersion,optionNames
|
||||||
|
assertEquals(expectedTransformers,
|
||||||
|
config.getTransformers().stream()
|
||||||
|
.map(t -> t.getTransformerName()+","
|
||||||
|
+t.getCoreVersion()+","
|
||||||
|
+t.getTransformOptions().stream().sorted().collect(Collectors.joining(",")))
|
||||||
|
.sorted()
|
||||||
|
.collect(Collectors.joining("\n")));
|
||||||
|
|
||||||
|
assertEquals(expectedOptions,
|
||||||
|
config.getTransformOptions().keySet().stream()
|
||||||
|
.sorted()
|
||||||
|
.collect(Collectors.joining(",")));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testTransformEndpoint() throws Exception
|
||||||
|
{
|
||||||
|
mockMvc.perform(
|
||||||
|
MockMvcRequestBuilders.multipart(ENDPOINT_TRANSFORM)
|
||||||
|
.file(new MockMultipartFile("file", null, MIMETYPE_TEXT_PLAIN,
|
||||||
|
"Start".getBytes(StandardCharsets.UTF_8)))
|
||||||
|
.param(SOURCE_MIMETYPE, MIMETYPE_TEXT_PLAIN)
|
||||||
|
.param(TARGET_MIMETYPE, MIMETYPE_PDF)
|
||||||
|
.param(PAGE_REQUEST_PARAM, "1"))
|
||||||
|
.andExpect(request().asyncStarted())
|
||||||
|
.andDo(MvcResult::getAsyncResult)
|
||||||
|
.andExpect(status().isOk())
|
||||||
|
.andExpect(header().string("Content-Disposition",
|
||||||
|
"attachment; filename*=UTF-8''transform." + "pdf"))
|
||||||
|
.andExpect(content().string("Start -> TxT2Pdf(page=1)"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testTestTransformEndpointConvertsRequestParameters() throws Exception
|
||||||
|
{
|
||||||
|
// TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testInterceptOfTypeMismatchException() throws Exception
|
||||||
|
{
|
||||||
|
String message =
|
||||||
|
mockMvc.perform(
|
||||||
|
MockMvcRequestBuilders.get(ENDPOINT_TRANSFORM+"?"+FILE+"=NotaMultipartFile"))
|
||||||
|
// .param(SOURCE_MIMETYPE, MIMETYPE_TEXT_PLAIN)
|
||||||
|
// .param(TARGET_MIMETYPE, MIMETYPE_PDF)
|
||||||
|
// .param(PAGE_REQUEST_PARAM, "1")
|
||||||
|
.andExpect(status().isBadRequest())
|
||||||
|
.andReturn()
|
||||||
|
.getResponse()
|
||||||
|
.getContentAsString();
|
||||||
|
assertTrue(message.contains("Request parameter "+PAGE_REQUEST_PARAM+" is of the wrong type"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testInterceptOfMissingServletRequestParameterException() throws Exception
|
||||||
|
{
|
||||||
|
mockMvc.perform(
|
||||||
|
MockMvcRequestBuilders.multipart(ENDPOINT_TRANSFORM)
|
||||||
|
.file(new MockMultipartFile("file", null, MIMETYPE_TEXT_PLAIN,
|
||||||
|
"Start".getBytes(StandardCharsets.UTF_8))))
|
||||||
|
.andExpect(status().isBadRequest())
|
||||||
|
.andExpect(status().reason(containsString("Request parameter '"+SOURCE_MIMETYPE+"' is missing")));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testInterceptOfTransformException() throws Exception
|
||||||
|
{
|
||||||
|
mockMvc.perform(
|
||||||
|
MockMvcRequestBuilders.multipart(ENDPOINT_TRANSFORM)
|
||||||
|
.file(new MockMultipartFile("file", null, MIMETYPE_TEXT_PLAIN,
|
||||||
|
"Start".getBytes(StandardCharsets.UTF_8)))
|
||||||
|
.param(SOURCE_MIMETYPE, MIMETYPE_TEXT_PLAIN)
|
||||||
|
.param(TARGET_MIMETYPE, MIMETYPE_PDF)
|
||||||
|
.param("unknown", "1"))
|
||||||
|
// .andExpect(status().isBadRequest())
|
||||||
|
.andExpect(status().reason(containsString("No transforms were able to handle the request")));
|
||||||
|
|
||||||
|
|
||||||
|
// mockMvc.perform(
|
||||||
|
// MockMvcRequestBuilders.multipart(ENDPOINT_TRANSFORM)
|
||||||
|
// .file(new MockMultipartFile("file", null, MIMETYPE_TEXT_PLAIN,
|
||||||
|
// "Start".getBytes(StandardCharsets.UTF_8))))
|
||||||
|
// .andExpect(status().isBadRequest())
|
||||||
|
// .andExpect(status().reason(containsString("Request parameter '"+SOURCE_MIMETYPE+"' is missing")));
|
||||||
|
}
|
||||||
|
}
|
@@ -30,7 +30,7 @@ import com.google.common.collect.ImmutableList;
|
|||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
import org.alfresco.transform.base.TransformEngine;
|
import org.alfresco.transform.base.TransformEngine;
|
||||||
import org.alfresco.transform.base.probes.ProbeTestTransform;
|
import org.alfresco.transform.base.probes.ProbeTransform;
|
||||||
import org.alfresco.transform.config.SupportedSourceAndTarget;
|
import org.alfresco.transform.config.SupportedSourceAndTarget;
|
||||||
import org.alfresco.transform.config.TransformConfig;
|
import org.alfresco.transform.config.TransformConfig;
|
||||||
import org.alfresco.transform.config.TransformOptionValue;
|
import org.alfresco.transform.config.TransformOptionValue;
|
||||||
@@ -57,46 +57,16 @@ public abstract class AbstractTestTransformEngine implements TransformEngine
|
|||||||
|
|
||||||
@Override public String getStartupMessage()
|
@Override public String getStartupMessage()
|
||||||
{
|
{
|
||||||
return "Startup";
|
return "Startup "+getTransformEngineName()+
|
||||||
|
"\nLine 2 "+getTransformEngineName()+
|
||||||
|
"\nLine 3";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public TransformConfig getTransformConfig()
|
@Override public ProbeTransform getProbeTransform()
|
||||||
{
|
{
|
||||||
String docOptions = "docOptions";
|
return new ProbeTransform("quick.html", "quick.txt",
|
||||||
String imageOptions = "imageOptions";
|
|
||||||
return TransformConfig.builder()
|
|
||||||
// .withTransformOptions(ImmutableMap.of(
|
|
||||||
// docOptions, ImmutableSet.of(
|
|
||||||
// new TransformOptionValue(false, "page")),
|
|
||||||
// imageOptions, ImmutableSet.of(
|
|
||||||
// new TransformOptionValue(false, "width"),
|
|
||||||
// new TransformOptionValue(false, "height"))))
|
|
||||||
.withTransformers(ImmutableList.of(
|
|
||||||
Transformer.builder()
|
|
||||||
.withTransformerName("TxT2Pdf")
|
|
||||||
.withSupportedSourceAndTargetList(ImmutableSet.of(
|
|
||||||
SupportedSourceAndTarget.builder()
|
|
||||||
.withSourceMediaType(MIMETYPE_TEXT_PLAIN)
|
|
||||||
.withTargetMediaType(MIMETYPE_PDF)
|
|
||||||
.build()))
|
|
||||||
// .withTransformOptions(ImmutableSet.of(docOptions))
|
|
||||||
.build(),
|
|
||||||
Transformer.builder()
|
|
||||||
.withTransformerName("Pdf2Png")
|
|
||||||
.withSupportedSourceAndTargetList(ImmutableSet.of(
|
|
||||||
SupportedSourceAndTarget.builder()
|
|
||||||
.withSourceMediaType(MIMETYPE_PDF)
|
|
||||||
.withTargetMediaType(MIMETYPE_IMAGE_PNG)
|
|
||||||
.build()))
|
|
||||||
// .withTransformOptions(ImmutableSet.of(imageOptions))
|
|
||||||
.build()))
|
|
||||||
.build();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override public ProbeTestTransform getLivenessAndReadinessProbeTestTransform()
|
|
||||||
{
|
|
||||||
return new ProbeTestTransform("quick.html", "quick.txt",
|
|
||||||
MIMETYPE_HTML, MIMETYPE_TEXT_PLAIN, ImmutableMap.of(SOURCE_ENCODING, "UTF-8"),
|
MIMETYPE_HTML, MIMETYPE_TEXT_PLAIN, ImmutableMap.of(SOURCE_ENCODING, "UTF-8"),
|
||||||
119, 30, 150, 1024, 60 * 2 + 1, 60 * 2);
|
119, 30, 150, 1024, 60 * 2 + 1,
|
||||||
|
60 * 2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -26,6 +26,78 @@
|
|||||||
*/
|
*/
|
||||||
package org.alfresco.transform.base.components;
|
package org.alfresco.transform.base.components;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableList;
|
||||||
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
import com.google.common.collect.ImmutableSet;
|
||||||
|
import org.alfresco.transform.config.SupportedSourceAndTarget;
|
||||||
|
import org.alfresco.transform.config.TransformConfig;
|
||||||
|
import org.alfresco.transform.config.TransformOptionValue;
|
||||||
|
import org.alfresco.transform.config.TransformStep;
|
||||||
|
import org.alfresco.transform.config.Transformer;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static org.alfresco.transform.common.Mimetype.MIMETYPE_IMAGE_JPEG;
|
||||||
|
import static org.alfresco.transform.common.Mimetype.MIMETYPE_IMAGE_PNG;
|
||||||
|
import static org.alfresco.transform.common.Mimetype.MIMETYPE_PDF;
|
||||||
|
import static org.alfresco.transform.common.Mimetype.MIMETYPE_TEXT_PLAIN;
|
||||||
|
|
||||||
public class TestTransformEngineTwoTransformers extends AbstractTestTransformEngine
|
public class TestTransformEngineTwoTransformers extends AbstractTestTransformEngine
|
||||||
{
|
{
|
||||||
|
@Override public TransformConfig getTransformConfig()
|
||||||
|
{
|
||||||
|
String docOptions = "docOptions";
|
||||||
|
String imageOptions = "imageOptions";
|
||||||
|
return TransformConfig.builder()
|
||||||
|
.withTransformOptions(ImmutableMap.of(
|
||||||
|
docOptions, ImmutableSet.of(
|
||||||
|
new TransformOptionValue(false, "page")),
|
||||||
|
imageOptions, ImmutableSet.of(
|
||||||
|
new TransformOptionValue(false, "width"),
|
||||||
|
new TransformOptionValue(false, "height"))))
|
||||||
|
.withTransformers(ImmutableList.of(
|
||||||
|
Transformer.builder()
|
||||||
|
.withTransformerName("TxT2Pdf")
|
||||||
|
.withSupportedSourceAndTargetList(ImmutableSet.of(
|
||||||
|
SupportedSourceAndTarget.builder()
|
||||||
|
.withSourceMediaType(MIMETYPE_TEXT_PLAIN)
|
||||||
|
.withTargetMediaType(MIMETYPE_PDF)
|
||||||
|
.build()))
|
||||||
|
.withTransformOptions(ImmutableSet.of(docOptions))
|
||||||
|
.build(),
|
||||||
|
Transformer.builder()
|
||||||
|
.withTransformerName("Pdf2Png")
|
||||||
|
.withSupportedSourceAndTargetList(ImmutableSet.of(
|
||||||
|
SupportedSourceAndTarget.builder()
|
||||||
|
.withSourceMediaType(MIMETYPE_PDF)
|
||||||
|
.withTargetMediaType(MIMETYPE_IMAGE_PNG)
|
||||||
|
.build()))
|
||||||
|
.withTransformOptions(ImmutableSet.of(imageOptions))
|
||||||
|
.build(),
|
||||||
|
Transformer.builder()
|
||||||
|
.withTransformerName("Txt2PngViaPdf")
|
||||||
|
.withTransformerPipeline(List.of(
|
||||||
|
new TransformStep("TxT2Pdf", MIMETYPE_PDF),
|
||||||
|
new TransformStep("Pdf2Png", null)))
|
||||||
|
.withSupportedSourceAndTargetList(ImmutableSet.of(
|
||||||
|
SupportedSourceAndTarget.builder()
|
||||||
|
.withSourceMediaType(MIMETYPE_TEXT_PLAIN)
|
||||||
|
.withTargetMediaType(MIMETYPE_PDF)
|
||||||
|
.build()))
|
||||||
|
.withTransformOptions(ImmutableSet.of(imageOptions))
|
||||||
|
.build(),
|
||||||
|
Transformer.builder() // Unavailable until Pdf2Jpg is added
|
||||||
|
.withTransformerName("Txt2JpgViaPdf")
|
||||||
|
.withTransformerPipeline(List.of(
|
||||||
|
new TransformStep("TxT2Pdf", MIMETYPE_PDF),
|
||||||
|
new TransformStep("Pdf2Jpg", null)))
|
||||||
|
.withSupportedSourceAndTargetList(ImmutableSet.of(
|
||||||
|
SupportedSourceAndTarget.builder()
|
||||||
|
.withSourceMediaType(MIMETYPE_TEXT_PLAIN)
|
||||||
|
.withTargetMediaType(MIMETYPE_IMAGE_JPEG)
|
||||||
|
.build()))
|
||||||
|
.withTransformOptions(ImmutableSet.of(imageOptions))
|
||||||
|
.build()))
|
||||||
|
.build();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
14
engines/base/src/test/resources/logback.xml
Normal file
14
engines/base/src/test/resources/logback.xml
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<configuration>
|
||||||
|
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
|
||||||
|
<layout class="ch.qos.logback.classic.PatternLayout">
|
||||||
|
<Pattern>
|
||||||
|
%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n
|
||||||
|
</Pattern>
|
||||||
|
</layout>
|
||||||
|
</appender>
|
||||||
|
|
||||||
|
<root level="error">
|
||||||
|
<appender-ref ref="CONSOLE"/>
|
||||||
|
</root>
|
||||||
|
</configuration>
|
@@ -27,7 +27,7 @@
|
|||||||
package org.alfresco.transform.imagemagick;
|
package org.alfresco.transform.imagemagick;
|
||||||
|
|
||||||
import org.alfresco.transform.base.TransformEngine;
|
import org.alfresco.transform.base.TransformEngine;
|
||||||
import org.alfresco.transform.base.probes.ProbeTestTransform;
|
import org.alfresco.transform.base.probes.ProbeTransform;
|
||||||
import org.alfresco.transform.common.TransformConfigResourceReader;
|
import org.alfresco.transform.common.TransformConfigResourceReader;
|
||||||
import org.alfresco.transform.config.TransformConfig;
|
import org.alfresco.transform.config.TransformConfig;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@@ -66,9 +66,9 @@ public class ImageMagickTransformEngine implements TransformEngine
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ProbeTestTransform getLivenessAndReadinessProbeTestTransform()
|
public ProbeTransform getProbeTransform()
|
||||||
{
|
{
|
||||||
return new ProbeTestTransform("quick.jpg", "quick.png",
|
return new ProbeTransform("quick.jpg", "quick.png",
|
||||||
MIMETYPE_IMAGE_JPEG, MIMETYPE_IMAGE_PNG, Collections.emptyMap(),
|
MIMETYPE_IMAGE_JPEG, MIMETYPE_IMAGE_PNG, Collections.emptyMap(),
|
||||||
35593, 1024, 150, 1024, 60 * 15 + 1, 60 * 15);
|
35593, 1024, 150, 1024, 60 * 15 + 1, 60 * 15);
|
||||||
}
|
}
|
||||||
|
@@ -27,7 +27,7 @@
|
|||||||
package org.alfresco.transform.libreoffice;
|
package org.alfresco.transform.libreoffice;
|
||||||
|
|
||||||
import org.alfresco.transform.base.TransformEngine;
|
import org.alfresco.transform.base.TransformEngine;
|
||||||
import org.alfresco.transform.base.probes.ProbeTestTransform;
|
import org.alfresco.transform.base.probes.ProbeTransform;
|
||||||
import org.alfresco.transform.common.TransformConfigResourceReader;
|
import org.alfresco.transform.common.TransformConfigResourceReader;
|
||||||
import org.alfresco.transform.config.TransformConfig;
|
import org.alfresco.transform.config.TransformConfig;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@@ -67,9 +67,9 @@ public class LibreOfficeTransformEngine implements TransformEngine
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ProbeTestTransform getLivenessAndReadinessProbeTestTransform()
|
public ProbeTransform getProbeTransform()
|
||||||
{
|
{
|
||||||
return new ProbeTestTransform("quick.doc", "quick.pdf",
|
return new ProbeTransform("quick.doc", "quick.pdf",
|
||||||
MIMETYPE_WORD, MIMETYPE_PDF, Collections.emptyMap(),
|
MIMETYPE_WORD, MIMETYPE_PDF, Collections.emptyMap(),
|
||||||
11817, 1024, 150, 10240, 60 * 30 + 1, 60 * 15 + 20);
|
11817, 1024, 150, 10240, 60 * 30 + 1, 60 * 15 + 20);
|
||||||
}
|
}
|
||||||
|
@@ -28,7 +28,7 @@ package org.alfresco.transform.misc;
|
|||||||
|
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
import org.alfresco.transform.base.TransformEngine;
|
import org.alfresco.transform.base.TransformEngine;
|
||||||
import org.alfresco.transform.base.probes.ProbeTestTransform;
|
import org.alfresco.transform.base.probes.ProbeTransform;
|
||||||
import org.alfresco.transform.common.TransformConfigResourceReader;
|
import org.alfresco.transform.common.TransformConfigResourceReader;
|
||||||
import org.alfresco.transform.config.TransformConfig;
|
import org.alfresco.transform.config.TransformConfig;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@@ -71,9 +71,9 @@ public class MiscTransformEngine implements TransformEngine
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ProbeTestTransform getLivenessAndReadinessProbeTestTransform()
|
public ProbeTransform getProbeTransform()
|
||||||
{
|
{
|
||||||
return new ProbeTestTransform("quick.html", "quick.txt",
|
return new ProbeTransform("quick.html", "quick.txt",
|
||||||
MIMETYPE_HTML, MIMETYPE_TEXT_PLAIN, transformOptions,
|
MIMETYPE_HTML, MIMETYPE_TEXT_PLAIN, transformOptions,
|
||||||
119, 30, 150, 1024, 60 * 2 + 1, 60 * 2);
|
119, 30, 150, 1024, 60 * 2 + 1, 60 * 2);
|
||||||
}
|
}
|
||||||
|
@@ -27,7 +27,7 @@
|
|||||||
package org.alfresco.transform.pdfrenderer;
|
package org.alfresco.transform.pdfrenderer;
|
||||||
|
|
||||||
import org.alfresco.transform.base.TransformEngine;
|
import org.alfresco.transform.base.TransformEngine;
|
||||||
import org.alfresco.transform.base.probes.ProbeTestTransform;
|
import org.alfresco.transform.base.probes.ProbeTransform;
|
||||||
import org.alfresco.transform.common.TransformConfigResourceReader;
|
import org.alfresco.transform.common.TransformConfigResourceReader;
|
||||||
import org.alfresco.transform.config.TransformConfig;
|
import org.alfresco.transform.config.TransformConfig;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@@ -65,9 +65,9 @@ public class PdfRendererTransformEngine implements TransformEngine
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ProbeTestTransform getLivenessAndReadinessProbeTestTransform()
|
public ProbeTransform getProbeTransform()
|
||||||
{
|
{
|
||||||
return new ProbeTestTransform("quick.pdf", "quick.png",
|
return new ProbeTransform("quick.pdf", "quick.png",
|
||||||
MIMETYPE_PDF, MIMETYPE_IMAGE_PNG, Collections.emptyMap(),
|
MIMETYPE_PDF, MIMETYPE_IMAGE_PNG, Collections.emptyMap(),
|
||||||
7455, 1024, 150, 10240, 60 * 20 + 1, 60 * 15 - 15);
|
7455, 1024, 150, 10240, 60 * 20 + 1, 60 * 15 - 15);
|
||||||
}
|
}
|
||||||
|
@@ -27,7 +27,7 @@
|
|||||||
package org.alfresco.transform.tika;
|
package org.alfresco.transform.tika;
|
||||||
|
|
||||||
import org.alfresco.transform.base.TransformEngine;
|
import org.alfresco.transform.base.TransformEngine;
|
||||||
import org.alfresco.transform.base.probes.ProbeTestTransform;
|
import org.alfresco.transform.base.probes.ProbeTransform;
|
||||||
import org.alfresco.transform.common.TransformConfigResourceReader;
|
import org.alfresco.transform.common.TransformConfigResourceReader;
|
||||||
import org.alfresco.transform.config.TransformConfig;
|
import org.alfresco.transform.config.TransformConfig;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@@ -66,9 +66,9 @@ public class TikaTransformEngine implements TransformEngine
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ProbeTestTransform getLivenessAndReadinessProbeTestTransform()
|
public ProbeTransform getProbeTransform()
|
||||||
{
|
{
|
||||||
return new ProbeTestTransform("quick.pdf", "quick.txt",
|
return new ProbeTransform("quick.pdf", "quick.txt",
|
||||||
MIMETYPE_PDF, MIMETYPE_TEXT_PLAIN, Collections.emptyMap(),
|
MIMETYPE_PDF, MIMETYPE_TEXT_PLAIN, Collections.emptyMap(),
|
||||||
60, 16, 400, 10240, 60 * 30 + 1, 60 * 15 + 20);
|
60, 16, 400, 10240, 60 * 30 + 1, 60 * 15 + 20);
|
||||||
}
|
}
|
||||||
|
@@ -30,7 +30,7 @@ import org.alfresco.transform.base.AbstractBaseTest;
|
|||||||
import org.alfresco.transform.base.executors.RuntimeExec;
|
import org.alfresco.transform.base.executors.RuntimeExec;
|
||||||
import org.alfresco.transform.base.model.FileRefEntity;
|
import org.alfresco.transform.base.model.FileRefEntity;
|
||||||
import org.alfresco.transform.base.model.FileRefResponse;
|
import org.alfresco.transform.base.model.FileRefResponse;
|
||||||
import org.alfresco.transform.base.probes.ProbeTestTransform;
|
import org.alfresco.transform.base.probes.ProbeTransform;
|
||||||
import org.alfresco.transform.client.model.TransformReply;
|
import org.alfresco.transform.client.model.TransformReply;
|
||||||
import org.alfresco.transform.client.model.TransformRequest;
|
import org.alfresco.transform.client.model.TransformRequest;
|
||||||
import org.apache.poi.ooxml.POIXMLProperties;
|
import org.apache.poi.ooxml.POIXMLProperties;
|
||||||
@@ -265,9 +265,9 @@ public class TikaTest extends AbstractBaseTest
|
|||||||
public void testImmutableEmptyMap()
|
public void testImmutableEmptyMap()
|
||||||
{
|
{
|
||||||
// See ACS-373
|
// See ACS-373
|
||||||
ProbeTestTransform probeTestTransform = getProbeTestTransform();
|
ProbeTransform probeTransform = getProbeTestTransform();
|
||||||
ReflectionTestUtils.setField(probeTestTransform, "livenessTransformEnabled", true);
|
ReflectionTestUtils.setField(probeTransform, "livenessTransformEnabled", true);
|
||||||
probeTestTransform.doTransformOrNothing(httpServletRequest, true, controller);
|
probeTransform.doTransformOrNothing(httpServletRequest, true, controller);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@@ -80,6 +80,9 @@ public interface RequestParamMap
|
|||||||
String ENDPOINT_TEST = "/test";
|
String ENDPOINT_TEST = "/test";
|
||||||
String ENDPOINT_TRANSFORM_CONFIG = "/transform/config";
|
String ENDPOINT_TRANSFORM_CONFIG = "/transform/config";
|
||||||
String ENDPOINT_TRANSFORM_CONFIG_LATEST = ENDPOINT_TRANSFORM_CONFIG + "?" + CONFIG_VERSION + "=" + CONFIG_VERSION_LATEST;
|
String ENDPOINT_TRANSFORM_CONFIG_LATEST = ENDPOINT_TRANSFORM_CONFIG + "?" + CONFIG_VERSION + "=" + CONFIG_VERSION_LATEST;
|
||||||
|
String ENDPOINT_VERSION = "/version";
|
||||||
|
String ENDPOINT_READY = "/ready";
|
||||||
|
String ENDPOINT_LIVE = "/live";
|
||||||
String ENDPOINT_ERROR = "/error";
|
String ENDPOINT_ERROR = "/error";
|
||||||
String ENDPOINT_LOG = "/log";
|
String ENDPOINT_LOG = "/log";
|
||||||
String ENDPOINT_ROOT = "/";
|
String ENDPOINT_ROOT = "/";
|
||||||
|
@@ -52,6 +52,11 @@ public enum CoreFunction
|
|||||||
return comparableVersion.compareTo(fromVersion) >= 0 && comparableVersion.compareTo(toVersion) <= 0;
|
return comparableVersion.compareTo(fromVersion) >= 0 && comparableVersion.compareTo(toVersion) <= 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String standardizeCoreVersion(String version)
|
||||||
|
{
|
||||||
|
return newComparableVersion(version, NO_VERSION).toString();
|
||||||
|
}
|
||||||
|
|
||||||
CoreFunction(String fromVersion, String toVersion)
|
CoreFunction(String fromVersion, String toVersion)
|
||||||
{
|
{
|
||||||
this.fromVersion = newComparableVersion(fromVersion, NO_VERSION);
|
this.fromVersion = newComparableVersion(fromVersion, NO_VERSION);
|
||||||
|
@@ -67,14 +67,15 @@ public class CoreVersionDecorator
|
|||||||
Set.of(new TransformOptionValue(false, DIRECT_ACCESS_URL));
|
Set.of(new TransformOptionValue(false, DIRECT_ACCESS_URL));
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a {@link TransformConfig} that includes or excludes the {@code coreVersion} field.
|
* Returns a new {@link TransformConfig} that includes or excludes the {@code coreVersion} field and
|
||||||
|
* associated elements like directAccessUrl.
|
||||||
*/
|
*/
|
||||||
public static TransformConfig setOrClearCoreVersion(TransformConfig transformConfig, int configVersion)
|
public static TransformConfig setOrClearCoreVersion(TransformConfig transformConfig, int configVersion)
|
||||||
{
|
{
|
||||||
boolean includeCoreVersion = configVersion >= 2;
|
boolean includeCoreVersion = configVersion >= 2;
|
||||||
|
|
||||||
Map<String, Set<TransformOption>> transformOptions = new HashMap<>(transformConfig.getTransformOptions());
|
Map<String, Set<TransformOption>> transformOptions = new HashMap<>(transformConfig.getTransformOptions());
|
||||||
return TransformConfig.builder()
|
transformConfig = TransformConfig.builder()
|
||||||
// We may need to create new Transformers as we must not change the original.
|
// We may need to create new Transformers as we must not change the original.
|
||||||
.withTransformers(transformConfig.getTransformers().stream()
|
.withTransformers(transformConfig.getTransformers().stream()
|
||||||
.map(transformer -> {
|
.map(transformer -> {
|
||||||
@@ -85,7 +86,7 @@ public class CoreVersionDecorator
|
|||||||
.withCoreVersion(includeCoreVersion ? transformer.getCoreVersion() : null)
|
.withCoreVersion(includeCoreVersion ? transformer.getCoreVersion() : null)
|
||||||
.withTransformOptions(setOrClearCoreTransformOptions(
|
.withTransformOptions(setOrClearCoreTransformOptions(
|
||||||
includeCoreVersion ? transformer.getCoreVersion() : null,
|
includeCoreVersion ? transformer.getCoreVersion() : null,
|
||||||
transformOptions, transformer.getTransformOptions()))
|
transformer.getTransformOptions()))
|
||||||
// Original values
|
// Original values
|
||||||
.withTransformerName(transformer.getTransformerName())
|
.withTransformerName(transformer.getTransformerName())
|
||||||
.withTransformerPipeline(transformer.getTransformerPipeline())
|
.withTransformerPipeline(transformer.getTransformerPipeline())
|
||||||
@@ -104,19 +105,20 @@ public class CoreVersionDecorator
|
|||||||
.withOverrideSupported(transformConfig.getOverrideSupported())
|
.withOverrideSupported(transformConfig.getOverrideSupported())
|
||||||
.withSupportedDefaults(transformConfig.getSupportedDefaults())
|
.withSupportedDefaults(transformConfig.getSupportedDefaults())
|
||||||
.build();
|
.build();
|
||||||
|
addOrRemoveDirectAccessUrlOption(transformConfig.getTransformOptions(), transformConfig.getTransformers());
|
||||||
|
return transformConfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setCoreVersionOnSingleStepTransformers(TransformConfig transformConfig, String coreVersion)
|
public static void setCoreVersionOnSingleStepTransformers(TransformConfig transformConfig, String coreVersion)
|
||||||
{
|
{
|
||||||
Map<String, Set<TransformOption>> transformOptions = transformConfig.getTransformOptions();
|
|
||||||
List<Transformer> transformers = transformConfig.getTransformers();
|
List<Transformer> transformers = transformConfig.getTransformers();
|
||||||
transformers.stream()
|
transformers.stream()
|
||||||
.filter(CoreVersionDecorator::isSingleStep)
|
.filter(CoreVersionDecorator::isSingleStep)
|
||||||
.forEach(transformer -> {
|
.forEach(transformer -> {
|
||||||
transformer.setCoreVersion(coreVersion);
|
transformer.setCoreVersion(coreVersion);
|
||||||
transformer.setTransformOptions(setOrClearCoreTransformOptions(coreVersion,
|
transformer.setTransformOptions(setOrClearCoreTransformOptions(coreVersion, transformer.getTransformOptions()));
|
||||||
transformOptions, transformer.getTransformOptions()));
|
|
||||||
});
|
});
|
||||||
|
addOrRemoveDirectAccessUrlOption(transformConfig.getTransformOptions(), transformers);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -147,33 +149,43 @@ public class CoreVersionDecorator
|
|||||||
String coreVersion = NO_VERSION.equals(minCoreVersion) ? null : minCoreVersion.toString();
|
String coreVersion = NO_VERSION.equals(minCoreVersion) ? null : minCoreVersion.toString();
|
||||||
transformer.setCoreVersion(coreVersion);
|
transformer.setCoreVersion(coreVersion);
|
||||||
transformer.setTransformOptions(setOrClearCoreTransformOptions(transformer.getCoreVersion(),
|
transformer.setTransformOptions(setOrClearCoreTransformOptions(transformer.getCoreVersion(),
|
||||||
transformOptions, transformer.getTransformOptions()));
|
transformer.getTransformOptions()));
|
||||||
});
|
});
|
||||||
|
addOrRemoveDirectAccessUrlOption(transformOptions, transformers);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Set<String> setOrClearCoreTransformOptions(String coreVersion, Map<String,
|
private static Set<String> setOrClearCoreTransformOptions(String coreVersion, Set<String> transformerTransformOptions)
|
||||||
Set<TransformOption>> transformOptions, Set<String> transformerTransformOptions)
|
|
||||||
{
|
{
|
||||||
// If we have more options being added in future, consider adding an interface that will be implemented by
|
// If we have more options being added in the future, consider adding an interface that will be implemented by
|
||||||
// different implementations for each coreVersion and then iterate over them here.
|
// different implementations for each coreVersion and then iterate over them here.
|
||||||
transformerTransformOptions = new HashSet<>(transformerTransformOptions);
|
transformerTransformOptions = new HashSet<>(transformerTransformOptions);
|
||||||
if (CoreFunction.DIRECT_ACCESS_URL.isSupported(coreVersion))
|
if (CoreFunction.DIRECT_ACCESS_URL.isSupported(coreVersion))
|
||||||
{
|
{
|
||||||
// Added to the Transform config if any Transformers support it.
|
|
||||||
transformOptions.put(DIRECT_ACCESS_URL, DIRECT_ACCESS_URL_TRANSFORM_OPTIONS);
|
|
||||||
|
|
||||||
// Add DIRECT_ACCESS_URL to a copy of this Transformer's transform options.
|
// Add DIRECT_ACCESS_URL to a copy of this Transformer's transform options.
|
||||||
transformerTransformOptions.add(DIRECT_ACCESS_URL);
|
transformerTransformOptions.add(DIRECT_ACCESS_URL);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
transformOptions.remove(DIRECT_ACCESS_URL);
|
|
||||||
transformerTransformOptions.remove(DIRECT_ACCESS_URL);
|
transformerTransformOptions.remove(DIRECT_ACCESS_URL);
|
||||||
}
|
}
|
||||||
|
|
||||||
return transformerTransformOptions;
|
return transformerTransformOptions;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void addOrRemoveDirectAccessUrlOption(Map<String, Set<TransformOption>> transformOptions,
|
||||||
|
List<Transformer> transformers)
|
||||||
|
{
|
||||||
|
if (transformers.stream()
|
||||||
|
.anyMatch(transformer -> CoreFunction.DIRECT_ACCESS_URL.isSupported(transformer.getCoreVersion())))
|
||||||
|
{
|
||||||
|
transformOptions.put(DIRECT_ACCESS_URL, DIRECT_ACCESS_URL_TRANSFORM_OPTIONS);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
transformOptions.remove(DIRECT_ACCESS_URL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static boolean isSingleStep(Transformer transformer)
|
private static boolean isSingleStep(Transformer transformer)
|
||||||
{
|
{
|
||||||
return (transformer.getTransformerFailover() == null || transformer.getTransformerFailover().isEmpty()) &&
|
return (transformer.getTransformerFailover() == null || transformer.getTransformerFailover().isEmpty()) &&
|
||||||
|
@@ -56,7 +56,7 @@ public class TransformConfig
|
|||||||
|
|
||||||
public void setTransformOptions(Map<String, Set<TransformOption>> transformOptions)
|
public void setTransformOptions(Map<String, Set<TransformOption>> transformOptions)
|
||||||
{
|
{
|
||||||
this.transformOptions = transformOptions;
|
this.transformOptions = new HashMap<>(transformOptions);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Transformer> getTransformers()
|
public List<Transformer> getTransformers()
|
||||||
@@ -143,7 +143,7 @@ public class TransformConfig
|
|||||||
|
|
||||||
public Builder withTransformOptions(final Map<String, Set<TransformOption>> transformOptions)
|
public Builder withTransformOptions(final Map<String, Set<TransformOption>> transformOptions)
|
||||||
{
|
{
|
||||||
transformConfig.transformOptions = transformOptions;
|
transformConfig.setTransformOptions(transformOptions);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -212,7 +212,7 @@ public class Transformer
|
|||||||
|
|
||||||
public Builder withCoreVersion(final String coreVersion)
|
public Builder withCoreVersion(final String coreVersion)
|
||||||
{
|
{
|
||||||
transformer.coreVersion = coreVersion;
|
transformer.setCoreVersion(coreVersion);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -32,6 +32,7 @@ import java.util.Set;
|
|||||||
|
|
||||||
import static org.alfresco.transform.common.RequestParamMap.CONFIG_VERSION_DEFAULT;
|
import static org.alfresco.transform.common.RequestParamMap.CONFIG_VERSION_DEFAULT;
|
||||||
import static org.alfresco.transform.common.RequestParamMap.DIRECT_ACCESS_URL;
|
import static org.alfresco.transform.common.RequestParamMap.DIRECT_ACCESS_URL;
|
||||||
|
import static org.alfresco.transform.config.CoreFunction.standardizeCoreVersion;
|
||||||
import static org.alfresco.transform.config.CoreVersionDecorator.CONFIG_VERSION_INCLUDES_CORE_VERSION;
|
import static org.alfresco.transform.config.CoreVersionDecorator.CONFIG_VERSION_INCLUDES_CORE_VERSION;
|
||||||
import static org.alfresco.transform.config.CoreVersionDecorator.setCoreVersionOnMultiStepTransformers;
|
import static org.alfresco.transform.config.CoreVersionDecorator.setCoreVersionOnMultiStepTransformers;
|
||||||
import static org.alfresco.transform.config.CoreVersionDecorator.setCoreVersionOnSingleStepTransformers;
|
import static org.alfresco.transform.config.CoreVersionDecorator.setCoreVersionOnSingleStepTransformers;
|
||||||
@@ -213,4 +214,13 @@ class CoreVersionDecoratorTest
|
|||||||
true, true),
|
true, true),
|
||||||
setOrClearCoreVersion(transformConfigWithCoreVersion, CONFIG_VERSION_INCLUDES_CORE_VERSION));
|
setOrClearCoreVersion(transformConfigWithCoreVersion, CONFIG_VERSION_INCLUDES_CORE_VERSION));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void standardizeCoreVersionTest()
|
||||||
|
{
|
||||||
|
assertEquals("2.5.7", standardizeCoreVersion("2.5.7"));
|
||||||
|
assertEquals("2.5.7", standardizeCoreVersion("2.5.7-SNAPSHOT"));
|
||||||
|
assertEquals("2", standardizeCoreVersion("2"));
|
||||||
|
assertEquals("2.5.7", standardizeCoreVersion("2.5.7-A-SNAPSHOT"));
|
||||||
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user