added support for catalogue notifications

This commit is contained in:
Massimiliano Assante 2022-05-09 10:31:20 +02:00
parent f7d2a1e569
commit d632e3ed1a
2 changed files with 69 additions and 1 deletions

View File

@ -0,0 +1,28 @@
package org.gcube.portal.social.networking.ws.mappers;
import org.gcube.portal.databook.shared.NotificationType;
import org.gcube.portal.databook.shared.ex.NotificationTypeNotFoundException;
import org.gcube.social_networking.socialnetworking.model.beans.catalogue.CatalogueEventType;
public class CatalogueEventTypeMapper {
public CatalogueEventTypeMapper() {
}
public static NotificationType getType(CatalogueEventType type) throws NotificationTypeNotFoundException {
switch (type) {
case ITEM_PUBLISHED:
return NotificationType.CAT_ITEM_PUBLISHED;
case ITEM_REJECTED:
return NotificationType.CAT_ITEM_REJECTED;
case ITEM_REMOVED:
return NotificationType.CAT_ITEM_DELETE;
case ITEM_SUBMITTED:
return NotificationType.CAT_ITEM_SUBMITTED;
case ITEM_UPDATED:
return NotificationType.CAT_ITEM_UPDATED;
default:
throw new NotificationTypeNotFoundException("The Catalogue event could not be mapped");
}
}
}

View File

@ -40,6 +40,7 @@ import org.gcube.portal.social.networking.caches.UsersCache;
import org.gcube.portal.social.networking.liferay.ws.GroupManagerWSBuilder;
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.mappers.CatalogueEventTypeMapper;
import org.gcube.portal.social.networking.ws.mappers.JobMapper;
import org.gcube.portal.social.networking.ws.mappers.WorkspaceItemMapper;
import org.gcube.portal.social.networking.ws.outputs.ResponseBean;
@ -223,7 +224,46 @@ public class Notifications {
if (! event.idsAsGroup()) {
for (int i = 0; i < idsToNotify.length; i++) {
String userIdToNotify = idsToNotify[i];
deliveryResult = nm.notifyCatalogueEvent(NotificationType.CAT_ITEM_PUBLISHED, userIdToNotify, event.getItemId(), event.getNotifyText(), event.getItemURL());
deliveryResult =
nm.notifyCatalogueEvent(
CatalogueEventTypeMapper.getType(event.getType()),
userIdToNotify,
event.getItemId(),
event.getNotifyText(),
event.getItemURL());
}
} else { //the ids are contexts
for (int i = 0; i < idsToNotify.length; i++) {
String contextId = idsToNotify[i];
try {
ScopeBean scope = new ScopeBean(contextId);
if (scope.type() != ScopeBean.Type.VRE) {
logger.error("Context not a VRE");
status = Status.BAD_REQUEST;
responseBean.setSuccess(false);
responseBean.setMessage("Not a VRE Context, only VREs are supported");
return Response.status(status).entity(responseBean).build();
} else { // it is a context and it is a valid VRE
String[] userIdsToNotify = getUsernamesByContext(scope).toArray(new String[0]); //resolve the members
for (int j = 0; j < userIdsToNotify.length; j++) {
String userIdToNotify = userIdsToNotify[j];
deliveryResult =
nm.notifyCatalogueEvent(
CatalogueEventTypeMapper.getType(event.getType()),
userIdToNotify,
event.getItemId(),
event.getNotifyText(),
event.getItemURL());
}
}
}
catch(IllegalArgumentException e) {
status = Status.BAD_REQUEST;
logger.error("Context not valid", e);
responseBean.setSuccess(false);
responseBean.setMessage("Context not valid, must start with / " + e.getMessage());
return Response.status(status).entity(responseBean).build();
}
}
}
} catch(Exception e){