client for catalogue ready

This commit is contained in:
Massimiliano Assante 2022-05-09 12:48:28 +02:00
parent 1bfeba03f1
commit 8c4fbb49a4
3 changed files with 92 additions and 15 deletions

View File

@ -10,7 +10,7 @@
<groupId>org.gcube.social-networking</groupId>
<artifactId>social-service-client</artifactId>
<version>1.0.0</version>
<version>1.1.0-SNAPSHOT</version>
<name>social-networking-service-client</name>
<packaging>jar</packaging>
<description>The social networking web service client library</description>

View File

@ -9,6 +9,10 @@ import org.apache.commons.lang.Validate;
import org.gcube.portal.databook.shared.Notification;
import org.gcube.social_networking.social_networking_client_library.utils.HttpClient;
import org.gcube.social_networking.socialnetworking.model.beans.JobNotificationBean;
import org.gcube.social_networking.socialnetworking.model.beans.catalogue.CatalogueEvent;
import org.gcube.social_networking.socialnetworking.model.beans.catalogue.CatalogueEventType;
import org.gcube.social_networking.socialnetworking.model.beans.workspace.WorkspaceEvent;
import org.gcube.social_networking.socialnetworking.model.beans.workspace.WorkspaceEventType;
import org.gcube.social_networking.socialnetworking.model.output.ResponseBean;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -59,5 +63,31 @@ public class NotificationClient extends BaseClient{
HttpClient.post(new GenericType<ResponseBean<String>>(){}, request, notification);
}
/**
* Notify a catalogue event, types available see {@link WorkspaceEventType}
* @param event an instance of {@link WorkspaceEvent}
*/
public void sendWorkspaceEvent(WorkspaceEvent event) {
Validate.isTrue(event != null, "WorkspaceEvent cannot be null");
logger.debug("Request for sending workdspace notifications");
String thisMethodSignature = "workspace";
String request = getServiceEndpoint() + thisMethodSignature;
HttpClient.post(new GenericType<ResponseBean<String>>(){}, request, event);
}
/**
* Notify a catalogue event, types availeble see {@link CatalogueEventType}
* @param event an instance of {@link CatalogueEvent}
*/
public void senCatalogueEvent(CatalogueEvent event) {
Validate.isTrue(event != null, "CatalogueEvent cannot be null");
logger.debug("Request for sending CatalogueEvent notifications");
String thisMethodSignature = "catalogue";
String request = getServiceEndpoint() + thisMethodSignature;
HttpClient.post(new GenericType<ResponseBean<String>>(){}, request, event);
}
}

View File

@ -1,5 +1,6 @@
package org.gcube.portal.social_networking_client_library;
import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@ -11,7 +12,6 @@ import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.portal.databook.shared.EnhancedFeed;
import org.gcube.portal.databook.shared.Feed;
import org.gcube.portal.databook.shared.JobStatusType;
import org.gcube.portal.databook.shared.Notification;
import org.gcube.social_networking.social_networking_client_library.FullTextSearchClient;
import org.gcube.social_networking.social_networking_client_library.HashTagClient;
@ -24,6 +24,7 @@ import org.gcube.social_networking.social_networking_client_library.UserClient;
import org.gcube.social_networking.social_networking_client_library.VREClient;
import org.gcube.social_networking.socialnetworking.model.beans.ApplicationId;
import org.gcube.social_networking.socialnetworking.model.beans.JobNotificationBean;
import org.gcube.social_networking.socialnetworking.model.beans.JobStatusModelType;
import org.gcube.social_networking.socialnetworking.model.beans.Message;
import org.gcube.social_networking.socialnetworking.model.beans.MessageInbox;
import org.gcube.social_networking.socialnetworking.model.beans.MyVRE;
@ -31,6 +32,14 @@ import org.gcube.social_networking.socialnetworking.model.beans.PostInputBean;
import org.gcube.social_networking.socialnetworking.model.beans.Recipient;
import org.gcube.social_networking.socialnetworking.model.beans.UserProfile;
import org.gcube.social_networking.socialnetworking.model.beans.UserProfileExtended;
import org.gcube.social_networking.socialnetworking.model.beans.catalogue.CatalogueEvent;
import org.gcube.social_networking.socialnetworking.model.beans.catalogue.CatalogueEventType;
import org.gcube.social_networking.socialnetworking.model.beans.workspace.AddedItemEvent;
import org.gcube.social_networking.socialnetworking.model.beans.workspace.DeletedItemEvent;
import org.gcube.social_networking.socialnetworking.model.beans.workspace.FileItemBean;
import org.gcube.social_networking.socialnetworking.model.beans.workspace.FolderBean;
import org.gcube.social_networking.socialnetworking.model.beans.workspace.UpdatedItemEvent;
import org.gcube.social_networking.socialnetworking.model.beans.workspace.WorkspaceEvent;
import org.junit.Before;
import org.junit.Test;
import org.slf4j.Logger;
@ -48,6 +57,44 @@ public class TestClientServices {
//SecurityTokenProvider.instance.set("");
}
@Test
public void testCatalogueEvents() throws Exception {
NotificationClient nc = new NotificationClient();
String[] idstoNotify = {"andrea.rossi", "mister.pink"};
CatalogueEvent event =
new CatalogueEvent(
CatalogueEventType.ITEM_SUBMITTED,
idstoNotify,
"Wyscout soccer-logs dataset",
"submitted \"Wyscout soccer-logs dataset\", a dataset of soccer-logs for all the main soccer leagues in the world, from season 2014/2015 to the current one. ",
new URL("http://data.d4science.org/ctlg/ResourceCatalogue/wyscout_soccer-logs_dataset"));
nc.senCatalogueEvent(event);
}
@Test
public void testWorkspaceItemEvents() throws Exception {
NotificationClient nc = new NotificationClient();
boolean vreFolder = false;
FolderBean folder = new FolderBean("217cbe15-6408-41e5-9fda-628f56b8e803", "folderName", "folderTitle","displayName",
"/Workspace/_shared attachments", "90b8da48-d363-441a-a0a2-6f614ae747b9", vreFolder);
FileItemBean fileItem = new FileItemBean("90b8da48-d363-441a-f0a2-4f413ae747d7", "updated item.pdf", "updated item.pdf",
"/Workspace/_shared attachments/test updated item from client", folder);
String[] idstoNotify = {"andrea.rossi", "mister.pink"};
WorkspaceEvent event = new UpdatedItemEvent(idstoNotify, fileItem);
nc.sendWorkspaceEvent(event);
event = new AddedItemEvent(idstoNotify, fileItem);
nc.sendWorkspaceEvent(event);
event = new DeletedItemEvent(idstoNotify, "theDeletedFilenName.pdf", folder);
nc.sendWorkspaceEvent(event);
String[] contextIdstoNotify = {"/gcube/devsec/devVRE"};
event = new UpdatedItemEvent(contextIdstoNotify, true, fileItem);
nc.sendWorkspaceEvent(event);
}
@Test
public void testSearch() throws Exception {
FullTextSearchClient search = new FullTextSearchClient();
@ -116,19 +163,19 @@ public class TestClientServices {
}
}
// @Test
// public void sendJobNotification() throws Exception {
// NotificationClient notificationsClient = new NotificationClient();
// JobNotificationBean notification = new JobNotificationBean(
// "luca.frosini",
// UUID.randomUUID().toString(),
// "SmartExecutor Social Indexer",
// "SmartExecutor",
// JobStatusType.SUCCEEDED,
// "all ok");
// notificationsClient.sendJobNotification(notification);
// logger.debug("Sent job notification ");
// }
@Test
public void sendJobNotification() throws Exception {
NotificationClient notificationsClient = new NotificationClient();
JobNotificationBean notification = new JobNotificationBean(
"luca.frosini",
UUID.randomUUID().toString(),
"SmartExecutor Social Indexer",
"SmartExecutor",
JobStatusModelType.SUCCEEDED,
"all ok");
notificationsClient.sendJobNotification(notification);
logger.debug("Sent job notification ");
}
@Test
public void getProfile() throws Exception {