2018-02-19 16:35:01 +01:00
|
|
|
package org.gcube.social_networking.social_networking_client_library;
|
2017-10-21 22:35:21 +02:00
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
|
2018-02-16 19:22:14 +01:00
|
|
|
import javax.ws.rs.core.GenericType;
|
|
|
|
|
2017-10-21 22:35:21 +02:00
|
|
|
import org.apache.commons.lang.Validate;
|
|
|
|
import org.gcube.portal.databook.shared.Notification;
|
2018-02-19 16:35:01 +01:00
|
|
|
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.output.ResponseBean;
|
2017-10-21 22:35:21 +02:00
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Notifications client.
|
|
|
|
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
|
|
|
|
*/
|
2018-02-19 16:27:09 +01:00
|
|
|
public class NotificationClient extends BaseClient{
|
2017-10-21 22:35:21 +02:00
|
|
|
|
|
|
|
private static final String SUB_SERVICE_PATH = "2/notifications/";
|
2018-02-19 16:27:09 +01:00
|
|
|
private static Logger logger = LoggerFactory.getLogger(NotificationClient.class);
|
2017-10-21 22:35:21 +02:00
|
|
|
|
|
|
|
|
2018-02-19 16:27:09 +01:00
|
|
|
public NotificationClient() throws Exception {
|
2017-10-21 22:35:21 +02:00
|
|
|
super(SUB_SERVICE_PATH);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get range notifications
|
2018-02-16 19:22:14 +01:00
|
|
|
* @param from greater or equal to one
|
2017-10-21 22:35:21 +02:00
|
|
|
* @param quantity
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
public List<Notification> getNotifications(int from, int quantity){
|
|
|
|
|
2018-02-16 19:22:14 +01:00
|
|
|
Validate.isTrue(from >= 1, "From cannot be negative");
|
2017-10-21 22:35:21 +02:00
|
|
|
Validate.isTrue(from >= 0, "Quantity cannot be negative");
|
|
|
|
|
|
|
|
logger.debug("Request for getting notifications");
|
|
|
|
String thisMethodSignature = "get-range-notifications";
|
|
|
|
String request = getServiceEndpoint() + thisMethodSignature + "?from=" + from + "&quantity=" +quantity;
|
2018-02-17 18:51:38 +01:00
|
|
|
return HttpClient.get(new GenericType<ResponseBean<ArrayList<Notification>>>(){}, request);
|
2017-10-21 22:35:21 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Notify job status
|
|
|
|
* @param notification
|
|
|
|
* @return
|
|
|
|
*/
|
2017-10-24 15:39:29 +02:00
|
|
|
public void sendJobNotification(JobNotificationBean notification){
|
2017-10-21 22:35:21 +02:00
|
|
|
|
|
|
|
Validate.isTrue(notification != null, "Notification cannot be null");
|
|
|
|
logger.debug("Request for getting notifications");
|
|
|
|
String thisMethodSignature = "notify-job-status";
|
|
|
|
String request = getServiceEndpoint() + thisMethodSignature;
|
2018-02-17 18:51:38 +01:00
|
|
|
HttpClient.post(new GenericType<ResponseBean<String>>(){}, request, notification);
|
2017-10-21 22:35:21 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|