mirror of
https://github.com/Alfresco/alfresco-transform-core.git
synced 2025-08-14 17:58:27 +00:00
feature/ATS-16
This commit is contained in:
@@ -11,10 +11,25 @@
|
||||
*/
|
||||
package org.alfresco.transformer;
|
||||
|
||||
import static org.alfresco.repo.content.MimetypeMap.MIMETYPE_TEXT_PLAIN;
|
||||
import static org.alfresco.transformer.Tika.INCLUDE_CONTENTS;
|
||||
import static org.alfresco.transformer.Tika.NOT_EXTRACT_BOOKMARKS_TEXT;
|
||||
import static org.alfresco.transformer.Tika.PDF_BOX;
|
||||
import static org.alfresco.transformer.Tika.TARGET_ENCODING;
|
||||
import static org.alfresco.transformer.Tika.TARGET_MIMETYPE;
|
||||
import static org.alfresco.transformer.Tika.TRANSFORM_NAMES;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.apache.tika.exception.TikaException;
|
||||
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;
|
||||
@@ -22,13 +37,6 @@ import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import static org.alfresco.repo.content.MimetypeMap.MIMETYPE_TEXT_PLAIN;
|
||||
import static org.alfresco.transformer.Tika.*;
|
||||
|
||||
/**
|
||||
* Controller for the Docker based Tika transformers.
|
||||
*
|
||||
@@ -102,7 +110,7 @@ public class TikaController extends AbstractTransformerController
|
||||
};
|
||||
}
|
||||
|
||||
@PostMapping("/transform")
|
||||
@PostMapping(value = "/transform", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
||||
public ResponseEntity<Resource> transform(HttpServletRequest request,
|
||||
@RequestParam("file") MultipartFile sourceMultipartFile,
|
||||
@RequestParam("targetExtension") String targetExtension,
|
||||
@@ -122,7 +130,7 @@ public class TikaController extends AbstractTransformerController
|
||||
throw new TransformException(400, "Invalid transform value");
|
||||
}
|
||||
|
||||
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
|
||||
@@ -137,4 +145,21 @@ public class TikaController extends AbstractTransformerController
|
||||
|
||||
return createAttachment(targetFilename, targetFile, testDelay);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void processTransform(File sourceFile, File targetFile,
|
||||
Map<String, String> transformOptions, Long timeout)
|
||||
{
|
||||
|
||||
String transform = transformOptions.get("transform");
|
||||
Boolean includeContents = stringToBoolean("includeContents");
|
||||
Boolean notExtractBookmarksText = stringToBoolean("notExtractBookmarksText");
|
||||
String targetMimetype = transformOptions.get("targetMimetype");
|
||||
String targetEncoding = transformOptions.get("targetEncoding");
|
||||
|
||||
callTransform(sourceFile, targetFile, transform,
|
||||
includeContents != null && includeContents ? INCLUDE_CONTENTS : null,
|
||||
notExtractBookmarksText != null && notExtractBookmarksText ? NOT_EXTRACT_BOOKMARKS_TEXT: null,
|
||||
TARGET_MIMETYPE + targetMimetype, TARGET_ENCODING + targetEncoding);
|
||||
}
|
||||
}
|
||||
|
@@ -25,6 +25,44 @@
|
||||
*/
|
||||
package org.alfresco.transformer;
|
||||
|
||||
import static org.alfresco.repo.content.MimetypeMap.MIMETYPE_HTML;
|
||||
import static org.alfresco.repo.content.MimetypeMap.MIMETYPE_OPENXML_PRESENTATION;
|
||||
import static org.alfresco.repo.content.MimetypeMap.MIMETYPE_OPENXML_SPREADSHEET;
|
||||
import static org.alfresco.repo.content.MimetypeMap.MIMETYPE_OPENXML_WORDPROCESSING;
|
||||
import static org.alfresco.repo.content.MimetypeMap.MIMETYPE_OUTLOOK_MSG;
|
||||
import static org.alfresco.repo.content.MimetypeMap.MIMETYPE_PDF;
|
||||
import static org.alfresco.repo.content.MimetypeMap.MIMETYPE_TEXT_CSV;
|
||||
import static org.alfresco.repo.content.MimetypeMap.MIMETYPE_TEXT_PLAIN;
|
||||
import static org.alfresco.repo.content.MimetypeMap.MIMETYPE_WORD;
|
||||
import static org.alfresco.repo.content.MimetypeMap.MIMETYPE_XHTML;
|
||||
import static org.alfresco.repo.content.MimetypeMap.MIMETYPE_XML;
|
||||
import static org.alfresco.repo.content.MimetypeMap.MIMETYPE_ZIP;
|
||||
import static org.alfresco.transformer.Tika.ARCHIVE;
|
||||
import static org.alfresco.transformer.Tika.CSV;
|
||||
import static org.alfresco.transformer.Tika.DOC;
|
||||
import static org.alfresco.transformer.Tika.DOCX;
|
||||
import static org.alfresco.transformer.Tika.HTML;
|
||||
import static org.alfresco.transformer.Tika.MSG;
|
||||
import static org.alfresco.transformer.Tika.OUTLOOK_MSG;
|
||||
import static org.alfresco.transformer.Tika.PDF;
|
||||
import static org.alfresco.transformer.Tika.PDF_BOX;
|
||||
import static org.alfresco.transformer.Tika.POI;
|
||||
import static org.alfresco.transformer.Tika.POI_OFFICE;
|
||||
import static org.alfresco.transformer.Tika.POI_OO_XML;
|
||||
import static org.alfresco.transformer.Tika.PPTX;
|
||||
import static org.alfresco.transformer.Tika.TEXT_MINING;
|
||||
import static org.alfresco.transformer.Tika.TIKA_AUTO;
|
||||
import static org.alfresco.transformer.Tika.TXT;
|
||||
import static org.alfresco.transformer.Tika.XHTML;
|
||||
import static org.alfresco.transformer.Tika.XML;
|
||||
import static org.alfresco.transformer.Tika.XSLX;
|
||||
import static org.alfresco.transformer.Tika.ZIP;
|
||||
import static org.springframework.test.util.AssertionErrors.assertTrue;
|
||||
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;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||
@@ -34,12 +72,6 @@ import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.test.web.servlet.MvcResult;
|
||||
import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder;
|
||||
|
||||
import static org.alfresco.repo.content.MimetypeMap.*;
|
||||
import static org.alfresco.transformer.Tika.*;
|
||||
import static org.springframework.test.util.AssertionErrors.assertTrue;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.header;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
/**
|
||||
* Test the TikaController without a server.
|
||||
* Super class includes tests for the AbstractTransformerController.
|
||||
@@ -63,6 +95,16 @@ public class TikaControllerTest extends AbstractTransformerControllerTest
|
||||
String targetEncoding = "UTF-8";
|
||||
String targetMimetype = MIMETYPE_TEXT_PLAIN;
|
||||
|
||||
@Before
|
||||
public void before() throws Exception
|
||||
{
|
||||
controller.setAlfrescoSharedFileStoreClient(alfrescoSharedFileStoreClient);
|
||||
super.controller = controller;
|
||||
|
||||
sourceExtension = "pdf";
|
||||
targetExtension = "txt";
|
||||
}
|
||||
|
||||
private void transform(String transform, String sourceExtension, String targetExtension,
|
||||
String sourceMimetype, String targetMimetype,
|
||||
Boolean includeContents, String expectedContentContains) throws Exception
|
||||
@@ -350,4 +392,14 @@ public class TikaControllerTest extends AbstractTransformerControllerTest
|
||||
.andExpect(status().is(200))
|
||||
.andExpect(header().string("Content-Disposition", "attachment; filename*= UTF-8''quick." + targetExtension));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void updateTransformRequestWithSpecificOptions(TransformRequest transformRequest)
|
||||
{
|
||||
transformRequest.setSourceExtension(sourceExtension);
|
||||
transformRequest.setTargetExtension(targetExtension);
|
||||
transformRequest.getTransformationRequestOptions().put("transform", "PdfBox");
|
||||
transformRequest.getTransformationRequestOptions().put("targetMimetype", "text/plain");
|
||||
transformRequest.getTransformationRequestOptions().put("targetEncoding", "UTF-8");
|
||||
}
|
||||
}
|
||||
|
@@ -47,5 +47,5 @@ public class TikaHttpRequestTest extends AbstractHttpRequestTest
|
||||
protected String getSourceExtension()
|
||||
{
|
||||
return "pdf";
|
||||
};
|
||||
}
|
||||
}
|
||||
|
BIN
alfresco-docker-tika/src/test/resources/quick.pdf
Normal file
BIN
alfresco-docker-tika/src/test/resources/quick.pdf
Normal file
Binary file not shown.
Reference in New Issue
Block a user