mirror of
https://github.com/sismics/docs.git
synced 2024-11-25 15:17:57 +01:00
Document updated event on file create/delete
This commit is contained in:
parent
0ad7ef43d5
commit
508a1230e9
@ -649,7 +649,7 @@ public class DocumentResource extends BaseResource {
|
|||||||
// Delete the document
|
// Delete the document
|
||||||
documentDao.delete(document.getId(), principal.getId());
|
documentDao.delete(document.getId(), principal.getId());
|
||||||
|
|
||||||
// Raise file deleted events
|
// Raise file deleted events (don't bother sending document updated event)
|
||||||
for (File file : fileList) {
|
for (File file : fileList) {
|
||||||
FileDeletedAsyncEvent fileDeletedAsyncEvent = new FileDeletedAsyncEvent();
|
FileDeletedAsyncEvent fileDeletedAsyncEvent = new FileDeletedAsyncEvent();
|
||||||
fileDeletedAsyncEvent.setUserId(principal.getId());
|
fileDeletedAsyncEvent.setUserId(principal.getId());
|
||||||
|
@ -44,6 +44,7 @@ import com.sismics.docs.core.dao.jpa.DocumentDao;
|
|||||||
import com.sismics.docs.core.dao.jpa.FileDao;
|
import com.sismics.docs.core.dao.jpa.FileDao;
|
||||||
import com.sismics.docs.core.dao.jpa.UserDao;
|
import com.sismics.docs.core.dao.jpa.UserDao;
|
||||||
import com.sismics.docs.core.dao.jpa.dto.DocumentDto;
|
import com.sismics.docs.core.dao.jpa.dto.DocumentDto;
|
||||||
|
import com.sismics.docs.core.event.DocumentUpdatedAsyncEvent;
|
||||||
import com.sismics.docs.core.event.FileCreatedAsyncEvent;
|
import com.sismics.docs.core.event.FileCreatedAsyncEvent;
|
||||||
import com.sismics.docs.core.event.FileDeletedAsyncEvent;
|
import com.sismics.docs.core.event.FileDeletedAsyncEvent;
|
||||||
import com.sismics.docs.core.model.context.AppContext;
|
import com.sismics.docs.core.model.context.AppContext;
|
||||||
@ -160,7 +161,7 @@ public class FileResource extends BaseResource {
|
|||||||
user.setStorageCurrent(user.getStorageCurrent() + fileData.length);
|
user.setStorageCurrent(user.getStorageCurrent() + fileData.length);
|
||||||
userDao.updateQuota(user);
|
userDao.updateQuota(user);
|
||||||
|
|
||||||
// Raise a new file created event if we have a document
|
// Raise a new file created event and document updated event if we have a document
|
||||||
if (documentId != null) {
|
if (documentId != null) {
|
||||||
FileCreatedAsyncEvent fileCreatedAsyncEvent = new FileCreatedAsyncEvent();
|
FileCreatedAsyncEvent fileCreatedAsyncEvent = new FileCreatedAsyncEvent();
|
||||||
fileCreatedAsyncEvent.setUserId(principal.getId());
|
fileCreatedAsyncEvent.setUserId(principal.getId());
|
||||||
@ -169,6 +170,11 @@ public class FileResource extends BaseResource {
|
|||||||
fileCreatedAsyncEvent.setInputStream(fileInputStream);
|
fileCreatedAsyncEvent.setInputStream(fileInputStream);
|
||||||
fileCreatedAsyncEvent.setPdfInputStream(pdfIntputStream);
|
fileCreatedAsyncEvent.setPdfInputStream(pdfIntputStream);
|
||||||
AppContext.getInstance().getAsyncEventBus().post(fileCreatedAsyncEvent);
|
AppContext.getInstance().getAsyncEventBus().post(fileCreatedAsyncEvent);
|
||||||
|
|
||||||
|
DocumentUpdatedAsyncEvent documentUpdatedAsyncEvent = new DocumentUpdatedAsyncEvent();
|
||||||
|
documentUpdatedAsyncEvent.setUserId(principal.getId());
|
||||||
|
documentUpdatedAsyncEvent.setDocument(document);
|
||||||
|
AppContext.getInstance().getAsyncEventBus().post(documentUpdatedAsyncEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Always return OK
|
// Always return OK
|
||||||
@ -223,7 +229,7 @@ public class FileResource extends BaseResource {
|
|||||||
file.setOrder(fileDao.getByDocumentId(principal.getId(), documentId).size());
|
file.setOrder(fileDao.getByDocumentId(principal.getId(), documentId).size());
|
||||||
fileDao.update(file);
|
fileDao.update(file);
|
||||||
|
|
||||||
// Raise a new file created event (it wasn't sent during file creation)
|
// Raise a new file created event and document updated event (it wasn't sent during file creation)
|
||||||
try {
|
try {
|
||||||
java.nio.file.Path storedFile = DirectoryUtil.getStorageDirectory().resolve(id);
|
java.nio.file.Path storedFile = DirectoryUtil.getStorageDirectory().resolve(id);
|
||||||
InputStream fileInputStream = Files.newInputStream(storedFile);
|
InputStream fileInputStream = Files.newInputStream(storedFile);
|
||||||
@ -234,6 +240,11 @@ public class FileResource extends BaseResource {
|
|||||||
fileCreatedAsyncEvent.setFile(file);
|
fileCreatedAsyncEvent.setFile(file);
|
||||||
fileCreatedAsyncEvent.setInputStream(responseInputStream);
|
fileCreatedAsyncEvent.setInputStream(responseInputStream);
|
||||||
AppContext.getInstance().getAsyncEventBus().post(fileCreatedAsyncEvent);
|
AppContext.getInstance().getAsyncEventBus().post(fileCreatedAsyncEvent);
|
||||||
|
|
||||||
|
DocumentUpdatedAsyncEvent documentUpdatedAsyncEvent = new DocumentUpdatedAsyncEvent();
|
||||||
|
documentUpdatedAsyncEvent.setUserId(principal.getId());
|
||||||
|
documentUpdatedAsyncEvent.setDocument(document);
|
||||||
|
AppContext.getInstance().getAsyncEventBus().post(documentUpdatedAsyncEvent);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new ClientException("AttachError", "Error attaching file to document", e);
|
throw new ClientException("AttachError", "Error attaching file to document", e);
|
||||||
}
|
}
|
||||||
@ -353,13 +364,14 @@ public class FileResource extends BaseResource {
|
|||||||
return Response.status(Status.NOT_FOUND).build();
|
return Response.status(Status.NOT_FOUND).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Document document = null;
|
||||||
if (file.getDocumentId() == null) {
|
if (file.getDocumentId() == null) {
|
||||||
// It's an orphan file
|
// It's an orphan file
|
||||||
if (!file.getUserId().equals(principal.getId())) {
|
if (!file.getUserId().equals(principal.getId())) {
|
||||||
// But not ours
|
// But not ours
|
||||||
throw new ForbiddenClientException();
|
throw new ForbiddenClientException();
|
||||||
}
|
}
|
||||||
} else if (documentDao.getDocument(file.getDocumentId(), PermType.WRITE, principal.getId()) == null) {
|
} else if ((document = documentDao.getDocument(file.getDocumentId(), PermType.WRITE, principal.getId())) == null) {
|
||||||
return Response.status(Status.NOT_FOUND).build();
|
return Response.status(Status.NOT_FOUND).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -383,6 +395,14 @@ public class FileResource extends BaseResource {
|
|||||||
fileDeletedAsyncEvent.setFile(file);
|
fileDeletedAsyncEvent.setFile(file);
|
||||||
AppContext.getInstance().getAsyncEventBus().post(fileDeletedAsyncEvent);
|
AppContext.getInstance().getAsyncEventBus().post(fileDeletedAsyncEvent);
|
||||||
|
|
||||||
|
if (document != null) {
|
||||||
|
// Raise a new document updated
|
||||||
|
DocumentUpdatedAsyncEvent documentUpdatedAsyncEvent = new DocumentUpdatedAsyncEvent();
|
||||||
|
documentUpdatedAsyncEvent.setUserId(principal.getId());
|
||||||
|
documentUpdatedAsyncEvent.setDocument(document);
|
||||||
|
AppContext.getInstance().getAsyncEventBus().post(documentUpdatedAsyncEvent);
|
||||||
|
}
|
||||||
|
|
||||||
// Always return OK
|
// Always return OK
|
||||||
JsonObjectBuilder response = Json.createObjectBuilder()
|
JsonObjectBuilder response = Json.createObjectBuilder()
|
||||||
.add("status", "ok");
|
.add("status", "ok");
|
||||||
|
@ -366,7 +366,7 @@ public class UserResource extends BaseResource {
|
|||||||
AppContext.getInstance().getAsyncEventBus().post(documentDeletedAsyncEvent);
|
AppContext.getInstance().getAsyncEventBus().post(documentDeletedAsyncEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Raise deleted events for files
|
// Raise deleted events for files (don't bother sending document updated event)
|
||||||
for (File file : fileList) {
|
for (File file : fileList) {
|
||||||
FileDeletedAsyncEvent fileDeletedAsyncEvent = new FileDeletedAsyncEvent();
|
FileDeletedAsyncEvent fileDeletedAsyncEvent = new FileDeletedAsyncEvent();
|
||||||
fileDeletedAsyncEvent.setUserId(principal.getId());
|
fileDeletedAsyncEvent.setUserId(principal.getId());
|
||||||
@ -425,7 +425,7 @@ public class UserResource extends BaseResource {
|
|||||||
AppContext.getInstance().getAsyncEventBus().post(documentDeletedAsyncEvent);
|
AppContext.getInstance().getAsyncEventBus().post(documentDeletedAsyncEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Raise deleted events for files
|
// Raise deleted events for files (don't bother sending document updated event)
|
||||||
for (File file : fileList) {
|
for (File file : fileList) {
|
||||||
FileDeletedAsyncEvent fileDeletedAsyncEvent = new FileDeletedAsyncEvent();
|
FileDeletedAsyncEvent fileDeletedAsyncEvent = new FileDeletedAsyncEvent();
|
||||||
fileDeletedAsyncEvent.setUserId(principal.getId());
|
fileDeletedAsyncEvent.setUserId(principal.getId());
|
||||||
|
Loading…
Reference in New Issue
Block a user