From 9012b0bc582a405d35b10202960e5653dfc2bd42 Mon Sep 17 00:00:00 2001 From: Massimiliano Assante Date: Fri, 6 May 2022 17:15:48 +0200 Subject: [PATCH] added classes for catalogue notifications --- .../model/beans/catalogue/CatalogueEvent.java | 164 ++++++++++++++++++ .../beans/catalogue/CatalogueEventType.java | 10 ++ .../model/beans/workspace/AddedItemEvent.java | 2 +- .../model/beans/workspace/FileItemBean.java | 8 +- .../model/beans/workspace/WorkspaceEvent.java | 2 +- 5 files changed, 183 insertions(+), 3 deletions(-) create mode 100644 src/main/java/org/gcube/social_networking/socialnetworking/model/beans/catalogue/CatalogueEvent.java create mode 100644 src/main/java/org/gcube/social_networking/socialnetworking/model/beans/catalogue/CatalogueEventType.java diff --git a/src/main/java/org/gcube/social_networking/socialnetworking/model/beans/catalogue/CatalogueEvent.java b/src/main/java/org/gcube/social_networking/socialnetworking/model/beans/catalogue/CatalogueEvent.java new file mode 100644 index 0000000..b9bf7e8 --- /dev/null +++ b/src/main/java/org/gcube/social_networking/socialnetworking/model/beans/catalogue/CatalogueEvent.java @@ -0,0 +1,164 @@ +package org.gcube.social_networking.socialnetworking.model.beans.catalogue; + +import java.net.URL; +import java.util.Arrays; + +import javax.validation.constraints.NotNull; +import javax.ws.rs.DefaultValue; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * The CatalogueEvent super class + */ +@JsonIgnoreProperties(ignoreUnknown = true) +public class CatalogueEvent { + protected CatalogueEventType type; + + /** + * the username of the user you wish to notify + */ + @JsonProperty("idsToNotify") + @NotNull(message="recipients cannot be missing, use usernames or contexts") + protected String[] idsToNotify; + + /** + * the item identifier or name + */ + @JsonProperty("itemId") + protected String itemId; + /** + * the text that you want to write in the notification (text/plain) + */ + @JsonProperty("notifyText") + protected String notifyText; + /** + * the URL to redirect when clicking on the notification + */ + @JsonProperty("itemURL") + protected URL itemURL; + + /** + * optionl field, set to true if the idsToNotify are contexts, default is false + */ + @JsonProperty("idsAsGroup") + @DefaultValue("false") + protected boolean idsAsGroup = false; + + public CatalogueEvent() { + } + + + + /** + * for sending to users or groups + * @param type + * @param idsToNotify + * @param itemId + * @param notifyText + * @param itemURL + * @param idsAsGroup + */ + public CatalogueEvent(CatalogueEventType type, String[] idsToNotify, String itemId, String notifyText, URL itemURL, + boolean idsAsGroup) { + super(); + this.type = type; + this.idsToNotify = idsToNotify; + this.itemId = itemId; + this.notifyText = notifyText; + this.itemURL = itemURL; + this.idsAsGroup = idsAsGroup; + } + /** + * for sending to users + * @param type + * @param idsToNotify + * @param itemId + * @param notifyText + * @param itemURL + */ + public CatalogueEvent(CatalogueEventType type, String[] idsToNotify, String itemId, String notifyText, URL itemURL) { + super(); + this.type = type; + this.idsToNotify = idsToNotify; + this.itemId = itemId; + this.notifyText = notifyText; + this.itemURL = itemURL; + this.idsAsGroup = false; + } + + + + public CatalogueEventType getType() { + return type; + } + + + + public void setType(CatalogueEventType type) { + this.type = type; + } + + + + public String[] getIdsToNotify() { + return idsToNotify; + } + + public void setIdsToNotify(String[] idsToNotify) { + this.idsToNotify = idsToNotify; + } + /** + * + * @return true whether the idsToNotify have to be interpreted as groups and not usernames + */ + public boolean idsAsGroup() { + return idsAsGroup; + } + /** + * + * @param idsAsGroup set true whether the idsToNotify have to be interpreted as groups and not usernames, false otherwise + */ + public void setIdsAsGroup(boolean idsAsGroup) { + this.idsAsGroup = idsAsGroup; + } + + public String getItemId() { + return itemId; + } + + public void setItemId(String itemId) { + this.itemId = itemId; + } + + public String getNotifyText() { + return notifyText; + } + + public void setNotifyText(String notifyText) { + this.notifyText = notifyText; + } + + public URL getItemURL() { + return itemURL; + } + + public void setItemURL(URL itemURL) { + this.itemURL = itemURL; + } + + public boolean isIdsAsGroup() { + return idsAsGroup; + } + + + + @Override + public String toString() { + return "CatalogueEvent [type=" + type + ", idsToNotify=" + Arrays.toString(idsToNotify) + ", itemId=" + itemId + + ", notifyText=" + notifyText + ", itemURL=" + itemURL + ", idsAsGroup=" + idsAsGroup + "]"; + } + + +} diff --git a/src/main/java/org/gcube/social_networking/socialnetworking/model/beans/catalogue/CatalogueEventType.java b/src/main/java/org/gcube/social_networking/socialnetworking/model/beans/catalogue/CatalogueEventType.java new file mode 100644 index 0000000..5cfe420 --- /dev/null +++ b/src/main/java/org/gcube/social_networking/socialnetworking/model/beans/catalogue/CatalogueEventType.java @@ -0,0 +1,10 @@ +package org.gcube.social_networking.socialnetworking.model.beans.catalogue; + +public enum CatalogueEventType { + /** + * use to notify a user she got a workspace item new in some of her workspace shared folder + */ + ITEM_PUBLISHED; + + +} diff --git a/src/main/java/org/gcube/social_networking/socialnetworking/model/beans/workspace/AddedItemEvent.java b/src/main/java/org/gcube/social_networking/socialnetworking/model/beans/workspace/AddedItemEvent.java index b1a3f34..17d40eb 100644 --- a/src/main/java/org/gcube/social_networking/socialnetworking/model/beans/workspace/AddedItemEvent.java +++ b/src/main/java/org/gcube/social_networking/socialnetworking/model/beans/workspace/AddedItemEvent.java @@ -61,7 +61,7 @@ public class AddedItemEvent extends WorkspaceEvent { @Override public String toString() { - return "AddedItemEvent [item=" + item + ", TYPE=" + TYPE + ", idsToNotify=" + Arrays.toString(idsToNotify) + return "PublishedItemEvent [item=" + item + ", TYPE=" + TYPE + ", idsToNotify=" + Arrays.toString(idsToNotify) + ", idsAsGroup=" + idsAsGroup + "]"; } diff --git a/src/main/java/org/gcube/social_networking/socialnetworking/model/beans/workspace/FileItemBean.java b/src/main/java/org/gcube/social_networking/socialnetworking/model/beans/workspace/FileItemBean.java index e22a8ed..ec924c3 100644 --- a/src/main/java/org/gcube/social_networking/socialnetworking/model/beans/workspace/FileItemBean.java +++ b/src/main/java/org/gcube/social_networking/socialnetworking/model/beans/workspace/FileItemBean.java @@ -29,7 +29,13 @@ public class FileItemBean { public FileItemBean() { super(); } - + /** + * @param id + * @param name + * @param title + * @param path + * @param parent + */ public FileItemBean(String id, String name, String title, String path, FolderBean parent) { super(); this.id = id; diff --git a/src/main/java/org/gcube/social_networking/socialnetworking/model/beans/workspace/WorkspaceEvent.java b/src/main/java/org/gcube/social_networking/socialnetworking/model/beans/workspace/WorkspaceEvent.java index e979ae6..c97fa07 100644 --- a/src/main/java/org/gcube/social_networking/socialnetworking/model/beans/workspace/WorkspaceEvent.java +++ b/src/main/java/org/gcube/social_networking/socialnetworking/model/beans/workspace/WorkspaceEvent.java @@ -10,7 +10,7 @@ import com.fasterxml.jackson.annotation.JsonTypeInfo; import com.fasterxml.jackson.annotation.JsonTypeInfo.As; /** - * The WorkspaceEvent super class + * The CatalogueEvent super class */ @JsonIgnoreProperties(ignoreUnknown = true) @JsonTypeInfo(use = JsonTypeInfo.Id.NAME,