Пример #1
0
        /// <summary>
        /// Retrieve the Dimension references from mapping store
        /// </summary>
        /// <param name="parentSysId">
        /// The DSD primary key in the Mapping Store Database
        /// </param>
        /// <returns>
        /// The <see cref="IDictionaryOfSets{String, String}"/>.
        /// </returns>
        private IDictionaryOfSets <string, string> GetAttributeDimensionRefs(long parentSysId)
        {
            IDictionaryOfSets <string, string> mappedAttributes = new DictionaryOfSets <string, string>(StringComparer.Ordinal);

            using (DbCommand command = this._commandBuilder.Build(new ItemSqlQuery(this._attributeDimensionRefsInfo, parentSysId)))
            {
                using (IDataReader dataReader = this.MappingStoreDb.ExecuteReader(command))
                {
                    while (dataReader.Read())
                    {
                        string currGroupId = DataReaderHelper.GetString(dataReader, "AID");

                        ISet <string> dimensionList;
                        if (!mappedAttributes.TryGetValue(currGroupId, out dimensionList))
                        {
                            dimensionList = new HashSet <string>(StringComparer.Ordinal);
                            mappedAttributes.Add(currGroupId, dimensionList);
                        }

                        dimensionList.Add(DataReaderHelper.GetString(dataReader, "DID"));
                    }
                }
            }

            return(mappedAttributes);
        }
Пример #2
0
        /// <summary>
        /// Resolves all references and returns a Map containing all the input beans and the objects that are cross referenced,
        ///     the Map's key set contains the Identifiable that is the referencing object and the Map's value collection contains the referenced artifacts.
        /// </summary>
        /// <param name="beans">
        /// - the <see cref="IMutableObjects"/> container, containing all the beans to check references for
        /// </param>
        /// <param name="numberLevelsDeep">
        /// references, an argument of 0 (zero) implies there is no limit, and the resolver engine will continue re-cursing until it has found every directly and indirectly referenced artifact. Note that there is no risk of infinite recursion in calling this.
        /// </param>
        /// <param name="retrievalManager">
        /// - Used to resolve the structure references. Can be null, if supplied this is used to resolve any references that do not exist in the supplied beans
        /// </param>
        /// <returns>
        /// Map of referencing versus  references
        /// </returns>
        /// <exception cref="SdmxReferenceException">
        /// - if any of the references could not be resolved
        /// </exception>
        public MaintainableDictionary <IMaintainableMutableObject> ResolveReferences(
            IMutableObjects beans, int numberLevelsDeep, Func <IStructureReference, IMaintainableMutableObject> retrievalManager)
        {
            var missingReferences = new DictionaryOfSets <IMaintainableMutableObject, IStructureReference>(MaintainableMutableComparer.Instance);
            var returnMap         = this.ResolveReferencesInternal(beans, numberLevelsDeep, retrievalManager, missingReferences);

            if (missingReferences.Count > 0)
            {
                var keyValuePair = missingReferences.First();
                throw new SdmxReferenceException(keyValuePair.Key.ImmutableInstance, keyValuePair.Value.FirstOrDefault());
            }

            return(returnMap);
        }
        /// <summary>
        /// Returns a set of MaintainableObject that are cross referenced by the given identifiable structure
        /// </summary>
        /// <param name="identifiable">
        /// The identifiable object to retrieve the references for - What Do I Reference?
        /// </param>
        /// <param name="returnStub">
        /// ReturnStub if true, then will return the stubs that reference the structure
        /// </param>
        /// <param name="structures">
        /// Structures an optional parameter to further filter the list by structure type
        /// </param>
        /// <returns>
        /// The MaintainableObjects
        /// </returns>
        public ISet<IMaintainableObject> GetCrossReferencedStructures(IIdentifiableObject identifiable, bool returnStub, params SdmxStructureType[] structures)
        {
            ISet<IMaintainableObject> returnList = new HashSet<IMaintainableObject>();
            IDictionaryOfSets<SdmxStructureEnumType, IMaintainableRefObject> map = new DictionaryOfSets<SdmxStructureEnumType, IMaintainableRefObject>();
            foreach (var crossReference in identifiable.CrossReferences)
            {
                ISet<IMaintainableRefObject> references;
                if (!map.TryGetValue(crossReference.MaintainableStructureEnumType.EnumType, out references))
                {
                    references = new HashSet<IMaintainableRefObject>();
                    map.Add(crossReference.MaintainableStructureEnumType.EnumType, references);
                }

                if (references.Contains(crossReference.MaintainableReference))
                {
                    continue;
                }

                references.Add(crossReference.MaintainableReference);

                IMaintainableObject maint = this._sdmxObjectRetrievalManager.GetMaintainableObject(crossReference, returnStub, false);
                if (!returnList.Contains(maint))
                {
                    returnList.Add(maint);
                }
            }

            return returnList;
        }
        /// <summary>
        /// Resolves all references and returns a Map containing all the input beans and the objects that are cross referenced,
        ///     the Map's key set contains the Identifiable that is the referencing object and the Map's value collection contains the referenced artifacts.
        /// </summary>
        /// <param name="beans">
        /// - the <see cref="IMutableObjects"/> container, containing all the beans to check references for
        /// </param>
        /// <param name="numberLevelsDeep">
        /// references, an argument of 0 (zero) implies there is no limit, and the resolver engine will continue re-cursing until it has found every directly and indirectly referenced artifact. Note that there is no risk of infinite recursion in calling this.
        /// </param>
        /// <param name="retrievalManager">
        /// - Used to resolve the structure references. Can be null, if supplied this is used to resolve any references that do not exist in the supplied beans
        /// </param>
        /// <returns>
        /// Map of referencing versus  references
        /// </returns>
        /// <exception cref="SdmxReferenceException">
        /// - if any of the references could not be resolved
        /// </exception>
        public MaintainableDictionary<IMaintainableMutableObject> ResolveReferences(
            IMutableObjects beans, int numberLevelsDeep, Func<IStructureReference, IMaintainableMutableObject> retrievalManager)
        {
            var missingReferences = new DictionaryOfSets<IMaintainableMutableObject, IStructureReference>(MaintainableMutableComparer.Instance);
            var returnMap = this.ResolveReferencesInternal(beans, numberLevelsDeep, retrievalManager, missingReferences);
            if (missingReferences.Count > 0)
            {
                var keyValuePair = missingReferences.First();
                throw new SdmxReferenceException(keyValuePair.Key.ImmutableInstance, keyValuePair.Value.FirstOrDefault());
            }

            return returnMap;
        }
        /// <summary>
        /// Get subset workspace from <paramref name="query"/>
        /// </summary>
        /// <param name="query">
        /// The query.
        /// </param>
        /// <returns>
        /// The <see cref="IStructureWorkspace"/>.
        /// </returns>
        public virtual IStructureWorkspace GetSubsetWorkspace(params IStructureReference[] query)
        {
            ISet<IMaintainableObject> maintainablesSubset = new HashSet<IMaintainableObject>();
            IDictionaryOfSets<IIdentifiableObject, IIdentifiableObject> crossReferencedSubset = new DictionaryOfSets<IIdentifiableObject, IIdentifiableObject>();

            for (int i = 0; i < query.Length; i++)
            {
                IStructureReference currentQuery = query[i];
                ISet<IMaintainableObject> maintainableForStructure =
                    this._sdmxObjects.GetMaintainables(currentQuery.MaintainableStructureEnumType.EnumType);
                ISet<IMaintainableObject> maintainableMatches =
                    MaintainableUtil<IMaintainableObject>.FindMatches(maintainableForStructure, currentQuery);
                maintainablesSubset.AddAll(maintainableMatches);

                /* foreach */
                foreach (IMaintainableObject currentMatch in maintainableMatches)
                {
                    ISet<IIdentifiableObject> identifiables = (this._crossReferencedObjects == null)
                                                                  ? (new HashSet<IIdentifiableObject>())
                                                                  : this._crossReferencedObjects[currentMatch];
                    if (identifiables != null)
                    {
                        crossReferencedSubset.Add(currentMatch, identifiables);
                    }
                }
            }

            ISdmxObjects beansSubset = new SdmxObjectsImpl(this._sdmxObjects.Header, maintainablesSubset);
            return new StructureWorkspace(beansSubset, crossReferencedSubset);
        }