added NotificationMessage
This commit is contained in:
parent
0e7299f104
commit
d8a4046eed
|
@ -9,7 +9,6 @@
|
|||
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
<attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
|
||||
|
|
|
@ -25,6 +25,7 @@ import org.gcube.applicationsupportlayer.social.shared.SocialNetworkingUser;
|
|||
import org.gcube.common.authorization.library.provider.AuthorizationProvider;
|
||||
import org.gcube.common.authorization.library.utils.Caller;
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.gcube.common.storagehub.model.exceptions.InvalidCallParameters;
|
||||
import org.gcube.portal.databook.shared.Notification;
|
||||
import org.gcube.portal.notifications.bean.GenericItemBean;
|
||||
import org.gcube.portal.notifications.thread.JobStatusNotificationThread;
|
||||
|
@ -32,6 +33,9 @@ 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.JobNotificationBean;
|
||||
import org.gcube.portal.social.networking.ws.model.AddFileNotificationBean;
|
||||
import org.gcube.portal.social.networking.ws.model.AddFolderNotificationBean;
|
||||
import org.gcube.portal.social.networking.ws.model.NotificationMessage;
|
||||
import org.gcube.portal.social.networking.ws.outputs.ResponseBean;
|
||||
import org.gcube.portal.social.networking.ws.utils.CassandraConnection;
|
||||
import org.gcube.portal.social.networking.ws.utils.ErrorMessages;
|
||||
|
@ -155,4 +159,38 @@ public class Notifications {
|
|||
return Response.status(status).entity(responseBean).build();
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a JOB notification to a given recipient
|
||||
* @param job The job bean
|
||||
* @return
|
||||
* @throws ValidationException
|
||||
*/
|
||||
@POST
|
||||
@Path("notify/")
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
@StatusCodes ({
|
||||
@ResponseCode ( code = 200, condition = "Notification is sent correctly"),
|
||||
@ResponseCode ( code = 500, condition = ErrorMessages.ERROR_IN_API_RESULT)
|
||||
})
|
||||
public Response notify(
|
||||
@NotNull(message="input is missing")
|
||||
@Valid
|
||||
NotificationMessage message) throws ValidationException{
|
||||
|
||||
Caller caller = AuthorizationProvider.instance.get();
|
||||
String context = ScopeProvider.instance.get();
|
||||
|
||||
if (!message.getType().getNotificationClass().isInstance(message.getBean())) {
|
||||
//invalid call
|
||||
return Response.status(Status.BAD_REQUEST).build();
|
||||
}
|
||||
|
||||
//TODO: call notification method
|
||||
|
||||
return Response.ok().build();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
package org.gcube.portal.social.networking.ws.model;
|
||||
|
||||
public class AddFileNotificationBean implements NotificationBean {
|
||||
|
||||
private String filename;
|
||||
|
||||
public AddFileNotificationBean(String filename) {
|
||||
this.filename = filename;
|
||||
}
|
||||
|
||||
public String getFilename() {
|
||||
return filename;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
package org.gcube.portal.social.networking.ws.model;
|
||||
|
||||
public class AddFolderNotificationBean implements NotificationBean {
|
||||
|
||||
private String foldername;
|
||||
|
||||
public AddFolderNotificationBean(String foldername) {
|
||||
this.foldername = foldername;
|
||||
}
|
||||
|
||||
public String getFoldername() {
|
||||
return foldername;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
package org.gcube.portal.social.networking.ws.model;
|
||||
|
||||
interface NotificationBean {
|
||||
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
package org.gcube.portal.social.networking.ws.model;
|
||||
|
||||
public class NotificationMessage {
|
||||
|
||||
private NotificationType type;
|
||||
|
||||
private NotificationBean bean;
|
||||
|
||||
public NotificationMessage(NotificationType type, NotificationBean bean) {
|
||||
super();
|
||||
this.type = type;
|
||||
this.bean = bean;
|
||||
}
|
||||
|
||||
public NotificationType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public NotificationBean getBean() {
|
||||
return bean;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
package org.gcube.portal.social.networking.ws.model;
|
||||
|
||||
public enum NotificationType {
|
||||
|
||||
AddFileToWS(AddFileNotificationBean.class),
|
||||
AddFolderToWS(AddFolderNotificationBean.class);
|
||||
|
||||
|
||||
Class<? extends NotificationBean> beanClass;
|
||||
|
||||
NotificationType(Class<? extends NotificationBean> beanClass){
|
||||
this.beanClass = beanClass;
|
||||
}
|
||||
|
||||
|
||||
public Class<? extends NotificationBean> getNotificationClass(){
|
||||
return this.beanClass;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue