use of org.orcid.jaxb.model.notification.permission_rc3.NotificationPermission in project ORCID-Source by ORCID.
the class NotificationsTest method createPermissionNotificationWithAbsentAuthorizationUriElement.
@Test
public void createPermissionNotificationWithAbsentAuthorizationUriElement() 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("");
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_rc4/" + 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_rc3.NotificationPermission in project ORCID-Source by ORCID.
the class NotificationsTest method createNotificationInvalidWorkIDType.
@Test
public void createNotificationInvalidWorkIDType() throws JSONException {
NotificationPermission notification = unmarshallFromPath("/notification_2.0_rc4/samples/notification-permission-2.0_rc4.xml");
notification.setPutCode(null);
notification.getItems().getItems().get(0).getExternalIdentifier().setType("invalid");
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());
}
use of org.orcid.jaxb.model.notification.permission_rc3.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());
}
use of org.orcid.jaxb.model.notification.permission_rc3.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());
}
use of org.orcid.jaxb.model.notification.permission_rc3.NotificationPermission in project ORCID-Source by ORCID.
the class MapperFacadeFactory method getObject.
@Override
public MapperFacade getObject() throws Exception {
MapperFactory mapperFactory = getNewMapperFactory();
// Register converters
ConverterFactory converterFactory = mapperFactory.getConverterFactory();
converterFactory.registerConverter("externalIdentifierIdConverter", new ExternalIdentifierTypeConverter());
// Register factories
mapperFactory.registerObjectFactory(new WorkEntityFactory(workDao), TypeFactory.<NotificationWorkEntity>valueOf(NotificationWorkEntity.class), TypeFactory.<Item>valueOf(Item.class));
// Custom notification
ClassMapBuilder<NotificationCustom, NotificationCustomEntity> notificationCustomClassMap = mapperFactory.classMap(NotificationCustom.class, NotificationCustomEntity.class);
registerSourceConverters(mapperFactory, notificationCustomClassMap);
mapCommonFields(notificationCustomClassMap).register();
// Permission notification
ClassMapBuilder<NotificationPermission, NotificationAddItemsEntity> notificationPermissionClassMap = mapperFactory.classMap(NotificationPermission.class, NotificationAddItemsEntity.class);
registerSourceConverters(mapperFactory, notificationPermissionClassMap);
mapCommonFields(notificationPermissionClassMap.field("authorizationUrl.uri", "authorizationUrl").field("items.items", "notificationItems").customize(new CustomMapper<NotificationPermission, NotificationAddItemsEntity>() {
@Override
public void mapAtoB(NotificationPermission notification, NotificationAddItemsEntity entity, MappingContext context) {
if (StringUtils.isBlank(entity.getAuthorizationUrl())) {
String authUrl = orcidUrlManager.getBaseUrl() + notification.getAuthorizationUrl().getPath();
// validate
validateAndConvertToURI(authUrl);
entity.setAuthorizationUrl(authUrl);
}
}
@Override
public void mapBtoA(NotificationAddItemsEntity entity, NotificationPermission notification, MappingContext context) {
AuthorizationUrl authUrl = notification.getAuthorizationUrl();
if (authUrl != null) {
authUrl.setPath(extractFullPath(authUrl.getUri()));
authUrl.setHost(orcidUrlManager.getBaseHost());
}
}
})).register();
// Institutional sign in notification
ClassMapBuilder<NotificationInstitutionalConnection, NotificationInstitutionalConnectionEntity> institutionalConnectionNotificationClassMap = mapperFactory.classMap(NotificationInstitutionalConnection.class, NotificationInstitutionalConnectionEntity.class);
registerSourceConverters(mapperFactory, institutionalConnectionNotificationClassMap);
mapCommonFields(institutionalConnectionNotificationClassMap.field("authorizationUrl.uri", "authorizationUrl").customize(new CustomMapper<NotificationInstitutionalConnection, NotificationInstitutionalConnectionEntity>() {
@Override
public void mapAtoB(NotificationInstitutionalConnection notification, NotificationInstitutionalConnectionEntity entity, MappingContext context) {
if (StringUtils.isBlank(entity.getAuthorizationUrl())) {
String authUrl = orcidUrlManager.getBaseUrl() + notification.getAuthorizationUrl().getPath();
// validate
validateAndConvertToURI(authUrl);
entity.setAuthorizationUrl(authUrl);
}
}
@Override
public void mapBtoA(NotificationInstitutionalConnectionEntity entity, NotificationInstitutionalConnection notification, MappingContext context) {
AuthorizationUrl authUrl = notification.getAuthorizationUrl();
if (authUrl != null) {
authUrl.setPath(extractFullPath(authUrl.getUri()));
authUrl.setHost(orcidUrlManager.getBaseHost());
}
String providerId = entity.getAuthenticationProviderId();
if (StringUtils.isNotBlank(providerId)) {
String idpName = identityProviderManager.retrieveIdentitifyProviderName(providerId);
notification.setIdpName(idpName);
} else {
notification.setIdpName(LAST_RESORT_IDENTITY_PROVIDER_NAME);
}
}
})).register();
// Amend notification
ClassMapBuilder<NotificationAmended, NotificationAmendedEntity> amendNotificationClassMap = mapperFactory.classMap(NotificationAmended.class, NotificationAmendedEntity.class);
registerSourceConverters(mapperFactory, amendNotificationClassMap);
mapCommonFields(amendNotificationClassMap.exclude("amendedSection").customize(new CustomMapper<NotificationAmended, NotificationAmendedEntity>() {
@Override
public void mapAtoB(NotificationAmended a, NotificationAmendedEntity b, MappingContext context) {
if (a.getAmendedSection() != null) {
switch(a.getAmendedSection()) {
case AFFILIATION:
b.setAmendedSection(AmendedSection.AFFILIATION);
break;
case BIO:
b.setAmendedSection(AmendedSection.BIO);
break;
case EDUCATION:
b.setAmendedSection(AmendedSection.EDUCATION);
break;
case EMPLOYMENT:
b.setAmendedSection(AmendedSection.EMPLOYMENT);
break;
case EXTERNAL_IDENTIFIERS:
b.setAmendedSection(AmendedSection.EXTERNAL_IDENTIFIERS);
break;
case FUNDING:
b.setAmendedSection(AmendedSection.FUNDING);
break;
case PEER_REVIEW:
b.setAmendedSection(AmendedSection.PEER_REVIEW);
break;
case PREFERENCES:
b.setAmendedSection(AmendedSection.PREFERENCES);
break;
case UNKNOWN:
b.setAmendedSection(AmendedSection.UNKNOWN);
break;
case WORK:
b.setAmendedSection(AmendedSection.WORK);
break;
default:
b.setAmendedSection(AmendedSection.UNKNOWN);
break;
}
}
}
/**
* From database to model object, map amended sections for new affiliation types as AFFILIATION
*/
@Override
public void mapBtoA(NotificationAmendedEntity b, NotificationAmended a, MappingContext context) {
if (b.getAmendedSection() != null) {
switch(b.getAmendedSection()) {
case AFFILIATION:
case DISTINCTION:
case INVITED_POSITION:
case MEMBERSHIP:
case QUALIFICATION:
case SERVICE:
a.setAmendedSection(org.orcid.jaxb.model.notification.amended_v2.AmendedSection.AFFILIATION);
break;
case BIO:
a.setAmendedSection(org.orcid.jaxb.model.notification.amended_v2.AmendedSection.BIO);
break;
case EDUCATION:
a.setAmendedSection(org.orcid.jaxb.model.notification.amended_v2.AmendedSection.EDUCATION);
break;
case EMPLOYMENT:
a.setAmendedSection(org.orcid.jaxb.model.notification.amended_v2.AmendedSection.EMPLOYMENT);
break;
case EXTERNAL_IDENTIFIERS:
a.setAmendedSection(org.orcid.jaxb.model.notification.amended_v2.AmendedSection.EXTERNAL_IDENTIFIERS);
break;
case FUNDING:
a.setAmendedSection(org.orcid.jaxb.model.notification.amended_v2.AmendedSection.FUNDING);
break;
case PEER_REVIEW:
a.setAmendedSection(org.orcid.jaxb.model.notification.amended_v2.AmendedSection.PEER_REVIEW);
break;
case PREFERENCES:
a.setAmendedSection(org.orcid.jaxb.model.notification.amended_v2.AmendedSection.PREFERENCES);
break;
case UNKNOWN:
a.setAmendedSection(org.orcid.jaxb.model.notification.amended_v2.AmendedSection.UNKNOWN);
break;
case WORK:
a.setAmendedSection(org.orcid.jaxb.model.notification.amended_v2.AmendedSection.WORK);
break;
}
}
}
})).register();
mapperFactory.classMap(NotificationItemEntity.class, Item.class).fieldMap("externalIdType", "externalIdentifier.type").converter("externalIdentifierIdConverter").add().field("externalIdValue", "externalIdentifier.value").byDefault().register();
return mapperFactory.getMapperFacade();
}
Aggregations