mirror of
https://github.com/Alfresco/alfresco-transform-core.git
synced 2025-08-07 17:48:35 +00:00
ATS-531 : Reformat code
This commit is contained in:
@@ -58,25 +58,26 @@ import org.springframework.web.multipart.MultipartFile;
|
||||
*
|
||||
* Status Codes:
|
||||
*
|
||||
* 200 Success
|
||||
* 400 Bad Request: Request parameter <name> is missing (missing mandatory parameter)
|
||||
* 400 Bad Request: Request parameter <name> is of the wrong type
|
||||
* 400 Bad Request: Transformer exit code was not 0 (possible problem with the source file)
|
||||
* 400 Bad Request: The source filename was not supplied
|
||||
* 500 Internal Server Error: (no message with low level IO problems)
|
||||
* 500 Internal Server Error: The target filename was not supplied (should not happen as targetExtension is checked)
|
||||
* 500 Internal Server Error: Transformer version check exit code was not 0
|
||||
* 500 Internal Server Error: Transformer version check failed to create any output
|
||||
* 500 Internal Server Error: Could not read the target file
|
||||
* 500 Internal Server Error: The target filename was malformed (should not happen because of other checks)
|
||||
* 500 Internal Server Error: Transformer failed to create an output file (the exit code was 0, so there should be some content)
|
||||
* 500 Internal Server Error: Filename encoding error
|
||||
* 507 Insufficient Storage: Failed to store the source file
|
||||
* 200 Success
|
||||
* 400 Bad Request: Request parameter <name> is missing (missing mandatory parameter)
|
||||
* 400 Bad Request: Request parameter <name> is of the wrong type
|
||||
* 400 Bad Request: Transformer exit code was not 0 (possible problem with the source file)
|
||||
* 400 Bad Request: The source filename was not supplied
|
||||
* 500 Internal Server Error: (no message with low level IO problems)
|
||||
* 500 Internal Server Error: The target filename was not supplied (should not happen as targetExtension is checked)
|
||||
* 500 Internal Server Error: Transformer version check exit code was not 0
|
||||
* 500 Internal Server Error: Transformer version check failed to create any output
|
||||
* 500 Internal Server Error: Could not read the target file
|
||||
* 500 Internal Server Error: The target filename was malformed (should not happen because of other checks)
|
||||
* 500 Internal Server Error: Transformer failed to create an output file (the exit code was 0, so there should be some content)
|
||||
* 500 Internal Server Error: Filename encoding error
|
||||
* 507 Insufficient Storage: Failed to store the source file
|
||||
*/
|
||||
@Controller
|
||||
public class AlfrescoPdfRendererController extends AbstractTransformerController
|
||||
{
|
||||
private static final Logger logger = LoggerFactory.getLogger(AlfrescoPdfRendererController.class);
|
||||
private static final Logger logger = LoggerFactory.getLogger(
|
||||
AlfrescoPdfRendererController.class);
|
||||
|
||||
@Autowired
|
||||
private PdfRendererCommandExecutor commandExecutor;
|
||||
@@ -84,10 +85,13 @@ public class AlfrescoPdfRendererController extends AbstractTransformerController
|
||||
@Autowired
|
||||
public AlfrescoPdfRendererController()
|
||||
{
|
||||
logger.info("-----------------------------------------------------------------------------------------------------------------------------------------------------------");
|
||||
logger.info(
|
||||
"-----------------------------------------------------------------------------------------------------------------------------------------------------------");
|
||||
Arrays.stream(LICENCE.split("\\n")).forEach(logger::info);
|
||||
logger.info("alfresco-pdf-renderer uses the PDFium library from Google Inc. See the license at https://pdfium.googlesource.com/pdfium/+/master/LICENSE or in /pdfium.txt");
|
||||
logger.info("-----------------------------------------------------------------------------------------------------------------------------------------------------------");
|
||||
logger.info(
|
||||
"alfresco-pdf-renderer uses the PDFium library from Google Inc. See the license at https://pdfium.googlesource.com/pdfium/+/master/LICENSE or in /pdfium.txt");
|
||||
logger.info(
|
||||
"-----------------------------------------------------------------------------------------------------------------------------------------------------------");
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -139,18 +143,19 @@ public class AlfrescoPdfRendererController extends AbstractTransformerController
|
||||
@Deprecated
|
||||
@PostMapping(value = "/transform", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
||||
public ResponseEntity<Resource> transform(HttpServletRequest request,
|
||||
@RequestParam("file") MultipartFile sourceMultipartFile,
|
||||
@RequestParam("targetExtension") String targetExtension,
|
||||
@RequestParam(value = "timeout", required = false) Long timeout,
|
||||
@RequestParam(value = "testDelay", required = false) Long testDelay,
|
||||
@RequestParam("file") MultipartFile sourceMultipartFile,
|
||||
@RequestParam("targetExtension") String targetExtension,
|
||||
@RequestParam(value = "timeout", required = false) Long timeout,
|
||||
@RequestParam(value = "testDelay", required = false) Long testDelay,
|
||||
|
||||
@RequestParam(value = "page", required = false) Integer page,
|
||||
@RequestParam(value = "width", required = false) Integer width,
|
||||
@RequestParam(value = "height", required = false) Integer height,
|
||||
@RequestParam(value = "allowPdfEnlargement", required = false) Boolean allowPdfEnlargement,
|
||||
@RequestParam(value = "maintainPdfAspectRatio", required = false) Boolean maintainPdfAspectRatio)
|
||||
@RequestParam(value = "page", required = false) Integer page,
|
||||
@RequestParam(value = "width", required = false) Integer width,
|
||||
@RequestParam(value = "height", required = false) Integer height,
|
||||
@RequestParam(value = "allowPdfEnlargement", required = false) Boolean allowPdfEnlargement,
|
||||
@RequestParam(value = "maintainPdfAspectRatio", required = false) Boolean maintainPdfAspectRatio)
|
||||
{
|
||||
String targetFilename = createTargetFileName(sourceMultipartFile.getOriginalFilename(), targetExtension);
|
||||
String targetFilename = createTargetFileName(sourceMultipartFile.getOriginalFilename(),
|
||||
targetExtension);
|
||||
getProbeTestTransform().incrementTransformerCount();
|
||||
File sourceFile = createSourceFile(request, sourceMultipartFile);
|
||||
File targetFile = createTargetFile(request, targetFilename);
|
||||
|
@@ -37,17 +37,18 @@ import org.springframework.context.annotation.Bean;
|
||||
import io.micrometer.core.instrument.MeterRegistry;
|
||||
|
||||
@SpringBootApplication
|
||||
@EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class})
|
||||
@EnableAutoConfiguration(exclude = {DataSourceAutoConfiguration.class})
|
||||
public class Application
|
||||
{
|
||||
@Value("${container.name}")
|
||||
private String containerName;
|
||||
|
||||
@Bean
|
||||
public MeterRegistryCustomizer<MeterRegistry> metricsCommonTags() {
|
||||
public MeterRegistryCustomizer<MeterRegistry> metricsCommonTags()
|
||||
{
|
||||
return registry -> registry.config().commonTags("containerName", containerName);
|
||||
}
|
||||
|
||||
|
||||
public static void main(String[] args)
|
||||
{
|
||||
SpringApplication.run(Application.class, args);
|
||||
|
@@ -33,7 +33,7 @@ import org.alfresco.util.exec.RuntimeExec;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* CommandExecutor implementation for running PDF Renderer transformations. It runs the
|
||||
* CommandExecutor implementation for running PDF Renderer transformations. It runs the
|
||||
* transformation logic as a separate Shell process.
|
||||
*/
|
||||
@Component
|
||||
|
@@ -101,7 +101,7 @@ public class AlfrescoPdfRendererControllerTest extends AbstractTransformerContro
|
||||
{
|
||||
ReflectionTestUtils.setField(commandExecutor, "transformCommand", mockTransformCommand);
|
||||
ReflectionTestUtils.setField(commandExecutor, "checkCommand", mockCheckCommand);
|
||||
|
||||
|
||||
mockTransformCommand("pdf", "png", "application/pdf", true);
|
||||
}
|
||||
|
||||
@@ -118,7 +118,8 @@ public class AlfrescoPdfRendererControllerTest extends AbstractTransformerContro
|
||||
expectedSourceSuffix = null;
|
||||
expectedSourceFileBytes = readTestFile(sourceExtension);
|
||||
expectedTargetFileBytes = readTargetFileBytes ? readTestFile(targetExtension) : null;
|
||||
sourceFile = new MockMultipartFile("file", "quick." + sourceExtension, sourceMimetype, expectedSourceFileBytes);
|
||||
sourceFile = new MockMultipartFile("file", "quick." + sourceExtension, sourceMimetype,
|
||||
expectedSourceFileBytes);
|
||||
|
||||
when(mockTransformCommand.execute(any(), anyLong())).thenAnswer(
|
||||
(Answer<RuntimeExec.ExecutionResult>) invocation -> {
|
||||
@@ -134,8 +135,11 @@ public class AlfrescoPdfRendererControllerTest extends AbstractTransformerContro
|
||||
assertNotNull(actualTarget);
|
||||
if (expectedSourceSuffix != null)
|
||||
{
|
||||
assertTrue("The source file \""+actualSource+"\" should have ended in \""+expectedSourceSuffix+"\"", actualSource.endsWith(expectedSourceSuffix));
|
||||
actualSource = actualSource.substring(0, actualSource.length()-expectedSourceSuffix.length());
|
||||
assertTrue("The source file \"" + actualSource +
|
||||
"\" should have ended in \"" + expectedSourceSuffix + "\"",
|
||||
actualSource.endsWith(expectedSourceSuffix));
|
||||
actualSource = actualSource.substring(0,
|
||||
actualSource.length() - expectedSourceSuffix.length());
|
||||
}
|
||||
|
||||
assertNotNull(actualOptions);
|
||||
@@ -155,7 +159,7 @@ public class AlfrescoPdfRendererControllerTest extends AbstractTransformerContro
|
||||
int i = actualTarget.lastIndexOf('_');
|
||||
if (i >= 0)
|
||||
{
|
||||
String testFilename = actualTarget.substring(i+1);
|
||||
String testFilename = actualTarget.substring(i + 1);
|
||||
File testFile = getTestFile(testFilename, false);
|
||||
File targetFile = new File(actualTarget);
|
||||
generateTargetFileFromResourceFile(actualTargetExtension, testFile,
|
||||
@@ -164,7 +168,8 @@ public class AlfrescoPdfRendererControllerTest extends AbstractTransformerContro
|
||||
|
||||
// Check the supplied source file has not been changed.
|
||||
byte[] actualSourceFileBytes = Files.readAllBytes(new File(actualSource).toPath());
|
||||
assertTrue("Source file is not the same", Arrays.equals(expectedSourceFileBytes, actualSourceFileBytes));
|
||||
assertTrue("Source file is not the same",
|
||||
Arrays.equals(expectedSourceFileBytes, actualSourceFileBytes));
|
||||
|
||||
return mockExecutionResult;
|
||||
});
|
||||
@@ -174,7 +179,6 @@ public class AlfrescoPdfRendererControllerTest extends AbstractTransformerContro
|
||||
when(mockExecutionResult.getStdOut()).thenReturn("STDOUT");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected AbstractTransformerController getController()
|
||||
{
|
||||
@@ -185,7 +189,9 @@ public class AlfrescoPdfRendererControllerTest extends AbstractTransformerContro
|
||||
public void optionsTest() throws Exception
|
||||
{
|
||||
expectedOptions = "--width=321 --height=654 --allow-enlargement --maintain-aspect-ratio --page=2";
|
||||
mockMvc.perform(MockMvcRequestBuilders.multipart("/transform")
|
||||
mockMvc
|
||||
.perform(MockMvcRequestBuilders
|
||||
.multipart("/transform")
|
||||
.file(sourceFile)
|
||||
.param("targetExtension", targetExtension)
|
||||
|
||||
@@ -195,17 +201,19 @@ public class AlfrescoPdfRendererControllerTest extends AbstractTransformerContro
|
||||
.param("height", "654")
|
||||
.param("allowPdfEnlargement", "true")
|
||||
.param("maintainPdfAspectRatio", "true"))
|
||||
|
||||
.andExpect(status().is(OK.value()))
|
||||
.andExpect(content().bytes(expectedTargetFileBytes))
|
||||
.andExpect(header().string("Content-Disposition", "attachment; filename*= UTF-8''quick."+targetExtension));
|
||||
.andExpect(status().is(OK.value()))
|
||||
.andExpect(content().bytes(expectedTargetFileBytes))
|
||||
.andExpect(header().string("Content-Disposition",
|
||||
"attachment; filename*= UTF-8''quick." + targetExtension));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void optionsNegateBooleansTest() throws Exception
|
||||
{
|
||||
expectedOptions = "--width=321 --height=654 --page=2";
|
||||
mockMvc.perform(MockMvcRequestBuilders.multipart("/transform")
|
||||
mockMvc
|
||||
.perform(MockMvcRequestBuilders
|
||||
.multipart("/transform")
|
||||
.file(sourceFile)
|
||||
.param("targetExtension", targetExtension)
|
||||
|
||||
@@ -215,10 +223,10 @@ public class AlfrescoPdfRendererControllerTest extends AbstractTransformerContro
|
||||
.param("height", "654")
|
||||
.param("allowPdfEnlargement", "false")
|
||||
.param("maintainPdfAspectRatio", "false"))
|
||||
|
||||
.andExpect(status().is(OK.value()))
|
||||
.andExpect(content().bytes(expectedTargetFileBytes))
|
||||
.andExpect(header().string("Content-Disposition", "attachment; filename*= UTF-8''quick."+targetExtension));
|
||||
.andExpect(status().is(OK.value()))
|
||||
.andExpect(content().bytes(expectedTargetFileBytes))
|
||||
.andExpect(header().string("Content-Disposition",
|
||||
"attachment; filename*= UTF-8''quick." + targetExtension));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -237,7 +245,8 @@ public class AlfrescoPdfRendererControllerTest extends AbstractTransformerContro
|
||||
|
||||
mockMvc.perform(mockMvcRequest("/transform", sourceFile, "targetExtension", "xxx"))
|
||||
.andExpect(status().is(BAD_REQUEST.value()))
|
||||
.andExpect(status().reason(containsString("Transformer exit code was not 0: \nSTDERR")));
|
||||
.andExpect(status()
|
||||
.reason(containsString("Transformer exit code was not 0: \nSTDERR")));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -248,7 +257,6 @@ public class AlfrescoPdfRendererControllerTest extends AbstractTransformerContro
|
||||
File sourceFile = getTestFile("quick." + sourceExtension, true);
|
||||
String targetFileRef = UUID.randomUUID().toString();
|
||||
|
||||
|
||||
// Transformation Request POJO
|
||||
TransformRequest transformRequest = new TransformRequest();
|
||||
transformRequest.setRequestId("1");
|
||||
@@ -262,12 +270,14 @@ public class AlfrescoPdfRendererControllerTest extends AbstractTransformerContro
|
||||
|
||||
// HTTP Request
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.set(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=quick." + sourceExtension);
|
||||
headers.set(HttpHeaders.CONTENT_DISPOSITION,
|
||||
"attachment; filename=quick." + sourceExtension);
|
||||
ResponseEntity<Resource> response = new ResponseEntity<>(new FileSystemResource(
|
||||
sourceFile), headers, OK);
|
||||
|
||||
when(alfrescoSharedFileStoreClient.retrieveFile(sourceFileRef)).thenReturn(response);
|
||||
when(alfrescoSharedFileStoreClient.saveFile(any())).thenReturn(new FileRefResponse(new FileRefEntity(targetFileRef)));
|
||||
when(alfrescoSharedFileStoreClient.saveFile(any())).thenReturn(
|
||||
new FileRefResponse(new FileRefEntity(targetFileRef)));
|
||||
when(mockExecutionResult.getExitValue()).thenReturn(0);
|
||||
|
||||
// Update the Transformation Request with any specific params before sending it
|
||||
@@ -275,18 +285,20 @@ public class AlfrescoPdfRendererControllerTest extends AbstractTransformerContro
|
||||
|
||||
// Serialize and call the transformer
|
||||
String tr = objectMapper.writeValueAsString(transformRequest);
|
||||
String transformationReplyAsString = mockMvc.perform(MockMvcRequestBuilders.post("/transform")
|
||||
.header(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON_VALUE)
|
||||
.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE).content(tr))
|
||||
.andExpect(status().is(HttpStatus.CREATED.value()))
|
||||
.andReturn().getResponse().getContentAsString();
|
||||
String transformationReplyAsString = mockMvc
|
||||
.perform(MockMvcRequestBuilders
|
||||
.post("/transform")
|
||||
.header(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON_VALUE)
|
||||
.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE).content(tr))
|
||||
.andExpect(status().is(HttpStatus.CREATED.value()))
|
||||
.andReturn().getResponse().getContentAsString();
|
||||
|
||||
TransformReply transformReply = objectMapper.readValue(transformationReplyAsString, TransformReply.class);
|
||||
TransformReply transformReply = objectMapper.readValue(transformationReplyAsString,
|
||||
TransformReply.class);
|
||||
|
||||
// Assert the reply
|
||||
assertEquals(transformRequest.getRequestId(), transformReply.getRequestId());
|
||||
assertEquals(transformRequest.getClientData(), transformReply.getClientData());
|
||||
assertEquals(transformRequest.getSchema(), transformReply.getSchema());
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -48,7 +48,8 @@ public class AlfrescoPdfRendererQueueTransformServiceIT extends AbstractQueueTra
|
||||
@Override
|
||||
protected TransformRequest buildRequest()
|
||||
{
|
||||
return TransformRequest.builder()
|
||||
return TransformRequest
|
||||
.builder()
|
||||
.withRequestId(UUID.randomUUID().toString())
|
||||
.withSourceMediaType(MIMETYPE_OPENXML_WORDPROCESSING)
|
||||
.withTargetMediaType(MIMETYPE_PDF)
|
||||
|
Reference in New Issue
Block a user