mirror of
https://github.com/sismics/docs.git
synced 2024-11-25 23:27:57 +01:00
missing document updated events
This commit is contained in:
parent
d1a8fa38b0
commit
229d845a42
@ -10,10 +10,12 @@ import com.sismics.docs.core.dao.UserDao;
|
|||||||
import com.sismics.docs.core.dao.criteria.UserCriteria;
|
import com.sismics.docs.core.dao.criteria.UserCriteria;
|
||||||
import com.sismics.docs.core.dao.dto.RouteStepDto;
|
import com.sismics.docs.core.dao.dto.RouteStepDto;
|
||||||
import com.sismics.docs.core.dao.dto.UserDto;
|
import com.sismics.docs.core.dao.dto.UserDto;
|
||||||
|
import com.sismics.docs.core.event.DocumentUpdatedAsyncEvent;
|
||||||
import com.sismics.docs.core.event.RouteStepValidateEvent;
|
import com.sismics.docs.core.event.RouteStepValidateEvent;
|
||||||
import com.sismics.docs.core.model.context.AppContext;
|
import com.sismics.docs.core.model.context.AppContext;
|
||||||
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.util.context.ThreadLocalContext;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -26,17 +28,17 @@ public class RoutingUtil {
|
|||||||
/**
|
/**
|
||||||
* Update routing ACLs according to the current route step.
|
* Update routing ACLs according to the current route step.
|
||||||
*
|
*
|
||||||
* @param sourceId Source ID
|
* @param documentId Document ID
|
||||||
* @param currentStep Current route step
|
* @param currentStep Current route step
|
||||||
* @param previousStep Previous route step
|
* @param previousStep Previous route step
|
||||||
* @param userId User ID
|
* @param userId User ID
|
||||||
*/
|
*/
|
||||||
public static void updateAcl(String sourceId, RouteStepDto currentStep, RouteStepDto previousStep, String userId) {
|
public static void updateAcl(String documentId, RouteStepDto currentStep, RouteStepDto previousStep, String userId) {
|
||||||
AclDao aclDao = new AclDao();
|
AclDao aclDao = new AclDao();
|
||||||
|
|
||||||
if (previousStep != null) {
|
if (previousStep != null) {
|
||||||
// Remove the previous ACL
|
// Remove the previous ACL
|
||||||
aclDao.delete(sourceId, PermType.READ, previousStep.getTargetId(), userId, AclType.ROUTING);
|
aclDao.delete(documentId, PermType.READ, previousStep.getTargetId(), userId, AclType.ROUTING);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (currentStep != null) {
|
if (currentStep != null) {
|
||||||
@ -44,10 +46,16 @@ public class RoutingUtil {
|
|||||||
Acl acl = new Acl();
|
Acl acl = new Acl();
|
||||||
acl.setPerm(PermType.READ);
|
acl.setPerm(PermType.READ);
|
||||||
acl.setType(AclType.ROUTING);
|
acl.setType(AclType.ROUTING);
|
||||||
acl.setSourceId(sourceId);
|
acl.setSourceId(documentId);
|
||||||
acl.setTargetId(currentStep.getTargetId());
|
acl.setTargetId(currentStep.getTargetId());
|
||||||
aclDao.create(acl, userId);
|
aclDao.create(acl, userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Raise a document updated event
|
||||||
|
DocumentUpdatedAsyncEvent event = new DocumentUpdatedAsyncEvent();
|
||||||
|
event.setUserId(userId);
|
||||||
|
event.setDocumentId(documentId);
|
||||||
|
ThreadLocalContext.get().addAsyncEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -97,6 +97,8 @@ 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
|
||||||
|
|
||||||
// Returns the ACL
|
// Returns the ACL
|
||||||
JsonObjectBuilder response = Json.createObjectBuilder()
|
JsonObjectBuilder response = Json.createObjectBuilder()
|
||||||
.add("perm", acl.getPerm().name())
|
.add("perm", acl.getPerm().name())
|
||||||
@ -168,6 +170,8 @@ 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
|
||||||
|
|
||||||
// Always return OK
|
// Always return OK
|
||||||
JsonObjectBuilder response = Json.createObjectBuilder()
|
JsonObjectBuilder response = Json.createObjectBuilder()
|
||||||
.add("status", "ok");
|
.add("status", "ok");
|
||||||
|
@ -800,7 +800,7 @@ public class DocumentResource extends BaseResource {
|
|||||||
// Update relations
|
// Update relations
|
||||||
updateRelationList(id, relationList);
|
updateRelationList(id, relationList);
|
||||||
|
|
||||||
// Raise a document updated event (with the document to update Lucene)
|
// Raise a document updated event
|
||||||
DocumentUpdatedAsyncEvent documentUpdatedAsyncEvent = new DocumentUpdatedAsyncEvent();
|
DocumentUpdatedAsyncEvent documentUpdatedAsyncEvent = new DocumentUpdatedAsyncEvent();
|
||||||
documentUpdatedAsyncEvent.setUserId(principal.getId());
|
documentUpdatedAsyncEvent.setUserId(principal.getId());
|
||||||
documentUpdatedAsyncEvent.setDocumentId(id);
|
documentUpdatedAsyncEvent.setDocumentId(id);
|
||||||
|
@ -180,12 +180,6 @@ public class RouteResource extends BaseResource {
|
|||||||
throw new ClientException("ValidationError", "Invalid transition for this route step type");
|
throw new ClientException("ValidationError", "Invalid transition for this route step type");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate the step and update ACLs
|
|
||||||
routeStepDao.endRouteStep(routeStepDto.getId(), routeStepTransition, comment, principal.getId());
|
|
||||||
RouteStepDto newRouteStep = routeStepDao.getCurrentStep(documentId);
|
|
||||||
RoutingUtil.updateAcl(documentId, newRouteStep, routeStepDto, principal.getId());
|
|
||||||
RoutingUtil.sendRouteStepEmail(documentId, routeStepDto);
|
|
||||||
|
|
||||||
// Execute actions
|
// Execute actions
|
||||||
if (routeStepDto.getTransitions() != null) {
|
if (routeStepDto.getTransitions() != null) {
|
||||||
try (JsonReader reader = Json.createReader(new StringReader(routeStepDto.getTransitions()))) {
|
try (JsonReader reader = Json.createReader(new StringReader(routeStepDto.getTransitions()))) {
|
||||||
@ -206,6 +200,12 @@ public class RouteResource extends BaseResource {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Validate the step and update ACLs
|
||||||
|
routeStepDao.endRouteStep(routeStepDto.getId(), routeStepTransition, comment, principal.getId());
|
||||||
|
RouteStepDto newRouteStep = routeStepDao.getCurrentStep(documentId);
|
||||||
|
RoutingUtil.updateAcl(documentId, newRouteStep, routeStepDto, principal.getId());
|
||||||
|
RoutingUtil.sendRouteStepEmail(documentId, routeStepDto);
|
||||||
|
|
||||||
JsonObjectBuilder response = Json.createObjectBuilder()
|
JsonObjectBuilder response = Json.createObjectBuilder()
|
||||||
.add("readable", aclDao.checkPermission(documentId, PermType.READ, getTargetIdList(null)));
|
.add("readable", aclDao.checkPermission(documentId, PermType.READ, getTargetIdList(null)));
|
||||||
if (newRouteStep != null) {
|
if (newRouteStep != null) {
|
||||||
|
@ -6,12 +6,14 @@ import com.sismics.docs.core.constant.AclType;
|
|||||||
import com.sismics.docs.core.constant.PermType;
|
import com.sismics.docs.core.constant.PermType;
|
||||||
import com.sismics.docs.core.dao.AclDao;
|
import com.sismics.docs.core.dao.AclDao;
|
||||||
import com.sismics.docs.core.dao.ShareDao;
|
import com.sismics.docs.core.dao.ShareDao;
|
||||||
|
import com.sismics.docs.core.event.DocumentUpdatedAsyncEvent;
|
||||||
import com.sismics.docs.core.model.jpa.Acl;
|
import com.sismics.docs.core.model.jpa.Acl;
|
||||||
import com.sismics.docs.core.model.jpa.Share;
|
import com.sismics.docs.core.model.jpa.Share;
|
||||||
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.JsonUtil;
|
import com.sismics.util.JsonUtil;
|
||||||
|
import com.sismics.util.context.ThreadLocalContext;
|
||||||
|
|
||||||
import javax.json.Json;
|
import javax.json.Json;
|
||||||
import javax.json.JsonObjectBuilder;
|
import javax.json.JsonObjectBuilder;
|
||||||
@ -81,6 +83,12 @@ public class ShareResource extends BaseResource {
|
|||||||
acl.setTargetId(share.getId());
|
acl.setTargetId(share.getId());
|
||||||
aclDao.create(acl, principal.getId());
|
aclDao.create(acl, principal.getId());
|
||||||
|
|
||||||
|
// Raise a document updated event
|
||||||
|
DocumentUpdatedAsyncEvent event = new DocumentUpdatedAsyncEvent();
|
||||||
|
event.setUserId(principal.getId());
|
||||||
|
event.setDocumentId(documentId);
|
||||||
|
ThreadLocalContext.get().addAsyncEvent(event);
|
||||||
|
|
||||||
// Returns the created ACL
|
// Returns the created ACL
|
||||||
JsonObjectBuilder response = Json.createObjectBuilder()
|
JsonObjectBuilder response = Json.createObjectBuilder()
|
||||||
.add("perm", acl.getPerm().name())
|
.add("perm", acl.getPerm().name())
|
||||||
@ -131,6 +139,12 @@ public class ShareResource extends BaseResource {
|
|||||||
ShareDao shareDao = new ShareDao();
|
ShareDao shareDao = new ShareDao();
|
||||||
shareDao.delete(id);
|
shareDao.delete(id);
|
||||||
|
|
||||||
|
// Raise a document updated event
|
||||||
|
DocumentUpdatedAsyncEvent event = new DocumentUpdatedAsyncEvent();
|
||||||
|
event.setUserId(principal.getId());
|
||||||
|
event.setDocumentId(acl.getSourceId());
|
||||||
|
ThreadLocalContext.get().addAsyncEvent(event);
|
||||||
|
|
||||||
// Always return OK
|
// Always return OK
|
||||||
JsonObjectBuilder response = Json.createObjectBuilder()
|
JsonObjectBuilder response = Json.createObjectBuilder()
|
||||||
.add("status", "ok");
|
.add("status", "ok");
|
||||||
|
@ -332,6 +332,8 @@ 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());
|
||||||
|
Loading…
Reference in New Issue
Block a user