in progress
This commit is contained in:
parent
6c26aa65cc
commit
e08c03cd04
|
@ -0,0 +1,17 @@
|
|||
package org.gcube.application.cms.notifications;
|
||||
|
||||
public class NotificationGenericConstants {
|
||||
|
||||
public static enum CUSTOM_TARGET_PHASE {
|
||||
Any
|
||||
};
|
||||
|
||||
public static enum CUSTOM_USER_ROLES {
|
||||
Item_Creator, Any
|
||||
};
|
||||
|
||||
public static enum NOTIFICATION_TYPE {
|
||||
USER_POST, EMAIL, VRE_POST
|
||||
};
|
||||
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
package org.gcube.application.cms.notifications.config;
|
||||
|
||||
import org.gcube.com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public class ExportAsPDF {
|
||||
|
||||
Boolean export;
|
||||
String placeholder_msg;
|
||||
|
||||
}
|
|
@ -0,0 +1,94 @@
|
|||
package org.gcube.application.cms.notifications.social;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.gcube.portal.databook.shared.Post;
|
||||
import org.gcube.social_networking.social_networking_client_library.MessageClient;
|
||||
import org.gcube.social_networking.social_networking_client_library.PostClient;
|
||||
import org.gcube.social_networking.social_networking_client_library.UserClient;
|
||||
import org.gcube.social_networking.socialnetworking.model.beans.MessageInputBean;
|
||||
import org.gcube.social_networking.socialnetworking.model.beans.PostInputBean;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* The Class SocialClients.
|
||||
*
|
||||
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
|
||||
*
|
||||
* Mar 20, 2024
|
||||
*/
|
||||
@Slf4j
|
||||
public class SocialClients {
|
||||
|
||||
private PostClient postClient;
|
||||
private MessageClient messagesClient;
|
||||
private UserClient userClient;
|
||||
|
||||
/**
|
||||
* Instantiates a new social util.
|
||||
*/
|
||||
public SocialClients() {
|
||||
try {
|
||||
this.postClient = new PostClient();
|
||||
} catch (Exception e) {
|
||||
log.error("Error on instacing {}: ", PostClient.class.getSimpleName(), e);
|
||||
}
|
||||
|
||||
try {
|
||||
this.messagesClient = new MessageClient();
|
||||
} catch (Exception e) {
|
||||
log.error("Error on instacing {}: ", MessageClient.class.getSimpleName(), e);
|
||||
}
|
||||
|
||||
try {
|
||||
this.userClient = new UserClient();
|
||||
} catch (Exception e) {
|
||||
log.error("Error on instacing {}: ", UserClient.class.getSimpleName(), e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the usernames by role.
|
||||
*
|
||||
* @param roleName the role name
|
||||
* @return the usernames by role
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
public List<String> getUsernamesByRole(String roleName) throws Exception {
|
||||
return new ArrayList<String>(userClient.getAllUsernamesByRole(roleName));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the usernames by scope.
|
||||
*
|
||||
* @return the usernames by scope
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
public List<String> getUsernamesByScope() throws Exception {
|
||||
return new ArrayList<String>(userClient.getAllUsernamesContext());
|
||||
}
|
||||
|
||||
/**
|
||||
* Write message.
|
||||
*
|
||||
* @param msg the msg
|
||||
* @return the string
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
public String writeMessage(MessageInputBean msg) throws Exception {
|
||||
return messagesClient.writeMessage(msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Write user post.
|
||||
*
|
||||
* @param toWrite the to write
|
||||
* @return the post
|
||||
*/
|
||||
public Post writeUserPost(PostInputBean toWrite) {
|
||||
return postClient.writeUserPost(toWrite);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,62 @@
|
|||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.apache.commons.text.StringSubstitutor;
|
||||
import org.gcube.application.geoportal.common.utils.tests.GCubeTest;
|
||||
import org.junit.Test;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@Slf4j
|
||||
public class StringReplacerTest {
|
||||
|
||||
public static String NOTIFICATION_MESSAGE_FILE_PATH = String.format("%s%s",
|
||||
System.getProperty("user.dir"), "/src/test/resources/Notifications_Messages.properties");
|
||||
|
||||
public static final List<String> PLACEHOLDERS = Arrays.asList("MSG_MODERATION_REQUIRED", "MSG_ITEM_REJECTED",
|
||||
"MSG_ITEM_REJECTED_REVIEW_REQUIRED", "MSG_ITEM_PUBLISHED");
|
||||
|
||||
public static String USERNAME = "francesco.mangiacrapa";
|
||||
public static String PROJECT_NAME = "\"My Great Project\"";
|
||||
public static String GIS_LINK = "https://my_gis_link";
|
||||
|
||||
@Test
|
||||
public void checkReplace() {
|
||||
org.junit.Assume.assumeTrue(GCubeTest.isTestInfrastructureEnabled());
|
||||
|
||||
if (GCubeTest.isTestInfrastructureEnabled()) {
|
||||
|
||||
Map<String, String> valuesMap = new HashMap<>();
|
||||
valuesMap.put("user", USERNAME);
|
||||
valuesMap.put("project_name", PROJECT_NAME);
|
||||
valuesMap.put("gis_link", GIS_LINK);
|
||||
// Build StringSubstitutor
|
||||
StringSubstitutor sub = new StringSubstitutor(valuesMap);
|
||||
|
||||
try (InputStream input = new FileInputStream(NOTIFICATION_MESSAGE_FILE_PATH)) {
|
||||
Properties prop = new Properties();
|
||||
// load a properties file
|
||||
prop.load(input);
|
||||
|
||||
for (String placeholder : PLACEHOLDERS) {
|
||||
log.info("placeholder: {}", placeholder);
|
||||
String templateString = prop.getProperty(placeholder);
|
||||
log.info("templateString: {}", templateString);
|
||||
// Replace
|
||||
String resolvedString = sub.replace(templateString);
|
||||
log.info("resolvedString: {}", resolvedString);
|
||||
}
|
||||
|
||||
} catch (IOException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue