ready to release

This commit is contained in:
Massimiliano Assante 2022-10-20 19:17:13 +02:00
parent 3b367774cc
commit dcaaa4836b
6 changed files with 74 additions and 379 deletions

View File

@ -1,6 +1,6 @@
# Changelog
## [v2.8.0-SNAPSHOT] - 2022-10-20
## [v2.8.0] - 2022-10-20
- Feature #23891 Refactored following updates social lib
- Feature #23847 Social service: temporarily block of notifications for given username(s)

43
pom.xml
View File

@ -12,7 +12,7 @@
<groupId>org.gcube.portal</groupId>
<artifactId>social-networking-library-ws</artifactId>
<packaging>war</packaging>
<version>2.8.0-SNAPSHOT</version>
<version>2.8.0</version>
<name>social-networking-library-ws</name>
<description>Rest interface for the social networking library.</description>
<properties>
@ -72,7 +72,7 @@
<dependency>
<groupId>org.gcube.social-networking</groupId>
<artifactId>social-service-model</artifactId>
<version>[1.1.7-SNAPSHOT, 2.0.0)</version>
<version>[1.2.0-SNAPSHOT, 2.0.0)</version>
</dependency>
<dependency>
<groupId>net.sf.ehcache</groupId>
@ -98,6 +98,7 @@
<dependency>
<groupId>org.gcube.common</groupId>
<artifactId>storagehub-client-library</artifactId>
<version>2.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.sun.mail</groupId>
@ -348,25 +349,25 @@
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>kr.motd.maven</groupId>
<artifactId>sphinx-maven-plugin</artifactId>
<version>2.10.0</version>
<configuration>
<outputDirectory>${project.build.directory}/${project.artifactId}-${project.version}/docs</outputDirectory>
<builder>html</builder>
<configDirectory>${basedir}/docs</configDirectory>
<sourceDirectory>${basedir}/docs</sourceDirectory>
</configuration>
<executions>
<execution>
<phase>process-resources</phase>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- <plugin> -->
<!-- <groupId>kr.motd.maven</groupId> -->
<!-- <artifactId>sphinx-maven-plugin</artifactId> -->
<!-- <version>2.10.0</version> -->
<!-- <configuration> -->
<!-- <outputDirectory>${project.build.directory}/${project.artifactId}-${project.version}/docs</outputDirectory> -->
<!-- <builder>html</builder> -->
<!-- <configDirectory>${basedir}/docs</configDirectory> -->
<!-- <sourceDirectory>${basedir}/docs</sourceDirectory> -->
<!-- </configuration> -->
<!-- <executions> -->
<!-- <execution> -->
<!-- <phase>process-resources</phase> -->
<!-- <goals> -->
<!-- <goal>generate</goal> -->
<!-- </goals> -->
<!-- </execution> -->
<!-- </executions> -->
<!-- </plugin> -->
<!-- Enunciate Maven plugin -->
<plugin>
<groupId>com.webcohesion.enunciate</groupId>

View File

@ -1,105 +0,0 @@
package org.gcube.portal.social.networking.ws.inputs;
import java.io.Serializable;
import java.util.ArrayList;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
/**
* Generic input bean for methods that allow to write messages
*/
@JsonIgnoreProperties(ignoreUnknown = true) // ignore in serialization/deserialization
public class MessageInputBean implements Serializable {
private static final long serialVersionUID = -1317811686036127456L;
@JsonProperty("body")
@NotNull(message="body cannot be missing")
@Size(min=1, message="body cannot be empty")
private String body;
@JsonProperty("subject")
@NotNull(message="subject cannot be missing")
@Size(min=1, message="subject cannot be empty")
/**
* subject
*/
private String subject;
@JsonProperty("recipients")
@NotNull(message="recipients cannot be missing")
@Size(min=1, message="at least a recipient is needed")
@Valid // validate recursively
private ArrayList<Recipient> recipients;
/**
* a list of workspace item id valid in the workspace of the sender
*/
@JsonProperty("attachmentIds")
@Valid // validate recursively
private ArrayList<String> attachmentIds;
public MessageInputBean() {
super();
}
public MessageInputBean(String sender, String body, String subject,
ArrayList<Recipient> recipients) {
super();
//this.sender = sender;
this.body = body;
this.subject = subject;
this.recipients = recipients;
this.attachmentIds = new ArrayList<>();
}
public MessageInputBean(String sender, String body, String subject,
ArrayList<Recipient> recipients, ArrayList<String> attachmentIds) {
super();
//this.sender = sender;
this.body = body;
this.subject = subject;
this.recipients = recipients;
this.attachmentIds = attachmentIds;
}
public String getBody() {
return body;
}
public void setBody(String body) {
this.body = body;
}
public String getSubject() {
return subject;
}
public void setSubject(String subject) {
this.subject = subject;
}
public ArrayList<Recipient> getRecipients() {
return recipients;
}
public void setRecipients(ArrayList<Recipient> recipients) {
this.recipients = recipients;
}
public ArrayList<String> getAttachmentIds() {
return attachmentIds;
}
public void setAttachmentIds(ArrayList<String> attachmentIds) {
this.attachmentIds = attachmentIds;
}
@Override
public String toString() {
return "MessageInputBean [body=" + body + ", subject=" + subject + ", recipients=" + recipients
+ ", attachmentIds=" + attachmentIds + "]";
}
}

View File

@ -1,49 +0,0 @@
package org.gcube.portal.social.networking.ws.inputs;
import java.io.Serializable;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.webcohesion.enunciate.metadata.DocumentationExample;
/**
* Recipient message bean
* @author Costantino Perciante at ISTI-CNR
* (costantino.perciante@isti.cnr.it)
*
*/
@JsonIgnoreProperties(ignoreUnknown = true) // ignore in serialization/deserialization
public class Recipient implements Serializable{
private static final long serialVersionUID = 1071412144446514138L;
@JsonProperty("id")
@NotNull(message="recipient id must not be null")
@Size(min=1, message="recipient id must not be empty")
/*
* @param "The recipient of the message",
*/
@DocumentationExample("john.smith")
private String id;
public Recipient() {
super();
}
public Recipient(String id) {
super();
this.id = id;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
@Override
public String toString() {
return "Recipient [id=" + id + "]";
}
}

View File

@ -9,6 +9,7 @@ import javax.validation.Valid;
import javax.validation.ValidationException;
import javax.validation.constraints.NotNull;
import javax.ws.rs.Consumes;
import javax.ws.rs.FormParam;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
@ -22,6 +23,7 @@ import org.gcube.applicationsupportlayer.social.ApplicationNotificationsManager;
import org.gcube.applicationsupportlayer.social.NotificationsManager;
import org.gcube.applicationsupportlayer.social.shared.SocialNetworkingSite;
import org.gcube.applicationsupportlayer.social.shared.SocialNetworkingUser;
import org.gcube.common.authorization.control.annotations.AuthorizationControl;
import org.gcube.common.authorization.library.provider.AuthorizationProvider;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.common.authorization.library.utils.Caller;
@ -34,11 +36,13 @@ import org.gcube.portal.notifications.thread.MessageNotificationsThread;
import org.gcube.portal.social.networking.caches.SocialNetworkingSiteFinder;
import org.gcube.portal.social.networking.liferay.ws.LiferayJSONWsCredentials;
import org.gcube.portal.social.networking.liferay.ws.UserManagerWSBuilder;
import org.gcube.portal.social.networking.ws.inputs.MessageInputBean;
import org.gcube.portal.social.networking.ws.inputs.Recipient;
import org.gcube.portal.social.networking.ws.ex.AuthException;
import org.gcube.portal.social.networking.ws.inputs.UserSetNotificationBean;
import org.gcube.portal.social.networking.ws.outputs.ResponseBean;
import org.gcube.portal.social.networking.ws.utils.ErrorMessages;
import org.gcube.portal.social.networking.ws.utils.TokensUtils;
import org.gcube.social_networking.socialnetworking.model.beans.MessageInputBean;
import org.gcube.social_networking.socialnetworking.model.beans.Recipient;
import org.gcube.vomanagement.usermanagement.UserManager;
import org.gcube.vomanagement.usermanagement.exception.UserManagementSystemException;
import org.gcube.vomanagement.usermanagement.exception.UserRetrievalFault;
@ -241,6 +245,51 @@ public class Messages {
status = Status.INTERNAL_SERVER_ERROR;
}
return Response.status(status).entity(responseBean).build();
}
/**
* Set message read or unread
* @param messageId the message identifier
* @param read true to set read, false to set unread
* @return the result of the operation
* @throws ValidationException
*/
@POST
@Path("set-message-read/")
@Produces(MediaType.APPLICATION_JSON)
@StatusCodes ({
@ResponseCode ( code = 200, condition = "Message set Read or Unread is correctly executed"),
@ResponseCode ( code = 500, condition = ErrorMessages.ERROR_IN_API_RESULT)
})
public Response setMessageRead(
@NotNull(message="input is missing")
@FormParam("messageId") String messageId,
@FormParam("read") Boolean read) throws ValidationException{
Caller caller = AuthorizationProvider.instance.get();
ResponseBean responseBean = new ResponseBean();
Status status = Status.OK;
String opExecutor = "";
try{
opExecutor = caller.getClient().getId();
MessageManagerClient client = AbstractPlugin.messages().build();
client.setRead(messageId, read);
String toReturn = "set Message id:" + messageId + (read ? " read" : " unread");
logger.info("set Message id:" + messageId + " read?" + read + " for " + opExecutor);
responseBean.setSuccess(true);
responseBean.setResult(toReturn);
} catch(Exception e){
logger.error("Unable to set message read / unread property for user " + opExecutor, e);
responseBean.setSuccess(false);
responseBean.setMessage(e.getMessage());
status = Status.INTERNAL_SERVER_ERROR;
}
return Response.status(status).entity(responseBean).build();
}
}

View File

@ -1,201 +0,0 @@
package org.gcube.portal.test;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import org.apache.http.HttpHost;
import org.apache.http.HttpResponse;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.AuthCache;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.CredentialsProvider;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.protocol.HttpClientContext;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.auth.BasicScheme;
import org.apache.http.impl.client.BasicAuthCache;
import org.apache.http.impl.client.BasicCredentialsProvider;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.portal.social.networking.liferay.ws.LiferayJSONWsCredentials;
import org.gcube.portal.social.networking.ws.inputs.MessageInputBean;
import org.gcube.portal.social.networking.ws.inputs.Recipient;
import org.json.simple.JSONObject;
import com.fasterxml.jackson.databind.ObjectMapper;
public class JTests {
private static final String YOUR_TOKEN_HERE = "";
private static final String METHOD = "messages/writeMessageToUsers";
private static final String SCOPE = "/gcube";
//@Test
public void readSocialServiceEndPoint() throws Exception {
String findInContext = SCOPE;
ScopeProvider.instance.set(findInContext);
ServiceEndPointReaderSocial readerSE = new ServiceEndPointReaderSocial(findInContext);
System.out.println("Found base path " + readerSE.getBasePath());
}
//@Test
public void testWithApacheClient() throws Exception {
ServiceEndPointReaderSocial reader = new ServiceEndPointReaderSocial(SCOPE);
String requestForMessage = reader.getBasePath() + METHOD + "?gcube-token=" + YOUR_TOKEN_HERE;
requestForMessage = requestForMessage.replace("http", "https"); // remove the port (or set it to 443) otherwise you get an SSL error
System.out.println("Request url is going to be " + requestForMessage);
try(CloseableHttpClient client = HttpClientBuilder.create().build();){
HttpPost postRequest = new HttpPost(requestForMessage);
// put the sender, the recipients, subject and body of the mail here
StringEntity input = new StringEntity("sender=andrea.rossi&recipients=gianpaolo.coro&subject=Sample mail&body=Sample mail object");
input.setContentType("application/x-www-form-urlencoded");
postRequest.setEntity(input);
HttpResponse response = client.execute(postRequest);
System.out.println("Error is " + response.getStatusLine().getReasonPhrase());
if (response.getStatusLine().getStatusCode() != 201) {
throw new RuntimeException("Failed : HTTP error code : "
+ response.getStatusLine().getStatusCode());
}
BufferedReader br = new BufferedReader(
new InputStreamReader((response.getEntity().getContent())));
String output;
System.out.println("Output from Server .... \n");
while ((output = br.readLine()) != null) {
System.out.println(output);
}
System.out.println(response.toString());
}catch(Exception e){
System.err.println("error while performing post method " + e.toString());
}
}
//@Test
public void parserJSON() throws IOException{
MessageInputBean message = new MessageInputBean();
message.setBody("a caso");
message.setSubject("subject");
ArrayList<Recipient> recipients = new ArrayList<Recipient>();
Recipient recipient = new Recipient("recipient1");
recipients.add(recipient);
message.setRecipients(recipients);
//Object mapper instance
ObjectMapper mapper = new ObjectMapper();
//Convert POJO to JSON
String json = mapper.writeValueAsString(message);
MessageInputBean obje = mapper.readValue(json, MessageInputBean.class);
System.out.println(json);
System.out.println(obje);
}
//@Test
public void callLiferayWS() throws Exception{
HttpHost target = new HttpHost("localhost", 8080, "http");
CredentialsProvider credsProvider = new BasicCredentialsProvider();
credsProvider.setCredentials(
new AuthScope(target.getHostName(), target.getPort()),
new UsernamePasswordCredentials("test@liferay.com", "random321"));
CloseableHttpClient httpclient = HttpClients.custom()
.setDefaultCredentialsProvider(credsProvider).build();
try {
// Create AuthCache instance
AuthCache authCache = new BasicAuthCache();
// Generate BASIC scheme object and add it to the local
// auth cache
BasicScheme basicAuth = new BasicScheme();
authCache.put(target, basicAuth);
// Add AuthCache to the execution context
HttpClientContext localContext = HttpClientContext.create();
localContext.setAuthCache(authCache);
HttpGet httpget = new HttpGet("/api/jsonws" + "/user/get-user-by-screen-name/company-id/20155/screen-name/costantino.perciante");
System.out.println("Executing request " + httpget.getRequestLine() + " to target " + target);
CloseableHttpResponse response = httpclient.execute(target, httpget, localContext);
try {
System.out.println("----------------------------------------");
System.out.println(response.getStatusLine());
System.out.println(EntityUtils.toString(response.getEntity()));
} finally {
response.close();
}
} finally {
httpclient.close();
}
}
//@Test
public void retrieveCredentials(){
ScopeProvider.instance.set("/gcube");
LiferayJSONWsCredentials cred = LiferayJSONWsCredentials.getSingleton();
System.out.println("Password is " + cred.getPassword());
System.out.println("Host is " + cred.getHost());
}
//@Test
public void readGcoreEndPoint() throws Exception{
GcoreEndpointReader reader = new GcoreEndpointReader("/gcube");
reader.getResourceEntyName();
}
//@Test
public void sendNotification() throws ClientProtocolException, IOException{
String url ="https://socialnetworking-d-d4s.d4science.org/social-networking-library-ws/rest//2/notifications/notify-job-status?gcube-token=07f5f961-d0e0-4bc4-af90-a305e8b63ac7-98187548";
CloseableHttpClient client = HttpClientBuilder.create().build();
JSONObject obj = new JSONObject();
obj.put("job_id", "bbbbb");
obj.put("recipient", "costantino.perciante");
obj.put("job_name", "aaaaaa");
obj.put("service_name", "Test");
obj.put("status", "SUCCEEDED");
HttpPost request = new HttpPost(url);
request.addHeader("Content-type", ContentType.APPLICATION_JSON.toString());
StringEntity paramsEntity = new StringEntity(obj.toJSONString(), ContentType.APPLICATION_JSON);
request.setEntity(paramsEntity);
client.execute(request);
}
}