ATS-702/ATS-675 Change exception thrown by tranformers to TransformException

Due to the previous error handling, an incorrect status code of 200 was being produced following an error that should have caused a 400.
This commit is contained in:
David Edwards
2020-04-07 17:08:09 +01:00
parent b39f8815a3
commit 401fe68a57
8 changed files with 26 additions and 21 deletions

View File

@@ -32,6 +32,7 @@ import static org.alfresco.transformer.fs.FileManager.createAttachment;
import static org.alfresco.transformer.fs.FileManager.createSourceFile;
import static org.alfresco.transformer.fs.FileManager.createTargetFile;
import static org.alfresco.transformer.fs.FileManager.createTargetFileName;
import static org.springframework.http.HttpStatus.BAD_REQUEST;
import static org.springframework.http.HttpStatus.OK;
import static org.springframework.http.MediaType.MULTIPART_FORM_DATA_VALUE;
@@ -45,6 +46,7 @@ import java.util.Iterator;
import javax.servlet.http.HttpServletRequest;
import org.alfresco.transform.exceptions.TransformException;
import org.alfresco.transformer.logging.LogEntry;
import org.alfresco.transformer.probes.ProbeTestTransform;
import org.alfresco.transformer.transformers.AllInOneTransformer;
@@ -175,16 +177,8 @@ public class AIOController extends AbstractTransformerController
// TODO - remove this logginng
debugLogTransform("After filtering props request with: ", sourceMimetype, targetMimetype, transformOptions);
try
{
transformer.transform(sourceFile, targetFile, sourceMimetype, targetMimetype, transformOptions);
}
catch (Exception e)
{
logger.error(e.getMessage(), e);
}
transformer.transform(sourceFile, targetFile, sourceMimetype, targetMimetype, transformOptions);
final ResponseEntity<Resource> body = createAttachment(targetFilename, targetFile);
LogEntry.setTargetSize(targetFile.length());
long time = LogEntry.setStatusCodeAndMessage(OK.value(), "Success");

View File

@@ -26,8 +26,11 @@
*/
package org.alfresco.transformer.transformers;
import static org.springframework.http.HttpStatus.BAD_REQUEST;
import org.alfresco.transform.client.model.config.TransformConfig;
import org.alfresco.transform.client.model.config.TransformOption;
import org.alfresco.transform.exceptions.TransformException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -80,14 +83,14 @@ public class AllInOneTransformer implements Transformer
@Override
public void transform(File sourceFile, File targetFile, String sourceMimetype, String targetMimetype,
Map<String, String> transformOptions) throws Exception
Map<String, String> transformOptions) throws TransformException
{
String transformName = transformOptions.get(TRANSFORM_NAME_PARAMETER);
Transformer transformer = transformerTransformMapping.get(transformName);
if (transformer == null)
{
throw new Exception("No transformer mapping for : transform:" + transformName + " sourceMimetype:"
throw new TransformException(BAD_REQUEST.value(),"No transformer mapping for : transform:" + transformName + " sourceMimetype:"
+ sourceMimetype + " targetMimetype:" + targetMimetype);
}

View File

@@ -32,6 +32,7 @@ import static org.alfresco.transformer.util.Util.stringToLong;
import java.io.File;
import java.util.Map;
import org.alfresco.transform.exceptions.TransformException;
import org.alfresco.transformer.ImageMagickOptionsBuilder;
import org.alfresco.transformer.executors.ImageMagickCommandExecutor;
@@ -76,7 +77,7 @@ public class ImageMagickAdapter extends AbstractTransformer
@Override
public void transform(File sourceFile, File targetFile, String sourceMimetype, String targetMimetype,
Map<String, String> transformOptions) throws Exception
Map<String, String> transformOptions) throws TransformException
{
final String options = ImageMagickOptionsBuilder

View File

@@ -29,6 +29,7 @@ package org.alfresco.transformer.transformers;
import java.io.File;
import java.util.Map;
import org.alfresco.transform.exceptions.TransformException;
import org.alfresco.transformer.executors.LibreOfficeJavaExecutor;
public class LibreOfficeAdapter extends AbstractTransformer
@@ -50,7 +51,7 @@ public class LibreOfficeAdapter extends AbstractTransformer
@Override
public void transform(File sourceFile, File targetFile, String sourceMimetype, String targetMimetype,
Map<String, String> transformOptions) throws Exception
Map<String, String> transformOptions) throws TransformException
{
javaExecutor.call(sourceFile, targetFile);
}

View File

@@ -29,6 +29,8 @@ package org.alfresco.transformer.transformers;
import java.io.File;
import java.util.Map;
import org.alfresco.transform.exceptions.TransformException;
public class MiscAdapter extends AbstractTransformer
{
private static final String CONFIG_PREFIX = "misc";
@@ -48,8 +50,8 @@ public class MiscAdapter extends AbstractTransformer
}
@Override
public void transform(File sourceFile, File targetFile, String sourceMimetype, String targetMimetype, Map<String,
String> transformOptions) throws Exception
public void transform(File sourceFile, File targetFile, String sourceMimetype, String targetMimetype,
Map<String,String> transformOptions) throws TransformException
{
String transformerName = transformOptions.get(TRANSFORM_NAME_PARAMETER);
miscSelectingTransformer.transform(transformerName, sourceFile, targetFile,

View File

@@ -32,6 +32,7 @@ import java.io.File;
import java.util.Map;
import org.alfresco.transformer.executors.PdfRendererCommandExecutor;
import org.alfresco.transform.exceptions.TransformException;
import org.alfresco.transformer.PdfRendererOptionsBuilder;
@@ -62,8 +63,8 @@ public class PdfRendererAdapter extends AbstractTransformer
}
@Override
public void transform(File sourceFile, File targetFile, String sourceMimetype, String targetMimetype,
Map<String, String> transformOptions) throws Exception
public void transform(File sourceFile, File targetFile, String sourceMimetype, String targetMimetype,
Map<String, String> transformOptions) throws TransformException
{
final String options = PdfRendererOptionsBuilder

View File

@@ -26,6 +26,7 @@
*/
package org.alfresco.transformer.transformers;
import org.alfresco.transform.exceptions.TransformException;
import org.alfresco.transformer.executors.TikaJavaExecutor;
import java.io.File;
@@ -55,7 +56,8 @@ public class TikaAdapter extends AbstractTransformer
}
@Override
public void transform(File sourceFile, File targetFile, String sourceMimetype, String targetMimetype, Map<String, String> transformOptions) throws Exception
public void transform(File sourceFile, File targetFile, String sourceMimetype, String targetMimetype,
Map<String, String> transformOptions) throws TransformException
{
final String transform = transformOptions.get(TRANSFORM_NAME_PARAMETER);

View File

@@ -28,6 +28,7 @@ package org.alfresco.transformer.transformers;
import org.alfresco.transform.client.model.config.TransformConfig;
import org.alfresco.transform.exceptions.TransformException;
import java.io.File;
import java.util.Map;
@@ -58,10 +59,10 @@ public interface Transformer
* @param sourceFile
* @param targetFile
* @param transformOptions
* @throws Exception
* @throws TransformException - if there was a problem internally
*/
void transform(File sourceFile, File targetFile, String sourceMimetype,
String targetMimetype, Map<String, String> transformOptions) throws Exception;
String targetMimetype, Map<String, String> transformOptions) throws TransformException;
/**