2017-10-21 22:35:21 +02:00
|
|
|
package org.gcube.portal.social_networking_client_library;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import org.apache.commons.lang.Validate;
|
|
|
|
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
|
|
|
import org.gcube.portal.databook.shared.Notification;
|
|
|
|
import org.gcube.portal.social_networking_client_library.utils.HttpClient;
|
|
|
|
import org.gcube.portal.socialnetworking.model.input.JobNotificationBean;
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Notifications client.
|
|
|
|
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
|
|
|
|
*/
|
|
|
|
public class NotificationsClient extends BaseClient{
|
|
|
|
|
|
|
|
private static final String SUB_SERVICE_PATH = "2/notifications/";
|
|
|
|
private static Logger logger = LoggerFactory.getLogger(NotificationsClient.class);
|
|
|
|
|
|
|
|
|
|
|
|
public NotificationsClient() throws Exception {
|
|
|
|
super(SUB_SERVICE_PATH);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get range notifications
|
|
|
|
* @param from
|
|
|
|
* @param quantity
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
public List<Notification> getNotifications(int from, int quantity){
|
|
|
|
|
|
|
|
Validate.isTrue(from >= 0, "From cannot be negative");
|
|
|
|
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;
|
|
|
|
return HttpClient.get(new ArrayList<Notification>(0).getClass(), request, SecurityTokenProvider.instance.get());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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;
|
2017-10-24 15:39:29 +02:00
|
|
|
HttpClient.post(Void.class, request, SecurityTokenProvider.instance.get(), notification);
|
2017-10-21 22:35:21 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|