use of com.icodici.universa.node2.Notification in project ORCID-Source by ORCID.
the class UserConnectionManagerImpl method remove.
@Override
public void remove(String orcid, UserconnectionPK userConnectionPK) {
List<Notification> notifications = notificationManager.findNotificationAlertsByOrcid(orcid);
notifications.forEach(n -> {
if (n instanceof NotificationInstitutionalConnection) {
NotificationInstitutionalConnection nic = (NotificationInstitutionalConnection) n;
if (userConnectionPK.getProviderid().equals(nic.getAuthenticationProviderId())) {
notificationManager.flagAsArchived(orcid, n.getPutCode(), false);
}
}
});
userConnectionDao.remove(userConnectionPK);
}
use of com.icodici.universa.node2.Notification in project ORCID-Source by ORCID.
the class EmailMessageSenderImpl method sendEmailMessages.
@Override
public void sendEmailMessages() {
LOGGER.info("About to send email messages");
List<Object[]> orcidsWithUnsentNotifications = notificationDaoReadOnly.findRecordsWithUnsentNotifications();
for (final Object[] element : orcidsWithUnsentNotifications) {
String orcid = (String) element[0];
try {
Float emailFrequencyDays = Float.valueOf((float) element[1]);
Date recordActiveDate = (Date) element[2];
LOGGER.info("Sending messages for orcid: {}", orcid);
List<Notification> notifications = notificationManager.findNotificationsToSend(orcid, emailFrequencyDays, recordActiveDate);
if (!notifications.isEmpty()) {
LOGGER.info("Found {} messages to send for orcid: {}", notifications.size(), orcid);
EmailMessage digestMessage = createDigest(orcid, notifications);
digestMessage.setFrom(DIGEST_FROM_ADDRESS);
EmailEntity primaryEmail = emailDao.findPrimaryEmail(orcid);
if (primaryEmail == null) {
LOGGER.info("No primary email for orcid: " + orcid);
return;
}
digestMessage.setTo(primaryEmail.getId());
boolean successfullySent = mailGunManager.sendEmail(digestMessage.getFrom(), digestMessage.getTo(), digestMessage.getSubject(), digestMessage.getBodyText(), digestMessage.getBodyHtml());
if (successfullySent) {
flagAsSent(notifications);
}
} else {
LOGGER.info("There are no notifications to send for orcid: {}", orcid);
}
} catch (RuntimeException e) {
LOGGER.warn("Problem sending email message to user: " + orcid, e);
}
}
LOGGER.info("Finished sending email messages");
}
use of com.icodici.universa.node2.Notification in project ORCID-Source by ORCID.
the class NotificationManagerTest method testCreateAndDeleteNotification.
@Test
public void testCreateAndDeleteNotification() {
NotificationAmended notification = new NotificationAmended();
notification.setAmendedSection(AmendedSection.PEER_REVIEW);
Notification result = notificationManager.createNotification("4444-4444-4444-4441", notification);
assertNotNull(result.getPutCode());
notificationManager.removeNotification(result.getPutCode());
}
use of com.icodici.universa.node2.Notification in project ORCID-Source by ORCID.
the class NotificationManagerTest method testFindPermissionsByOrcidAndClient.
/**
* Test independent of spring context, sets up NotificationManager with
* mocked notifiation dao and notification adapter
*/
@Test
public void testFindPermissionsByOrcidAndClient() {
List<Notification> notificationPermissions = IntStream.range(0, 10).mapToObj(i -> new NotificationPermission()).collect(Collectors.toList());
NotificationDao notificationDao = mock(NotificationDaoImpl.class);
JpaJaxbNotificationAdapter adapter = mock(JpaJaxbNotificationAdapterImpl.class);
when(notificationDao.findPermissionsByOrcidAndClient(anyString(), anyString(), anyInt(), anyInt())).thenReturn(new ArrayList<NotificationEntity>());
when(adapter.toNotification(Matchers.<ArrayList<NotificationEntity>>any())).thenReturn(notificationPermissions);
NotificationManager notificationManager = new NotificationManagerImpl();
ReflectionTestUtils.setField(notificationManager, "notificationAdapter", adapter);
ReflectionTestUtils.setField(notificationManager, "notificationDao", notificationDao);
NotificationPermissions notifications = notificationManager.findPermissionsByOrcidAndClient("some-orcid", "some-client", 0, OrcidApiConstants.MAX_NOTIFICATIONS_AVAILABLE);
assertEquals(notificationPermissions.size(), notifications.getNotifications().size());
}
use of com.icodici.universa.node2.Notification in project ORCID-Source by ORCID.
the class NotificationsApiServiceDelegatorImpl method addPermissionNotification.
@Override
@AccessControl(requiredScope = ScopePathType.PREMIUM_NOTIFICATION)
public Response addPermissionNotification(UriInfo uriInfo, String orcid, NotificationPermission notification) {
checkIfProfileDeprecated(orcid);
notificationValidationManager.validateNotificationPermission(notification);
ProfileEntity profile = profileEntityCacheManager.retrieve(orcid);
if (profile == null) {
throw OrcidNotFoundException.newInstance(orcid);
}
if (profile.getSendMemberUpdateRequests() != null && !profile.getSendMemberUpdateRequests()) {
Map<String, String> params = new HashMap<String, String>();
params.put("orcid", orcid);
throw new OrcidNotificationException(params);
}
Notification createdNotification = notificationManager.createNotification(orcid, notification);
try {
return Response.created(new URI(uriInfo.getAbsolutePath() + "/" + createdNotification.getPutCode())).build();
} catch (URISyntaxException e) {
throw new RuntimeException(localeManager.resolveMessage("apiError.notification_uri.exception"), e);
}
}
Aggregations