Search in sources :

Example 6 with NotificationCustom

use of org.orcid.jaxb.model.notification.custom_v2.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.notification.custom_v2.NotificationCustom) Notification(org.orcid.jaxb.model.notification_v2.Notification) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 7 with NotificationCustom

use of org.orcid.jaxb.model.notification.custom_v2.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("singleWorkExternalIdentifierFromJsonConverter", new SingleWorkExternalIdentifierFromJsonConverter());
    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.notification.custom_v2.NotificationCustom) NotificationAddItemsEntity(org.orcid.persistence.jpa.entities.NotificationAddItemsEntity) MappingContext(ma.glasnost.orika.MappingContext) AuthorizationUrl(org.orcid.jaxb.model.notification.permission_v2.AuthorizationUrl) SingleWorkExternalIdentifierFromJsonConverter(org.orcid.core.adapter.impl.jsonidentifiers.SingleWorkExternalIdentifierFromJsonConverter) Item(org.orcid.jaxb.model.notification.permission_v2.Item) DefaultMapperFactory(ma.glasnost.orika.impl.DefaultMapperFactory) NotificationPermission(org.orcid.jaxb.model.notification.permission_v2.NotificationPermission) NotificationAmendedEntity(org.orcid.persistence.jpa.entities.NotificationAmendedEntity) NotificationInstitutionalConnection(org.orcid.model.notification.institutional_sign_in_v2.NotificationInstitutionalConnection) NotificationCustomEntity(org.orcid.persistence.jpa.entities.NotificationCustomEntity) NotificationWorkEntity(org.orcid.persistence.jpa.entities.NotificationWorkEntity) ExternalIdentifierTypeConverter(org.orcid.core.adapter.impl.jsonidentifiers.ExternalIdentifierTypeConverter) DefaultMapperFactory(ma.glasnost.orika.impl.DefaultMapperFactory) MapperFactory(ma.glasnost.orika.MapperFactory) NotificationAmended(org.orcid.jaxb.model.notification.amended_v2.NotificationAmended)

Example 8 with NotificationCustom

use of org.orcid.jaxb.model.notification.custom_v2.NotificationCustom in project ORCID-Source by ORCID.

the class NotificationManagerImpl method sendNotificationToAddedDelegate.

@Override
@Transactional
public void sendNotificationToAddedDelegate(String userGrantingPermission, DelegationDetails... delegatesGrantedByUser) {
    ProfileEntity profile = profileEntityCacheManager.retrieve(userGrantingPermission);
    Locale userLocale = getUserLocaleFromProfileEntity(profile);
    String subject = getSubject("email.subject.added_as_delegate", userLocale);
    for (DelegationDetails newDelegation : delegatesGrantedByUser) {
        ProfileEntity delegateProfileEntity = profileDao.find(newDelegation.getDelegateSummary().getOrcidIdentifier().getPath());
        Boolean sendAdministrativeChangeNotifications = delegateProfileEntity.getSendAdministrativeChangeNotifications();
        if (sendAdministrativeChangeNotifications == null || !sendAdministrativeChangeNotifications) {
            LOGGER.debug("Not sending added delegate email, because option to send administrative change notifications not set to true for delegate: {}", delegateProfileEntity.getId());
            return;
        }
        org.orcid.jaxb.model.record_v2.Email primaryEmail = emailManager.findPrimaryEmail(userGrantingPermission);
        String grantingOrcidEmail = primaryEmail.getEmail();
        String emailNameForDelegate = deriveEmailFriendlyName(delegateProfileEntity);
        String email = delegateProfileEntity.getPrimaryEmail().getId();
        Map<String, Object> templateParams = new HashMap<String, Object>();
        templateParams.put("emailNameForDelegate", emailNameForDelegate);
        templateParams.put("grantingOrcidValue", userGrantingPermission);
        templateParams.put("grantingOrcidName", deriveEmailFriendlyName(profile));
        templateParams.put("baseUri", orcidUrlManager.getBaseUrl());
        templateParams.put("baseUriHttp", orcidUrlManager.getBaseUriHttp());
        templateParams.put("grantingOrcidEmail", grantingOrcidEmail);
        templateParams.put("subject", subject);
        addMessageParams(templateParams, userLocale);
        // Generate body from template
        String body = templateManager.processTemplate("added_as_delegate_email.ftl", templateParams);
        // Generate html from template
        String html = templateManager.processTemplate("added_as_delegate_email_html.ftl", templateParams);
        boolean notificationsEnabled = delegateProfileEntity.getEnableNotifications();
        if (notificationsEnabled) {
            NotificationCustom notification = new NotificationCustom();
            notification.setNotificationType(NotificationType.CUSTOM);
            notification.setSubject(subject);
            notification.setBodyHtml(html);
            createNotification(newDelegation.getDelegateSummary().getOrcidIdentifier().getPath(), notification);
        } else {
            mailGunManager.sendEmail(DELEGATE_NOTIFY_ORCID_ORG, email, subject, body, html);
        }
    }
}
Also used : Locale(java.util.Locale) HashMap(java.util.HashMap) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) NotificationCustom(org.orcid.jaxb.model.notification.custom_v2.NotificationCustom) DelegationDetails(org.orcid.jaxb.model.message.DelegationDetails) Transactional(org.springframework.transaction.annotation.Transactional)

Example 9 with NotificationCustom

use of org.orcid.jaxb.model.notification.custom_v2.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(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.notification.custom_v2.NotificationCustom) NotificationCustomEntity(org.orcid.persistence.jpa.entities.NotificationCustomEntity) Notification(org.orcid.jaxb.model.notification_v2.Notification) Test(org.junit.Test)

Aggregations

NotificationCustom (org.orcid.jaxb.model.notification.custom_v2.NotificationCustom)9 Test (org.junit.Test)4 Notification (org.orcid.jaxb.model.notification_v2.Notification)4 HashMap (java.util.HashMap)3 Locale (java.util.Locale)3 ProfileEntity (org.orcid.persistence.jpa.entities.ProfileEntity)3 NotificationAmended (org.orcid.jaxb.model.notification.amended_v2.NotificationAmended)2 AuthorizationUrl (org.orcid.jaxb.model.notification.permission_v2.AuthorizationUrl)2 NotificationPermission (org.orcid.jaxb.model.notification.permission_v2.NotificationPermission)2 ClientDetailsEntity (org.orcid.persistence.jpa.entities.ClientDetailsEntity)2 NotificationCustomEntity (org.orcid.persistence.jpa.entities.NotificationCustomEntity)2 ArrayList (java.util.ArrayList)1 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 BaseTest (org.orcid.core.BaseTest)1 ExternalIdentifierTypeConverter (org.orcid.core.adapter.impl.jsonidentifiers.ExternalIdentifierTypeConverter)1