mirror of
https://github.com/Alfresco/alfresco-transform-core.git
synced 2025-07-07 18:24:50 +00:00
MNT-24883 base engine changes to maintain source file name
This commit is contained in:
parent
278f1405ae
commit
b5ed905fed
@ -26,19 +26,16 @@
|
|||||||
*/
|
*/
|
||||||
package org.alfresco.transform.base.fs;
|
package org.alfresco.transform.base.fs;
|
||||||
|
|
||||||
import jakarta.servlet.http.Part;
|
import static java.nio.file.StandardCopyOption.REPLACE_EXISTING;
|
||||||
import org.alfresco.transform.base.logging.LogEntry;
|
|
||||||
import org.alfresco.transform.base.util.Util;
|
import static org.springframework.http.HttpHeaders.CONTENT_DISPOSITION;
|
||||||
import org.alfresco.transform.common.ExtensionService;
|
import static org.springframework.http.HttpStatus.BAD_REQUEST;
|
||||||
import org.alfresco.transform.exceptions.TransformException;
|
import static org.springframework.http.HttpStatus.INSUFFICIENT_STORAGE;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import static org.springframework.http.HttpStatus.INTERNAL_SERVER_ERROR;
|
||||||
import org.springframework.core.io.Resource;
|
import static org.springframework.util.StringUtils.getFilename;
|
||||||
import org.springframework.core.io.UrlResource;
|
|
||||||
import org.springframework.http.ResponseEntity;
|
import static org.alfresco.transform.common.ExtensionService.getExtensionForMimetype;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
|
||||||
import org.springframework.web.util.UriUtils;
|
|
||||||
|
|
||||||
import jakarta.servlet.http.HttpServletRequest;
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
@ -47,14 +44,20 @@ import java.net.MalformedURLException;
|
|||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
|
import jakarta.servlet.http.Part;
|
||||||
|
|
||||||
import static java.nio.file.StandardCopyOption.REPLACE_EXISTING;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import static org.alfresco.transform.common.ExtensionService.getExtensionForMimetype;
|
import org.springframework.core.io.Resource;
|
||||||
import static org.springframework.http.HttpHeaders.CONTENT_DISPOSITION;
|
import org.springframework.core.io.UrlResource;
|
||||||
import static org.springframework.http.HttpStatus.BAD_REQUEST;
|
import org.springframework.http.ResponseEntity;
|
||||||
import static org.springframework.http.HttpStatus.INSUFFICIENT_STORAGE;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
import static org.springframework.http.HttpStatus.INTERNAL_SERVER_ERROR;
|
import org.springframework.web.util.UriUtils;
|
||||||
import static org.springframework.util.StringUtils.getFilename;
|
|
||||||
|
import org.alfresco.transform.base.logging.LogEntry;
|
||||||
|
import org.alfresco.transform.base.util.Util;
|
||||||
|
import org.alfresco.transform.common.ExtensionService;
|
||||||
|
import org.alfresco.transform.exceptions.TransformException;
|
||||||
|
|
||||||
public class FileManager
|
public class FileManager
|
||||||
{
|
{
|
||||||
@ -62,8 +65,7 @@ public class FileManager
|
|||||||
public static final String TARGET_FILE = "targetFile";
|
public static final String TARGET_FILE = "targetFile";
|
||||||
|
|
||||||
private FileManager()
|
private FileManager()
|
||||||
{
|
{}
|
||||||
}
|
|
||||||
|
|
||||||
public static File createSourceFile(HttpServletRequest request, InputStream inputStream, String sourceMimetype)
|
public static File createSourceFile(HttpServletRequest request, InputStream inputStream, String sourceMimetype)
|
||||||
{
|
{
|
||||||
@ -72,7 +74,8 @@ public class FileManager
|
|||||||
|
|
||||||
String extension = "." + getExtensionForMimetype(sourceMimetype);
|
String extension = "." + getExtensionForMimetype(sourceMimetype);
|
||||||
File file;
|
File file;
|
||||||
if (request != null && request.getParts() != null) {
|
if (request != null && request.getParts() != null)
|
||||||
|
{
|
||||||
String submittedFileName = request.getParts().stream()
|
String submittedFileName = request.getParts().stream()
|
||||||
.map(Part::getSubmittedFileName)
|
.map(Part::getSubmittedFileName)
|
||||||
.findFirst()
|
.findFirst()
|
||||||
@ -99,8 +102,8 @@ public class FileManager
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static File createSourceDocFileWithSameName(HttpServletRequest request, String sourceFileName, InputStream inputStream, String sourceMimetype)
|
||||||
public static File createSourceDocFileWithSameName(HttpServletRequest request, String sourceFileName, InputStream inputStream, String sourceMimetype) {
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
File file = TempFileProvider.createTempDirForDocFile(sourceFileName);
|
File file = TempFileProvider.createTempDirForDocFile(sourceFileName);
|
||||||
@ -111,14 +114,14 @@ public class FileManager
|
|||||||
}
|
}
|
||||||
LogEntry.setSource(file.getName(), file.length());
|
LogEntry.setSource(file.getName(), file.length());
|
||||||
return file;
|
return file;
|
||||||
} catch (Exception e)
|
}
|
||||||
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
throw new TransformException(INSUFFICIENT_STORAGE, "Failed to store the source file", e);
|
throw new TransformException(INSUFFICIENT_STORAGE, "Failed to store the source file", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static File createTargetFile(HttpServletRequest request, String sourceMimetype, String targetMimetype)
|
public static File createTargetFile(HttpServletRequest request, String sourceMimetype, String targetMimetype)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
@ -239,8 +242,7 @@ public class FileManager
|
|||||||
public static class TempFileProvider
|
public static class TempFileProvider
|
||||||
{
|
{
|
||||||
private TempFileProvider()
|
private TempFileProvider()
|
||||||
{
|
{}
|
||||||
}
|
|
||||||
|
|
||||||
public static File createTempFile(final String prefix, final String suffix)
|
public static File createTempFile(final String prefix, final String suffix)
|
||||||
{
|
{
|
||||||
@ -253,7 +255,8 @@ public class FileManager
|
|||||||
{
|
{
|
||||||
throw new RuntimeException(
|
throw new RuntimeException(
|
||||||
"Failed to created temp file: \n prefix: " + prefix +
|
"Failed to created temp file: \n prefix: " + prefix +
|
||||||
"\n suffix: " + suffix + "\n directory: " + directory, e);
|
"\n suffix: " + suffix + "\n directory: " + directory,
|
||||||
|
e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,17 +21,17 @@
|
|||||||
*/
|
*/
|
||||||
package org.alfresco.transform.client.model;
|
package org.alfresco.transform.client.model;
|
||||||
|
|
||||||
import org.alfresco.transform.common.ExtensionService;
|
import static org.alfresco.transform.messages.TransformStack.PIPELINE_FLAG;
|
||||||
import org.alfresco.transform.messages.TransformStack;
|
import static org.alfresco.transform.messages.TransformStack.levelBuilder;
|
||||||
|
import static org.alfresco.transform.messages.TransformStack.setInitialTransformRequestOptions;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
import static org.alfresco.transform.messages.TransformStack.PIPELINE_FLAG;
|
import org.alfresco.transform.common.ExtensionService;
|
||||||
import static org.alfresco.transform.messages.TransformStack.levelBuilder;
|
import org.alfresco.transform.messages.TransformStack;
|
||||||
import static org.alfresco.transform.messages.TransformStack.setInitialTransformRequestOptions;
|
|
||||||
|
|
||||||
// This class is in the package org.alfresco.transform.messages in HxP because that is more readable, but in
|
// This class is in the package org.alfresco.transform.messages in HxP because that is more readable, but in
|
||||||
// org.alfresco.transform.client.model in Alfresco for backward compatibility.
|
// org.alfresco.transform.client.model in Alfresco for backward compatibility.
|
||||||
@ -161,11 +161,13 @@ public class TransformRequest implements Serializable
|
|||||||
this.internalContext = internalContext;
|
this.internalContext = internalContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getSourceFileName() {
|
public String getSourceFileName()
|
||||||
|
{
|
||||||
return sourceFileName;
|
return sourceFileName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSourceFileName(String sourceFileName) {
|
public void setSourceFileName(String sourceFileName)
|
||||||
|
{
|
||||||
this.sourceFileName = sourceFileName;
|
this.sourceFileName = sourceFileName;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -188,7 +190,8 @@ public class TransformRequest implements Serializable
|
|||||||
return Objects.hash(requestId);
|
return Objects.hash(requestId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public String toString()
|
@Override
|
||||||
|
public String toString()
|
||||||
{
|
{
|
||||||
return "TransformRequest{" +
|
return "TransformRequest{" +
|
||||||
"requestId='" + requestId + '\'' +
|
"requestId='" + requestId + '\'' +
|
||||||
@ -206,10 +209,7 @@ public class TransformRequest implements Serializable
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets up the internal context structure when a client request is initially received by the router,
|
* Sets up the internal context structure when a client request is initially received by the router, so that we don't have to keep checking if bits of it are initialised. Prior to making this call, the id, sourceMimetypes, targetMimetype, transformRequestOptions and sourceReference should have been set, if they are to be set.
|
||||||
* so that we don't have to keep checking if bits of it are initialised. Prior to making this call,
|
|
||||||
* the id, sourceMimetypes, targetMimetype, transformRequestOptions and sourceReference should have
|
|
||||||
* been set, if they are to be set.
|
|
||||||
*/
|
*/
|
||||||
public TransformRequest initialiseContextWhenReceivedByRouter()
|
public TransformRequest initialiseContextWhenReceivedByRouter()
|
||||||
{
|
{
|
||||||
@ -233,7 +233,8 @@ public class TransformRequest implements Serializable
|
|||||||
{
|
{
|
||||||
private final TransformRequest request = new TransformRequest();
|
private final TransformRequest request = new TransformRequest();
|
||||||
|
|
||||||
private Builder() {}
|
private Builder()
|
||||||
|
{}
|
||||||
|
|
||||||
public Builder withRequestId(final String requestId)
|
public Builder withRequestId(final String requestId)
|
||||||
{
|
{
|
||||||
@ -310,7 +311,8 @@ public class TransformRequest implements Serializable
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder withSourceFileName(final String sourceFileName) {
|
public Builder withSourceFileName(final String sourceFileName)
|
||||||
|
{
|
||||||
request.sourceFileName = sourceFileName;
|
request.sourceFileName = sourceFileName;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user