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