Search in sources :

Example 11 with Notification

use of org.orcid.jaxb.model.notification_v2.Notification in project ORCID-Source by ORCID.

the class NotificationManagerTest method filterActionedNotificationAlertsTest.

@Test
public void filterActionedNotificationAlertsTest() {
    TargetProxyHelper.injectIntoProxy(notificationManager, "notificationDao", mockNotificationDao);
    when(mockNotificationDao.findByOricdAndId(Matchers.anyString(), Matchers.anyLong())).thenReturn(null);
    List<Notification> notifications = IntStream.range(0, 10).mapToObj(new IntFunction<Notification>() {

        @Override
        public Notification apply(int value) {
            if (value % 3 == 0) {
                NotificationInstitutionalConnection n = new NotificationInstitutionalConnection();
                n.setSource(new Source("0000-0000-0000-0000"));
                n.setPutCode(Long.valueOf(value));
                return n;
            } else {
                NotificationPermission n = new NotificationPermission();
                n.setPutCode(Long.valueOf(value));
                return n;
            }
        }
    }).collect(Collectors.toList());
    assertEquals(10, notifications.size());
    notifications = notificationManager.filterActionedNotificationAlerts(notifications, "some-orcid");
    assertEquals(6, notifications.size());
    for (Notification n : notifications) {
        assertEquals(NotificationType.PERMISSION, n.getNotificationType());
        assertNotNull(n.getPutCode());
        assertThat(n.getPutCode(), not(anyOf(is(Long.valueOf(0)), is(Long.valueOf(3)), is(Long.valueOf(6)), is(Long.valueOf(9)))));
    }
}
Also used : NotificationInstitutionalConnection(org.orcid.model.notification.institutional_sign_in_v2.NotificationInstitutionalConnection) IntFunction(java.util.function.IntFunction) NotificationPermission(org.orcid.jaxb.model.notification.permission_v2.NotificationPermission) Source(org.orcid.jaxb.model.common_v2.Source) Notification(org.orcid.jaxb.model.notification_v2.Notification) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Example 12 with Notification

use of org.orcid.jaxb.model.notification_v2.Notification in project ORCID-Source by ORCID.

the class NotificationManagerTest method testCreateCustomNotification.

@Test
public void testCreateCustomNotification() {
    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";
    NotificationCustom notification = new NotificationCustom();
    notification.setSubject("Test subject");
    notification.setLang("en-gb");
    Notification result = notificationManager.createNotification(testOrcid, notification);
    assertNotNull(result);
    assertTrue(result instanceof NotificationCustom);
    NotificationCustom customResult = (NotificationCustom) result;
    assertEquals("Test subject", customResult.getSubject());
    assertEquals("en-gb", customResult.getLang());
}
Also used : NotificationCustom(org.orcid.jaxb.model.notification.custom_v2.NotificationCustom) ClientDetailsEntity(org.orcid.persistence.jpa.entities.ClientDetailsEntity) SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Notification(org.orcid.jaxb.model.notification_v2.Notification) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Example 13 with Notification

use of org.orcid.jaxb.model.notification_v2.Notification in project ORCID-Source by ORCID.

the class JpaJaxbNotificationAdapterTest method testCustomEntityToNotification.

@Test
public void testCustomEntityToNotification() {
    NotificationCustomEntity notificationEntity = new NotificationCustomEntity();
    notificationEntity.setId(123L);
    notificationEntity.setNotificationType(NotificationType.CUSTOM);
    notificationEntity.setSubject("Test subject");
    notificationEntity.setDateCreated(DateUtils.convertToDate("2014-01-01T09:17:56"));
    notificationEntity.setReadDate(DateUtils.convertToDate("2014-03-04T17:43:06"));
    Notification notification = jpaJaxbNotificationAdapter.toNotification(notificationEntity);
    assertNotNull(notification);
    assertTrue(notification instanceof NotificationCustom);
    NotificationCustom notificationCustom = (NotificationCustom) notification;
    assertEquals(NotificationType.CUSTOM, notification.getNotificationType());
    assertEquals("Test subject", notificationCustom.getSubject());
    assertEquals("2014-01-01T09:17:56.000Z", notification.getCreatedDate().toXMLFormat());
    assertEquals("2014-03-04T17:43:06.000Z", notification.getReadDate().toXMLFormat());
}
Also used : NotificationCustom(org.orcid.jaxb.model.notification.custom_v2.NotificationCustom) NotificationCustomEntity(org.orcid.persistence.jpa.entities.NotificationCustomEntity) Notification(org.orcid.jaxb.model.notification_v2.Notification) Test(org.junit.Test)

Example 14 with Notification

use of org.orcid.jaxb.model.notification_v2.Notification in project ORCID-Source by ORCID.

the class NotificationController method addSubjectToNotifications.

private void addSubjectToNotifications(List<Notification> notifications) {
    for (Notification notification : notifications) {
        if (notification instanceof NotificationPermission) {
            NotificationPermission naa = (NotificationPermission) notification;
            String customSubject = naa.getNotificationSubject();
            if (StringUtils.isNotBlank(customSubject)) {
                naa.setSubject(customSubject);
            } else {
                naa.setSubject(getMessage(buildInternationalizationKey(NotificationType.class, naa.getNotificationType().value())));
            }
        } else if (notification instanceof NotificationAmended) {
            NotificationAmended na = (NotificationAmended) notification;
            na.setSubject(getMessage(buildInternationalizationKey(NotificationType.class, na.getNotificationType().value())));
        } else if (notification instanceof NotificationInstitutionalConnection) {
            NotificationInstitutionalConnection nic = (NotificationInstitutionalConnection) notification;
            nic.setSubject(getMessage(buildInternationalizationKey(NotificationType.class, nic.getNotificationType().value())));
        }
    }
}
Also used : NotificationInstitutionalConnection(org.orcid.model.notification.institutional_sign_in_v2.NotificationInstitutionalConnection) NotificationType(org.orcid.jaxb.model.notification_v2.NotificationType) NotificationPermission(org.orcid.jaxb.model.notification.permission_v2.NotificationPermission) Notification(org.orcid.jaxb.model.notification_v2.Notification) NotificationAmended(org.orcid.jaxb.model.notification.amended_v2.NotificationAmended)

Example 15 with Notification

use of org.orcid.jaxb.model.notification_v2.Notification in project ORCID-Source by ORCID.

the class NotificationController method getAmendedNotificationHtml.

@RequestMapping(value = "/AMENDED/{id}/notification.html", produces = OrcidApiConstants.HTML_UTF)
public ModelAndView getAmendedNotificationHtml(@PathVariable("id") String id) {
    ModelAndView mav = new ModelAndView();
    Notification notification = notificationManager.findByOrcidAndId(getCurrentUserOrcid(), Long.valueOf(id));
    addSourceDescription(notification);
    mav.addObject("notification", notification);
    mav.addObject("emailName", notificationManager.deriveEmailFriendlyName(getEffectiveProfile()));
    mav.setViewName("notification/amended_notification");
    mav.addObject("noIndex", true);
    return mav;
}
Also used : ModelAndView(org.springframework.web.servlet.ModelAndView) Notification(org.orcid.jaxb.model.notification_v2.Notification) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

Notification (org.orcid.jaxb.model.notification_v2.Notification)18 NotificationPermission (org.orcid.jaxb.model.notification.permission_v2.NotificationPermission)6 Test (org.junit.Test)5 NotificationCustom (org.orcid.jaxb.model.notification.custom_v2.NotificationCustom)5 NotificationInstitutionalConnection (org.orcid.model.notification.institutional_sign_in_v2.NotificationInstitutionalConnection)5 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 AccessControl (org.orcid.core.security.visibility.aop.AccessControl)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 URISyntaxException (java.net.URISyntaxException)2 HashSet (java.util.HashSet)2 List (java.util.List)2 IntFunction (java.util.function.IntFunction)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 OrcidNotificationNotFoundException (org.orcid.core.exception.OrcidNotificationNotFoundException)2 Source (org.orcid.jaxb.model.common_v2.Source)2 SourceClientId (org.orcid.jaxb.model.common_v2.SourceClientId)2 NotificationAmended (org.orcid.jaxb.model.notification.amended_v2.NotificationAmended)2 NotificationType (org.orcid.jaxb.model.notification_v2.NotificationType)2 ClientDetailsEntity (org.orcid.persistence.jpa.entities.ClientDetailsEntity)2