public static Locale MapLanguageToLocale(LanguageInfo source, AbstractLookupHelper lookupHelper, AbstractMappingEngine masterMapper) { var output = new Locale(); // var output = GetObjectReference(source.Alias.EncodeAsGuid(), lookupHelper, () => new Locale()); MapLanguageToLocale(source, output, lookupHelper, masterMapper); return(output); }
/// <summary> /// Used to map AttributeTypes when mapping to the EntitySchema /// </summary> /// <param name="attributeType"></param> /// <param name="lookupHelper"></param> /// <param name="masterMapper"></param> /// <param name="attributeTypeCache">A local cache to resolve already resolved AttributeTypes</param> /// <returns></returns> private Model.Attribution.MetaData.AttributeType MapAttributeTypeDefinition( AttributeType attributeType, AbstractLookupHelper lookupHelper, AbstractMappingEngine masterMapper, ICollection <Model.Attribution.MetaData.AttributeType> attributeTypeCache = null) { //check if its already been resolved by alias if (attributeTypeCache != null) { var found = attributeTypeCache.SingleOrDefault(x => (Guid)x.Id.Value == attributeType.Id); if (found != null) { return(found); } } //TODO: //- Remove Ordinal, SerializationType, Status, Dates //- Add PreValue xml //- var mapped = new Model.Attribution.MetaData.AttributeType(); MapAttributeTypeDefinition(attributeType, mapped, lookupHelper, masterMapper); //add the mapped object to the cache if it exists if (attributeTypeCache != null) { attributeTypeCache.Add(mapped); } return(mapped); }
public static NodeVersionStatusType MapStatusType(RevisionStatusType source, AbstractLookupHelper lookupHelper, AbstractMappingEngine masterMapper) { var output = GetObjectReference(source.Id, lookupHelper, () => new NodeVersionStatusType()); MapStatusType(source, output, lookupHelper, masterMapper); return(output); }
public Revision <TypedEntity> MapRevision(NodeVersion source, AbstractLookupHelper lookupHelper, AbstractMappingEngine masterMapper) { var output = new Revision <TypedEntity>(); MapRevision(source, output, lookupHelper, masterMapper); return(output); }
private IEnumerable <Relation> PopulateIncomingRelations( Node source, IRelatableEntity destination, IRelatableEntity relatableEntitySource, AbstractLookupHelper lookupHelper, AbstractMappingEngine masterMapper) { foreach (var relation in source.IncomingRelations) { if (relation.StartNode.Id == relation.EndNode.Id) { throw new InvalidOperationException("Cannot relate nodes to themselves"); } var startRelatedEntity = relation.StartNode.Id == (Guid)destination.Id.Value ? destination : GetEntityFromNodeRelation(relation.StartNode, lookupHelper, masterMapper); yield return(new Relation(new RelationType(relation.NodeRelationType.Alias), startRelatedEntity, relatableEntitySource, relation.Ordinal, relation.NodeRelationTags.Select(nodeRelationTag => new RelationMetaDatum(nodeRelationTag.Name, nodeRelationTag.Value)).ToArray())); } }
public TypedEntity MapTypedEntityForRevision(NodeVersion node, AbstractLookupHelper lookupHelper, AbstractMappingEngine masterMapper) { var mapped = new TypedEntity(); MapTypedEntityForRevision(node, mapped, lookupHelper, masterMapper); return(mapped); }
public static NodeVersion MapFromRevision(Revision <TypedEntity> source, AbstractLookupHelper lookupHelper, AbstractMappingEngine masterMapper) { var output = GetObjectReference(source.MetaData.Id, lookupHelper, () => new NodeVersion()); MapFromRevision(source, output, lookupHelper, masterMapper); return(output); }
public Model.Attribution.MetaData.AttributeDefinition MapAttributeDefinition( AttributeDefinition attributeDefinition, AbstractLookupHelper lookupHelper, AbstractMappingEngine masterMapper) { return(MapAttributeDefinition(attributeDefinition, lookupHelper, masterMapper, null)); }
public LanguageInfo MapLocaleToLanguage(Locale source, AbstractLookupHelper lookupHelper, AbstractMappingEngine masterMapper) { var output = new LanguageInfo(); MapLocaleToLanguage(source, output, lookupHelper, masterMapper); return(output); }
public static NodeVersion MapTypedEntityForRevision(TypedEntity typedEntity, AbstractLookupHelper lookupHelper, AbstractMappingEngine masterMapper) { var mapped = new NodeVersion(); MapTypedEntityForRevision(typedEntity, mapped, lookupHelper, masterMapper); return(mapped); }
public void MapLocaleToLanguage(Locale source, LanguageInfo destination, AbstractLookupHelper lookupHelper, AbstractMappingEngine masterMapper) { destination.Alias = source.Alias; destination.Name = source.Name; destination.Key = source.LanguageIso; // TODO: Refactor LanguageInfo to just use Alias destination.InferCultureFromKey(); // TODO: Lookup Fallbacks using a delegate to the Localization system }
/// <summary> /// Returns an IRelatableEntity based on a Node, used in the Populate relations methods /// </summary> /// <param name="relationNode"></param> /// <param name="lookupHelper"></param> /// <param name="masterMapper"></param> /// <returns></returns> private IRelatableEntity GetEntityFromNodeRelation(Node relationNode, AbstractLookupHelper lookupHelper, AbstractMappingEngine masterMapper) { //NOTE: The type check only works when you have NH's Lazy load configuration for relations set to "no-proxy"! return((relationNode is AttributeSchemaDefinition) ? MapAttributeSchemaDefinition((AttributeSchemaDefinition)relationNode, lookupHelper, masterMapper) : (IRelatableEntity)MapTypedEntityForRevision(GetMostRecentVersion(relationNode), lookupHelper, masterMapper)); }
public void MapAttributeDefinition( AttributeDefinition source, Model.Attribution.MetaData.AttributeDefinition destination, AbstractLookupHelper lookupHelper, AbstractMappingEngine masterMapper) { MapAttributeDefinition(source, destination, lookupHelper, masterMapper, null); }
/// <summary> /// Gets a reference to an object if it already exists in the set maintained by the lookup helper, otherwise calls a factory to create a new instance. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="id">The id.</param> /// <param name="lookupHelper">The lookup helper.</param> /// <param name="factory">The factory.</param> /// <returns></returns> /// <remarks></remarks> private static T GetObjectReference <T>(HiveId id, AbstractLookupHelper lookupHelper, Func <T> factory) where T : class, IReferenceByGuid { T output = null; if (!id.IsNullValueOrEmpty()) { output = lookupHelper.Lookup <T>(id); } return(output ?? factory.Invoke()); }
public static Attribute MapAttribute(TypedAttribute attribute, AbstractLookupHelper lookupHelper, AbstractMappingEngine masterMapper) { //TODO: //- Remove Dates //- Add Ordinal to Rdbms for sorting within a tab var mapped = GetObjectReference(attribute.Id, lookupHelper, () => new Attribute()); MapAttribute(attribute, mapped, lookupHelper, masterMapper); return(mapped); }
public TypedAttribute MapAttribute(Attribute attribute, AbstractLookupHelper lookupHelper, AbstractMappingEngine masterMapper) { //TODO: //- Remove Dates //- Add Ordinal to Rdbms for sorting within a tab var mapped = new TypedAttribute(); MapAttribute(attribute, mapped, lookupHelper, masterMapper); return(mapped); }
/// <summary> /// Used to map attribute definitions when mapping the EntitySchema /// </summary> /// <param name="attributeDefinition"></param> /// <param name="lookupHelper"></param> /// <param name="masterMapper"></param> /// <param name="attributeTypeCache">A local cache object to resolve already resolved AttributeTypes</param> /// <returns></returns> private Model.Attribution.MetaData.AttributeDefinition MapAttributeDefinition( AttributeDefinition attributeDefinition, AbstractLookupHelper lookupHelper, AbstractMappingEngine masterMapper, ICollection <Model.Attribution.MetaData.AttributeType> attributeTypeCache) { //TODO: //- Add ConcurrencyToken to Rdbms model //- Remove Status, Dates var mapped = new Model.Attribution.MetaData.AttributeDefinition(); MapAttributeDefinition(attributeDefinition, mapped, lookupHelper, masterMapper, attributeTypeCache); return(mapped); }
/// <summary> /// Used to map attribute definitions when mapping the EntitySchema /// </summary> /// <param name="source"></param> /// <param name="destination"></param> /// <param name="lookupHelper"></param> /// <param name="masterMapper"></param> /// <param name="attributeTypeCache">A local cache object to resolve already resolved AttributeTypes</param> private void MapAttributeDefinition( AttributeDefinition source, Model.Attribution.MetaData.AttributeDefinition destination, AbstractLookupHelper lookupHelper, AbstractMappingEngine masterMapper, ICollection <Model.Attribution.MetaData.AttributeType> attributeTypeCache = null) { destination.Ordinal = source.Ordinal; destination.Alias = source.Alias; destination.AttributeType = MapAttributeTypeDefinition(source.AttributeType, lookupHelper, masterMapper, attributeTypeCache); destination.Id = (HiveId)source.Id; destination.Name = source.Name; destination.Description = source.Description; destination.RenderTypeProviderConfigOverride = source.XmlConfiguration; destination.AttributeGroup = MapAttributeGroupDefinition(source.AttributeDefinitionGroup, lookupHelper, masterMapper); }
private void OldMapRelations <T>(T source, IRelatableEntity destination, AbstractLookupHelper lookupHelper, AbstractMappingEngine masterMapper) where T : Node { //destination.Relations.Clear(); //destination.Relations.LazyLookAhead = (axis) => //{ // switch (axis) // { // case HierarchyScope.Children: // case HierarchyScope.Descendents: // case HierarchyScope.DescendentsOrSelf: // return CheckCountOutgoingRelations(source, destination, lookupHelper, masterMapper); // case HierarchyScope.AllOrNone: // return // CheckCountIncomingRelations(source, destination, lookupHelper, masterMapper) + // CheckCountOutgoingRelations(source, destination, lookupHelper, masterMapper); // case HierarchyScope.Ancestors: // case HierarchyScope.AncestorsOrSelf: // return CheckCountIncomingRelations(source, destination, lookupHelper, masterMapper); // } // return 0; //}; //destination.Relations.LazyLoadFactory = (relatableEntitySource, axis) => //{ // switch (axis) // { // case HierarchyScope.Children: // case HierarchyScope.Descendents: // case HierarchyScope.DescendentsOrSelf: // return PopulateOutgoingRelations(source, destination, relatableEntitySource, lookupHelper, masterMapper); // case HierarchyScope.AllOrNone: // return PopulateIncomingRelations(source, destination, relatableEntitySource, lookupHelper, masterMapper) // .Concat(PopulateOutgoingRelations(source, destination, relatableEntitySource, lookupHelper, masterMapper)); // case HierarchyScope.Ancestors: // case HierarchyScope.AncestorsOrSelf: // return PopulateIncomingRelations(source, destination, relatableEntitySource, lookupHelper, masterMapper); // } // return Enumerable.Empty<Relation>(); //}; }
private static void MapRelations(Node enclosingNode, IRelatableEntity source, AbstractLookupHelper lookupHelper, AbstractMappingEngine masterMapper) { /* Temporary: do nothing */ return; }
public static void MapTypedEntityForRevision(TypedEntity source, NodeVersion destinationVersion, AbstractLookupHelper lookupHelper, AbstractMappingEngine masterMapper) { // Map the parent node of the node-version var enclosingNode = destinationVersion.Node; if (enclosingNode == null) { enclosingNode = new Node(); destinationVersion.Node = enclosingNode; enclosingNode.NodeVersions.Add(destinationVersion); } enclosingNode.DateCreated = source.UtcCreated; enclosingNode.Id = (Guid)source.Id.Value; MapVersion(source, destinationVersion, enclosingNode, lookupHelper, masterMapper); //destinationNode.NodeVersions.Add(nodeVersion); MapRelations(enclosingNode, source, lookupHelper, masterMapper); }
public static AttributeSchemaDefinition MapAttributeSchemaDefinition(EntitySchema entitySchema, AbstractLookupHelper lookupHelper, AbstractMappingEngine masterMapper) { var rdbmsMapped = GetObjectReference(entitySchema.Id, lookupHelper, () => new AttributeSchemaDefinition()); MapAttributeSchemaDefinition(entitySchema, rdbmsMapped, lookupHelper, masterMapper); return(rdbmsMapped); }
public static void MapAttributeSchemaDefinition(EntitySchema source, AttributeSchemaDefinition destinationSchema, AbstractLookupHelper lookupHelper, AbstractMappingEngine masterMapper) { destinationSchema.Alias = source.Alias; destinationSchema.Id = (Guid)source.Id.Value; destinationSchema.Name = source.Name; destinationSchema.DateCreated = source.UtcCreated; destinationSchema.XmlConfiguration = source.XmlConfiguration.ToString(); destinationSchema.SchemaType = source.SchemaType; // Find groups in both source and destination that exist, and remap them at the destination // Then find groups only at the source, and add them // Then find groups only at the destination, and remove them var groupsToRemove = MergeMapCollections( source.AttributeGroups, destinationSchema.AttributeDefinitionGroups, (sourceGroup, destGroup) => MapAttributeDefinitionGroup(sourceGroup, destGroup, lookupHelper, masterMapper), sourceGroup => MapAttributeDefinitionGroup(sourceGroup, lookupHelper, masterMapper), (sourceGroup, destGroup) => destGroup.AttributeSchemaDefinition = destinationSchema, (sourceGroup, destGroup) => sourceGroup.Alias == destGroup.Alias ); // Now do the same for the attribute definitions var defsToRemove = MergeMapCollections( source.AttributeDefinitions, destinationSchema.AttributeDefinitions, (sourceDef, destDef) => MapAttributeDefinition(sourceDef, destDef, lookupHelper, masterMapper), sourceDef => MapAttributeDefinition(sourceDef, lookupHelper, masterMapper), (sourceDef, destDef) => { destDef.AttributeSchemaDefinition = destinationSchema; if (sourceDef.AttributeGroup == null) { return; } var localDefCopy = sourceDef; var mappedGroup = destinationSchema.AttributeDefinitionGroups.Single(x => x.Alias == localDefCopy.AttributeGroup.Alias); destDef.AttributeDefinitionGroup = mappedGroup; }, (sourceGroup, destGroup) => sourceGroup.Alias == destGroup.Alias ); // Hack for beta: make sure if there are any remaining AttributeDefinitions referenced via a group, but not in the AttributeDefinitions collection, // we delete it from the group var defsToDelete = new List <AttributeDefinition>(); foreach (var attributeDefinitionGroup in destinationSchema.AttributeDefinitionGroups) { foreach (var attributeDefinition in attributeDefinitionGroup.AttributeDefinitions) { if (!destinationSchema.AttributeDefinitions.Contains(attributeDefinition)) { defsToDelete.Add(attributeDefinition); } } } foreach (var attributeDefinition in defsToDelete) { foreach (var attributeDefinitionGroup in destinationSchema.AttributeDefinitionGroups) { attributeDefinitionGroup.AttributeDefinitions.Remove(attributeDefinition); } } MapRelations(destinationSchema, source, lookupHelper, masterMapper); }
public static IEnumerable <AttributeDefinitionGroup> MapAttributeDefinitionGroups(IEnumerable <AttributeGroup> source, AbstractLookupHelper lookupHelper, AbstractMappingEngine masterMapper) { return(source.Select(x => MapAttributeDefinitionGroup(x, lookupHelper, masterMapper))); }
public static AttributeDefinitionGroup MapAttributeDefinitionGroup(AttributeGroup attributeGroup, AbstractLookupHelper lookupHelper, AbstractMappingEngine masterMapper) { var mapped = GetObjectReference(attributeGroup.Id, lookupHelper, () => new AttributeDefinitionGroup()); MapAttributeDefinitionGroup(attributeGroup, mapped, lookupHelper, masterMapper); return(mapped); }
public static void MapAttributeDefinitionGroup(AttributeGroup source, AttributeDefinitionGroup destination, AbstractLookupHelper lookupHelper, AbstractMappingEngine masterMapper) { destination.Alias = source.Alias; destination.Id = (Guid)source.Id.Value; destination.Name = source.Name; destination.DateCreated = source.UtcCreated; destination.Ordinal = source.Ordinal; }
public static IEnumerable <Attribute> MapAttributes(IEnumerable <TypedAttribute> attributes, AbstractLookupHelper lookupHelper, AbstractMappingEngine masterMapper) { return(attributes.Select(x => MapAttribute(x, lookupHelper, masterMapper))); }
public static void MapAttribute(TypedAttribute source, Attribute destination, AbstractLookupHelper lookupHelper, AbstractMappingEngine masterMapper) { destination.AttributeDefinition = MapAttributeDefinition(source.AttributeDefinition, lookupHelper, masterMapper); destination.Id = (Guid)source.Id.Value; var mapLanguageToLocale = MapLanguageToLocale(FixedLocales.Default, lookupHelper, masterMapper); Func <string, bool> keyNotFoundPredicate = x => source.Values.All(y => y.Key != x); destination.AttributeStringValues.RemoveAll(x => keyNotFoundPredicate.Invoke(x.ValueKey)); destination.AttributeDecimalValues.RemoveAll(x => keyNotFoundPredicate.Invoke(x.ValueKey)); destination.AttributeLongStringValues.RemoveAll(x => keyNotFoundPredicate.Invoke(x.ValueKey)); destination.AttributeIntegerValues.RemoveAll(x => keyNotFoundPredicate.Invoke(x.ValueKey)); destination.AttributeDateValues.RemoveAll(x => keyNotFoundPredicate.Invoke(x.ValueKey)); foreach (var value in source.Values) { switch (source.AttributeDefinition.AttributeType.SerializationType.DataSerializationType) { case DataSerializationTypes.LongString: var longString = destination.AttributeLongStringValues.FirstOrDefault(x => x.ValueKey == value.Key) ?? new AttributeLongStringValue() { Locale = mapLanguageToLocale, ValueKey = value.Key, Attribute = destination }; if (value.Value != null) { longString.Value = value.Value.ToString(); } destination.AttributeLongStringValues.Add(longString); break; case DataSerializationTypes.Boolean: case DataSerializationTypes.SmallInt: case DataSerializationTypes.LargeInt: var intVal = destination.AttributeIntegerValues.FirstOrDefault(x => x.ValueKey == value.Key) ?? new AttributeIntegerValue() { Locale = mapLanguageToLocale, ValueKey = value.Key, Attribute = destination }; if (value.Value != null) { intVal.Value = Convert.ToInt32(value.Value); } destination.AttributeIntegerValues.Add(intVal); break; case DataSerializationTypes.Decimal: var decimalValue = destination.AttributeDecimalValues.FirstOrDefault(x => x.ValueKey == value.Key) ?? new AttributeDecimalValue() { Locale = mapLanguageToLocale, ValueKey = value.Key, Attribute = destination }; if (value.Value != null) { decimalValue.Value = (int)value.Value; } destination.AttributeDecimalValues.Add(decimalValue); break; case DataSerializationTypes.Date: var dateVal = destination.AttributeDateValues.FirstOrDefault(x => x.ValueKey == value.Key) ?? new AttributeDateValue() { Locale = mapLanguageToLocale, ValueKey = value.Key, Attribute = destination }; if (value.Value != null) { if (value.Value is DateTimeOffset) { dateVal.Value = (DateTimeOffset)value.Value; } else if (value.Value is DateTime) { dateVal.Value = new DateTimeOffset((DateTime)value.Value); } } destination.AttributeDateValues.Add(dateVal); break; case DataSerializationTypes.String: default: var shortString = destination.AttributeStringValues.FirstOrDefault(x => x.ValueKey == value.Key) ?? new AttributeStringValue() { Locale = mapLanguageToLocale, ValueKey = value.Key, Attribute = destination }; if (value.Value != null) { shortString.Value = value.Value.ToString(); } destination.AttributeStringValues.Add(shortString); break; } } }
public static void MapFromRevision(Revision <TypedEntity> source, NodeVersion destination, AbstractLookupHelper lookupHelper, AbstractMappingEngine masterMapper) { var masterNode = destination; if (masterNode == null) { MapTypedEntityForRevision(source.Item, lookupHelper, masterMapper); } else { MapTypedEntityForRevision(source.Item, masterNode, lookupHelper, masterMapper); } // Overwrite the default status history that was created by MapVersion // since in this mapping method, we actually have real revision info // The MapVersion method, in lieu of any data about a revision, adds a status history of "Created", which we can remove var revisionData = source.MetaData; var rdbmsStatusHistory = CreateRdbmsStatusHistory(destination, revisionData, lookupHelper, masterMapper); var createdStatusHistory = destination.NodeVersionStatuses.FirstOrDefault(x => x.NodeVersionStatusType.Alias == FixedStatusTypes.Created.Alias); if (createdStatusHistory != null) { destination.NodeVersionStatuses.Remove(createdStatusHistory); } destination.NodeVersionStatuses.Add(rdbmsStatusHistory); }
public ManualMapperv2(AbstractLookupHelper lookupHelper, ProviderMetadata hiveProvider) { _lookupHelper = lookupHelper; _hiveProvider = hiveProvider; _rdbmsToModelMapper = new RdbmsToModelMapper(_hiveProvider); }
public static AttributeDefinition MapAttributeDefinition(Model.Attribution.MetaData.AttributeDefinition attributeDefinition, AbstractLookupHelper lookupHelper, AbstractMappingEngine masterMapper) { Mandate.ParameterNotNull(attributeDefinition, "attributeDefinition"); var mapped = GetObjectReference(attributeDefinition.Id, lookupHelper, () => new AttributeDefinition()); MapAttributeDefinition(attributeDefinition, mapped, lookupHelper, masterMapper); return(mapped); }