partially implemented worspace notif support
This commit is contained in:
parent
d8a4046eed
commit
fd1eb389c3
24
pom.xml
24
pom.xml
|
@ -70,6 +70,11 @@
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<!-- end enunciate deps -->
|
<!-- end enunciate deps -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.gcube.social-networking</groupId>
|
||||||
|
<artifactId>social-service-model</artifactId>
|
||||||
|
<version>[1.1.0-SNAPSHOT, 2.0.0)</version>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>net.sf.ehcache</groupId>
|
<groupId>net.sf.ehcache</groupId>
|
||||||
<artifactId>ehcache</artifactId>
|
<artifactId>ehcache</artifactId>
|
||||||
|
@ -302,7 +307,6 @@
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
<finalName>${project.name}</finalName>
|
|
||||||
<plugins>
|
<plugins>
|
||||||
<!-- Enunciate Maven plugin -->
|
<!-- Enunciate Maven plugin -->
|
||||||
<plugin>
|
<plugin>
|
||||||
|
@ -345,6 +349,24 @@
|
||||||
</execution>
|
</execution>
|
||||||
</executions>
|
</executions>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-javadoc-plugin</artifactId>
|
||||||
|
<configuration>
|
||||||
|
<additionalparam>-Xdoclint:none</additionalparam>
|
||||||
|
<additionalJOption>-Xdoclint:none</additionalJOption>
|
||||||
|
</configuration>
|
||||||
|
<version>3.1.0</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>generate-doc</id>
|
||||||
|
<phase>install</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>jar</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
</project>
|
</project>
|
|
@ -0,0 +1,57 @@
|
||||||
|
package org.gcube.portal.social.networking.ws.mappers;
|
||||||
|
|
||||||
|
import org.gcube.applicationsupportlayer.social.shared.SocialFileItem;
|
||||||
|
import org.gcube.applicationsupportlayer.social.shared.SocialSharedFolder;
|
||||||
|
import org.gcube.social_networking.socialnetworking.model.beans.SharedFolderBean;
|
||||||
|
import org.gcube.social_networking.socialnetworking.model.beans.WorkspaceFileItemBean;
|
||||||
|
|
||||||
|
public class WorkspaceItemMapper {
|
||||||
|
|
||||||
|
public WorkspaceItemMapper() {
|
||||||
|
// TODO Auto-generated constructor stub
|
||||||
|
}
|
||||||
|
|
||||||
|
public static SocialFileItem getFileItem(WorkspaceFileItemBean item) {
|
||||||
|
String id = null;
|
||||||
|
String name= null;
|
||||||
|
String title= null;
|
||||||
|
String path= null;
|
||||||
|
SocialSharedFolder parent = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
id = item.getId();
|
||||||
|
name = item.getName();
|
||||||
|
title = item.getTitle();
|
||||||
|
path = item.getPath();
|
||||||
|
parent = getSharedFolder(item.getParent());
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
SocialFileItem toReturn = new SocialFileItem(id, name, title, path, parent);
|
||||||
|
return toReturn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static SocialSharedFolder getSharedFolder(SharedFolderBean item) {
|
||||||
|
|
||||||
|
String id = null;
|
||||||
|
String name= null;
|
||||||
|
String title= null;
|
||||||
|
String displayName= null;
|
||||||
|
String path= null;
|
||||||
|
String parentId= null;
|
||||||
|
boolean vreFolder = false;
|
||||||
|
try {
|
||||||
|
id = item.getId();
|
||||||
|
name = item.getName();
|
||||||
|
title = item.getTitle();
|
||||||
|
displayName = item.getDisplayName();
|
||||||
|
path = item.getPath();
|
||||||
|
parentId = item.getParentId();
|
||||||
|
vreFolder = item.isVreFolder();
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
SocialSharedFolder toReturn = new SocialSharedFolder(id, name, title, displayName, path, parentId, vreFolder);
|
||||||
|
return toReturn;
|
||||||
|
}
|
||||||
|
}
|
|
@ -20,8 +20,10 @@ import javax.ws.rs.core.Response.Status;
|
||||||
|
|
||||||
import org.gcube.applicationsupportlayer.social.ApplicationNotificationsManager;
|
import org.gcube.applicationsupportlayer.social.ApplicationNotificationsManager;
|
||||||
import org.gcube.applicationsupportlayer.social.NotificationsManager;
|
import org.gcube.applicationsupportlayer.social.NotificationsManager;
|
||||||
|
import org.gcube.applicationsupportlayer.social.shared.SocialFileItem;
|
||||||
import org.gcube.applicationsupportlayer.social.shared.SocialNetworkingSite;
|
import org.gcube.applicationsupportlayer.social.shared.SocialNetworkingSite;
|
||||||
import org.gcube.applicationsupportlayer.social.shared.SocialNetworkingUser;
|
import org.gcube.applicationsupportlayer.social.shared.SocialNetworkingUser;
|
||||||
|
import org.gcube.applicationsupportlayer.social.shared.SocialSharedFolder;
|
||||||
import org.gcube.common.authorization.library.provider.AuthorizationProvider;
|
import org.gcube.common.authorization.library.provider.AuthorizationProvider;
|
||||||
import org.gcube.common.authorization.library.utils.Caller;
|
import org.gcube.common.authorization.library.utils.Caller;
|
||||||
import org.gcube.common.scope.api.ScopeProvider;
|
import org.gcube.common.scope.api.ScopeProvider;
|
||||||
|
@ -33,12 +35,15 @@ 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.LiferayJSONWsCredentials;
|
||||||
import org.gcube.portal.social.networking.liferay.ws.UserManagerWSBuilder;
|
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.inputs.JobNotificationBean;
|
||||||
import org.gcube.portal.social.networking.ws.model.AddFileNotificationBean;
|
import org.gcube.portal.social.networking.ws.mappers.WorkspaceItemMapper;
|
||||||
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.outputs.ResponseBean;
|
||||||
import org.gcube.portal.social.networking.ws.utils.CassandraConnection;
|
import org.gcube.portal.social.networking.ws.utils.CassandraConnection;
|
||||||
import org.gcube.portal.social.networking.ws.utils.ErrorMessages;
|
import org.gcube.portal.social.networking.ws.utils.ErrorMessages;
|
||||||
|
import org.gcube.social_networking.socialnetworking.model.beans.SharedFolderBean;
|
||||||
|
import org.gcube.social_networking.socialnetworking.model.beans.WSAddedItemNotificationBean;
|
||||||
|
import org.gcube.social_networking.socialnetworking.model.beans.WSSharedFolderNotificationBean;
|
||||||
|
import org.gcube.social_networking.socialnetworking.model.beans.WorkspaceFileItemBean;
|
||||||
|
import org.gcube.social_networking.socialnetworking.model.beans.WorkspaceNotificationMessage;
|
||||||
import org.gcube.vomanagement.usermanagement.model.GCubeUser;
|
import org.gcube.vomanagement.usermanagement.model.GCubeUser;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
@ -52,9 +57,9 @@ import com.webcohesion.enunciate.metadata.rs.StatusCodes;
|
||||||
*/
|
*/
|
||||||
@Path("2/notifications")
|
@Path("2/notifications")
|
||||||
@RequestHeaders ({
|
@RequestHeaders ({
|
||||||
@RequestHeader( name = "Authorization", description = "Bearer token, see https://dev.d4science.org/how-to-access-resources"),
|
@RequestHeader( name = "Authorization", description = "Bearer token, see https://dev.d4science.org/how-to-access-resources"),
|
||||||
@RequestHeader( name = "Content-Type", description = "application/json")
|
@RequestHeader( name = "Content-Type", description = "application/json")
|
||||||
})
|
})
|
||||||
public class Notifications {
|
public class Notifications {
|
||||||
|
|
||||||
// Logger
|
// Logger
|
||||||
|
@ -160,23 +165,23 @@ public class Notifications {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send a JOB notification to a given recipient
|
* Send a Workspace notification to a given user
|
||||||
* @param job The job bean
|
* @param message
|
||||||
* @return
|
* @return
|
||||||
* @throws ValidationException
|
* @throws ValidationException
|
||||||
*/
|
*/
|
||||||
@POST
|
@POST
|
||||||
@Path("notify/")
|
@Path("notify-ws/")
|
||||||
@Consumes(MediaType.APPLICATION_JSON)
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
@StatusCodes ({
|
@StatusCodes ({
|
||||||
@ResponseCode ( code = 200, condition = "Notification is sent correctly"),
|
@ResponseCode ( code = 200, condition = "Workspace Notification is sent correctly"),
|
||||||
@ResponseCode ( code = 500, condition = ErrorMessages.ERROR_IN_API_RESULT)
|
@ResponseCode ( code = 500, condition = ErrorMessages.ERROR_IN_API_RESULT)
|
||||||
})
|
})
|
||||||
public Response notify(
|
public Response notifyWs(
|
||||||
@NotNull(message="input is missing")
|
@NotNull(message="input is missing")
|
||||||
@Valid
|
@Valid
|
||||||
NotificationMessage message) throws ValidationException{
|
WorkspaceNotificationMessage message) throws ValidationException{
|
||||||
|
|
||||||
Caller caller = AuthorizationProvider.instance.get();
|
Caller caller = AuthorizationProvider.instance.get();
|
||||||
String context = ScopeProvider.instance.get();
|
String context = ScopeProvider.instance.get();
|
||||||
|
@ -185,12 +190,80 @@ public class Notifications {
|
||||||
//invalid call
|
//invalid call
|
||||||
return Response.status(Status.BAD_REQUEST).build();
|
return Response.status(Status.BAD_REQUEST).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: call notification method
|
ResponseBean responseBean = new ResponseBean();
|
||||||
|
Status status = Status.OK;
|
||||||
return Response.ok().build();
|
|
||||||
|
try{
|
||||||
|
switch (message.getType()) {
|
||||||
|
case WP_ITEM_NEW:
|
||||||
|
WSAddedItemNotificationBean wpItemBean = (WSAddedItemNotificationBean) message.getBean();
|
||||||
|
GCubeUser userRecipient = UserManagerWSBuilder.getInstance().getUserManager().getUserByUsername(wpItemBean.getUserIdToNotify());
|
||||||
|
// notifications are sent by using the user allowed to use liferay's json apis
|
||||||
|
SocialNetworkingSite site = SocialNetworkingSiteFinder.getSocialNetworkingSiteFromScope(context);
|
||||||
|
GCubeUser senderUser = UserManagerWSBuilder.getInstance().getUserManager().getUserByEmail(LiferayJSONWsCredentials.getSingleton().getUser());
|
||||||
|
SocialNetworkingUser user = new SocialNetworkingUser(senderUser.getUsername(), senderUser.getEmail(), senderUser.getFullname(), senderUser.getUserAvatarURL());
|
||||||
|
NotificationsManager nm = new ApplicationNotificationsManager(UserManagerWSBuilder.getInstance().getUserManager(), site, context, user);
|
||||||
|
nm.notifyAddedItem(context, WorkspaceItemMapper.getFileItem(wpItemBean.getItem()), WorkspaceItemMapper.getSharedFolder(wpItemBean.getFolder()));
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} catch(Exception e){
|
||||||
|
logger.error("Unable to send job notification", e);
|
||||||
|
responseBean.setSuccess(false);
|
||||||
|
responseBean.setMessage(e.getMessage());
|
||||||
|
status = Status.INTERNAL_SERVER_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Response.status(status).entity(responseBean).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send a Workspace notification to a given user
|
||||||
|
* @param userIdToNotify the user you want to notify
|
||||||
|
* @param newItem the new shared {@link SocialFileItem} instance
|
||||||
|
* @param sharedFolder the shared folder {@link SocialSharedFolder} instance
|
||||||
|
* @return
|
||||||
|
* @throws ValidationException
|
||||||
|
*/
|
||||||
|
@POST
|
||||||
|
@Path("notify-ws-item-new/")
|
||||||
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
|
@StatusCodes ({
|
||||||
|
@ResponseCode ( code = 200, condition = "Workspace Notification is sent correctly"),
|
||||||
|
@ResponseCode ( code = 500, condition = ErrorMessages.ERROR_IN_API_RESULT)
|
||||||
|
})
|
||||||
|
public Response notifyWsItemNew(
|
||||||
|
@NotNull(message="input is missing")
|
||||||
|
@Valid
|
||||||
|
String userIdToNotify,
|
||||||
|
@NotNull(message="input is missing")
|
||||||
|
@Valid
|
||||||
|
WorkspaceFileItemBean fileItem) throws ValidationException{
|
||||||
|
|
||||||
|
Caller caller = AuthorizationProvider.instance.get();
|
||||||
|
String context = ScopeProvider.instance.get();
|
||||||
|
ResponseBean responseBean = new ResponseBean();
|
||||||
|
Status status = Status.OK;
|
||||||
|
|
||||||
|
try{
|
||||||
|
// notifications are sent by using the user allowed to use liferay's json apis
|
||||||
|
SocialNetworkingSite site = SocialNetworkingSiteFinder.getSocialNetworkingSiteFromScope(context);
|
||||||
|
GCubeUser senderUser = UserManagerWSBuilder.getInstance().getUserManager().getUserByEmail(LiferayJSONWsCredentials.getSingleton().getUser());
|
||||||
|
SocialNetworkingUser user = new SocialNetworkingUser(senderUser.getUsername(), senderUser.getEmail(), senderUser.getFullname(), senderUser.getUserAvatarURL());
|
||||||
|
NotificationsManager nm = new ApplicationNotificationsManager(UserManagerWSBuilder.getInstance().getUserManager(), site, context, user);
|
||||||
|
nm.notifyAddedItem(context, WorkspaceItemMapper.getFileItem(fileItem), WorkspaceItemMapper.getSharedFolder(fileItem.getParent()));
|
||||||
|
} catch(Exception e){
|
||||||
|
logger.error("Unable to send job notification", e);
|
||||||
|
responseBean.setSuccess(false);
|
||||||
|
responseBean.setMessage(e.getMessage());
|
||||||
|
status = Status.INTERNAL_SERVER_ERROR;
|
||||||
|
}
|
||||||
|
return Response.status(status).entity(responseBean).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,16 +0,0 @@
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,15 +0,0 @@
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,5 +0,0 @@
|
||||||
package org.gcube.portal.social.networking.ws.model;
|
|
||||||
|
|
||||||
interface NotificationBean {
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,25 +0,0 @@
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,20 +0,0 @@
|
||||||
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