mirror of
https://github.com/sismics/docs.git
synced 2024-11-22 14:07:55 +01:00
#68: User ID available in events fired by a user
This commit is contained in:
parent
67171e05b9
commit
0ad7ef43d5
@ -8,7 +8,7 @@ import com.sismics.docs.core.model.jpa.Document;
|
||||
*
|
||||
* @author bgamard
|
||||
*/
|
||||
public class DocumentCreatedAsyncEvent {
|
||||
public class DocumentCreatedAsyncEvent extends UserEvent {
|
||||
/**
|
||||
* Created document.
|
||||
*/
|
||||
|
@ -8,7 +8,7 @@ import com.sismics.docs.core.model.jpa.Document;
|
||||
*
|
||||
* @author bgamard
|
||||
*/
|
||||
public class DocumentDeletedAsyncEvent {
|
||||
public class DocumentDeletedAsyncEvent extends UserEvent {
|
||||
/**
|
||||
* Created document.
|
||||
*/
|
||||
|
@ -8,7 +8,7 @@ import com.sismics.docs.core.model.jpa.Document;
|
||||
*
|
||||
* @author bgamard
|
||||
*/
|
||||
public class DocumentUpdatedAsyncEvent {
|
||||
public class DocumentUpdatedAsyncEvent extends UserEvent {
|
||||
/**
|
||||
* Created document.
|
||||
*/
|
||||
|
@ -11,7 +11,7 @@ import com.sismics.docs.core.model.jpa.File;
|
||||
*
|
||||
* @author bgamard
|
||||
*/
|
||||
public class FileCreatedAsyncEvent {
|
||||
public class FileCreatedAsyncEvent extends UserEvent {
|
||||
/**
|
||||
* Created file.
|
||||
*/
|
||||
|
@ -8,7 +8,7 @@ import com.sismics.docs.core.model.jpa.File;
|
||||
*
|
||||
* @author bgamard
|
||||
*/
|
||||
public class FileDeletedAsyncEvent {
|
||||
public class FileDeletedAsyncEvent extends UserEvent {
|
||||
/**
|
||||
* Deleted file.
|
||||
*/
|
||||
|
@ -0,0 +1,21 @@
|
||||
package com.sismics.docs.core.event;
|
||||
|
||||
/**
|
||||
* Event fired by a user.
|
||||
*
|
||||
* @author bgamard
|
||||
*/
|
||||
public abstract class UserEvent {
|
||||
/**
|
||||
* User ID who fired the event.
|
||||
*/
|
||||
private String userId;
|
||||
|
||||
public String getUserId() {
|
||||
return userId;
|
||||
}
|
||||
|
||||
public void setUserId(String userId) {
|
||||
this.userId = userId;
|
||||
}
|
||||
}
|
@ -482,6 +482,7 @@ public class DocumentResource extends BaseResource {
|
||||
|
||||
// Raise a document created event
|
||||
DocumentCreatedAsyncEvent documentCreatedAsyncEvent = new DocumentCreatedAsyncEvent();
|
||||
documentCreatedAsyncEvent.setUserId(principal.getId());
|
||||
documentCreatedAsyncEvent.setDocument(document);
|
||||
AppContext.getInstance().getAsyncEventBus().post(documentCreatedAsyncEvent);
|
||||
|
||||
@ -588,6 +589,7 @@ public class DocumentResource extends BaseResource {
|
||||
|
||||
// Raise a document updated event
|
||||
DocumentUpdatedAsyncEvent documentUpdatedAsyncEvent = new DocumentUpdatedAsyncEvent();
|
||||
documentUpdatedAsyncEvent.setUserId(principal.getId());
|
||||
documentUpdatedAsyncEvent.setDocument(document);
|
||||
AppContext.getInstance().getAsyncEventBus().post(documentUpdatedAsyncEvent);
|
||||
|
||||
@ -650,12 +652,14 @@ public class DocumentResource extends BaseResource {
|
||||
// Raise file deleted events
|
||||
for (File file : fileList) {
|
||||
FileDeletedAsyncEvent fileDeletedAsyncEvent = new FileDeletedAsyncEvent();
|
||||
fileDeletedAsyncEvent.setUserId(principal.getId());
|
||||
fileDeletedAsyncEvent.setFile(file);
|
||||
AppContext.getInstance().getAsyncEventBus().post(fileDeletedAsyncEvent);
|
||||
}
|
||||
|
||||
// Raise a document deleted event
|
||||
DocumentDeletedAsyncEvent documentDeletedAsyncEvent = new DocumentDeletedAsyncEvent();
|
||||
documentDeletedAsyncEvent.setUserId(principal.getId());
|
||||
documentDeletedAsyncEvent.setDocument(document);
|
||||
AppContext.getInstance().getAsyncEventBus().post(documentDeletedAsyncEvent);
|
||||
|
||||
|
@ -163,6 +163,7 @@ public class FileResource extends BaseResource {
|
||||
// Raise a new file created event if we have a document
|
||||
if (documentId != null) {
|
||||
FileCreatedAsyncEvent fileCreatedAsyncEvent = new FileCreatedAsyncEvent();
|
||||
fileCreatedAsyncEvent.setUserId(principal.getId());
|
||||
fileCreatedAsyncEvent.setDocument(document);
|
||||
fileCreatedAsyncEvent.setFile(file);
|
||||
fileCreatedAsyncEvent.setInputStream(fileInputStream);
|
||||
@ -228,6 +229,7 @@ public class FileResource extends BaseResource {
|
||||
InputStream fileInputStream = Files.newInputStream(storedFile);
|
||||
final InputStream responseInputStream = EncryptionUtil.decryptInputStream(fileInputStream, user.getPrivateKey());
|
||||
FileCreatedAsyncEvent fileCreatedAsyncEvent = new FileCreatedAsyncEvent();
|
||||
fileCreatedAsyncEvent.setUserId(principal.getId());
|
||||
fileCreatedAsyncEvent.setDocument(document);
|
||||
fileCreatedAsyncEvent.setFile(file);
|
||||
fileCreatedAsyncEvent.setInputStream(responseInputStream);
|
||||
@ -377,6 +379,7 @@ public class FileResource extends BaseResource {
|
||||
|
||||
// Raise a new file deleted event
|
||||
FileDeletedAsyncEvent fileDeletedAsyncEvent = new FileDeletedAsyncEvent();
|
||||
fileDeletedAsyncEvent.setUserId(principal.getId());
|
||||
fileDeletedAsyncEvent.setFile(file);
|
||||
AppContext.getInstance().getAsyncEventBus().post(fileDeletedAsyncEvent);
|
||||
|
||||
|
@ -361,6 +361,7 @@ public class UserResource extends BaseResource {
|
||||
// Raise deleted events for documents
|
||||
for (Document document : documentList) {
|
||||
DocumentDeletedAsyncEvent documentDeletedAsyncEvent = new DocumentDeletedAsyncEvent();
|
||||
documentDeletedAsyncEvent.setUserId(principal.getId());
|
||||
documentDeletedAsyncEvent.setDocument(document);
|
||||
AppContext.getInstance().getAsyncEventBus().post(documentDeletedAsyncEvent);
|
||||
}
|
||||
@ -368,6 +369,7 @@ public class UserResource extends BaseResource {
|
||||
// Raise deleted events for files
|
||||
for (File file : fileList) {
|
||||
FileDeletedAsyncEvent fileDeletedAsyncEvent = new FileDeletedAsyncEvent();
|
||||
fileDeletedAsyncEvent.setUserId(principal.getId());
|
||||
fileDeletedAsyncEvent.setFile(file);
|
||||
AppContext.getInstance().getAsyncEventBus().post(fileDeletedAsyncEvent);
|
||||
}
|
||||
@ -418,6 +420,7 @@ public class UserResource extends BaseResource {
|
||||
// Raise deleted events for documents
|
||||
for (Document document : documentList) {
|
||||
DocumentDeletedAsyncEvent documentDeletedAsyncEvent = new DocumentDeletedAsyncEvent();
|
||||
documentDeletedAsyncEvent.setUserId(principal.getId());
|
||||
documentDeletedAsyncEvent.setDocument(document);
|
||||
AppContext.getInstance().getAsyncEventBus().post(documentDeletedAsyncEvent);
|
||||
}
|
||||
@ -425,6 +428,7 @@ public class UserResource extends BaseResource {
|
||||
// Raise deleted events for files
|
||||
for (File file : fileList) {
|
||||
FileDeletedAsyncEvent fileDeletedAsyncEvent = new FileDeletedAsyncEvent();
|
||||
fileDeletedAsyncEvent.setUserId(principal.getId());
|
||||
fileDeletedAsyncEvent.setFile(file);
|
||||
AppContext.getInstance().getAsyncEventBus().post(fileDeletedAsyncEvent);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user