Search in sources :

Example 1 with NotificationCustom

use of org.orcid.jaxb.model.v3.dev1.notification.custom.NotificationCustom in project ORCID-Source by ORCID.

the class NotificationController method getCustomNotificationHtml.

@RequestMapping(value = "/CUSTOM/{id}/notification.html", produces = OrcidApiConstants.HTML_UTF)
@ResponseBody
public String getCustomNotificationHtml(HttpServletResponse response, @PathVariable("id") String id) {
    Notification notification = notificationManager.findByOrcidAndId(getCurrentUserOrcid(), Long.valueOf(id));
    response.addHeader("X-Robots-Tag", "noindex");
    if (notification instanceof NotificationCustom) {
        return ((NotificationCustom) notification).getBodyHtml();
    } else {
        return "Notification is of wrong type";
    }
}
Also used : NotificationCustom(org.orcid.jaxb.model.v3.dev1.notification.custom.NotificationCustom) Notification(org.orcid.jaxb.model.v3.dev1.notification.Notification) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 2 with NotificationCustom

use of org.orcid.jaxb.model.v3.dev1.notification.custom.NotificationCustom 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();
}
Also used : NotificationInstitutionalConnectionEntity(org.orcid.persistence.jpa.entities.NotificationInstitutionalConnectionEntity) ConverterFactory(ma.glasnost.orika.converter.ConverterFactory) NotificationCustom(org.orcid.jaxb.model.v3.dev1.notification.custom.NotificationCustom) NotificationAddItemsEntity(org.orcid.persistence.jpa.entities.NotificationAddItemsEntity) MappingContext(ma.glasnost.orika.MappingContext) AuthorizationUrl(org.orcid.jaxb.model.v3.dev1.notification.permission.AuthorizationUrl) Item(org.orcid.jaxb.model.v3.dev1.notification.permission.Item) DefaultMapperFactory(ma.glasnost.orika.impl.DefaultMapperFactory) NotificationPermission(org.orcid.jaxb.model.v3.dev1.notification.permission.NotificationPermission) NotificationAmendedEntity(org.orcid.persistence.jpa.entities.NotificationAmendedEntity) NotificationInstitutionalConnection(org.orcid.model.v3.dev1.notification.institutional_sign_in.NotificationInstitutionalConnection) WorkEntityFactory(org.orcid.core.adapter.impl.WorkEntityFactory) NotificationCustomEntity(org.orcid.persistence.jpa.entities.NotificationCustomEntity) NotificationWorkEntity(org.orcid.persistence.jpa.entities.NotificationWorkEntity) ExternalIdentifierTypeConverter(org.orcid.core.adapter.jsonidentifier.converter.ExternalIdentifierTypeConverter) DefaultMapperFactory(ma.glasnost.orika.impl.DefaultMapperFactory) MapperFactory(ma.glasnost.orika.MapperFactory) NotificationAmended(org.orcid.jaxb.model.v3.dev1.notification.amended.NotificationAmended)

Example 3 with NotificationCustom

use of org.orcid.jaxb.model.v3.dev1.notification.custom.NotificationCustom in project ORCID-Source by ORCID.

the class NotificationManagerImpl method sendDelegationRequestEmail.

@Override
public void sendDelegationRequestEmail(String managedOrcid, String trustedOrcid, String link) {
    // Create map of template params
    Map<String, Object> templateParams = new HashMap<String, Object>();
    templateParams.put("baseUri", orcidUrlManager.getBaseUrl());
    templateParams.put("baseUriHttp", orcidUrlManager.getBaseUriHttp());
    templateParams.put("link", link);
    ProfileEntity managedEntity = profileEntityCacheManager.retrieve(managedOrcid);
    ProfileEntity trustedEntity = profileEntityCacheManager.retrieve(trustedOrcid);
    String emailNameForDelegate = deriveEmailFriendlyName(managedEntity);
    String trustedOrcidName = deriveEmailFriendlyName(trustedEntity);
    templateParams.put("emailNameForDelegate", emailNameForDelegate);
    templateParams.put("trustedOrcidName", trustedOrcidName);
    templateParams.put("trustedOrcidValue", trustedOrcid);
    templateParams.put("managedOrcidValue", managedOrcid);
    String primaryEmail = emailManager.findPrimaryEmail(managedOrcid).getEmail();
    if (primaryEmail == null) {
        LOGGER.info("Cant send admin delegate email if primary email is null: {}", managedOrcid);
        return;
    }
    org.orcid.jaxb.model.common_v2.Locale locale = managedEntity.getLocale();
    Locale userLocale = LocaleUtils.toLocale("en");
    if (locale != null) {
        userLocale = LocaleUtils.toLocale(locale.value());
    }
    addMessageParams(templateParams, userLocale);
    String htmlBody = templateManager.processTemplate("admin_delegate_request_html.ftl", templateParams);
    // Send message
    if (apiRecordCreationEmailEnabled) {
        String subject = messages.getMessage("email.subject.admin_as_delegate", new Object[] { trustedOrcidName }, userLocale);
        boolean notificationsEnabled = trustedEntity != null ? trustedEntity.getEnableNotifications() : false;
        if (notificationsEnabled) {
            NotificationCustom notification = new NotificationCustom();
            notification.setNotificationType(NotificationType.CUSTOM);
            notification.setSubject(subject);
            notification.setBodyHtml(htmlBody);
            createNotification(managedOrcid, notification);
        } else {
            mailGunManager.sendEmail(DELEGATE_NOTIFY_ORCID_ORG, primaryEmail, subject, null, htmlBody);
        }
        profileEventDao.persist(new ProfileEventEntity(managedOrcid, ProfileEventType.ADMIN_PROFILE_DELEGATION_REQUEST));
    } else {
        LOGGER.debug("Not sending admin delegate email, because API record creation email option is disabled. Message would have been: {}", htmlBody);
    }
}
Also used : Locale(java.util.Locale) ProfileEventEntity(org.orcid.persistence.jpa.entities.ProfileEventEntity) HashMap(java.util.HashMap) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) NotificationCustom(org.orcid.jaxb.model.v3.dev1.notification.custom.NotificationCustom)

Example 4 with NotificationCustom

use of org.orcid.jaxb.model.v3.dev1.notification.custom.NotificationCustom in project ORCID-Source by ORCID.

the class NotificationManagerImpl method sendAutoDeprecateNotification.

@Override
public void sendAutoDeprecateNotification(String primaryOrcid, String deprecatedOrcid) {
    ProfileEntity primaryProfileEntity = profileEntityCacheManager.retrieve(primaryOrcid);
    ProfileEntity deprecatedProfileEntity = profileEntityCacheManager.retrieve(deprecatedOrcid);
    ClientDetailsEntity clientDetails = clientDetailsEntityCacheManager.retrieve(deprecatedProfileEntity.getSource().getSourceId());
    Locale userLocale = LocaleUtils.toLocale(primaryProfileEntity.getLocale() == null ? org.orcid.jaxb.model.message.Locale.EN.value() : primaryProfileEntity.getLocale().value());
    // Create map of template params
    Map<String, Object> templateParams = new HashMap<String, Object>();
    String subject = getSubject("email.subject.auto_deprecate", userLocale);
    String assetsUrl = getAssetsUrl();
    Date deprecatedAccountCreationDate = deprecatedProfileEntity.getDateCreated();
    // Create map of template params
    templateParams.put("primaryId", primaryOrcid);
    templateParams.put("name", deriveEmailFriendlyName(primaryProfileEntity));
    templateParams.put("assetsUrl", assetsUrl);
    templateParams.put("subject", subject);
    templateParams.put("clientName", clientDetails.getClientName());
    templateParams.put("deprecatedAccountCreationDate", deprecatedAccountCreationDate);
    templateParams.put("deprecatedId", deprecatedOrcid);
    addMessageParams(templateParams, userLocale);
    // Generate html from template
    String html = templateManager.processTemplate("auto_deprecated_account_html.ftl", templateParams);
    NotificationCustom notification = new NotificationCustom();
    notification.setNotificationType(NotificationType.CUSTOM);
    notification.setSubject(subject);
    notification.setBodyHtml(html);
    createNotification(primaryOrcid, notification);
}
Also used : Locale(java.util.Locale) NotificationCustom(org.orcid.jaxb.model.v3.dev1.notification.custom.NotificationCustom) ClientDetailsEntity(org.orcid.persistence.jpa.entities.ClientDetailsEntity) HashMap(java.util.HashMap) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) Date(java.util.Date)

Example 5 with NotificationCustom

use of org.orcid.jaxb.model.v3.dev1.notification.custom.NotificationCustom in project ORCID-Source by ORCID.

the class JpaJaxbNotificationAdapterTest method testCustomEntityToNotification.

@Test
public void testCustomEntityToNotification() {
    NotificationCustomEntity notificationEntity = new NotificationCustomEntity();
    notificationEntity.setId(123L);
    notificationEntity.setNotificationType(org.orcid.jaxb.model.notification_v2.NotificationType.CUSTOM);
    notificationEntity.setSubject("Test subject");
    notificationEntity.setDateCreated(DateUtils.convertToDate("2014-01-01T09:17:56"));
    notificationEntity.setReadDate(DateUtils.convertToDate("2014-03-04T17:43:06"));
    Notification notification = jpaJaxbNotificationAdapter.toNotification(notificationEntity);
    assertNotNull(notification);
    assertTrue(notification instanceof NotificationCustom);
    NotificationCustom notificationCustom = (NotificationCustom) notification;
    assertEquals(NotificationType.CUSTOM, notification.getNotificationType());
    assertEquals("Test subject", notificationCustom.getSubject());
    assertEquals("2014-01-01T09:17:56.000Z", notification.getCreatedDate().toXMLFormat());
    assertEquals("2014-03-04T17:43:06.000Z", notification.getReadDate().toXMLFormat());
}
Also used : NotificationCustom(org.orcid.jaxb.model.v3.dev1.notification.custom.NotificationCustom) NotificationCustomEntity(org.orcid.persistence.jpa.entities.NotificationCustomEntity) Notification(org.orcid.jaxb.model.v3.dev1.notification.Notification) Test(org.junit.Test)

Aggregations

NotificationCustom (org.orcid.jaxb.model.v3.dev1.notification.custom.NotificationCustom)8 HashMap (java.util.HashMap)3 Locale (java.util.Locale)3 Test (org.junit.Test)3 Notification (org.orcid.jaxb.model.v3.dev1.notification.Notification)3 ProfileEntity (org.orcid.persistence.jpa.entities.ProfileEntity)3 ClientDetailsEntity (org.orcid.persistence.jpa.entities.ClientDetailsEntity)2 NotificationCustomEntity (org.orcid.persistence.jpa.entities.NotificationCustomEntity)2 Date (java.util.Date)1 MapperFactory (ma.glasnost.orika.MapperFactory)1 MappingContext (ma.glasnost.orika.MappingContext)1 ConverterFactory (ma.glasnost.orika.converter.ConverterFactory)1 DefaultMapperFactory (ma.glasnost.orika.impl.DefaultMapperFactory)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1 WorkEntityFactory (org.orcid.core.adapter.impl.WorkEntityFactory)1 ExternalIdentifierTypeConverter (org.orcid.core.adapter.jsonidentifier.converter.ExternalIdentifierTypeConverter)1 NotificationAmended (org.orcid.jaxb.model.v3.dev1.notification.amended.NotificationAmended)1 AuthorizationUrl (org.orcid.jaxb.model.v3.dev1.notification.permission.AuthorizationUrl)1 Item (org.orcid.jaxb.model.v3.dev1.notification.permission.Item)1 NotificationPermission (org.orcid.jaxb.model.v3.dev1.notification.permission.NotificationPermission)1