indexing in transactional context

This commit is contained in:
Benjamin Gamard 2018-03-31 13:22:59 +02:00
parent b54debe2e5
commit e72dab2a6e
2 changed files with 19 additions and 13 deletions

View File

@ -3,6 +3,7 @@ package com.sismics.docs.core.listener.async;
import com.google.common.eventbus.Subscribe;
import com.sismics.docs.core.event.DocumentDeletedAsyncEvent;
import com.sismics.docs.core.model.context.AppContext;
import com.sismics.docs.core.util.TransactionUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -20,16 +21,18 @@ public class DocumentDeletedAsyncListener {
/**
* Document deleted.
*
* @param documentDeletedAsyncEvent Document deleted event
* @throws Exception
* @param event Document deleted event
* @throws Exception e
*/
@Subscribe
public void on(final DocumentDeletedAsyncEvent documentDeletedAsyncEvent) throws Exception {
public void on(final DocumentDeletedAsyncEvent event) {
if (log.isInfoEnabled()) {
log.info("Document deleted event: " + documentDeletedAsyncEvent.toString());
log.info("Document deleted event: " + event.toString());
}
TransactionUtil.handle(() -> {
// Update index
AppContext.getInstance().getIndexingHandler().deleteDocument(documentDeletedAsyncEvent.getDocumentId());
AppContext.getInstance().getIndexingHandler().deleteDocument(event.getDocumentId());
});
}
}

View File

@ -5,6 +5,7 @@ import com.sismics.docs.core.event.FileDeletedAsyncEvent;
import com.sismics.docs.core.model.context.AppContext;
import com.sismics.docs.core.model.jpa.File;
import com.sismics.docs.core.util.FileUtil;
import com.sismics.docs.core.util.TransactionUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -22,20 +23,22 @@ public class FileDeletedAsyncListener {
/**
* File deleted.
*
* @param fileDeletedAsyncEvent File deleted event
* @param event File deleted event
* @throws Exception e
*/
@Subscribe
public void on(final FileDeletedAsyncEvent fileDeletedAsyncEvent) throws Exception {
public void on(final FileDeletedAsyncEvent event) throws Exception {
if (log.isInfoEnabled()) {
log.info("File deleted event: " + fileDeletedAsyncEvent.toString());
log.info("File deleted event: " + event.toString());
}
// Delete the file from storage
File file = fileDeletedAsyncEvent.getFile();
File file = event.getFile();
FileUtil.delete(file);
TransactionUtil.handle(() -> {
// Update index
AppContext.getInstance().getIndexingHandler().deleteDocument(file.getId());
});
}
}