use of org.orcid.persistence.jpa.entities.NotificationEntity in project ORCID-Source by ORCID.
the class NotificationManagerImpl method createNotification.
@Override
public Notification createNotification(String orcid, Notification notification) {
if (notification.getPutCode() != null) {
throw new IllegalArgumentException("Put code must be null when creating a new notification");
}
NotificationEntity notificationEntity = notificationAdapter.toNotificationEntity(notification);
ProfileEntity profile = profileEntityCacheManager.retrieve(orcid);
if (profile == null) {
throw OrcidNotFoundException.newInstance(orcid);
}
notificationEntity.setProfile(profile);
SourceEntity sourceEntity = sourceManager.retrieveSourceEntity();
if (sourceEntity != null) {
// Set source id
if (sourceEntity.getSourceProfile() != null) {
notificationEntity.setSourceId(sourceEntity.getSourceProfile().getId());
}
if (sourceEntity.getSourceClient() != null) {
notificationEntity.setClientSourceId(sourceEntity.getSourceClient().getId());
}
} else {
// If we can't find source id, set the user as the source
notificationEntity.setSourceId(orcid);
}
notificationDao.persist(notificationEntity);
return notificationAdapter.toNotification(notificationEntity);
}
use of org.orcid.persistence.jpa.entities.NotificationEntity in project ORCID-Source by ORCID.
the class NotificationManagerTest method testAmendEmail.
@Test
public void testAmendEmail() throws JAXBException, IOException, URISyntaxException {
SourceEntity sourceEntity = new SourceEntity(new ClientDetailsEntity("APP-5555555555555555"));
when(sourceManager.retrieveSourceEntity()).thenReturn(sourceEntity);
when(sourceManager.retrieveSourceOrcid()).thenReturn("APP-5555555555555555");
String testOrcid = "0000-0000-0000-0003";
for (Locale locale : Locale.values()) {
NotificationEntity previousNotification = notificationDao.findLatestByOrcid(testOrcid);
long minNotificationId = previousNotification != null ? previousNotification.getId() : -1;
profileEntityManager.updateLocale(testOrcid, locale);
notificationManager.sendAmendEmail(testOrcid, AmendedSection.UNKNOWN, Collections.emptyList());
// New notification entity should have been created
NotificationEntity latestNotification = notificationDao.findLatestByOrcid(testOrcid);
assertNotNull(latestNotification);
assertTrue(latestNotification.getId() > minNotificationId);
assertEquals(org.orcid.jaxb.model.notification_v2.NotificationType.AMENDED, latestNotification.getNotificationType());
}
}
use of org.orcid.persistence.jpa.entities.NotificationEntity 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