mirror of
https://github.com/sismics/docs.git
synced 2024-11-15 18:57:56 +01:00
indexing in transactional context
This commit is contained in:
parent
5c5a3f614f
commit
716954aa9a
@ -39,7 +39,7 @@ public class DocumentCreatedAsyncListener {
|
||||
contributor.setUserId(event.getUserId());
|
||||
contributorDao.create(contributor);
|
||||
|
||||
// Update Lucene index
|
||||
// Update index
|
||||
AppContext.getInstance().getIndexingHandler().createDocument(event.getDocument());
|
||||
});
|
||||
}
|
||||
|
@ -29,7 +29,7 @@ public class DocumentDeletedAsyncListener {
|
||||
log.info("Document deleted event: " + documentDeletedAsyncEvent.toString());
|
||||
}
|
||||
|
||||
// Update Lucene index
|
||||
// Update index
|
||||
AppContext.getInstance().getIndexingHandler().deleteDocument(documentDeletedAsyncEvent.getDocumentId());
|
||||
}
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ public class FileDeletedAsyncListener {
|
||||
File file = fileDeletedAsyncEvent.getFile();
|
||||
FileUtil.delete(file);
|
||||
|
||||
// Update Lucene index
|
||||
// Update index
|
||||
AppContext.getInstance().getIndexingHandler().deleteDocument(file.getId());
|
||||
}
|
||||
}
|
||||
|
@ -53,8 +53,8 @@ public class FileProcessingAsyncListener {
|
||||
|
||||
processFile(event);
|
||||
|
||||
// Update Lucene index
|
||||
AppContext.getInstance().getIndexingHandler().createFile(event.getFile());
|
||||
// Update index
|
||||
TransactionUtil.handle(() -> AppContext.getInstance().getIndexingHandler().createFile(event.getFile()));
|
||||
|
||||
FileUtil.endProcessingFile(event.getFile().getId());
|
||||
}
|
||||
@ -70,10 +70,13 @@ public class FileProcessingAsyncListener {
|
||||
log.info("File updated event: " + event.toString());
|
||||
}
|
||||
|
||||
TransactionUtil.handle(() -> {
|
||||
// Generate thumbnail, extract content
|
||||
processFile(event);
|
||||
|
||||
// Update Lucene index
|
||||
// Update index
|
||||
AppContext.getInstance().getIndexingHandler().updateFile(event.getFile());
|
||||
});
|
||||
|
||||
FileUtil.endProcessingFile(event.getFile().getId());
|
||||
}
|
||||
@ -94,12 +97,9 @@ public class FileProcessingAsyncListener {
|
||||
}
|
||||
|
||||
// Get the user from the database
|
||||
final AtomicReference<User> user = new AtomicReference<>();
|
||||
TransactionUtil.handle(() -> {
|
||||
UserDao userDao = new UserDao();
|
||||
user.set(userDao.getById(event.getUserId()));
|
||||
});
|
||||
if (user.get() == null) {
|
||||
User user = userDao.getById(event.getUserId());
|
||||
if (user == null) {
|
||||
// The user has been deleted meanwhile
|
||||
FileUtil.endProcessingFile(file.getId());
|
||||
return;
|
||||
@ -107,7 +107,7 @@ public class FileProcessingAsyncListener {
|
||||
|
||||
// Generate file variations
|
||||
try {
|
||||
Cipher cipher = EncryptionUtil.getEncryptionCipher(user.get().getPrivateKey());
|
||||
Cipher cipher = EncryptionUtil.getEncryptionCipher(user.getPrivateKey());
|
||||
BufferedImage image = formatHandler.generateThumbnail(event.getUnencryptedFile());
|
||||
if (image != null) {
|
||||
// Generate thumbnails from image
|
||||
@ -142,7 +142,6 @@ public class FileProcessingAsyncListener {
|
||||
log.info(MessageFormat.format("File content extracted in {0}ms", System.currentTimeMillis() - startTime));
|
||||
|
||||
// Save the file to database
|
||||
TransactionUtil.handle(() -> {
|
||||
FileDao fileDao = new FileDao();
|
||||
if (fileDao.getActiveById(file.getId()) == null) {
|
||||
// The file has been deleted since the text extraction started, ignore the result
|
||||
@ -151,6 +150,5 @@ public class FileProcessingAsyncListener {
|
||||
|
||||
file.setContent(content.get());
|
||||
fileDao.update(file);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user