mirror of
https://github.com/sismics/docs.git
synced 2024-11-22 05:57:57 +01:00
Fire some more indexing events
This commit is contained in:
parent
68729e3b54
commit
d819c05669
@ -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();
|
||||
}
|
||||
}
|
@ -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();
|
||||
}
|
||||
}
|
@ -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());
|
||||
});
|
||||
}
|
||||
}
|
@ -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());
|
||||
});
|
||||
}
|
||||
}
|
@ -124,6 +124,8 @@ public class AppContext {
|
||||
asyncEventBus.register(new DocumentDeletedAsyncListener());
|
||||
asyncEventBus.register(new RebuildIndexAsyncListener());
|
||||
asyncEventBus.register(new TemporaryFileCleanupAsyncListener());
|
||||
asyncEventBus.register(new AclCreatedAsyncListener());
|
||||
asyncEventBus.register(new AclDeletedAsyncListener());
|
||||
|
||||
mailEventBus = newAsyncEventBus();
|
||||
mailEventBus.register(new PasswordLostAsyncListener());
|
||||
|
@ -70,6 +70,20 @@ public interface IndexingHandler {
|
||||
*/
|
||||
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.
|
||||
*
|
||||
|
@ -168,6 +168,16 @@ public class LuceneIndexingHandler implements IndexingHandler {
|
||||
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
|
||||
public void findByCriteria(PaginatedList<DocumentDto> paginatedList, DocumentCriteria criteria, SortCriteria sortCriteria) throws Exception {
|
||||
Map<String, Object> parameterMap = new HashMap<>();
|
||||
|
@ -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.dto.GroupDto;
|
||||
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.Document;
|
||||
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.ForbiddenClientException;
|
||||
import com.sismics.rest.util.ValidationUtil;
|
||||
import com.sismics.util.context.ThreadLocalContext;
|
||||
|
||||
import javax.json.Json;
|
||||
import javax.json.JsonArrayBuilder;
|
||||
@ -97,7 +100,11 @@ public class AclResource extends BaseResource {
|
||||
if (!aclDao.checkPermission(acl.getSourceId(), acl.getPerm(), Lists.newArrayList(acl.getTargetId()))) {
|
||||
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
|
||||
JsonObjectBuilder response = Json.createObjectBuilder()
|
||||
@ -170,7 +177,11 @@ public class AclResource extends BaseResource {
|
||||
// Delete the ACL
|
||||
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
|
||||
JsonObjectBuilder response = Json.createObjectBuilder()
|
||||
|
@ -332,8 +332,6 @@ public class TagResource extends BaseResource {
|
||||
throw new NotFoundException();
|
||||
}
|
||||
|
||||
// TODO Update event for associated documents
|
||||
|
||||
// Delete the tag
|
||||
TagDao tagDao = new TagDao();
|
||||
tagDao.delete(id, principal.getId());
|
||||
|
Loading…
Reference in New Issue
Block a user