Search in sources :

Example 1 with NotificationPermission

use of org.orcid.jaxb.model.notification.permission_v2.NotificationPermission in project ORCID-Source by ORCID.

the class NotificationManagerImpl method findPermissionsByOrcidAndClient.

@Override
@Transactional(readOnly = true)
public NotificationPermissions findPermissionsByOrcidAndClient(String orcid, String client, int firstResult, int maxResults) {
    NotificationPermissions notifications = new NotificationPermissions();
    List<Notification> notificationsForOrcidAndClient = notificationAdapter.toNotification(notificationDao.findPermissionsByOrcidAndClient(orcid, client, firstResult, maxResults));
    List<NotificationPermission> notificationPermissions = new ArrayList<>();
    notificationsForOrcidAndClient.forEach(n -> notificationPermissions.add((NotificationPermission) n));
    notifications.setNotifications(notificationPermissions);
    return notifications;
}
Also used : NotificationPermissions(org.orcid.jaxb.model.notification.permission_v2.NotificationPermissions) ArrayList(java.util.ArrayList) NotificationPermission(org.orcid.jaxb.model.notification.permission_v2.NotificationPermission) Notification(org.orcid.jaxb.model.notification_v2.Notification) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with NotificationPermission

use of org.orcid.jaxb.model.notification.permission_v2.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.notification.permission_v2.AuthorizationUrl) OrcidValidationException(org.orcid.core.exception.OrcidValidationException) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI)

Example 3 with NotificationPermission

use of org.orcid.jaxb.model.notification.permission_v2.NotificationPermission in project ORCID-Source by ORCID.

the class NotificationsTest method createPermissionNotificationWithBlankAuthorizationUri.

@Test
public void createPermissionNotificationWithBlankAuthorizationUri() throws JSONException {
    NotificationPermission notification = unmarshallFromPath("/notification_2.0_rc3/samples/notification-permission-2.0_rc3.xml");
    notification.setPutCode(null);
    AuthorizationUrl authUrl = notification.getAuthorizationUrl();
    authUrl.setUri("");
    String accessToken = oauthHelper.getClientCredentialsAccessToken(client1ClientId, client1ClientSecret, ScopePathType.PREMIUM_NOTIFICATION);
    ClientResponse postResponse = notificationsClient.addPermissionNotificationXml(testUser1OrcidId, notification, accessToken);
    assertNotNull(postResponse);
    assertEquals(Response.Status.CREATED.getStatusCode(), postResponse.getStatus());
    String locationPath = postResponse.getLocation().getPath();
    assertTrue("Location header path should match pattern, but was " + locationPath, locationPath.matches(".*/v2.0_rc3/" + testUser1OrcidId + "/notification-permission/\\d+"));
    String putCodeString = locationPath.substring(locationPath.lastIndexOf('/') + 1);
    Long putCode = Long.valueOf(putCodeString);
    ClientResponse viewResponse = notificationsClient.viewPermissionNotificationXml(testUser1OrcidId, putCode, accessToken);
    assertEquals(Response.Status.OK.getStatusCode(), viewResponse.getStatus());
    NotificationPermission retrievedNotification = viewResponse.getEntity(NotificationPermission.class);
    assertNotNull(retrievedNotification);
    assertTrue(retrievedNotification.getAuthorizationUrl().getPath().endsWith(authUrl.getPath()));
    assertFalse(retrievedNotification.getAuthorizationUrl().getPath().startsWith("http"));
    assertTrue(retrievedNotification.getAuthorizationUrl().getUri().startsWith("http"));
}
Also used : AuthorizationUrl(org.orcid.jaxb.model.notification.permission_rc3.AuthorizationUrl) ClientResponse(com.sun.jersey.api.client.ClientResponse) NotificationPermission(org.orcid.jaxb.model.notification.permission_rc3.NotificationPermission) Test(org.junit.Test)

Example 4 with NotificationPermission

use of org.orcid.jaxb.model.notification.permission_v2.NotificationPermission in project ORCID-Source by ORCID.

the class NotificationsTest method createPermissionNotificationWithUnencodedSpaceInAuthorizationPath.

@Test
public void createPermissionNotificationWithUnencodedSpaceInAuthorizationPath() throws JSONException {
    NotificationPermission notification = unmarshallFromPath("/notification_2.0_rc3/samples/notification-permission-2.0_rc3.xml");
    notification.setPutCode(null);
    AuthorizationUrl authUrl = notification.getAuthorizationUrl();
    authUrl.setUri(null);
    authUrl.setPath("/oauth/authorize?client_id=0000-0003-4223-0632&response_type=code&scope=/read-limited /activities/update&redirect_uri=https://developers.google.com/oauthplayground");
    String accessToken = oauthHelper.getClientCredentialsAccessToken(client1ClientId, client1ClientSecret, ScopePathType.PREMIUM_NOTIFICATION);
    ClientResponse response = notificationsClient.addPermissionNotificationXml(testUser1OrcidId, notification, accessToken);
    assertNotNull(response);
    assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatus());
    assertNull(response.getLocation());
}
Also used : AuthorizationUrl(org.orcid.jaxb.model.notification.permission_rc3.AuthorizationUrl) ClientResponse(com.sun.jersey.api.client.ClientResponse) NotificationPermission(org.orcid.jaxb.model.notification.permission_rc3.NotificationPermission) Test(org.junit.Test)

Example 5 with NotificationPermission

use of org.orcid.jaxb.model.notification.permission_v2.NotificationPermission in project ORCID-Source by ORCID.

the class NotificationsTest method unmarshall.

public NotificationPermission unmarshall(Reader reader) {
    try {
        JAXBContext context = JAXBContext.newInstance(NotificationPermission.class.getPackage().getName());
        Unmarshaller unmarshaller = context.createUnmarshaller();
        return (NotificationPermission) unmarshaller.unmarshal(reader);
    } catch (JAXBException e) {
        throw new RuntimeException("Unable to unmarshall orcid message" + e);
    }
}
Also used : JAXBException(javax.xml.bind.JAXBException) JAXBContext(javax.xml.bind.JAXBContext) NotificationPermission(org.orcid.jaxb.model.notification.permission_rc3.NotificationPermission) Unmarshaller(javax.xml.bind.Unmarshaller)

Aggregations

Test (org.junit.Test)45 ClientResponse (com.sun.jersey.api.client.ClientResponse)41 NotificationPermission (org.orcid.jaxb.model.notification.permission_v2.NotificationPermission)24 AuthorizationUrl (org.orcid.jaxb.model.notification.permission_v2.AuthorizationUrl)12 NotificationPermission (org.orcid.jaxb.model.notification.permission_rc2.NotificationPermission)8 NotificationPermission (org.orcid.jaxb.model.notification.permission_rc3.NotificationPermission)8 NotificationPermission (org.orcid.jaxb.model.notification.permission_rc4.NotificationPermission)8 JAXBContext (javax.xml.bind.JAXBContext)7 JAXBException (javax.xml.bind.JAXBException)7 Unmarshaller (javax.xml.bind.Unmarshaller)7 NotificationPermission (org.orcid.jaxb.model.notification.permission_rc1.NotificationPermission)7 NotificationAmended (org.orcid.jaxb.model.notification.amended_v2.NotificationAmended)5 Notification (org.orcid.jaxb.model.notification_v2.Notification)5 NotificationInstitutionalConnection (org.orcid.model.notification.institutional_sign_in_v2.NotificationInstitutionalConnection)5 SourceClientId (org.orcid.jaxb.model.common_v2.SourceClientId)4 AuthorizationUrl (org.orcid.jaxb.model.notification.permission_rc3.AuthorizationUrl)4 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 Source (org.orcid.jaxb.model.common_v2.Source)3 AuthorizationUrl (org.orcid.jaxb.model.notification.permission_rc1.AuthorizationUrl)3