use of org.orcid.model.v3.dev1.notification.institutional_sign_in.NotificationInstitutionalConnection in project ORCID-Source by ORCID.
the class MapperFacadeFactory method getObject.
@Override
public MapperFacade getObject() throws Exception {
MapperFactory mapperFactory = new DefaultMapperFactory.Builder().build();
// 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).register();
mapperFactory.classMap(NotificationItemEntity.class, Item.class).fieldMap("externalIdType", "externalIdentifier.type").converter("externalIdentifierIdConverter").add().field("externalIdValue", "externalIdentifier.value").byDefault().register();
return mapperFactory.getMapperFacade();
}
use of org.orcid.model.v3.dev1.notification.institutional_sign_in.NotificationInstitutionalConnection in project ORCID-Source by ORCID.
the class NotificationManagerTest method filterActionedNotificationAlertsTest.
@Test
public void filterActionedNotificationAlertsTest() {
TargetProxyHelper.injectIntoProxy(notificationManager, "notificationDao", mockNotificationDao);
when(mockNotificationDao.findByOricdAndId(Matchers.anyString(), Matchers.anyLong())).thenReturn(null);
List<Notification> notifications = IntStream.range(0, 10).mapToObj(new IntFunction<Notification>() {
@Override
public Notification apply(int value) {
if (value % 3 == 0) {
NotificationInstitutionalConnection n = new NotificationInstitutionalConnection();
n.setSource(new Source("0000-0000-0000-0000"));
n.setPutCode(Long.valueOf(value));
return n;
} else {
NotificationPermission n = new NotificationPermission();
n.setPutCode(Long.valueOf(value));
return n;
}
}
}).collect(Collectors.toList());
assertEquals(10, notifications.size());
notifications = notificationManager.filterActionedNotificationAlerts(notifications, "some-orcid");
assertEquals(6, notifications.size());
for (Notification n : notifications) {
assertEquals(NotificationType.PERMISSION, n.getNotificationType());
assertNotNull(n.getPutCode());
assertThat(n.getPutCode(), not(anyOf(is(Long.valueOf(0)), is(Long.valueOf(3)), is(Long.valueOf(6)), is(Long.valueOf(9)))));
}
}
use of org.orcid.model.v3.dev1.notification.institutional_sign_in.NotificationInstitutionalConnection 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.model.v3.dev1.notification.institutional_sign_in.NotificationInstitutionalConnection 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())));
}
}
}
Aggregations