updated notifications management
This commit is contained in:
parent
b502ad0c2d
commit
ede76d625b
|
@ -1,18 +1,18 @@
|
|||
# REVIEW ACTION
|
||||
TITLE_REVIEW_REQUIRED=Review required for ${project_name}
|
||||
MSG_REVIEW_REQUIRED=${user} submitted the project ${project_name} (id: ${project_id}). You are kindly requested to review it and decide either to APPROVE or REJECT it. See Gis Project at ${gis_link}
|
||||
MSG_REVIEW_REQUIRED=${user} submitted the project ${project_name} (id: ${project_id}). You are kindly requested to review it and decide either to APPROVE or REJECT it. See the Project at ${private_data_entry_link}
|
||||
# REJECTED ACTION
|
||||
TITLE_ITEM_REJECTED=Rejected ${project_name}
|
||||
MSG_ITEM_REJECTED=The project ${project_name} (id: ${project_id}) has just been rejected by ${user}
|
||||
# REJECTED ACTION
|
||||
TITLE_ITEM_REJECTED_REVIEW_REQUIRED=Rejected ${project_name}
|
||||
MSG_ITEM_REJECTED_REVIEW_REQUIRED=The project ${project_name} has just been rejected. You are kindly requested to review it
|
||||
MSG_ITEM_REJECTED_REVIEW_REQUIRED=The project ${project_name} has just been rejected. You are kindly requested to review it. See the Project at ${private_data_entry_link}
|
||||
# PUBLISHED ACTION
|
||||
TITLE_ITEM_PUBLISHED=Published ${project_name}
|
||||
MSG_ITEM_PUBLISHED=The project ${project_name} has just been published. See Gis Project at ${gis_link}
|
||||
MSG_ITEM_PUBLISHED=The project ${project_name} has just been published. See the Project at ${public_data_viewer_link}
|
||||
# CREATED ACTION
|
||||
TITLE_ITEM_CREATED=Created ${project_name}
|
||||
MSG_ITEM_CREATED=The project ${project_name} (id: ${project_id}) has just been created.
|
||||
MSG_ITEM_CREATED=The project ${project_name} (id: ${project_id}) has just been created. See the Project at ${private_data_entry_link}
|
||||
# DELETED ACTION
|
||||
TITLE_ITEM_DELETED=Deleted ${project_name}
|
||||
MSG_ITEM_DELETED=The project ${project_name} has just been deleted.
|
||||
|
@ -20,4 +20,4 @@ MSG_ITEM_DELETED=The project ${project_name} has just been deleted.
|
|||
TITLE_ITEM_UPDATED=Updated ${project_name}
|
||||
MSG_ITEM_UPDATED=The project ${project_name} (id: ${project_id}) has just been updated.
|
||||
# GO TO PDF ACTION
|
||||
MSG_GO_TO_PDF=Go to PDF report at ${pdf_link}
|
||||
MSG_GO_TO_PDF=Go to PDF report at ${project_as_pdf_link}
|
|
@ -5,13 +5,14 @@ import java.util.Map;
|
|||
import org.gcube.portlets.user.uriresolvermanager.UriResolverManager;
|
||||
import org.gcube.portlets.user.uriresolvermanager.resolvers.query.GeoportalResolverQueryStringBuilder;
|
||||
import org.gcube.portlets.user.uriresolvermanager.resolvers.query.GeoportalResolverQueryStringBuilder.RESOLVE_AS;
|
||||
import org.gcube.portlets.user.uriresolvermanager.resolvers.query.GeoportalResolverQueryStringBuilder.TARGET_GEOPORTAL_APP;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@Slf4j
|
||||
public class GisClient {
|
||||
|
||||
public static String gisLink(RESOLVE_AS resolveAs, String profileID, String projectID, String scope, boolean shortLink) {
|
||||
public static String gisLink(RESOLVE_AS resolveAs, String profileID, String projectID, String scope, TARGET_GEOPORTAL_APP targetApp, boolean shortLink) {
|
||||
log.debug("called gisLink as {} for scope {}, profileId {}, projectId {} ", resolveAs, scope, profileID,
|
||||
projectID);
|
||||
|
||||
|
@ -23,6 +24,8 @@ public class GisClient {
|
|||
GeoportalResolverQueryStringBuilder builder = new GeoportalResolverQueryStringBuilder(profileID, projectID);
|
||||
builder.scope(scope);
|
||||
builder.resolverAs(resolveAs);
|
||||
|
||||
builder.targetApp(targetApp);
|
||||
Map<String, String> params = builder.buildQueryParameters();
|
||||
theLink = uriResolverManager.getLink(params, shortLink);
|
||||
log.info("Geoportal GisViewer link is {} ", theLink);
|
||||
|
|
|
@ -12,16 +12,14 @@ import org.gcube.application.cms.notifications.NotificationGenericConstants;
|
|||
import org.gcube.application.cms.notifications.config.NotificationFor;
|
||||
import org.gcube.application.cms.notifications.config.NotificationWhen;
|
||||
import org.gcube.application.cms.notifications.config.SubscribeNotificationEvent;
|
||||
import org.gcube.application.cms.notifications.gis.GisClient;
|
||||
import org.gcube.application.cms.notifications.manage.mapping.MappingToCatalogue;
|
||||
import org.gcube.application.cms.notifications.social.SocialClients;
|
||||
import org.gcube.application.cms.notifications.substitutor.NMessagesPlaceholdersSubstitutorUtil;
|
||||
import org.gcube.application.cms.notifications.substitutor.SubstitutorMessagesMap;
|
||||
import org.gcube.application.cms.notifications.substitutor.SubstitutorPlaceholdersMap;
|
||||
import org.gcube.application.cms.plugins.events.ItemObserved;
|
||||
import org.gcube.application.geoportal.common.model.document.Project;
|
||||
import org.gcube.application.geoportal.common.model.document.accounting.User;
|
||||
import org.gcube.application.geoportal.common.model.document.lifecycle.LifecycleInformation;
|
||||
import org.gcube.portlets.user.uriresolvermanager.resolvers.query.GeoportalResolverQueryStringBuilder.RESOLVE_AS;
|
||||
import org.gcube.social_networking.socialnetworking.model.beans.catalogue.CatalogueEventType;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
@ -53,11 +51,8 @@ public class ManageDoActionNotification {
|
|||
this.nMPlaceholdersS = nMPlaceholdersSUtil;
|
||||
this.itemObserved = itemObserved;
|
||||
|
||||
// Creating the map for replacing the placeholder with their values
|
||||
SubstitutorMessagesMap placeholderMapValues = new SubstitutorMessagesMap();
|
||||
String gisLink = GisClient.gisLink(RESOLVE_AS.PRIVATE, itemObserved.getUCD_Id(), itemObserved.getProjectId(),
|
||||
itemObserved.getContext().getId(), true);
|
||||
placeholderMapValues.putGisLink(gisLink);
|
||||
// Creating the map for replacing the basic placeholders with their values
|
||||
SubstitutorPlaceholdersMap placeholderMapValues = new SubstitutorPlaceholdersMap();
|
||||
placeholderMapValues.putProjectId(itemObserved.getProjectId());
|
||||
LinkedHashMap<String, Object> docAsMap = itemObserved.getDocumentEntries(1);
|
||||
String projectName = docAsMap.size() > 0 ? docAsMap.values().stream().findFirst().get() + ""
|
||||
|
@ -101,7 +96,6 @@ public class ManageDoActionNotification {
|
|||
if (notificationsCompliantToPhase != null && notificationsCompliantToPhase.size() > 0) {
|
||||
// GET LIST USER COMPLIANT TO ROLES
|
||||
List<User> notifyUsers = getListUserCompliantToRoles(notificationFor, itemObserved, false);
|
||||
final SocialClients socialClients = new SocialClients();
|
||||
CatalogueEventType catalogueEventType = MappingToCatalogue.toCatalogueEventType(itemPhase,
|
||||
lastInvokedStep);
|
||||
|
||||
|
@ -112,7 +106,7 @@ public class ManageDoActionNotification {
|
|||
}
|
||||
|
||||
try {
|
||||
NotifyUsers mnu = new NotifyUsers(socialClients, notificationsCompliantToPhase,
|
||||
NotifyUsers mnu = new NotifyUsers(itemObserved, notificationsCompliantToPhase,
|
||||
nMPlaceholdersS, notifyUsers, catalogueEventType);
|
||||
mnu.sendNotification();
|
||||
} catch (Exception e) {
|
||||
|
|
|
@ -10,6 +10,8 @@ import org.gcube.application.cms.notifications.config.Notify;
|
|||
import org.gcube.application.cms.notifications.config.serviceaccount.GeoportalServiceAccount;
|
||||
import org.gcube.application.cms.notifications.social.SocialClients;
|
||||
import org.gcube.application.cms.notifications.substitutor.NMessagesPlaceholdersSubstitutorUtil;
|
||||
import org.gcube.application.cms.plugins.events.ItemObserved;
|
||||
import org.gcube.application.geoportal.common.model.document.Project;
|
||||
import org.gcube.application.geoportal.common.model.document.accounting.User;
|
||||
import org.gcube.common.authorization.utils.manager.SecretManager;
|
||||
import org.gcube.common.authorization.utils.manager.SecretManagerProvider;
|
||||
|
@ -30,11 +32,13 @@ public class NotifyUsers {
|
|||
private List<NotificationWhen> listNotificationWhen;
|
||||
private SocialClients socialClients;
|
||||
private CatalogueEventType catalogueEventType;
|
||||
private ItemObserved<Project> itemObserved;
|
||||
|
||||
public NotifyUsers(SocialClients socialClients, List<NotificationWhen> listWhen,
|
||||
public NotifyUsers(ItemObserved<Project> itemObserved, List<NotificationWhen> listWhen,
|
||||
NMessagesPlaceholdersSubstitutorUtil nMPlaceholdersSUtil, List<User> recipientUsers,
|
||||
CatalogueEventType catalogueEventType) {
|
||||
this.socialClients = socialClients;
|
||||
this.socialClients = new SocialClients();
|
||||
this.itemObserved = itemObserved;
|
||||
this.listNotificationWhen = listWhen;
|
||||
this.recipientUsers = recipientUsers;
|
||||
this.nMPlaceholdersSUtil = nMPlaceholdersSUtil;
|
||||
|
@ -53,9 +57,8 @@ public class NotifyUsers {
|
|||
log.debug("Building message...");
|
||||
String subject = "Message";
|
||||
String body = null;
|
||||
|
||||
subject = nMPlaceholdersSUtil.replacePlaceholder(notify.getPlaceholder_title());
|
||||
body = nMPlaceholdersSUtil.replacePlaceholder(notify.getPlaceholder_msg());
|
||||
subject = nMPlaceholdersSUtil.replacePlaceholder(itemObserved, notify.getPlaceholder_title());
|
||||
body = nMPlaceholdersSUtil.replacePlaceholder(itemObserved, notify.getPlaceholder_msg());
|
||||
|
||||
log.debug("subject: {}", subject);
|
||||
log.debug("body: {}", body);
|
||||
|
@ -142,7 +145,8 @@ public class NotifyUsers {
|
|||
catalogueEvent.setType(catalogueEventType);
|
||||
catalogueEvent.setNotifyText(bodyMessage);
|
||||
catalogueEvent.setItemId(subject);
|
||||
String itemURL = nMPlaceholdersSUtil.getPlaceholderMapValues().getGisLink();
|
||||
|
||||
String itemURL = nMPlaceholdersSUtil.getPlaceholderMapValues().getFirstApplicationLink();
|
||||
if (itemURL != null) {
|
||||
catalogueEvent.setItemURL(new URL(itemURL));
|
||||
}
|
||||
|
|
|
@ -6,6 +6,9 @@ import java.net.URL;
|
|||
import java.util.Properties;
|
||||
|
||||
import org.apache.commons.text.StringSubstitutor;
|
||||
import org.gcube.application.cms.notifications.manage.ResolveProjectLinkFromPlaceholder;
|
||||
import org.gcube.application.cms.plugins.events.ItemObserved;
|
||||
import org.gcube.application.geoportal.common.model.document.Project;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
|
@ -15,7 +18,7 @@ public class NMessagesPlaceholdersSubstitutorUtil {
|
|||
private String linkToNotificationMessages;
|
||||
private Properties notificationMessagesProperties;
|
||||
|
||||
private SubstitutorMessagesMap placeholderMapValues;
|
||||
private SubstitutorPlaceholdersMap placeholderMapValues;
|
||||
|
||||
private StringSubstitutor stringSub;
|
||||
|
||||
|
@ -39,16 +42,18 @@ public class NMessagesPlaceholdersSubstitutorUtil {
|
|||
return linkToNotificationMessages;
|
||||
}
|
||||
|
||||
public void setPlaceholderMapValues(SubstitutorMessagesMap placeholderMapValues) {
|
||||
public void setPlaceholderMapValues(SubstitutorPlaceholdersMap placeholderMapValues) {
|
||||
this.placeholderMapValues = placeholderMapValues;
|
||||
stringSub = new StringSubstitutor(placeholderMapValues);
|
||||
}
|
||||
|
||||
public String replacePlaceholder(String notificationPlaceholder) {
|
||||
public String replacePlaceholder(ItemObserved<Project> itemObserved, String notificationPlaceholder) {
|
||||
|
||||
if (notificationPlaceholder == null || notificationPlaceholder.isEmpty())
|
||||
return notificationPlaceholder;
|
||||
|
||||
this.placeholderMapValues = ResolveProjectLinkFromPlaceholder.resolveLink(itemObserved, placeholderMapValues, notificationPlaceholder);
|
||||
|
||||
log.trace("stringSub is {}",stringSub);
|
||||
|
||||
if (stringSub != null) {
|
||||
|
@ -65,7 +70,7 @@ public class NMessagesPlaceholdersSubstitutorUtil {
|
|||
return notificationPlaceholder;
|
||||
}
|
||||
|
||||
public SubstitutorMessagesMap getPlaceholderMapValues() {
|
||||
public SubstitutorPlaceholdersMap getPlaceholderMapValues() {
|
||||
return placeholderMapValues;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,42 +0,0 @@
|
|||
package org.gcube.application.cms.notifications.substitutor;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public class SubstitutorMessagesMap extends HashMap<String, String> {
|
||||
|
||||
public static final String PROJECT_ID = "project_id";
|
||||
public static final String GIS_LINK = "gis_link";
|
||||
public static final String PROJECT_NAME = "project_name";
|
||||
public static final String USER = "user";
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public SubstitutorMessagesMap() {
|
||||
super();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String put(String key, String value) {
|
||||
return super.put(key, value);
|
||||
}
|
||||
|
||||
public String putUser(String username) {
|
||||
return super.put(USER, username);
|
||||
}
|
||||
|
||||
public String putProjectName(String projectName) {
|
||||
return super.put(PROJECT_NAME, projectName);
|
||||
}
|
||||
|
||||
public String putGisLink(String gisLink) {
|
||||
return super.put(GIS_LINK, gisLink);
|
||||
}
|
||||
|
||||
public String putProjectId(String projectId) {
|
||||
return super.put(PROJECT_ID, projectId);
|
||||
}
|
||||
|
||||
public String getGisLink() {
|
||||
return super.get(GIS_LINK);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,81 @@
|
|||
package org.gcube.application.cms.notifications.substitutor;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public class SubstitutorPlaceholdersMap extends HashMap<String, String> {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 6815259883194732178L;
|
||||
|
||||
public static final String PROJECT_ID = "project_id";
|
||||
public static final String PROJECT_NAME = "project_name";
|
||||
public static final String USER = "user";
|
||||
|
||||
public static final String PRIVATE_DATA_ENTRY_LINK = "private_data_entry_link";
|
||||
public static final String PUBLIC_DATA_ENTRY_LINK = "public_data_entry_link";
|
||||
public static final String PRIVATE_DATA_VIEWER_LINK = "private_data_viewer_link";
|
||||
public static final String PUBLIC_DATA_VIEWER_LINK = "public_data_viewer_link";
|
||||
|
||||
public SubstitutorPlaceholdersMap() {
|
||||
super();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String put(String key, String value) {
|
||||
return put(key, value);
|
||||
}
|
||||
|
||||
public String putUser(String username) {
|
||||
return put(USER, username);
|
||||
}
|
||||
|
||||
public String putProjectName(String projectName) {
|
||||
return put(PROJECT_NAME, projectName);
|
||||
}
|
||||
|
||||
public String putProjectId(String projectId) {
|
||||
return put(PROJECT_ID, projectId);
|
||||
}
|
||||
|
||||
public String putPrivateDataEntryLink(String link) {
|
||||
return put(PRIVATE_DATA_ENTRY_LINK, link);
|
||||
}
|
||||
|
||||
public String putPublicDataEntryLink(String link) {
|
||||
return put(PUBLIC_DATA_ENTRY_LINK, link);
|
||||
}
|
||||
|
||||
public String putPrivateDataViewerLink(String link) {
|
||||
return put(PRIVATE_DATA_VIEWER_LINK, link);
|
||||
}
|
||||
|
||||
public String putPublicDataViewerLink(String link) {
|
||||
return put(PUBLIC_DATA_VIEWER_LINK, link);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the first application link.
|
||||
*
|
||||
* @return the first application link
|
||||
*/
|
||||
// not best solution
|
||||
public String getFirstApplicationLink() {
|
||||
|
||||
if (get(PRIVATE_DATA_ENTRY_LINK) != null) {
|
||||
return get(PRIVATE_DATA_ENTRY_LINK);
|
||||
}
|
||||
if (super.get(PUBLIC_DATA_ENTRY_LINK) != null) {
|
||||
return get(PUBLIC_DATA_ENTRY_LINK);
|
||||
}
|
||||
if (super.get(PRIVATE_DATA_VIEWER_LINK) != null) {
|
||||
return get(PRIVATE_DATA_VIEWER_LINK);
|
||||
}
|
||||
if (super.get(PUBLIC_DATA_VIEWER_LINK) != null) {
|
||||
return get(PUBLIC_DATA_VIEWER_LINK);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
|
@ -6,7 +6,7 @@ import java.util.List;
|
|||
import java.util.Properties;
|
||||
|
||||
import org.apache.commons.text.StringSubstitutor;
|
||||
import org.gcube.application.cms.notifications.substitutor.SubstitutorMessagesMap;
|
||||
import org.gcube.application.cms.notifications.substitutor.SubstitutorPlaceholdersMap;
|
||||
import org.gcube.application.geoportal.common.utils.tests.GCubeTest;
|
||||
import org.junit.Test;
|
||||
|
||||
|
@ -25,7 +25,7 @@ public class StringReplacerTest {
|
|||
public static String USERNAME = "francesco.mangiacrapa";
|
||||
public static String PROJECT_ID = "12345";
|
||||
public static String PROJECT_NAME = "\"My Great Project\"";
|
||||
public static String GIS_LINK = "https://my_gis_link";
|
||||
public static String APPLICATION_LINK = "https://my_gis_link";
|
||||
|
||||
public static String FILE_URL = "https://code-repo.d4science.org/gCubeSystem/gcube-cms-suite/raw/branch/event_manager/D4S_UCDs/DEV/devVRE/notifications/Notifications_Messages.properties";
|
||||
|
||||
|
@ -34,14 +34,14 @@ public class StringReplacerTest {
|
|||
org.junit.Assume.assumeTrue(GCubeTest.isTestInfrastructureEnabled());
|
||||
|
||||
// Map<String, String> valuesMap = new HashMap<>();
|
||||
// valuesMap.put(SubstitutorMessagesMap.USER, USERNAME);
|
||||
// valuesMap.put(SubstitutorMessagesMap.PROJECT_NAME, PROJECT_NAME);
|
||||
// valuesMap.put(SubstitutorMessagesMap.GIS_LINK, GIS_LINK);
|
||||
// valuesMap.put(SubstitutorMessagesMap.PROJECT_ID, PROJECT_ID);
|
||||
// valuesMap.put(SubstitutorPlaceholdersMap.USER, USERNAME);
|
||||
// valuesMap.put(SubstitutorPlaceholdersMap.PROJECT_NAME, PROJECT_NAME);
|
||||
// valuesMap.put(SubstitutorPlaceholdersMap.GIS_LINK, GIS_LINK);
|
||||
// valuesMap.put(SubstitutorPlaceholdersMap.PROJECT_ID, PROJECT_ID);
|
||||
|
||||
SubstitutorMessagesMap smp = new SubstitutorMessagesMap();
|
||||
SubstitutorPlaceholdersMap smp = new SubstitutorPlaceholdersMap();
|
||||
smp.putUser(USERNAME);
|
||||
smp.putGisLink(GIS_LINK);
|
||||
smp.putPublicDataEntryLink(APPLICATION_LINK);
|
||||
smp.putProjectId(PROJECT_ID);
|
||||
smp.putProjectName(PROJECT_NAME);
|
||||
|
||||
|
|
Loading…
Reference in New Issue