indexing in transactional context

This commit is contained in:
Benjamin Gamard 2018-03-30 21:16:13 +02:00
parent 5c5a3f614f
commit 716954aa9a
4 changed files with 22 additions and 24 deletions

View File

@ -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());
});
}

View File

@ -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());
}
}

View File

@ -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());
}
}

View File

@ -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);
});
}
}