#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

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

View File

@ -60,6 +60,9 @@ 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);
@ -251,7 +254,6 @@ 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);
@ -260,6 +262,7 @@ public class FileUtil {
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

@ -270,13 +270,25 @@ public class TestFileResource extends BaseJerseyTest {
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