Search in sources :

Example 26 with MapperFactory

use of ma.glasnost.orika.MapperFactory in project ORCID-Source by ORCID.

the class MapperFacadeFactory method getGroupIdRecordMapperFacade.

public MapperFacade getGroupIdRecordMapperFacade() {
    MapperFactory mapperFactory = getNewMapperFactory();
    ClassMapBuilder<GroupIdRecord, GroupIdRecordEntity> classMap = mapperFactory.classMap(GroupIdRecord.class, GroupIdRecordEntity.class);
    addV2CommonFields(classMap);
    registerSourceConverters(mapperFactory, classMap);
    classMap.field("name", "groupName");
    classMap.field("groupId", "groupId");
    classMap.field("description", "groupDescription");
    classMap.field("type", "groupType");
    classMap.register();
    return mapperFactory.getMapperFacade();
}
Also used : GroupIdRecord(org.orcid.jaxb.model.groupid_v2.GroupIdRecord) DefaultMapperFactory(ma.glasnost.orika.impl.DefaultMapperFactory) MapperFactory(ma.glasnost.orika.MapperFactory) GroupIdRecordEntity(org.orcid.persistence.jpa.entities.GroupIdRecordEntity)

Example 27 with MapperFactory

use of ma.glasnost.orika.MapperFactory in project ORCID-Source by ORCID.

the class MapperFacadeFactory method getObject.

@Override
public MapperFacade getObject() throws Exception {
    MapperFactory mapperFactory = getNewMapperFactory();
    // 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.exclude("amendedSection").customize(new CustomMapper<NotificationAmended, NotificationAmendedEntity>() {

        @Override
        public void mapAtoB(NotificationAmended a, NotificationAmendedEntity b, MappingContext context) {
            if (a.getAmendedSection() != null) {
                switch(a.getAmendedSection()) {
                    case AFFILIATION:
                        b.setAmendedSection(AmendedSection.AFFILIATION);
                        break;
                    case BIO:
                        b.setAmendedSection(AmendedSection.BIO);
                        break;
                    case EDUCATION:
                        b.setAmendedSection(AmendedSection.EDUCATION);
                        break;
                    case EMPLOYMENT:
                        b.setAmendedSection(AmendedSection.EMPLOYMENT);
                        break;
                    case EXTERNAL_IDENTIFIERS:
                        b.setAmendedSection(AmendedSection.EXTERNAL_IDENTIFIERS);
                        break;
                    case FUNDING:
                        b.setAmendedSection(AmendedSection.FUNDING);
                        break;
                    case PEER_REVIEW:
                        b.setAmendedSection(AmendedSection.PEER_REVIEW);
                        break;
                    case PREFERENCES:
                        b.setAmendedSection(AmendedSection.PREFERENCES);
                        break;
                    case UNKNOWN:
                        b.setAmendedSection(AmendedSection.UNKNOWN);
                        break;
                    case WORK:
                        b.setAmendedSection(AmendedSection.WORK);
                        break;
                    default:
                        b.setAmendedSection(AmendedSection.UNKNOWN);
                        break;
                }
            }
        }

        /**
         * From database to model object, map amended sections for new affiliation types as AFFILIATION
         */
        @Override
        public void mapBtoA(NotificationAmendedEntity b, NotificationAmended a, MappingContext context) {
            if (b.getAmendedSection() != null) {
                switch(b.getAmendedSection()) {
                    case AFFILIATION:
                    case DISTINCTION:
                    case INVITED_POSITION:
                    case MEMBERSHIP:
                    case QUALIFICATION:
                    case SERVICE:
                        a.setAmendedSection(org.orcid.jaxb.model.notification.amended_v2.AmendedSection.AFFILIATION);
                        break;
                    case BIO:
                        a.setAmendedSection(org.orcid.jaxb.model.notification.amended_v2.AmendedSection.BIO);
                        break;
                    case EDUCATION:
                        a.setAmendedSection(org.orcid.jaxb.model.notification.amended_v2.AmendedSection.EDUCATION);
                        break;
                    case EMPLOYMENT:
                        a.setAmendedSection(org.orcid.jaxb.model.notification.amended_v2.AmendedSection.EMPLOYMENT);
                        break;
                    case EXTERNAL_IDENTIFIERS:
                        a.setAmendedSection(org.orcid.jaxb.model.notification.amended_v2.AmendedSection.EXTERNAL_IDENTIFIERS);
                        break;
                    case FUNDING:
                        a.setAmendedSection(org.orcid.jaxb.model.notification.amended_v2.AmendedSection.FUNDING);
                        break;
                    case PEER_REVIEW:
                        a.setAmendedSection(org.orcid.jaxb.model.notification.amended_v2.AmendedSection.PEER_REVIEW);
                        break;
                    case PREFERENCES:
                        a.setAmendedSection(org.orcid.jaxb.model.notification.amended_v2.AmendedSection.PREFERENCES);
                        break;
                    case UNKNOWN:
                        a.setAmendedSection(org.orcid.jaxb.model.notification.amended_v2.AmendedSection.UNKNOWN);
                        break;
                    case WORK:
                        a.setAmendedSection(org.orcid.jaxb.model.notification.amended_v2.AmendedSection.WORK);
                        break;
                }
            }
        }
    })).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) Item(org.orcid.jaxb.model.notification.permission_v2.Item) 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.jsonidentifier.converter.ExternalIdentifierTypeConverter) DefaultMapperFactory(ma.glasnost.orika.impl.DefaultMapperFactory) MapperFactory(ma.glasnost.orika.MapperFactory) NotificationAmended(org.orcid.jaxb.model.notification.amended_v2.NotificationAmended)

Example 28 with MapperFactory

use of ma.glasnost.orika.MapperFactory in project ORCID-Source by ORCID.

the class MapperFacadeFactory method getFundingMapperFacade.

public MapperFacade getFundingMapperFacade() {
    MapperFactory mapperFactory = new DefaultMapperFactory.Builder().build();
    ConverterFactory converterFactory = mapperFactory.getConverterFactory();
    converterFactory.registerConverter("fundingExternalIdentifiersConverterId", new JSONFundingExternalIdentifiersConverterV3());
    converterFactory.registerConverter("fundingContributorsConverterId", new JsonOrikaConverter<FundingContributors>());
    ClassMapBuilder<Funding, ProfileFundingEntity> fundingClassMap = mapperFactory.classMap(Funding.class, ProfileFundingEntity.class);
    addV3CommonFields(fundingClassMap);
    registerSourceConverters(mapperFactory, fundingClassMap);
    fundingClassMap.field("type", "type");
    fundingClassMap.field("organizationDefinedType.content", "organizationDefinedType");
    fundingClassMap.field("title.title.content", "title");
    fundingClassMap.field("title.translatedTitle.content", "translatedTitle");
    fundingClassMap.field("title.translatedTitle.languageCode", "translatedTitleLanguageCode");
    fundingClassMap.field("description", "description");
    fundingClassMap.field("amount.content", "numericAmount");
    fundingClassMap.field("amount.currencyCode", "currencyCode");
    fundingClassMap.field("url.value", "url");
    fundingClassMap.fieldBToA("org.name", "organization.name");
    fundingClassMap.fieldBToA("org.city", "organization.address.city");
    fundingClassMap.fieldBToA("org.region", "organization.address.region");
    fundingClassMap.fieldBToA("org.country", "organization.address.country");
    fundingClassMap.fieldBToA("org.orgDisambiguated.sourceId", "organization.disambiguatedOrganization.disambiguatedOrganizationIdentifier");
    fundingClassMap.fieldBToA("org.orgDisambiguated.sourceType", "organization.disambiguatedOrganization.disambiguationSource");
    fundingClassMap.fieldBToA("org.orgDisambiguated.id", "organization.disambiguatedOrganization.id");
    fundingClassMap.fieldMap("externalIdentifiers", "externalIdentifiersJson").converter("fundingExternalIdentifiersConverterId").add();
    fundingClassMap.fieldMap("contributors", "contributorsJson").converter("fundingContributorsConverterId").add();
    fundingClassMap.register();
    ClassMapBuilder<FundingSummary, ProfileFundingEntity> fundingSummaryClassMap = mapperFactory.classMap(FundingSummary.class, ProfileFundingEntity.class);
    addV3CommonFields(fundingSummaryClassMap);
    registerSourceConverters(mapperFactory, fundingSummaryClassMap);
    fundingSummaryClassMap.field("type", "type");
    fundingSummaryClassMap.field("title.title.content", "title");
    fundingSummaryClassMap.field("title.translatedTitle.content", "translatedTitle");
    fundingSummaryClassMap.field("title.translatedTitle.languageCode", "translatedTitleLanguageCode");
    fundingSummaryClassMap.fieldMap("externalIdentifiers", "externalIdentifiersJson").converter("fundingExternalIdentifiersConverterId").add();
    fundingSummaryClassMap.fieldBToA("org.name", "organization.name");
    fundingSummaryClassMap.fieldBToA("org.city", "organization.address.city");
    fundingSummaryClassMap.fieldBToA("org.region", "organization.address.region");
    fundingSummaryClassMap.fieldBToA("org.country", "organization.address.country");
    fundingSummaryClassMap.fieldBToA("org.orgDisambiguated.sourceId", "organization.disambiguatedOrganization.disambiguatedOrganizationIdentifier");
    fundingSummaryClassMap.fieldBToA("org.orgDisambiguated.sourceType", "organization.disambiguatedOrganization.disambiguationSource");
    fundingSummaryClassMap.fieldBToA("org.orgDisambiguated.id", "organization.disambiguatedOrganization.id");
    fundingSummaryClassMap.register();
    mapperFactory.classMap(FuzzyDate.class, StartDateEntity.class).field("year.value", "year").field("month.value", "month").field("day.value", "day").register();
    mapperFactory.classMap(FuzzyDate.class, EndDateEntity.class).field("year.value", "year").field("month.value", "month").field("day.value", "day").register();
    return mapperFactory.getMapperFacade();
}
Also used : Funding(org.orcid.jaxb.model.v3.dev1.record.Funding) DefaultMapperFactory(ma.glasnost.orika.impl.DefaultMapperFactory) DefaultMapperFactory(ma.glasnost.orika.impl.DefaultMapperFactory) MapperFactory(ma.glasnost.orika.MapperFactory) FundingContributors(org.orcid.jaxb.model.v3.dev1.record.FundingContributors) FundingSummary(org.orcid.jaxb.model.v3.dev1.record.summary.FundingSummary) JSONFundingExternalIdentifiersConverterV3(org.orcid.core.adapter.jsonidentifier.converter.JSONFundingExternalIdentifiersConverterV3) ConverterFactory(ma.glasnost.orika.converter.ConverterFactory) ProfileFundingEntity(org.orcid.persistence.jpa.entities.ProfileFundingEntity)

Example 29 with MapperFactory

use of ma.glasnost.orika.MapperFactory in project ORCID-Source by ORCID.

the class MapperFacadeFactory method getKeywordMapperFacade.

public MapperFacade getKeywordMapperFacade() {
    MapperFactory mapperFactory = new DefaultMapperFactory.Builder().build();
    ClassMapBuilder<Keyword, ProfileKeywordEntity> keywordClassMap = mapperFactory.classMap(Keyword.class, ProfileKeywordEntity.class);
    addV3DateFields(keywordClassMap);
    registerSourceConverters(mapperFactory, keywordClassMap);
    keywordClassMap.field("putCode", "id");
    keywordClassMap.field("content", "keywordName");
    keywordClassMap.fieldBToA("displayIndex", "displayIndex");
    keywordClassMap.byDefault();
    keywordClassMap.register();
    return mapperFactory.getMapperFacade();
}
Also used : ProfileKeywordEntity(org.orcid.persistence.jpa.entities.ProfileKeywordEntity) Keyword(org.orcid.jaxb.model.v3.dev1.record.Keyword) DefaultMapperFactory(ma.glasnost.orika.impl.DefaultMapperFactory) DefaultMapperFactory(ma.glasnost.orika.impl.DefaultMapperFactory) MapperFactory(ma.glasnost.orika.MapperFactory)

Example 30 with MapperFactory

use of ma.glasnost.orika.MapperFactory in project ORCID-Source by ORCID.

the class MapperFacadeFactory method getEmailMapperFacade.

public MapperFacade getEmailMapperFacade() {
    MapperFactory mapperFactory = new DefaultMapperFactory.Builder().build();
    ClassMapBuilder<Email, EmailEntity> emailClassMap = mapperFactory.classMap(Email.class, EmailEntity.class);
    emailClassMap.byDefault();
    emailClassMap.field("email", "id");
    emailClassMap.field("primary", "primary");
    emailClassMap.field("verified", "verified");
    addV3DateFields(emailClassMap);
    registerSourceConverters(mapperFactory, emailClassMap);
    emailClassMap.register();
    return mapperFactory.getMapperFacade();
}
Also used : Email(org.orcid.jaxb.model.v3.dev1.record.Email) DefaultMapperFactory(ma.glasnost.orika.impl.DefaultMapperFactory) DefaultMapperFactory(ma.glasnost.orika.impl.DefaultMapperFactory) MapperFactory(ma.glasnost.orika.MapperFactory) EmailEntity(org.orcid.persistence.jpa.entities.EmailEntity)

Aggregations

MapperFactory (ma.glasnost.orika.MapperFactory)42 DefaultMapperFactory (ma.glasnost.orika.impl.DefaultMapperFactory)42 ConverterFactory (ma.glasnost.orika.converter.ConverterFactory)9 OrgAffiliationRelationEntity (org.orcid.persistence.jpa.entities.OrgAffiliationRelationEntity)9 MappingContext (ma.glasnost.orika.MappingContext)4 NotificationWorkEntity (org.orcid.persistence.jpa.entities.NotificationWorkEntity)3 Date (java.util.Date)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 Map (java.util.Map)2 TreeSet (java.util.TreeSet)2 MapperFacade (ma.glasnost.orika.MapperFacade)2 ExternalIdentifierTypeConverter (org.orcid.core.adapter.jsonidentifier.converter.ExternalIdentifierTypeConverter)2 JSONWorkExternalIdentifiersConverterV2 (org.orcid.core.adapter.jsonidentifier.converter.JSONWorkExternalIdentifiersConverterV2)2 JSONWorkExternalIdentifiersConverterV3 (org.orcid.core.adapter.jsonidentifier.converter.JSONWorkExternalIdentifiersConverterV3)2 OtherName (org.orcid.jaxb.model.record_v2.OtherName)2 RecordCorrection (org.orcid.model.record_correction.RecordCorrection)2 ClientDetailsEntity (org.orcid.persistence.jpa.entities.ClientDetailsEntity)2 ClientRedirectUriEntity (org.orcid.persistence.jpa.entities.ClientRedirectUriEntity)2 ClientSecretEntity (org.orcid.persistence.jpa.entities.ClientSecretEntity)2