Exemplo n.º 1
0
        /// <summary>
        /// If a source is tagged as polymorphic source, get the list of original source
        /// </summary>
        /// <param name="projDir"></param>
        /// <param name="ctx"></param>
        /// <param name="source"></param>
        /// <param name="attrCtxParam"></param>
        /// <returns></returns>
        internal static Dictionary <string, List <ProjectionAttributeState> > GetPolymorphicSourceSet(
            ProjectionDirective projDir,
            CdmCorpusContext ctx,
            CdmEntityReference source,
            ResolvedAttributeSet rasSource)
        {
            Dictionary <string, List <ProjectionAttributeState> > polySources = new Dictionary <string, List <ProjectionAttributeState> >();

            // TODO (sukanyas): when projection based polymorphic source is made available - the following line will have to be changed
            // for now assuming non-projections based polymorphic source
            CdmEntityDefinition sourceDef = source.FetchObjectDefinition <CdmEntityDefinition>(projDir.ResOpt);

            foreach (CdmAttributeItem attr in sourceDef.Attributes)
            {
                if (attr.ObjectType == CdmObjectType.EntityAttributeDef)
                {
                    // the attribute context for this entity typed attribute was already created by the `FetchResolvedAttributes` that happens before this function call.
                    // we are only interested in linking the attributes to the entity that they came from and the attribute context nodes should not be taken into account.
                    // create this dummy attribute context so the resolution code works properly and discard it after.
                    AttributeContextParameters attrCtxParam = new AttributeContextParameters
                    {
                        Regarding = attr,
                        type      = CdmAttributeContextType.PassThrough,
                        under     = new CdmAttributeContext(ctx, "discard")
                    };
                    ResolvedAttributeSet raSet = ((CdmEntityAttributeDefinition)attr).FetchResolvedAttributes(projDir.ResOpt, attrCtxParam);
                    foreach (ResolvedAttribute resAttr in raSet.Set)
                    {
                        // we got a null ctx because null was passed in to fetch, but the nodes are in the parent's tree
                        // so steal them based on name
                        var resAttSrc = rasSource.Get(resAttr.ResolvedName);
                        if (resAttSrc != null)
                        {
                            resAttr.AttCtx = resAttSrc.AttCtx;
                        }

                        ProjectionAttributeState projAttrState = new ProjectionAttributeState(ctx)
                        {
                            CurrentResolvedAttribute = resAttr,
                            PreviousStateList        = null
                        };

                        // the key doesn't exist, initialize with an empty list first
                        if (!polySources.ContainsKey(resAttr.ResolvedName))
                        {
                            polySources[resAttr.ResolvedName] = new List <ProjectionAttributeState>();
                        }
                        polySources[resAttr.ResolvedName].Add(projAttrState);
                    }
                }
            }

            return(polySources);
        }
Exemplo n.º 2
0
        /// <summary>
        /// If a source is tagged as polymorphic source, get the list of original source
        /// </summary>
        /// <param name="projDir"></param>
        /// <param name="ctx"></param>
        /// <param name="source"></param>
        /// <param name="attrCtxParam"></param>
        /// <returns></returns>
        internal static Dictionary <string, List <ProjectionAttributeState> > GetPolymorphicSourceSet(
            ProjectionDirective projDir,
            CdmCorpusContext ctx,
            CdmEntityReference source,
            ResolvedAttributeSet rasSource,
            AttributeContextParameters attrCtxParam)
        {
            Dictionary <string, List <ProjectionAttributeState> > polySources = new Dictionary <string, List <ProjectionAttributeState> >();

            // TODO (sukanyas): when projection based polymorphic source is made available - the following line will have to be changed
            // for now assuming non-projections based polymorphic source
            CdmEntityDefinition sourceDef = source.FetchObjectDefinition <CdmEntityDefinition>(projDir.ResOpt);

            foreach (CdmAttributeItem attr in sourceDef.Attributes)
            {
                if (attr.ObjectType == CdmObjectType.EntityAttributeDef)
                {
                    ResolvedAttributeSet raSet = ((CdmEntityAttributeDefinition)attr).FetchResolvedAttributes(projDir.ResOpt, null);
                    foreach (ResolvedAttribute resAttr in raSet.Set)
                    {
                        // we got a null ctx because null was passed in to fetch, but the nodes are in the parent's tree
                        // so steal them based on name
                        var resAttSrc = rasSource.Get(resAttr.ResolvedName);
                        if (resAttSrc != null)
                        {
                            resAttr.AttCtx = resAttSrc.AttCtx;
                        }

                        ProjectionAttributeState projAttrState = new ProjectionAttributeState(ctx)
                        {
                            CurrentResolvedAttribute = resAttr,
                            PreviousStateList        = null
                        };

                        // the key already exists, just add to the existing list
                        if (polySources.ContainsKey(resAttr.ResolvedName))
                        {
                            List <ProjectionAttributeState> exisitingSet = polySources[resAttr.ResolvedName];
                            exisitingSet.Add(projAttrState);
                            polySources[resAttr.ResolvedName] = exisitingSet;
                        }
                        else
                        {
                            List <ProjectionAttributeState> pasList = new List <ProjectionAttributeState>();
                            pasList.Add(projAttrState);
                            polySources.Add(resAttr.ResolvedName, pasList);
                        }
                    }
                }
            }

            return(polySources);
        }