use of org.orcid.jaxb.model.notification_v2.Notification in project ORCID-Source by ORCID.
the class EmailMessageSenderImpl method sendEmailMessages.
@Override
public void sendEmailMessages() {
LOGGER.info("About to send email messages");
List<String> orcidsWithMessagesToSend = notificationDaoReadOnly.findOrcidsWithNotificationsToSend();
for (final String orcid : orcidsWithMessagesToSend) {
try {
LOGGER.info("Sending messages for orcid: {}", orcid);
List<Notification> notifications = notificationManager.findUnsentByOrcid(orcid);
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);
}
} catch (RuntimeException e) {
LOGGER.warn("Problem sending email message to user: " + orcid, e);
}
}
LOGGER.info("Finished sending email messages");
}
use of org.orcid.jaxb.model.notification_v2.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 org.orcid.jaxb.model.notification_v2.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());
}
Aggregations