feature/ATS-16

This commit is contained in:
Lucian Tuca
2018-08-17 09:32:25 +01:00
parent c4ca88d876
commit dda632c7a5
22 changed files with 983 additions and 145 deletions

View File

@@ -11,22 +11,24 @@
*/
package org.alfresco.transformer;
import java.io.File;
import java.util.HashMap;
import java.util.Map;
import java.util.StringJoiner;
import javax.servlet.http.HttpServletRequest;
import org.alfresco.util.exec.RuntimeExec;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.Resource;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.util.HashMap;
import java.util.Map;
import java.util.StringJoiner;
/**
* Controller for the Docker based alfresco-pdf-renderer transformer.
*
@@ -111,7 +113,35 @@ public class AlfrescoPdfRendererController extends AbstractTransformerController
};
}
@PostMapping("/transform")
@Override
protected void processTransform(File sourceFile, File targetFile,
Map<String, String> transformOptions, Long timeout)
{
String page = transformOptions.get("page");
Integer pageOption = page == null ? null : Integer.parseInt(page);
String width = transformOptions.get("width");
Integer widthOption = width == null ? null : Integer.parseInt(width);
String height = transformOptions.get("height");
Integer heightOption = height == null ? null : Integer.parseInt(height);
String allowEnlargement = transformOptions.get("allowEnlargement");
Boolean allowEnlargementOption =
allowEnlargement == null ? null : Boolean.parseBoolean(allowEnlargement);
String maintainAspectRatio = transformOptions.get("maintainAspectRatio");
Boolean maintainAspectRatioOption =
maintainAspectRatio == null ? null : Boolean.parseBoolean(maintainAspectRatio);
String options = buildTransformOptions(pageOption, widthOption, heightOption,
allowEnlargementOption, maintainAspectRatioOption);
executeTransformCommand(options, sourceFile, targetFile, timeout);
}
@Deprecated
@PostMapping(value = "/transform", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public ResponseEntity<Resource> transform(HttpServletRequest request,
@RequestParam("file") MultipartFile sourceMultipartFile,
@RequestParam("targetExtension") String targetExtension,
@@ -124,11 +154,21 @@ public class AlfrescoPdfRendererController extends AbstractTransformerController
@RequestParam(value = "allowEnlargement", required = false) Boolean allowEnlargement,
@RequestParam(value = "maintainAspectRatio", required = false) Boolean maintainAspectRatio)
{
String targetFilename = createTargetFileName(sourceMultipartFile, targetExtension);
String targetFilename = createTargetFileName(sourceMultipartFile.getOriginalFilename(), targetExtension);
File sourceFile = createSourceFile(request, sourceMultipartFile);
File targetFile = createTargetFile(request, targetFilename);
// Both files are deleted by TransformInterceptor.afterCompletion
String options = buildTransformOptions(page, width, height, allowEnlargement,
maintainAspectRatio);
executeTransformCommand(options, sourceFile, targetFile, timeout);
return createAttachment(targetFilename, targetFile, testDelay);
}
public String buildTransformOptions(Integer page,Integer width,Integer height,Boolean allowEnlargement,Boolean maintainAspectRatio)
{
StringJoiner args = new StringJoiner(" ");
if (width != null && width >= 0)
{
@@ -150,9 +190,6 @@ public class AlfrescoPdfRendererController extends AbstractTransformerController
{
args.add("--page=" + page);
}
String options = args.toString();
executeTransformCommand(options, sourceFile, targetFile, timeout);
return createAttachment(targetFilename, targetFile, testDelay);
return args.toString();
}
}

View File

@@ -25,6 +25,11 @@
*/
package org.alfresco.transformer;
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.status;
import org.alfresco.transform.client.model.TransformRequest;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -33,10 +38,6 @@ import org.springframework.boot.test.mock.mockito.SpyBean;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import java.io.IOException;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
/**
* Test the AlfrescoPdfRendererController without a server.
* Super class includes tests for the AbstractTransformerController.
@@ -49,8 +50,10 @@ public class AlfrescoPdfRendererControllerTest extends AbstractTransformerContro
private AlfrescoPdfRendererController controller;
@Before
public void before() throws IOException
public void before() throws Exception
{
controller.setAlfrescoSharedFileStoreClient(alfrescoSharedFileStoreClient);
super.controller = controller;
super.mockTransformCommand(controller, "pdf", "png", "application/pdf", true);
}
@@ -93,4 +96,11 @@ public class AlfrescoPdfRendererControllerTest extends AbstractTransformerContro
.andExpect(content().bytes(expectedTargetFileBytes))
.andExpect(header().string("Content-Disposition", "attachment; filename*= UTF-8''quick."+targetExtension));
}
@Override
protected void updateTransformRequestWithSpecificOptions(TransformRequest transformRequest)
{
transformRequest.setSourceExtension("pdf");
transformRequest.setTargetExtension("png");
}
}