Search in sources :

Example 1 with NotificationAmended

use of org.orcid.jaxb.model.v3.dev1.notification.amended.NotificationAmended 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 2 with NotificationAmended

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

the class NotificationManagerImpl method sendAmendEmail.

@Override
public void sendAmendEmail(String userOrcid, AmendedSection amendedSection, Collection<Item> items) {
    String amenderOrcid = sourceManager.retrieveSourceOrcid();
    ProfileEntity record = profileEntityCacheManager.retrieve(userOrcid);
    Locale locale = getUserLocaleFromProfileEntity(record);
    if (amenderOrcid == null) {
        LOGGER.info("Not sending amend email to {} because amender is null", userOrcid);
        return;
    }
    if (amenderOrcid.equals(userOrcid)) {
        LOGGER.debug("Not sending amend email, because self edited: {}", userOrcid);
        return;
    }
    Boolean sendChangeNotifications = record.getSendChangeNotifications();
    if (sendChangeNotifications == null || !sendChangeNotifications) {
        LOGGER.debug("Not sending amend email, because option to send change notifications is disabled: {}", userOrcid);
        return;
    }
    org.orcid.jaxb.model.common_v2.OrcidType amenderType = profileDao.retrieveOrcidType(amenderOrcid);
    if (amenderType != null && OrcidType.ADMIN.equals(OrcidType.fromValue(amenderType.value()))) {
        LOGGER.debug("Not sending amend email, because modified by admin ({}): {}", amenderOrcid, userOrcid);
        return;
    }
    String subject = getSubject("email.subject.amend", locale);
    // Create map of template params
    Map<String, Object> templateParams = new HashMap<String, Object>();
    templateParams.put("emailName", deriveEmailFriendlyName(record));
    templateParams.put("orcid", userOrcid);
    templateParams.put("amenderName", extractAmenderName(userOrcid, amenderOrcid));
    templateParams.put("baseUri", orcidUrlManager.getBaseUrl());
    templateParams.put("baseUriHttp", orcidUrlManager.getBaseUriHttp());
    templateParams.put("subject", subject);
    addMessageParams(templateParams, locale);
    // Generate body from template
    String body = templateManager.processTemplate("amend_email.ftl", templateParams);
    // Generate html from template
    String html = templateManager.processTemplate("amend_email_html.ftl", templateParams);
    boolean notificationsEnabled = record.getEnableNotifications();
    if (notificationsEnabled) {
        NotificationAmended notification = new NotificationAmended();
        notification.setNotificationType(NotificationType.AMENDED);
        notification.setAmendedSection(amendedSection);
        if (items != null) {
            notification.setItems(new Items(new ArrayList<>(items)));
        }
        createNotification(userOrcid, notification);
    } else {
        String primaryEmail = emailManager.findPrimaryEmail(userOrcid).getEmail();
        mailGunManager.sendEmail(AMEND_NOTIFY_ORCID_ORG, primaryEmail, subject, body, html);
    }
}
Also used : Locale(java.util.Locale) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) Items(org.orcid.jaxb.model.v3.dev1.notification.permission.Items) NotificationAmended(org.orcid.jaxb.model.v3.dev1.notification.amended.NotificationAmended)

Example 3 with NotificationAmended

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

the class JpaJaxbNotificationAdapterTest method testToNotificationAmendedEntity.

@Test
public void testToNotificationAmendedEntity() {
    NotificationAmended notification = new NotificationAmended();
    notification.setNotificationType(NotificationType.AMENDED);
    Source source = new Source();
    notification.setSource(source);
    SourceClientId clientId = new SourceClientId();
    source.setSourceClientId(clientId);
    clientId.setPath("APP-5555-5555-5555-5555");
    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 NotificationAmendedEntity);
    NotificationAmendedEntity notificationAmendedEntity = (NotificationAmendedEntity) notificationEntity;
    assertNotNull(notificationEntity);
    assertEquals(org.orcid.jaxb.model.notification_v2.NotificationType.AMENDED, notificationEntity.getNotificationType());
    // Source
    assertNull(notificationAmendedEntity.getSourceId());
    assertNull(notificationAmendedEntity.getClientSourceId());
    assertNull(notificationAmendedEntity.getElementSourceId());
}
Also used : NotificationAmendedEntity(org.orcid.persistence.jpa.entities.NotificationAmendedEntity) Item(org.orcid.jaxb.model.v3.dev1.notification.permission.Item) SourceClientId(org.orcid.jaxb.model.v3.dev1.common.SourceClientId) ExternalID(org.orcid.jaxb.model.v3.dev1.record.ExternalID) Items(org.orcid.jaxb.model.v3.dev1.notification.permission.Items) NotificationEntity(org.orcid.persistence.jpa.entities.NotificationEntity) Source(org.orcid.jaxb.model.v3.dev1.common.Source) NotificationAmended(org.orcid.jaxb.model.v3.dev1.notification.amended.NotificationAmended) Test(org.junit.Test)

Example 4 with NotificationAmended

use of org.orcid.jaxb.model.v3.dev1.notification.amended.NotificationAmended 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())));
        }
    }
}
Also used : NotificationInstitutionalConnection(org.orcid.model.v3.dev1.notification.institutional_sign_in.NotificationInstitutionalConnection) NotificationType(org.orcid.jaxb.model.v3.dev1.notification.NotificationType) NotificationPermission(org.orcid.jaxb.model.v3.dev1.notification.permission.NotificationPermission) Notification(org.orcid.jaxb.model.v3.dev1.notification.Notification) NotificationAmended(org.orcid.jaxb.model.v3.dev1.notification.amended.NotificationAmended)

Aggregations

NotificationAmended (org.orcid.jaxb.model.v3.dev1.notification.amended.NotificationAmended)4 Item (org.orcid.jaxb.model.v3.dev1.notification.permission.Item)2 Items (org.orcid.jaxb.model.v3.dev1.notification.permission.Items)2 NotificationPermission (org.orcid.jaxb.model.v3.dev1.notification.permission.NotificationPermission)2 NotificationInstitutionalConnection (org.orcid.model.v3.dev1.notification.institutional_sign_in.NotificationInstitutionalConnection)2 NotificationAmendedEntity (org.orcid.persistence.jpa.entities.NotificationAmendedEntity)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Locale (java.util.Locale)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 Test (org.junit.Test)1 WorkEntityFactory (org.orcid.core.adapter.impl.WorkEntityFactory)1 ExternalIdentifierTypeConverter (org.orcid.core.adapter.jsonidentifier.converter.ExternalIdentifierTypeConverter)1 Source (org.orcid.jaxb.model.v3.dev1.common.Source)1 SourceClientId (org.orcid.jaxb.model.v3.dev1.common.SourceClientId)1 Notification (org.orcid.jaxb.model.v3.dev1.notification.Notification)1 NotificationType (org.orcid.jaxb.model.v3.dev1.notification.NotificationType)1