#182: fix thumbnail for orphan files

This commit is contained in:
Benjamin Gamard 2018-03-14 18:12:19 +01:00
parent 2a619849f4
commit 94e18146fd
3 changed files with 34 additions and 17 deletions

View File

@ -96,10 +96,12 @@ public class FileCreatedAsyncListener {
fileDao.update(file); fileDao.update(file);
} }
}); });
// Update Lucene index if (file.getDocumentId() != null) {
LuceneDao luceneDao = new LuceneDao(); // Update Lucene index
luceneDao.createFile(event.getFile()); LuceneDao luceneDao = new LuceneDao();
luceneDao.createFile(event.getFile());
}
FileUtil.endProcessingFile(file.getId()); FileUtil.endProcessingFile(file.getId());
} }

View File

@ -60,7 +60,10 @@ public class FileUtil {
*/ */
public static String extractContent(String language, File file, Path unencryptedFile, Path unencryptedPdfFile) { public static String extractContent(String language, File file, Path unencryptedFile, Path unencryptedPdfFile) {
String content = null; String content = null;
if (language == null) {
return null;
}
if (ImageUtil.isImage(file.getMimeType())) { if (ImageUtil.isImage(file.getMimeType())) {
content = ocrFile(unencryptedFile, language); content = ocrFile(unencryptedFile, language);
} else if (VideoUtil.isVideo(file.getMimeType())) { } else if (VideoUtil.isVideo(file.getMimeType())) {
@ -251,15 +254,15 @@ public class FileUtil {
userDao.updateQuota(user); userDao.updateQuota(user);
// Raise a new file created event and document updated event if we have a document // Raise a new file created event and document updated event if we have a document
if (documentId != null) { startProcessingFile(fileId);
startProcessingFile(fileId); FileCreatedAsyncEvent fileCreatedAsyncEvent = new FileCreatedAsyncEvent();
FileCreatedAsyncEvent fileCreatedAsyncEvent = new FileCreatedAsyncEvent(); fileCreatedAsyncEvent.setUserId(userId);
fileCreatedAsyncEvent.setUserId(userId); fileCreatedAsyncEvent.setLanguage(language);
fileCreatedAsyncEvent.setLanguage(language); fileCreatedAsyncEvent.setFile(file);
fileCreatedAsyncEvent.setFile(file); fileCreatedAsyncEvent.setUnencryptedFile(unencryptedFile);
fileCreatedAsyncEvent.setUnencryptedFile(unencryptedFile); ThreadLocalContext.get().addAsyncEvent(fileCreatedAsyncEvent);
ThreadLocalContext.get().addAsyncEvent(fileCreatedAsyncEvent);
if (documentId != null) {
DocumentUpdatedAsyncEvent documentUpdatedAsyncEvent = new DocumentUpdatedAsyncEvent(); DocumentUpdatedAsyncEvent documentUpdatedAsyncEvent = new DocumentUpdatedAsyncEvent();
documentUpdatedAsyncEvent.setUserId(userId); documentUpdatedAsyncEvent.setUserId(userId);
documentUpdatedAsyncEvent.setDocumentId(documentId); documentUpdatedAsyncEvent.setDocumentId(documentId);

View File

@ -262,21 +262,33 @@ public class TestFileResource extends BaseJerseyTest {
Assert.assertNotNull(file1Id); Assert.assertNotNull(file1Id);
} }
} }
// Get all orphan files // Get all orphan files
JsonObject json = target().path("/file/list").request() JsonObject json = target().path("/file/list").request()
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, file3Token) .cookie(TokenBasedSecurityFilter.COOKIE_NAME, file3Token)
.get(JsonObject.class); .get(JsonObject.class);
JsonArray files = json.getJsonArray("files"); JsonArray files = json.getJsonArray("files");
Assert.assertEquals(1, files.size()); Assert.assertEquals(1, files.size());
// Get the file data // Get the thumbnail data
Response response = target().path("/file/" + file1Id + "/data").request() Response response = target().path("/file/" + file1Id + "/data")
.queryParam("size", "thumb")
.request()
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, file3Token) .cookie(TokenBasedSecurityFilter.COOKIE_NAME, file3Token)
.get(); .get();
Assert.assertEquals(Status.OK, Status.fromStatusCode(response.getStatus()));
InputStream is = (InputStream) response.getEntity(); InputStream is = (InputStream) response.getEntity();
byte[] fileBytes = ByteStreams.toByteArray(is); byte[] fileBytes = ByteStreams.toByteArray(is);
Assert.assertEquals(MimeType.IMAGE_JPEG, MimeTypeUtil.guessMimeType(fileBytes, null)); Assert.assertEquals(MimeType.IMAGE_JPEG, MimeTypeUtil.guessMimeType(fileBytes, null));
Assert.assertTrue(fileBytes.length > 0);
// Get the file data
response = target().path("/file/" + file1Id + "/data").request()
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, file3Token)
.get();
is = (InputStream) response.getEntity();
fileBytes = ByteStreams.toByteArray(is);
Assert.assertEquals(MimeType.IMAGE_JPEG, MimeTypeUtil.guessMimeType(fileBytes, null));
Assert.assertEquals(163510, fileBytes.length); Assert.assertEquals(163510, fileBytes.length);
// Create a document // Create a document