use of org.orcid.jaxb.model.notification.permission_v2.AuthorizationUrl 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());
}
use of org.orcid.jaxb.model.notification.permission_v2.AuthorizationUrl 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"));
}
use of org.orcid.jaxb.model.notification.permission_v2.AuthorizationUrl 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());
}
use of org.orcid.jaxb.model.notification.permission_v2.AuthorizationUrl in project ORCID-Source by ORCID.
the class NotificationsTest method createPermissionNotificationWithTrailingSpaceInAuthorizationUrl.
@Test
public void createPermissionNotificationWithTrailingSpaceInAuthorizationUrl() 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(authUrl.getUri() + " ");
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());
}
use of org.orcid.jaxb.model.notification.permission_v2.AuthorizationUrl in project ORCID-Source by ORCID.
the class JpaJaxbNotificationAdapterTest method testToNotificationPermissionEntity.
@Test
public void testToNotificationPermissionEntity() {
NotificationPermission notification = new NotificationPermission();
notification.setNotificationType(NotificationType.PERMISSION);
String authorizationUrlString = "https://orcid.org/oauth/authorize?client_id=APP-U4UKCNSSIM1OCVQY&response_type=code&scope=/orcid-works/create&redirect_uri=http://somethirdparty.com";
AuthorizationUrl url = new AuthorizationUrl();
notification.setAuthorizationUrl(url);
notification.setNotificationIntro("This is the intro");
notification.setNotificationSubject("This is the subject");
Source source = new Source();
notification.setSource(source);
SourceClientId clientId = new SourceClientId();
source.setSourceClientId(clientId);
clientId.setPath("APP-5555-5555-5555-5555");
url.setUri(authorizationUrlString);
Items activities = new Items();
notification.setItems(activities);
Item activity = new Item();
activities.getItems().add(activity);
activity.setItemType(ItemType.WORK);
activity.setItemName("Latest Research Article");
ExternalID extId = new ExternalID();
activity.setExternalIdentifier(extId);
extId.setType("doi");
extId.setValue("1234/abc123");
NotificationEntity notificationEntity = jpaJaxbNotificationAdapter.toNotificationEntity(notification);
assertTrue(notificationEntity instanceof NotificationAddItemsEntity);
NotificationAddItemsEntity addActivitiesEntity = (NotificationAddItemsEntity) notificationEntity;
assertNotNull(notificationEntity);
assertEquals(NotificationType.PERMISSION, notificationEntity.getNotificationType());
assertEquals(authorizationUrlString, addActivitiesEntity.getAuthorizationUrl());
assertEquals(notification.getNotificationIntro(), notificationEntity.getNotificationIntro());
assertEquals(notification.getNotificationSubject(), notificationEntity.getNotificationSubject());
// Source
assertNull(notificationEntity.getSourceId());
assertNull(notificationEntity.getClientSourceId());
assertNull(notificationEntity.getElementSourceId());
Set<NotificationItemEntity> activityEntities = addActivitiesEntity.getNotificationItems();
assertNotNull(activityEntities);
assertEquals(1, activityEntities.size());
NotificationItemEntity activityEntity = activityEntities.iterator().next();
assertEquals(ItemType.WORK, activityEntity.getItemType());
assertEquals("Latest Research Article", activityEntity.getItemName());
assertEquals("DOI", activityEntity.getExternalIdType());
assertEquals("1234/abc123", activityEntity.getExternalIdValue());
}
Aggregations