Search in sources :

Example 46 with NotificationPermission

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

the class NotificationsTest method createPermissionNotificationWithUnencodedSpaceInAuthorizationPath.

@Test
public void createPermissionNotificationWithUnencodedSpaceInAuthorizationPath() throws JSONException {
    NotificationPermission notification = unmarshallFromPath("/notification_2.0_rc4/samples/notification-permission-2.0_rc4.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_rc4.AuthorizationUrl) ClientResponse(com.sun.jersey.api.client.ClientResponse) NotificationPermission(org.orcid.jaxb.model.notification.permission_rc4.NotificationPermission) Test(org.junit.Test)

Example 47 with NotificationPermission

use of org.orcid.jaxb.model.notification.permission_rc2.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.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 48 with NotificationPermission

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

the class NotificationsTest method createNotificationInvalidWorkIDType.

@Test
public void createNotificationInvalidWorkIDType() throws JSONException {
    NotificationPermission notification = unmarshallFromPath("/notification_2.1/samples/notification-permission-2.1.xml");
    notification.setPutCode(null);
    notification.getItems().getItems().get(0).getExternalIdentifier().setType("invalid");
    String accessToken = oauthHelper.getClientCredentialsAccessToken(client1ClientId, client1ClientSecret, ScopePathType.PREMIUM_NOTIFICATION);
    ClientResponse response = notificationsClient_V2_1.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.notification.permission_v2.NotificationPermission) Test(org.junit.Test)

Example 49 with NotificationPermission

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

the class NotificationsTest method createPermissionNotificationWithTrailingSpaceInAuthorizationUrl.

@Test
public void createPermissionNotificationWithTrailingSpaceInAuthorizationUrl() throws JSONException {
    NotificationPermission notification = unmarshallFromPath("/notification_2.1/samples/notification-permission-2.1.xml");
    notification.setPutCode(null);
    AuthorizationUrl authUrl = notification.getAuthorizationUrl();
    authUrl.setUri(authUrl.getUri() + "    ");
    String accessToken = oauthHelper.getClientCredentialsAccessToken(client1ClientId, client1ClientSecret, ScopePathType.PREMIUM_NOTIFICATION);
    ClientResponse response = notificationsClient_V2_1.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_v2.AuthorizationUrl) ClientResponse(com.sun.jersey.api.client.ClientResponse) NotificationPermission(org.orcid.jaxb.model.notification.permission_v2.NotificationPermission) Test(org.junit.Test)

Example 50 with NotificationPermission

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

the class NotificationsTest method createPermissionNotification.

@Test
public void createPermissionNotification() throws JSONException {
    NotificationPermission notification = unmarshallFromPath("/notification_2.1/samples/notification-permission-2.1.xml");
    notification.setPutCode(null);
    String accessToken = oauthHelper.getClientCredentialsAccessToken(client1ClientId, client1ClientSecret, ScopePathType.PREMIUM_NOTIFICATION);
    ClientResponse response = notificationsClient_V2_1.addPermissionNotificationXml(testUser1OrcidId, notification, accessToken);
    assertNotNull(response);
    assertEquals(Response.Status.CREATED.getStatusCode(), response.getStatus());
    String locationPath = response.getLocation().getPath();
    assertTrue("Location header path should match pattern, but was " + locationPath, locationPath.matches(".*/v2.1/" + testUser1OrcidId + "/notification-permission/\\d+"));
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) NotificationPermission(org.orcid.jaxb.model.notification.permission_v2.NotificationPermission) Test(org.junit.Test)

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)11 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 Notification (org.orcid.jaxb.model.notification_v2.Notification)6 NotificationInstitutionalConnection (org.orcid.model.notification.institutional_sign_in_v2.NotificationInstitutionalConnection)5 NotificationAmended (org.orcid.jaxb.model.notification.amended_v2.NotificationAmended)4 AuthorizationUrl (org.orcid.jaxb.model.notification.permission_rc2.AuthorizationUrl)4 AuthorizationUrl (org.orcid.jaxb.model.notification.permission_rc3.AuthorizationUrl)4 AuthorizationUrl (org.orcid.jaxb.model.notification.permission_rc4.AuthorizationUrl)4 ArrayList (java.util.ArrayList)3 Source (org.orcid.jaxb.model.common_v2.Source)3 SourceClientId (org.orcid.jaxb.model.common_v2.SourceClientId)3