use of ma.glasnost.orika.MappingContext in project ORCID-Source by ORCID.
the class SalesForceMapperFacadeFactory method registerMemberMap.
public void registerMemberMap(MapperFactory mapperFactory) {
ClassMapBuilder<Member, JSONObject> classMap = mapperFactory.classMap(Member.class, JSONObject.class).mapNulls(false).mapNullsInReverse(false);
ConverterFactory converterFactory = mapperFactory.getConverterFactory();
converterFactory.registerConverter(new CommunityTypeConverter());
converterFactory.registerConverter(new ReverseCommunityTypeConverter());
classMap.field("id", "Id");
classMap.field("name", "Name");
classMap.field("publicDisplayName", "Public_Display_Name__c");
classMap.field("websiteUrl", "Website");
classMap.field("researchCommunity", "Research_Community__c");
classMap.field("country", "BillingCountry");
classMap.field("description", "Public_Display_Description__c");
classMap.field("logoUrl", "Logo_Description__c");
classMap.field("publicDisplayEmail", "Public_Display_Email__c");
classMap.customize(new CustomMapper<Member, JSONObject>() {
@Override
public void mapBtoA(JSONObject b, Member a, MappingContext context) {
JSONObject opportunitiesObject = b.optJSONObject("Opportunities");
if (opportunitiesObject != null) {
JSONArray recordsArray = opportunitiesObject.optJSONArray("records");
if (recordsArray != null && recordsArray.length() > 0) {
try {
JSONObject first = recordsArray.getJSONObject(0);
Object urlObj = first.getJSONObject("attributes").opt("url");
a.setMainOpportunityPath(JSONObject.NULL.equals(urlObj) ? null : urlObj.toString());
Object consortiumLeadIdObj = first.opt("Consortia_Lead__c");
a.setConsortiumLeadId(JSONObject.NULL.equals(consortiumLeadIdObj) ? null : consortiumLeadIdObj.toString());
} catch (JSONException e) {
throw new RuntimeException("Error reading first opportunity record", e);
}
}
}
}
});
classMap.register();
}
use of ma.glasnost.orika.MappingContext 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();
}
use of ma.glasnost.orika.MappingContext in project ORCID-Source by ORCID.
the class VersionConverterImplV2_0ToV2_1 method upgrade.
@Override
public V2Convertible upgrade(V2Convertible objectToUpgrade) {
Object objectToConvert = objectToUpgrade.getObjectToConvert();
Object targetObject = v2VersionObjectFactory.createEquivalentInstance(objectToConvert, UPPER_VERSION);
MappingContext context = new MappingContext.Factory().getContext();
context.setProperty("downgrade", false);
mapper.map(objectToConvert, targetObject, context);
return new V2Convertible(targetObject, UPPER_VERSION);
}
use of ma.glasnost.orika.MappingContext in project ORCID-Source by ORCID.
the class VersionConverterImplV2_0ToV2_1 method downgrade.
@Override
public V2Convertible downgrade(V2Convertible objectToDowngrade) {
Object objectToConvert = objectToDowngrade.getObjectToConvert();
Object targetObject = v2VersionObjectFactory.createEquivalentInstance(objectToConvert, LOWER_VERSION);
MappingContext context = new MappingContext.Factory().getContext();
context.setProperty("downgrade", true);
mapper.map(objectToConvert, targetObject, context);
return new V2Convertible(targetObject, LOWER_VERSION);
}
Aggregations