Fire some more indexing events

This commit is contained in:
Benjamin Gamard 2018-04-01 23:06:45 +02:00
parent 68729e3b54
commit d819c05669
9 changed files with 173 additions and 4 deletions

View File

@ -0,0 +1,31 @@
package com.sismics.docs.core.event;
import com.google.common.base.MoreObjects;
/**
* ACL created event.
*
* @author bgamard
*/
public class AclCreatedAsyncEvent extends UserEvent {
/**
* Source ID.
*/
private String sourceId;
public String getSourceId() {
return sourceId;
}
public AclCreatedAsyncEvent setSourceId(String sourceId) {
this.sourceId = sourceId;
return this;
}
@Override
public String toString() {
return MoreObjects.toStringHelper(this)
.add("sourceId", sourceId)
.toString();
}
}

View File

@ -0,0 +1,31 @@
package com.sismics.docs.core.event;
import com.google.common.base.MoreObjects;
/**
* ACL deleted event.
*
* @author bgamard
*/
public class AclDeletedAsyncEvent extends UserEvent {
/**
* Source ID.
*/
private String sourceId;
public String getSourceId() {
return sourceId;
}
public AclDeletedAsyncEvent setSourceId(String sourceId) {
this.sourceId = sourceId;
return this;
}
@Override
public String toString() {
return MoreObjects.toStringHelper(this)
.add("sourceId", sourceId)
.toString();
}
}

View File

@ -0,0 +1,36 @@
package com.sismics.docs.core.listener.async;
import com.google.common.eventbus.Subscribe;
import com.sismics.docs.core.event.AclCreatedAsyncEvent;
import com.sismics.docs.core.model.context.AppContext;
import com.sismics.docs.core.util.TransactionUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Listener on ACL created.
*
* @author bgamard
*/
public class AclCreatedAsyncListener {
/**
* Logger.
*/
private static final Logger log = LoggerFactory.getLogger(AclCreatedAsyncListener.class);
/**
* ACL created.
*
* @param event ACL created event
*/
@Subscribe
public void on(final AclCreatedAsyncEvent event) {
if (log.isInfoEnabled()) {
log.info("ACL created event: " + event.toString());
}
TransactionUtil.handle(() -> {
AppContext.getInstance().getIndexingHandler().createAcl(event.getSourceId());
});
}
}

View File

@ -0,0 +1,36 @@
package com.sismics.docs.core.listener.async;
import com.google.common.eventbus.Subscribe;
import com.sismics.docs.core.event.AclDeletedAsyncEvent;
import com.sismics.docs.core.model.context.AppContext;
import com.sismics.docs.core.util.TransactionUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Listener on ACL deleted.
*
* @author bgamard
*/
public class AclDeletedAsyncListener {
/**
* Logger.
*/
private static final Logger log = LoggerFactory.getLogger(AclDeletedAsyncListener.class);
/**
* ACL deleted.
*
* @param event ACL deleted event
*/
@Subscribe
public void on(final AclDeletedAsyncEvent event) {
if (log.isInfoEnabled()) {
log.info("ACL deleted event: " + event.toString());
}
TransactionUtil.handle(() -> {
AppContext.getInstance().getIndexingHandler().deleteAcl(event.getSourceId());
});
}
}

View File

@ -124,6 +124,8 @@ public class AppContext {
asyncEventBus.register(new DocumentDeletedAsyncListener()); asyncEventBus.register(new DocumentDeletedAsyncListener());
asyncEventBus.register(new RebuildIndexAsyncListener()); asyncEventBus.register(new RebuildIndexAsyncListener());
asyncEventBus.register(new TemporaryFileCleanupAsyncListener()); asyncEventBus.register(new TemporaryFileCleanupAsyncListener());
asyncEventBus.register(new AclCreatedAsyncListener());
asyncEventBus.register(new AclDeletedAsyncListener());
mailEventBus = newAsyncEventBus(); mailEventBus = newAsyncEventBus();
mailEventBus.register(new PasswordLostAsyncListener()); mailEventBus.register(new PasswordLostAsyncListener());

View File

@ -70,6 +70,20 @@ public interface IndexingHandler {
*/ */
void deleteDocument(String id); void deleteDocument(String id);
/**
* Create an ACL.
*
* @param sourceId Source ID
*/
void createAcl(String sourceId);
/**
* Delete an ACL.
*
* @param sourceId Source ID
*/
void deleteAcl(String sourceId);
/** /**
* Searches documents by criteria. * Searches documents by criteria.
* *

View File

@ -168,6 +168,16 @@ public class LuceneIndexingHandler implements IndexingHandler {
handle(indexWriter -> indexWriter.deleteDocuments(new Term("id", id))); handle(indexWriter -> indexWriter.deleteDocuments(new Term("id", id)));
} }
@Override
public void createAcl(String sourceId) {
// Lucene does not index ACLs
}
@Override
public void deleteAcl(String sourceId) {
// Lucene does not index ACLs
}
@Override @Override
public void findByCriteria(PaginatedList<DocumentDto> paginatedList, DocumentCriteria criteria, SortCriteria sortCriteria) throws Exception { public void findByCriteria(PaginatedList<DocumentDto> paginatedList, DocumentCriteria criteria, SortCriteria sortCriteria) throws Exception {
Map<String, Object> parameterMap = new HashMap<>(); Map<String, Object> parameterMap = new HashMap<>();

View File

@ -9,6 +9,8 @@ import com.sismics.docs.core.dao.criteria.GroupCriteria;
import com.sismics.docs.core.dao.criteria.UserCriteria; import com.sismics.docs.core.dao.criteria.UserCriteria;
import com.sismics.docs.core.dao.dto.GroupDto; import com.sismics.docs.core.dao.dto.GroupDto;
import com.sismics.docs.core.dao.dto.UserDto; import com.sismics.docs.core.dao.dto.UserDto;
import com.sismics.docs.core.event.AclCreatedAsyncEvent;
import com.sismics.docs.core.event.AclDeletedAsyncEvent;
import com.sismics.docs.core.model.jpa.Acl; import com.sismics.docs.core.model.jpa.Acl;
import com.sismics.docs.core.model.jpa.Document; import com.sismics.docs.core.model.jpa.Document;
import com.sismics.docs.core.model.jpa.Tag; import com.sismics.docs.core.model.jpa.Tag;
@ -17,6 +19,7 @@ import com.sismics.docs.core.util.jpa.SortCriteria;
import com.sismics.rest.exception.ClientException; import com.sismics.rest.exception.ClientException;
import com.sismics.rest.exception.ForbiddenClientException; import com.sismics.rest.exception.ForbiddenClientException;
import com.sismics.rest.util.ValidationUtil; import com.sismics.rest.util.ValidationUtil;
import com.sismics.util.context.ThreadLocalContext;
import javax.json.Json; import javax.json.Json;
import javax.json.JsonArrayBuilder; import javax.json.JsonArrayBuilder;
@ -97,7 +100,11 @@ public class AclResource extends BaseResource {
if (!aclDao.checkPermission(acl.getSourceId(), acl.getPerm(), Lists.newArrayList(acl.getTargetId()))) { if (!aclDao.checkPermission(acl.getSourceId(), acl.getPerm(), Lists.newArrayList(acl.getTargetId()))) {
aclDao.create(acl, principal.getId()); aclDao.create(acl, principal.getId());
// TODO Update event for direct and indirect documents // Raise an ACL created event
AclCreatedAsyncEvent event = new AclCreatedAsyncEvent();
event.setUserId(principal.getId());
event.setSourceId(sourceId);
ThreadLocalContext.get().addAsyncEvent(event);
// Returns the ACL // Returns the ACL
JsonObjectBuilder response = Json.createObjectBuilder() JsonObjectBuilder response = Json.createObjectBuilder()
@ -170,7 +177,11 @@ public class AclResource extends BaseResource {
// Delete the ACL // Delete the ACL
aclDao.delete(sourceId, perm, targetId, principal.getId(), AclType.USER); aclDao.delete(sourceId, perm, targetId, principal.getId(), AclType.USER);
// TODO Update event for direct and indirect documents // Raise an ACL deleted event
AclDeletedAsyncEvent event = new AclDeletedAsyncEvent();
event.setUserId(principal.getId());
event.setSourceId(sourceId);
ThreadLocalContext.get().addAsyncEvent(event);
// Always return OK // Always return OK
JsonObjectBuilder response = Json.createObjectBuilder() JsonObjectBuilder response = Json.createObjectBuilder()

View File

@ -332,8 +332,6 @@ public class TagResource extends BaseResource {
throw new NotFoundException(); throw new NotFoundException();
} }
// TODO Update event for associated documents
// Delete the tag // Delete the tag
TagDao tagDao = new TagDao(); TagDao tagDao = new TagDao();
tagDao.delete(id, principal.getId()); tagDao.delete(id, principal.getId());