mirror of
https://github.com/Alfresco/alfresco-transform-core.git
synced 2025-10-08 14:51:18 +00:00
MNT-24883 base engine changes to maintain source file name
This commit is contained in:
@@ -26,35 +26,18 @@
|
||||
*/
|
||||
package org.alfresco.transform.base.transform;
|
||||
|
||||
import org.alfresco.transform.base.TransformManager;
|
||||
import org.alfresco.transform.base.sfs.SharedFileStoreClient;
|
||||
import org.alfresco.transform.base.messaging.TransformReplySender;
|
||||
import org.alfresco.transform.base.model.FileRefResponse;
|
||||
import org.alfresco.transform.base.probes.ProbeTransform;
|
||||
import org.alfresco.transform.base.registry.CustomTransformers;
|
||||
import org.alfresco.transform.client.model.InternalContext;
|
||||
import org.alfresco.transform.client.model.TransformReply;
|
||||
import org.alfresco.transform.client.model.TransformRequest;
|
||||
import org.alfresco.transform.common.ExtensionService;
|
||||
import org.alfresco.transform.exceptions.TransformException;
|
||||
import org.alfresco.transform.common.TransformerDebug;
|
||||
import org.alfresco.transform.messages.TransformRequestValidator;
|
||||
import org.alfresco.transform.messages.TransformStack;
|
||||
import org.alfresco.transform.registry.TransformServiceRegistry;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.validation.DirectFieldBindingResult;
|
||||
import org.springframework.validation.Errors;
|
||||
import org.springframework.web.client.HttpClientErrorException;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import static java.util.stream.Collectors.joining;
|
||||
|
||||
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.alfresco.transform.base.fs.FileManager.createAttachment;
|
||||
import static org.alfresco.transform.base.fs.FileManager.createTargetFile;
|
||||
import static org.alfresco.transform.base.fs.FileManager.getDirectAccessUrlInputStream;
|
||||
import static org.alfresco.transform.base.fs.FileManager.getMultipartFileInputStream;
|
||||
import static org.alfresco.transform.common.RequestParamMap.DIRECT_ACCESS_URL;
|
||||
|
||||
import jakarta.jms.Destination;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.File;
|
||||
@@ -67,16 +50,35 @@ import java.io.OutputStream;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import jakarta.jms.Destination;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
|
||||
import static java.util.stream.Collectors.joining;
|
||||
import static org.alfresco.transform.base.fs.FileManager.createAttachment;
|
||||
import static org.alfresco.transform.base.fs.FileManager.createTargetFile;
|
||||
import static org.alfresco.transform.base.fs.FileManager.getDirectAccessUrlInputStream;
|
||||
import static org.alfresco.transform.base.fs.FileManager.getMultipartFileInputStream;
|
||||
import static org.alfresco.transform.common.RequestParamMap.DIRECT_ACCESS_URL;
|
||||
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 org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.validation.DirectFieldBindingResult;
|
||||
import org.springframework.validation.Errors;
|
||||
import org.springframework.web.client.HttpClientErrorException;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import org.alfresco.transform.base.messaging.TransformReplySender;
|
||||
import org.alfresco.transform.base.model.FileRefResponse;
|
||||
import org.alfresco.transform.base.probes.ProbeTransform;
|
||||
import org.alfresco.transform.base.registry.CustomTransformers;
|
||||
import org.alfresco.transform.base.sfs.SharedFileStoreClient;
|
||||
import org.alfresco.transform.client.model.InternalContext;
|
||||
import org.alfresco.transform.client.model.TransformReply;
|
||||
import org.alfresco.transform.client.model.TransformRequest;
|
||||
import org.alfresco.transform.common.ExtensionService;
|
||||
import org.alfresco.transform.common.TransformerDebug;
|
||||
import org.alfresco.transform.exceptions.TransformException;
|
||||
import org.alfresco.transform.messages.TransformRequestValidator;
|
||||
import org.alfresco.transform.messages.TransformStack;
|
||||
import org.alfresco.transform.registry.TransformServiceRegistry;
|
||||
|
||||
/**
|
||||
* Handles the transform requests from either http or a message.
|
||||
@@ -102,8 +104,6 @@ public class TransformHandler
|
||||
private TransformerDebug transformerDebug;
|
||||
|
||||
private final AtomicInteger httpRequestCount = new AtomicInteger(1);
|
||||
@Autowired
|
||||
private TransformManager transformManager;
|
||||
|
||||
public ResponseEntity<Resource> handleHttpRequest(HttpServletRequest request,
|
||||
MultipartFile sourceMultipartFile, String sourceMimetype, String targetMimetype,
|
||||
@@ -112,9 +112,8 @@ public class TransformHandler
|
||||
AtomicReference<ResponseEntity<Resource>> responseEntity = new AtomicReference<>();
|
||||
|
||||
new ProcessHandler(sourceMimetype, targetMimetype, requestParameters,
|
||||
"e" + httpRequestCount.getAndIncrement(), transformRegistry,
|
||||
transformerDebug, probeTransform, customTransformers)
|
||||
{
|
||||
"e" + httpRequestCount.getAndIncrement(), transformRegistry,
|
||||
transformerDebug, probeTransform, customTransformers) {
|
||||
@Override
|
||||
protected void init() throws IOException
|
||||
{
|
||||
@@ -146,7 +145,7 @@ public class TransformHandler
|
||||
protected void sendTransformResponse(TransformManagerImpl transformManager)
|
||||
{
|
||||
String extension = ExtensionService.getExtensionForTargetMimetype(targetMimetype, sourceMimetype);
|
||||
responseEntity.set(createAttachment("transform."+extension, transformManager.getTargetFile()));
|
||||
responseEntity.set(createAttachment("transform." + extension, transformManager.getTargetFile()));
|
||||
}
|
||||
}.handleTransformRequest();
|
||||
|
||||
@@ -154,12 +153,11 @@ public class TransformHandler
|
||||
}
|
||||
|
||||
public void handleProbeRequest(String sourceMimetype, String targetMimetype, Map<String, String> transformOptions,
|
||||
File sourceFile, File targetFile, ProbeTransform probeTransform)
|
||||
File sourceFile, File targetFile, ProbeTransform probeTransform)
|
||||
{
|
||||
new ProcessHandler(sourceMimetype, targetMimetype, transformOptions,
|
||||
"p" + httpRequestCount.getAndIncrement(), transformRegistry,
|
||||
transformerDebug, probeTransform, customTransformers)
|
||||
{
|
||||
"p" + httpRequestCount.getAndIncrement(), transformRegistry,
|
||||
transformerDebug, probeTransform, customTransformers) {
|
||||
@Override
|
||||
protected void init() throws IOException
|
||||
{
|
||||
@@ -190,13 +188,12 @@ public class TransformHandler
|
||||
}
|
||||
|
||||
public TransformReply handleMessageRequest(TransformRequest request, Long timeout, Destination replyToQueue,
|
||||
ProbeTransform probeTransform)
|
||||
ProbeTransform probeTransform)
|
||||
{
|
||||
TransformReply reply = createBasicTransformReply(request);
|
||||
new ProcessHandler(request.getSourceMediaType(), request.getTargetMediaType(),
|
||||
request.getTransformRequestOptions(),"unset", transformRegistry,
|
||||
transformerDebug, probeTransform, customTransformers)
|
||||
{
|
||||
request.getTransformRequestOptions(), "unset", transformRegistry,
|
||||
transformerDebug, probeTransform, customTransformers) {
|
||||
@Override
|
||||
protected void init() throws IOException
|
||||
{
|
||||
@@ -341,12 +338,12 @@ public class TransformHandler
|
||||
}
|
||||
|
||||
private InputStream getInputStreamForHandleHttpRequest(Map<String, String> requestParameters,
|
||||
MultipartFile sourceMultipartFile)
|
||||
MultipartFile sourceMultipartFile)
|
||||
{
|
||||
final String directUrl = requestParameters.getOrDefault(DIRECT_ACCESS_URL, "");
|
||||
return new BufferedInputStream(directUrl.isBlank()
|
||||
? getMultipartFileInputStream(sourceMultipartFile)
|
||||
: getDirectAccessUrlInputStream(directUrl));
|
||||
? getMultipartFileInputStream(sourceMultipartFile)
|
||||
: getDirectAccessUrlInputStream(directUrl));
|
||||
}
|
||||
|
||||
private InputStream getInputStreamForHandleProbeRequest(File sourceFile)
|
||||
@@ -423,8 +420,8 @@ public class TransformHandler
|
||||
{
|
||||
e = e.getCause();
|
||||
sb.append(", cause ")
|
||||
.append(e.getClass().getSimpleName()).append(": ")
|
||||
.append(e.getMessage());
|
||||
.append(e.getClass().getSimpleName()).append(": ")
|
||||
.append(e.getMessage());
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
|
@@ -59,7 +59,6 @@ public class TransformManagerImpl implements TransformManager
|
||||
private String targetMimetype;
|
||||
private File sourceFile;
|
||||
private File targetFile;
|
||||
|
||||
private boolean keepTargetFile;
|
||||
private boolean createSourceFileCalled;
|
||||
private boolean createTargetFileCalled;
|
||||
|
@@ -29,13 +29,13 @@ package org.alfresco.transform.base.util;
|
||||
public class Util
|
||||
{
|
||||
private Util()
|
||||
{
|
||||
}
|
||||
{}
|
||||
|
||||
/**
|
||||
* Safely converts a {@link String} to an {@link Integer}
|
||||
*
|
||||
* @param param String to be converted
|
||||
* @param param
|
||||
* String to be converted
|
||||
* @return Null if param is null or converted value as {@link Integer}
|
||||
*/
|
||||
public static Integer stringToInteger(final String param)
|
||||
@@ -46,7 +46,8 @@ public class Util
|
||||
/**
|
||||
* Safely converts a {@link String} to a {@link Boolean}
|
||||
*
|
||||
* @param param String to be converted
|
||||
* @param param
|
||||
* String to be converted
|
||||
* @return Null if param is null or converted value as {@link Boolean}
|
||||
*/
|
||||
public static Boolean stringToBoolean(final String param)
|
||||
@@ -57,7 +58,8 @@ public class Util
|
||||
/**
|
||||
* Safely converts a {@link String} to a {@link Long}
|
||||
*
|
||||
* @param param String to be converted
|
||||
* @param param
|
||||
* String to be converted
|
||||
* @return Null if param is null or converted value as {@link Boolean}
|
||||
*/
|
||||
public static Long stringToLong(final String param)
|
||||
@@ -67,12 +69,13 @@ public class Util
|
||||
|
||||
/**
|
||||
* check if given file name is a doc file
|
||||
*
|
||||
* @param filename
|
||||
* @return if file is .doc*
|
||||
*/
|
||||
public static boolean isDocFile(String filename)
|
||||
{
|
||||
String extension = filename.substring(filename.lastIndexOf('.') );
|
||||
String extension = filename.substring(filename.lastIndexOf('.'));
|
||||
return extension.startsWith(".doc");
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user