use of org.orcid.jaxb.model.v3.dev1.notification.permission.AuthorizationUrl in project ORCID-Source by ORCID.
the class NotificationManagerImpl method sendAcknowledgeMessage.
@Override
public void sendAcknowledgeMessage(String userOrcid, String clientId) throws UnsupportedEncodingException {
ProfileEntity profileEntity = profileEntityCacheManager.retrieve(userOrcid);
ClientDetailsEntity clientDetails = clientDetailsEntityCacheManager.retrieve(clientId);
Locale userLocale = (profileEntity.getLocale() == null || profileEntity.getLocale().value() == null) ? Locale.ENGLISH : LocaleUtils.toLocale(profileEntity.getLocale().value());
String subject = getSubject("email.subject.institutional_sign_in", userLocale);
String authorizationUrl = buildAuthorizationUrlForInstitutionalSignIn(clientDetails);
// Create map of template params
Map<String, Object> templateParams = new HashMap<String, Object>();
templateParams.put("emailName", deriveEmailFriendlyName(profileEntity));
templateParams.put("orcid", userOrcid);
templateParams.put("baseUri", orcidUrlManager.getBaseUrl());
templateParams.put("subject", subject);
templateParams.put("clientName", clientDetails.getClientName());
templateParams.put("authorization_url", authorizationUrl);
addMessageParams(templateParams, userLocale);
// Generate body from template
String body = templateManager.processTemplate("authenticate_request_email.ftl", templateParams);
// Generate html from template
String html = templateManager.processTemplate("authenticate_request_email_html.ftl", templateParams);
boolean notificationsEnabled = profileEntity.getEnableNotifications();
if (notificationsEnabled) {
NotificationInstitutionalConnection notification = new NotificationInstitutionalConnection();
notification.setNotificationType(NotificationType.INSTITUTIONAL_CONNECTION);
notification.setAuthorizationUrl(new AuthorizationUrl(authorizationUrl));
NotificationInstitutionalConnectionEntity notificationEntity = (NotificationInstitutionalConnectionEntity) notificationAdapter.toNotificationEntity(notification);
notificationEntity.setProfile(new ProfileEntity(userOrcid));
notificationEntity.setClientSourceId(clientId);
notificationEntity.setAuthenticationProviderId(clientDetails.getAuthenticationProviderId());
notificationDao.persist(notificationEntity);
} else {
Emails emails = emailManager.getEmails(userOrcid);
String primaryEmail = null;
if (emails == null || emails.getEmails() == null) {
throw new IllegalArgumentException("Unable to find primary email for: " + userOrcid);
}
for (org.orcid.jaxb.model.v3.dev1.record.Email email : emails.getEmails()) {
if (email.isPrimary()) {
primaryEmail = email.getEmail();
}
}
mailGunManager.sendEmail(UPDATE_NOTIFY_ORCID_ORG, primaryEmail, subject, body, html);
}
}
use of org.orcid.jaxb.model.v3.dev1.notification.permission.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(org.orcid.jaxb.model.notification_v2.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(org.orcid.jaxb.model.notification.permission_v2.ItemType.WORK, activityEntity.getItemType());
assertEquals("Latest Research Article", activityEntity.getItemName());
assertEquals("DOI", activityEntity.getExternalIdType());
assertEquals("1234/abc123", activityEntity.getExternalIdValue());
}
use of org.orcid.jaxb.model.v3.dev1.notification.permission.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.v3.dev1.notification.permission.AuthorizationUrl in project ORCID-Source by ORCID.
the class NotificationsTest method createPermissionNotificationWithUnencodedSpaceInAuthorizationPath.
@Test
public void createPermissionNotificationWithUnencodedSpaceInAuthorizationPath() throws JSONException {
NotificationPermission notification = unmarshallFromPath("/notification_3.0_dev1/samples/notification-permission-3.0_dev1.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_V3_0_dev1.addPermissionNotificationXml(testUser1OrcidId, notification, accessToken);
assertNotNull(response);
assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatus());
assertNull(response.getLocation());
}
Aggregations