Search in sources :

Example 11 with NotificationPermission

use of org.orcid.jaxb.model.v3.dev1.notification.permission.NotificationPermission in project ORCID-Source by ORCID.

the class NotificationValidationManagerImpl method validateNotificationPermission.

@Override
public void validateNotificationPermission(NotificationPermission notification) {
    AuthorizationUrl authorizationUrl = notification.getAuthorizationUrl();
    String uriString = authorizationUrl.getUri();
    if (StringUtils.isNotBlank(uriString)) {
        try {
            new URI(uriString);
        } catch (URISyntaxException e) {
            throw new OrcidValidationException("Bad authorization uri", e);
        }
    }
    externalIDValidator.validateNotificationItems(notification.getItems());
}
Also used : AuthorizationUrl(org.orcid.jaxb.model.v3.dev1.notification.permission.AuthorizationUrl) OrcidValidationException(org.orcid.core.exception.OrcidValidationException) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI)

Example 12 with NotificationPermission

use of org.orcid.jaxb.model.v3.dev1.notification.permission.NotificationPermission 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.v3.dev1.notification.Notification) AccessControl(org.orcid.core.security.visibility.aop.AccessControl)

Example 13 with NotificationPermission

use of org.orcid.jaxb.model.v3.dev1.notification.permission.NotificationPermission 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.v3.dev1.notification.institutional_sign_in.NotificationInstitutionalConnection) NotificationType(org.orcid.jaxb.model.v3.dev1.notification.NotificationType) NotificationPermission(org.orcid.jaxb.model.v3.dev1.notification.permission.NotificationPermission) Notification(org.orcid.jaxb.model.v3.dev1.notification.Notification) NotificationAmended(org.orcid.jaxb.model.v3.dev1.notification.amended.NotificationAmended)

Example 14 with NotificationPermission

use of org.orcid.jaxb.model.v3.dev1.notification.permission.NotificationPermission 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) Notification(org.orcid.jaxb.model.v3.dev1.notification.Notification) Arrays(java.util.Arrays) Locale(org.orcid.jaxb.model.v3.dev1.common.Locale) TargetProxyHelper(org.orcid.test.TargetProxyHelper) Date(java.util.Date) OrcidJUnit4ClassRunner(org.orcid.test.OrcidJUnit4ClassRunner) URISyntaxException(java.net.URISyntaxException) ProfileEventEntity(org.orcid.persistence.jpa.entities.ProfileEventEntity) RecordNameEntity(org.orcid.persistence.jpa.entities.RecordNameEntity) DBUnitTest(org.orcid.test.DBUnitTest) Assert.assertThat(org.junit.Assert.assertThat) NotificationType(org.orcid.jaxb.model.v3.dev1.notification.NotificationType) MockitoAnnotations(org.mockito.MockitoAnnotations) Pair(org.apache.commons.lang3.tuple.Pair) ProfileDao(org.orcid.persistence.dao.ProfileDao) NotificationDao(org.orcid.persistence.dao.NotificationDao) After(org.junit.After) ProfileEntityCacheManager(org.orcid.core.manager.ProfileEntityCacheManager) NotificationInstitutionalConnection(org.orcid.model.v3.dev1.notification.institutional_sign_in.NotificationInstitutionalConnection) AfterClass(org.junit.AfterClass) OrcidProfile(org.orcid.jaxb.model.message.OrcidProfile) Resource(javax.annotation.Resource) EncryptionManager(org.orcid.core.manager.EncryptionManager) 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) Email(org.orcid.jaxb.model.v3.dev1.record.Email) EmailEntity(org.orcid.persistence.jpa.entities.EmailEntity) Source(org.orcid.jaxb.model.v3.dev1.common.Source) JpaJaxbNotificationAdapterImpl(org.orcid.core.adapter.v3.impl.JpaJaxbNotificationAdapterImpl) NotificationDaoImpl(org.orcid.persistence.dao.impl.NotificationDaoImpl) GenericDao(org.orcid.persistence.dao.GenericDao) NotificationManagerImpl(org.orcid.core.manager.v3.impl.NotificationManagerImpl) Mockito.mock(org.mockito.Mockito.mock) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) IntStream(java.util.stream.IntStream) NotificationCustomEntity(org.orcid.persistence.jpa.entities.NotificationCustomEntity) CoreMatchers.anyOf(org.hamcrest.CoreMatchers.anyOf) BeforeClass(org.junit.BeforeClass) NotificationPermissions(org.orcid.jaxb.model.v3.dev1.notification.permission.NotificationPermissions) Matchers(org.mockito.Matchers) Mock(org.mockito.Mock) CoreMatchers.not(org.hamcrest.CoreMatchers.not) RunWith(org.junit.runner.RunWith) ArrayUtils(org.apache.commons.lang3.ArrayUtils) NotificationPermission(org.orcid.jaxb.model.v3.dev1.notification.permission.NotificationPermission) MailGunManager(org.orcid.core.manager.impl.MailGunManager) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Answer(org.mockito.stubbing.Answer) InvocationOnMock(org.mockito.invocation.InvocationOnMock) NotificationCustom(org.orcid.jaxb.model.v3.dev1.notification.custom.NotificationCustom) EmailEventEntity(org.orcid.persistence.jpa.entities.EmailEventEntity) 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) CollectionUtils(org.springframework.cglib.core.CollectionUtils) OrcidMessage(org.orcid.jaxb.model.message.OrcidMessage) Assert.assertNotNull(org.junit.Assert.assertNotNull) AmendedSection(org.orcid.jaxb.model.v3.dev1.notification.amended.AmendedSection) 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) LocalDateTime(org.joda.time.LocalDateTime) OrcidApiConstants(org.orcid.core.api.OrcidApiConstants) Mockito.verify(org.mockito.Mockito.verify) Mockito(org.mockito.Mockito) Mockito.never(org.mockito.Mockito.never) EmailEventType(org.orcid.persistence.jpa.entities.EmailEventType) ContextConfiguration(org.springframework.test.context.ContextConfiguration) SecurityQuestionEntity(org.orcid.persistence.jpa.entities.SecurityQuestionEntity) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) JpaJaxbNotificationAdapter(org.orcid.core.adapter.v3.JpaJaxbNotificationAdapter) Transactional(org.springframework.transaction.annotation.Transactional) NotificationDao(org.orcid.persistence.dao.NotificationDao) JpaJaxbNotificationAdapter(org.orcid.core.adapter.v3.JpaJaxbNotificationAdapter) NotificationPermissions(org.orcid.jaxb.model.v3.dev1.notification.permission.NotificationPermissions) NotificationPermission(org.orcid.jaxb.model.v3.dev1.notification.permission.NotificationPermission) NotificationEntity(org.orcid.persistence.jpa.entities.NotificationEntity) Notification(org.orcid.jaxb.model.v3.dev1.notification.Notification) NotificationManagerImpl(org.orcid.core.manager.v3.impl.NotificationManagerImpl) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Example 15 with NotificationPermission

use of org.orcid.jaxb.model.v3.dev1.notification.permission.NotificationPermission in project ORCID-Source by ORCID.

the class NotificationsTest method createNotificationInvalidWorkIDType.

@Test
public void createNotificationInvalidWorkIDType() throws JSONException {
    NotificationPermission notification = unmarshallFromPath("/notification_3.0_dev1/samples/notification-permission-3.0_dev1.xml");
    notification.setPutCode(null);
    notification.getItems().getItems().get(0).getExternalIdentifier().setType("invalid");
    String accessToken = oauthHelper.getClientCredentialsAccessToken(client1ClientId, client1ClientSecret, ScopePathType.PREMIUM_NOTIFICATION);
    ClientResponse response = notificationsClient_V3_0_dev1.addPermissionNotificationXml(testUser1OrcidId, notification, accessToken);
    assertNotNull(response);
    assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatus());
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) NotificationPermission(org.orcid.jaxb.model.v3.dev1.notification.permission.NotificationPermission) Test(org.junit.Test)

Aggregations

NotificationPermission (org.orcid.jaxb.model.v3.dev1.notification.permission.NotificationPermission)14 Test (org.junit.Test)10 ClientResponse (com.sun.jersey.api.client.ClientResponse)7 AuthorizationUrl (org.orcid.jaxb.model.v3.dev1.notification.permission.AuthorizationUrl)7 Notification (org.orcid.jaxb.model.v3.dev1.notification.Notification)5 NotificationInstitutionalConnection (org.orcid.model.v3.dev1.notification.institutional_sign_in.NotificationInstitutionalConnection)4 URISyntaxException (java.net.URISyntaxException)3 URI (java.net.URI)2 ArrayList (java.util.ArrayList)2 IntFunction (java.util.function.IntFunction)2 JAXBContext (javax.xml.bind.JAXBContext)2 JAXBException (javax.xml.bind.JAXBException)2 Unmarshaller (javax.xml.bind.Unmarshaller)2 Source (org.orcid.jaxb.model.v3.dev1.common.Source)2 NotificationType (org.orcid.jaxb.model.v3.dev1.notification.NotificationType)2 Item (org.orcid.jaxb.model.v3.dev1.notification.permission.Item)2 NotificationAddItemsEntity (org.orcid.persistence.jpa.entities.NotificationAddItemsEntity)2 ProfileEntity (org.orcid.persistence.jpa.entities.ProfileEntity)2 IOException (java.io.IOException)1 Arrays (java.util.Arrays)1