MNT-24883 base engine changes to maintain source file name

This commit is contained in:
bsayan2
2025-05-23 19:32:01 +05:30
parent 8aa4c65855
commit 1187cf0d33
3 changed files with 62 additions and 63 deletions

View File

@@ -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,
@@ -113,8 +113,7 @@ public class TransformHandler
new ProcessHandler(sourceMimetype, targetMimetype, requestParameters,
"e" + httpRequestCount.getAndIncrement(), transformRegistry,
transformerDebug, probeTransform, customTransformers)
{
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();
@@ -158,8 +157,7 @@ public class TransformHandler
{
new ProcessHandler(sourceMimetype, targetMimetype, transformOptions,
"p" + httpRequestCount.getAndIncrement(), transformRegistry,
transformerDebug, probeTransform, customTransformers)
{
transformerDebug, probeTransform, customTransformers) {
@Override
protected void init() throws IOException
{
@@ -194,9 +192,8 @@ public class TransformHandler
{
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
{

View File

@@ -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;

View File

@@ -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");
}
}