mirror of
https://github.com/sismics/docs.git
synced 2024-11-22 05:57:57 +01:00
#182: fix thumbnail for orphan files
This commit is contained in:
parent
2a619849f4
commit
94e18146fd
@ -96,10 +96,12 @@ public class FileCreatedAsyncListener {
|
||||
fileDao.update(file);
|
||||
}
|
||||
});
|
||||
|
||||
// Update Lucene index
|
||||
LuceneDao luceneDao = new LuceneDao();
|
||||
luceneDao.createFile(event.getFile());
|
||||
|
||||
if (file.getDocumentId() != null) {
|
||||
// Update Lucene index
|
||||
LuceneDao luceneDao = new LuceneDao();
|
||||
luceneDao.createFile(event.getFile());
|
||||
}
|
||||
|
||||
FileUtil.endProcessingFile(file.getId());
|
||||
}
|
||||
|
@ -60,7 +60,10 @@ public class FileUtil {
|
||||
*/
|
||||
public static String extractContent(String language, File file, Path unencryptedFile, Path unencryptedPdfFile) {
|
||||
String content = null;
|
||||
|
||||
if (language == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (ImageUtil.isImage(file.getMimeType())) {
|
||||
content = ocrFile(unencryptedFile, language);
|
||||
} else if (VideoUtil.isVideo(file.getMimeType())) {
|
||||
@ -251,15 +254,15 @@ public class FileUtil {
|
||||
userDao.updateQuota(user);
|
||||
|
||||
// Raise a new file created event and document updated event if we have a document
|
||||
if (documentId != null) {
|
||||
startProcessingFile(fileId);
|
||||
FileCreatedAsyncEvent fileCreatedAsyncEvent = new FileCreatedAsyncEvent();
|
||||
fileCreatedAsyncEvent.setUserId(userId);
|
||||
fileCreatedAsyncEvent.setLanguage(language);
|
||||
fileCreatedAsyncEvent.setFile(file);
|
||||
fileCreatedAsyncEvent.setUnencryptedFile(unencryptedFile);
|
||||
ThreadLocalContext.get().addAsyncEvent(fileCreatedAsyncEvent);
|
||||
startProcessingFile(fileId);
|
||||
FileCreatedAsyncEvent fileCreatedAsyncEvent = new FileCreatedAsyncEvent();
|
||||
fileCreatedAsyncEvent.setUserId(userId);
|
||||
fileCreatedAsyncEvent.setLanguage(language);
|
||||
fileCreatedAsyncEvent.setFile(file);
|
||||
fileCreatedAsyncEvent.setUnencryptedFile(unencryptedFile);
|
||||
ThreadLocalContext.get().addAsyncEvent(fileCreatedAsyncEvent);
|
||||
|
||||
if (documentId != null) {
|
||||
DocumentUpdatedAsyncEvent documentUpdatedAsyncEvent = new DocumentUpdatedAsyncEvent();
|
||||
documentUpdatedAsyncEvent.setUserId(userId);
|
||||
documentUpdatedAsyncEvent.setDocumentId(documentId);
|
||||
|
@ -262,21 +262,33 @@ public class TestFileResource extends BaseJerseyTest {
|
||||
Assert.assertNotNull(file1Id);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Get all orphan files
|
||||
JsonObject json = target().path("/file/list").request()
|
||||
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, file3Token)
|
||||
.get(JsonObject.class);
|
||||
JsonArray files = json.getJsonArray("files");
|
||||
Assert.assertEquals(1, files.size());
|
||||
|
||||
// Get the file data
|
||||
Response response = target().path("/file/" + file1Id + "/data").request()
|
||||
|
||||
// Get the thumbnail data
|
||||
Response response = target().path("/file/" + file1Id + "/data")
|
||||
.queryParam("size", "thumb")
|
||||
.request()
|
||||
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, file3Token)
|
||||
.get();
|
||||
Assert.assertEquals(Status.OK, Status.fromStatusCode(response.getStatus()));
|
||||
InputStream is = (InputStream) response.getEntity();
|
||||
byte[] fileBytes = ByteStreams.toByteArray(is);
|
||||
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);
|
||||
|
||||
// Create a document
|
||||
|
Loading…
Reference in New Issue
Block a user