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