use of edu.harvard.iq.dataverse.UserNotification in project dataverse by IQSS.
the class Notifications method getAllNotificationsForUser.
@GET
@Path("all")
public Response getAllNotificationsForUser() {
User user;
try {
user = findUserOrDie();
} catch (WrappedResponse ex) {
return error(Response.Status.UNAUTHORIZED, "You must supply an API token.");
}
if (user == null) {
return error(Response.Status.BAD_REQUEST, "A user could not be found based on the API token.");
}
if (!(user instanceof AuthenticatedUser)) {
// It's unlikely we'll reach this error. A Guest doesn't have an API token and would have been blocked above.
return error(Response.Status.BAD_REQUEST, "Only an AuthenticatedUser can have notifications.");
}
AuthenticatedUser authenticatedUser = (AuthenticatedUser) user;
JsonArrayBuilder jsonArrayBuilder = Json.createArrayBuilder();
List<UserNotification> notifications = userNotificationSvc.findByUser(authenticatedUser.getId());
for (UserNotification notification : notifications) {
NullSafeJsonBuilder notificationObjectBuilder = jsonObjectBuilder();
JsonArrayBuilder reasonsForReturn = Json.createArrayBuilder();
Type type = notification.getType();
notificationObjectBuilder.add("id", notification.getId());
notificationObjectBuilder.add("type", type.toString());
/* FIXME - Re-add reasons for return if/when they are added to the notifications page.
if (Type.RETURNEDDS.equals(type) || Type.SUBMITTEDDS.equals(type)) {
JsonArrayBuilder reasons = getReasonsForReturn(notification);
for (JsonValue reason : reasons.build()) {
reasonsForReturn.add(reason);
}
notificationObjectBuilder.add("reasonsForReturn", reasonsForReturn);
}
*/
jsonArrayBuilder.add(notificationObjectBuilder);
}
JsonObjectBuilder result = Json.createObjectBuilder().add("notifications", jsonArrayBuilder);
return ok(result);
}
use of edu.harvard.iq.dataverse.UserNotification in project dataverse by IQSS.
the class MailUtilTest method setUp.
@Before
public void setUp() {
rootDataverseName = "LibraScholar";
userNotification = new UserNotification();
}
use of edu.harvard.iq.dataverse.UserNotification in project dataverse by IQSS.
the class ConfirmEmailServiceBean method sendLinkOnEmailChange.
/**
* @todo: We expect to send two messages. One at signup and another at email
* change.
*/
private void sendLinkOnEmailChange(AuthenticatedUser aUser, String confirmationUrl) throws ConfirmEmailException {
String messageBody = BundleUtil.getStringFromBundle("notification.email.changeEmail", Arrays.asList(aUser.getFirstName(), confirmationUrl, ConfirmEmailUtil.friendlyExpirationTime(systemConfig.getMinutesUntilConfirmEmailTokenExpires())));
logger.log(Level.FINE, "messageBody:{0}", messageBody);
try {
String toAddress = aUser.getEmail();
try {
Dataverse rootDataverse = dataverseService.findRootDataverse();
if (rootDataverse != null) {
String rootDataverseName = rootDataverse.getName();
// FIXME: consider refactoring this into MailServiceBean.sendNotificationEmail. CONFIRMEMAIL may be the only type where we don't want an in-app notification.
UserNotification userNotification = new UserNotification();
userNotification.setType(UserNotification.Type.CONFIRMEMAIL);
String subject = MailUtil.getSubjectTextBasedOnNotification(userNotification, rootDataverseName, null);
logger.fine("sending email to " + toAddress + " with this subject: " + subject);
mailService.sendSystemEmail(toAddress, subject, messageBody);
}
} catch (Exception e) {
logger.info("The root dataverse is not present. Don't send a notification to dataverseAdmin.");
}
} catch (Exception ex) {
/**
* @todo get more specific about the exception that's thrown when
* `asadmin create-javamail-resource` (or equivalent) hasn't been
* run.
*/
throw new ConfirmEmailException("Problem sending email confirmation link possibily due to mail server not being configured.");
}
logger.log(Level.FINE, "attempted to send mail to {0}", aUser.getEmail());
}
use of edu.harvard.iq.dataverse.UserNotification in project dataverse by IQSS.
the class DataverseUserPage method displayNotification.
public void displayNotification() {
for (UserNotification userNotification : notificationsList) {
switch(userNotification.getType()) {
case ASSIGNROLE:
case REVOKEROLE:
// Can either be a dataverse or dataset, so search both
Dataverse dataverse = dataverseService.find(userNotification.getObjectId());
if (dataverse != null) {
userNotification.setRoleString(this.getRoleStringFromUser(this.getCurrentUser(), dataverse));
userNotification.setTheObject(dataverse);
} else {
Dataset dataset = datasetService.find(userNotification.getObjectId());
if (dataset != null) {
userNotification.setRoleString(this.getRoleStringFromUser(this.getCurrentUser(), dataset));
userNotification.setTheObject(dataset);
} else {
DataFile datafile = fileService.find(userNotification.getObjectId());
userNotification.setRoleString(this.getRoleStringFromUser(this.getCurrentUser(), datafile));
userNotification.setTheObject(datafile);
}
}
break;
case CREATEDV:
userNotification.setTheObject(dataverseService.find(userNotification.getObjectId()));
break;
case REQUESTFILEACCESS:
DataFile file = fileService.find(userNotification.getObjectId());
userNotification.setTheObject(file.getOwner());
break;
case GRANTFILEACCESS:
case REJECTFILEACCESS:
userNotification.setTheObject(datasetService.find(userNotification.getObjectId()));
break;
case MAPLAYERUPDATED:
case CREATEDS:
case SUBMITTEDDS:
case PUBLISHEDDS:
case RETURNEDDS:
userNotification.setTheObject(datasetVersionService.find(userNotification.getObjectId()));
break;
case MAPLAYERDELETEFAILED:
userNotification.setTheObject(fileService.findFileMetadata(userNotification.getObjectId()));
break;
case CREATEACC:
userNotification.setTheObject(userNotification.getUser());
break;
case CHECKSUMFAIL:
userNotification.setTheObject(datasetService.find(userNotification.getObjectId()));
break;
case FILESYSTEMIMPORT:
userNotification.setTheObject(datasetVersionService.find(userNotification.getObjectId()));
break;
case CHECKSUMIMPORT:
userNotification.setTheObject(datasetVersionService.find(userNotification.getObjectId()));
break;
}
userNotification.setDisplayAsRead(userNotification.isReadNotification());
if (userNotification.isReadNotification() == false) {
userNotification.setReadNotification(true);
userNotificationService.save(userNotification);
}
}
}
use of edu.harvard.iq.dataverse.UserNotification in project dataverse by IQSS.
the class DataverseUserPage method remove.
public String remove(Long notificationId) {
UserNotification userNotification = userNotificationService.find(notificationId);
userNotificationService.delete(userNotification);
for (UserNotification uNotification : notificationsList) {
if (Objects.equals(uNotification.getId(), userNotification.getId())) {
notificationsList.remove(uNotification);
break;
}
}
return null;
}
Aggregations