Search in sources :

Example 26 with Notification

use of org.oasis_open.docs.ws_tx.wsat._2006._06.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);
}
Also used : NotificationInstitutionalConnection(org.orcid.model.notification.institutional_sign_in_v2.NotificationInstitutionalConnection) Notification(org.orcid.jaxb.model.notification_v2.Notification)

Example 27 with Notification

use of org.oasis_open.docs.ws_tx.wsat._2006._06.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");
}
Also used : EmailMessage(org.orcid.core.manager.EmailMessage) EmailEntity(org.orcid.persistence.jpa.entities.EmailEntity) Date(java.util.Date) Notification(org.orcid.jaxb.model.notification_v2.Notification)

Example 28 with Notification

use of org.oasis_open.docs.ws_tx.wsat._2006._06.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());
}
Also used : Notification(org.orcid.jaxb.model.notification_v2.Notification) NotificationAmended(org.orcid.jaxb.model.notification.amended_v2.NotificationAmended) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Example 29 with Notification

use of org.oasis_open.docs.ws_tx.wsat._2006._06.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());
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) Arrays(java.util.Arrays) TargetProxyHelper(org.orcid.test.TargetProxyHelper) OrcidJUnit4ClassRunner(org.orcid.test.OrcidJUnit4ClassRunner) URISyntaxException(java.net.URISyntaxException) ProfileEventEntity(org.orcid.persistence.jpa.entities.ProfileEventEntity) NotificationPermissions(org.orcid.jaxb.model.notification.permission_v2.NotificationPermissions) NotificationPermission(org.orcid.jaxb.model.notification.permission_v2.NotificationPermission) RecordNameEntity(org.orcid.persistence.jpa.entities.RecordNameEntity) DBUnitTest(org.orcid.test.DBUnitTest) Assert.assertThat(org.junit.Assert.assertThat) MockitoAnnotations(org.mockito.MockitoAnnotations) AmendedSection(org.orcid.jaxb.model.notification.amended_v2.AmendedSection) ProfileDao(org.orcid.persistence.dao.ProfileDao) Source(org.orcid.jaxb.model.common_v2.Source) NotificationDao(org.orcid.persistence.dao.NotificationDao) After(org.junit.After) NotificationManagerImpl(org.orcid.core.manager.impl.NotificationManagerImpl) NotificationType(org.orcid.jaxb.model.notification_v2.NotificationType) AfterClass(org.junit.AfterClass) OrcidProfile(org.orcid.jaxb.model.message.OrcidProfile) Resource(javax.annotation.Resource) OrcidOauth2TokenDetailService(org.orcid.core.oauth.OrcidOauth2TokenDetailService) ClientDetailsEntity(org.orcid.persistence.jpa.entities.ClientDetailsEntity) Set(java.util.Set) Collectors(java.util.stream.Collectors) JAXBException(javax.xml.bind.JAXBException) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) NotificationEntity(org.orcid.persistence.jpa.entities.NotificationEntity) List(java.util.List) EmailEntity(org.orcid.persistence.jpa.entities.EmailEntity) NotificationDaoImpl(org.orcid.persistence.dao.impl.NotificationDaoImpl) GenericDao(org.orcid.persistence.dao.GenericDao) Mockito.mock(org.mockito.Mockito.mock) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) IntStream(java.util.stream.IntStream) Notification(org.orcid.jaxb.model.notification_v2.Notification) NotificationCustomEntity(org.orcid.persistence.jpa.entities.NotificationCustomEntity) CoreMatchers.anyOf(org.hamcrest.CoreMatchers.anyOf) BeforeClass(org.junit.BeforeClass) Matchers(org.mockito.Matchers) Mock(org.mockito.Mock) CoreMatchers.not(org.hamcrest.CoreMatchers.not) RunWith(org.junit.runner.RunWith) MailGunManager(org.orcid.core.manager.impl.MailGunManager) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) NotificationAmended(org.orcid.jaxb.model.notification.amended_v2.NotificationAmended) Answer(org.mockito.stubbing.Answer) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Locale(org.orcid.jaxb.model.common_v2.Locale) ArgumentMatchers.anyInt(org.mockito.ArgumentMatchers.anyInt) JAXBContext(javax.xml.bind.JAXBContext) IntFunction(java.util.function.IntFunction) Before(org.junit.Before) Unmarshaller(javax.xml.bind.Unmarshaller) SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) OrcidMessage(org.orcid.jaxb.model.message.OrcidMessage) Assert.assertNotNull(org.junit.Assert.assertNotNull) Assert.assertTrue(org.junit.Assert.assertTrue) ReflectionTestUtils(org.springframework.test.util.ReflectionTestUtils) Mockito.times(org.mockito.Mockito.times) IOException(java.io.IOException) Test(org.junit.Test) ClientDetailsDao(org.orcid.persistence.dao.ClientDetailsDao) Mockito.when(org.mockito.Mockito.when) JpaJaxbNotificationAdapterImpl(org.orcid.core.adapter.impl.JpaJaxbNotificationAdapterImpl) NotificationInstitutionalConnection(org.orcid.model.notification.institutional_sign_in_v2.NotificationInstitutionalConnection) OrcidApiConstants(org.orcid.core.api.OrcidApiConstants) Mockito.verify(org.mockito.Mockito.verify) NotificationCustom(org.orcid.jaxb.model.notification.custom_v2.NotificationCustom) Mockito(org.mockito.Mockito) Visibility(org.orcid.jaxb.model.common_v2.Visibility) Mockito.never(org.mockito.Mockito.never) JpaJaxbNotificationAdapter(org.orcid.core.adapter.JpaJaxbNotificationAdapter) ContextConfiguration(org.springframework.test.context.ContextConfiguration) SecurityQuestionEntity(org.orcid.persistence.jpa.entities.SecurityQuestionEntity) Email(org.orcid.jaxb.model.record_v2.Email) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Transactional(org.springframework.transaction.annotation.Transactional) NotificationDao(org.orcid.persistence.dao.NotificationDao) JpaJaxbNotificationAdapter(org.orcid.core.adapter.JpaJaxbNotificationAdapter) NotificationPermissions(org.orcid.jaxb.model.notification.permission_v2.NotificationPermissions) NotificationPermission(org.orcid.jaxb.model.notification.permission_v2.NotificationPermission) NotificationEntity(org.orcid.persistence.jpa.entities.NotificationEntity) Notification(org.orcid.jaxb.model.notification_v2.Notification) NotificationManagerImpl(org.orcid.core.manager.impl.NotificationManagerImpl) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Example 30 with Notification

use of org.oasis_open.docs.ws_tx.wsat._2006._06.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);
    }
}
Also used : HashMap(java.util.HashMap) OrcidNotificationException(org.orcid.core.exception.OrcidNotificationException) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) Notification(org.orcid.jaxb.model.notification_v2.Notification) AccessControl(org.orcid.core.security.visibility.aop.AccessControl)

Aggregations

Notification (org.oasis_open.docs.ws_tx.wsat._2006._06.Notification)28 Notification (org.orcid.jaxb.model.notification_v2.Notification)18 ArjunaContext (com.arjuna.webservices11.wsarj.ArjunaContext)15 MAP (org.jboss.ws.api.addressing.MAP)15 MessageContext (javax.xml.ws.handler.MessageContext)13 Task (com.arjuna.services.framework.task.Task)11 Action (javax.xml.ws.Action)11 MAPEndpoint (org.jboss.ws.api.addressing.MAPEndpoint)11 HashMap (java.util.HashMap)8 Test (org.junit.Test)8 AccessControl (org.orcid.core.security.visibility.aop.AccessControl)6 NotificationAmended (org.orcid.jaxb.model.notification.amended_v2.NotificationAmended)5 NotificationPermission (org.orcid.jaxb.model.notification.permission_v2.NotificationPermission)5 NotificationInstitutionalConnection (org.orcid.model.notification.institutional_sign_in_v2.NotificationInstitutionalConnection)5 ArrayList (java.util.ArrayList)4 NotificationCustom (org.orcid.jaxb.model.notification.custom_v2.NotificationCustom)4 ProfileEntity (org.orcid.persistence.jpa.entities.ProfileEntity)4 DBUnitTest (org.orcid.test.DBUnitTest)4 URISyntaxException (java.net.URISyntaxException)3 HashSet (java.util.HashSet)3