public void WriteStructures(ISdmxObjects sdmxObjects)
        {
            foreach (var maintainableObject in sdmxObjects.GetAllMaintainables())
            {
                PrintMaintainable(maintainableObject);
            }

            Close();
        }
        /// <summary>
        /// Builds Mutable beans from a collection of beans
        /// </summary>
        /// <param name="buildFrom">
        /// beans to build from
        /// </param>
        /// <returns>
        /// Mutable bean copies
        /// </returns>
        /// <exception cref="BuilderException">
        /// - If anything goes wrong during the build process
        /// </exception>
        public virtual IMutableObjects Build(ISdmxObjects buildFrom)
        {
            IMutableObjects mutableBeans = new MutableObjectsImpl();

            /* foreach */
            foreach (IMaintainableObject currentMaintainable in buildFrom.GetAllMaintainables())
            {
                mutableBeans.AddIdentifiable(currentMaintainable.MutableInstance);
            }

            return mutableBeans;
        }
Exemplo n.º 3
0
        /// <summary>
        /// Gets Maintainable SDMX objects from workspace.
        /// </summary>
        /// <returns>Maintainable SDMX objects.</returns>
        private ISet <IMaintainableObject> GetMaintainableObjects()
        {
            IStructureWorkspace workspace;

            using (IReadableDataLocation rdl = this._readableDataLocation)
            {
                workspace = this._structureParsingManager.ParseStructures(rdl);
            }

            ISdmxObjects sdmxObjects = workspace.GetStructureObjects(false);

            ISet <IMaintainableObject> maintainable = sdmxObjects.GetAllMaintainables();

            return(maintainable);
        }
        /// <summary>
        /// The build success response.
        /// </summary>
        /// <param name="beans">
        /// The beans.
        /// </param>
        /// <returns>
        /// The <see cref="RegistryInterface"/>.
        /// </returns>
        public RegistryInterface BuildSuccessResponse(ISdmxObjects beans)
        {
            var responseType = new RegistryInterface();
            RegistryInterfaceType regInterface = responseType.Content;
            regInterface.Header = this._headerXmlsBuilder.Build(beans.Header);
            var returnType = new SubmitStructureResponseType();
            regInterface.SubmitStructureResponse = returnType;


            this.ProcessMaintainables(returnType, beans.GetAllMaintainables());
            return responseType;
        }
        /// <summary>
        /// Builds a success response along with the query results
        /// </summary>
        /// <param name="beans">
        /// - the beans that were successfully returned from the query
        /// </param>
        /// <param name="schemaVersion">
        /// - the version of the schema to output the response in
        /// </param>
        /// <param name="returnAsStructureMessage">
        /// returns a structure message if true, otherwise returns as a query structure response
        /// </param>
        /// <returns>
        /// The <see cref="XTypedElement"/>.
        /// </returns>
        public virtual XTypedElement BuildSuccessResponse(
            ISdmxObjects beans, SdmxSchemaEnumType schemaVersion, bool returnAsStructureMessage)
        {
            XTypedElement response = null;
            switch (schemaVersion)
            {
                case SdmxSchemaEnumType.VersionTwoPointOne:
                    if (beans.GetAllMaintainables().Count == 0)
                    {
                        response = this._errorResponseBuilder21.BuildErrorResponse(SdmxErrorCodeEnumType.NoResultsFound);
                    }

                    response = this._structV21Builder.Build(beans);
                    break;
                case SdmxSchemaEnumType.VersionTwo:
                    if (returnAsStructureMessage)
                    {
                        response = this._structv2Builder.Build(beans);
                    }

                    response = this._queryStructureResponseBuilderV2.BuildSuccessResponse(beans);
                    break;
                case SdmxSchemaEnumType.VersionOne:
                    response = this._structv1Builder.Build(beans);
                    break;
                default:
                    throw new SdmxNotImplementedException(ExceptionCode.Unsupported, schemaVersion);
            }
            base.WriteSchemaLocation(response, schemaVersion);
            return response;
        }
        /// <summary>
        /// Increments the versions of sdmx objects
        /// </summary>
        /// <param name="sdmxObjects">
        /// The sdmx objects.
        /// </param>
        public void IncrementVersions(ISdmxObjects sdmxObjects)
        {
            _log.Info("Update Versions of Structures if existing structures found");
            //Store a map of old versions vs the new version
            IDictionary<IStructureReference, IStructureReference> oldVsNew =
                new Dictionary<IStructureReference, IStructureReference>();
            IDictionary<IMaintainableObject, IMaintainableObject> oldMaintVsNew =
                new Dictionary<IMaintainableObject, IMaintainableObject>();
            ISet<IMaintainableObject> updatedMaintainables = new HashSet<IMaintainableObject>();
            ISet<IMaintainableObject> oldMaintainables = new HashSet<IMaintainableObject>();

            foreach (IMaintainableObject currentMaint in sdmxObjects.GetAllMaintainables())
            {
                _log.Debug("Auto Version - check latest version for maintainable: " + currentMaint);

                IMaintainableObject persistedMaintainable = this._structureVersionRetrievalManager.GetLatest(currentMaint);
                if (persistedMaintainable == null)
                {
                    persistedMaintainable = this._beanRetrievalManager.GetMaintainableObject(currentMaint.AsReference);
                }
                if (persistedMaintainable != null)
                {
                    if (VersionableUtil.IsHigherVersion(persistedMaintainable.Version, currentMaint.Version))
                    {
                        //Modify version of maintainable to be the same as persisted maintainable
                        IMaintainableMutableObject mutableInstance = currentMaint.MutableInstance;
                        mutableInstance.Version = persistedMaintainable.Version;

                        //Remove the Maintainable from the submission - as we've changed the versions
                        sdmxObjects.RemoveMaintainable(currentMaint);

                        //currentMaint = mutableInstance.ImmutableInstance;
                    }
                    if (persistedMaintainable.Version.Equals(currentMaint.Version))
                    {
                        _log.Debug("Latest version is '" + persistedMaintainable.Version + "' perform update checks");
                        if (!currentMaint.DeepEquals(persistedMaintainable, true))
                        {
                            ISet<IIdentifiableObject> allIdentifiables1 = currentMaint.IdentifiableComposites;
                            ISet<IIdentifiableObject> allIdentifiables2 = persistedMaintainable.IdentifiableComposites;

                            bool containsAll = allIdentifiables1.ContainsAll(allIdentifiables2)
                                               && allIdentifiables2.ContainsAll(allIdentifiables1);
                            if (_log.IsInfoEnabled)
                            {
                                string increment = containsAll ? "Minor" : "Major";
                                _log.Info("Perform " + increment + " Version Increment for structure:" + currentMaint.Urn);
                            }

                            //Increment the version number
                            IMaintainableObject newVersion = this.IncrmentVersion(
                                currentMaint, persistedMaintainable.Version, !containsAll);

                            //Remove the Maintainable from the submission
                            sdmxObjects.RemoveMaintainable(currentMaint);

                            //Store the newly updated maintainable in a container for further processing
                            updatedMaintainables.Add(newVersion);
                            oldMaintainables.Add(currentMaint);
                            //Store the old version number mappings to the new version number
                            oldMaintVsNew.Add(currentMaint, newVersion);
                            oldVsNew.Add(currentMaint.AsReference, newVersion.AsReference);

                            string oldVersionNumber = currentMaint.Version;
                            AddOldVsNewReferences(oldVersionNumber, newVersion, oldVsNew);
                        }
                    }
                }
            }

            //Create a set of parent sdmxObjects to not update (regardless of version)
            ISet<IMaintainableObject> filterSet = new HashSet<IMaintainableObject>(updatedMaintainables);
            filterSet.AddAll(sdmxObjects.GetAllMaintainables());

            //Get all the referencing structures to reversion them
            IEnumerable<IMaintainableObject> referencingStructures = this.RecurseUpTree(oldMaintainables, new HashSet<IMaintainableObject>(), filterSet);

            foreach (IMaintainableObject currentReferencingStructure in referencingStructures)
            {
                _log.Info("Perform Minor Version Increment on referencing structure:" + currentReferencingStructure);
                String newVersionNumber;
                if (oldMaintVsNew.ContainsKey(currentReferencingStructure))
                {
                    //The old maintainable is also in the submission and has had it's version number incremented, use this version
                    var tmp = oldMaintVsNew[currentReferencingStructure];
                    //currentReferencingStructure = oldMaintVsNew[currentReferencingStructure];
                    updatedMaintainables.Remove(tmp);
                    newVersionNumber = currentReferencingStructure.Version;
                }
                else
                {
                    newVersionNumber = VersionableUtil.IncrementVersion(currentReferencingStructure.Version, false);
                }
                IMaintainableObject updatedMaintainable =
                    this._crossReferenceReversionEngine.UdpateReferences(
                        currentReferencingStructure, oldVsNew, newVersionNumber);
                AddOldVsNewReferences(currentReferencingStructure.Version, updatedMaintainable, oldVsNew);

                updatedMaintainables.Add(updatedMaintainable);
            }

            foreach (IMaintainableObject currentReferencingStructure in updatedMaintainables)
            {
                IMaintainableObject updatedMaintainable =
                    this._crossReferenceReversionEngine.UdpateReferences(
                        currentReferencingStructure, oldVsNew, currentReferencingStructure.Version);
                sdmxObjects.AddIdentifiable(updatedMaintainable);
            }

            //Update the references of any structures that existed in the submission
            foreach (IMaintainableObject currentReferencingStructure in sdmxObjects.GetAllMaintainables())
            {
                IMaintainableObject updatedMaintainable =
                    this._crossReferenceReversionEngine.UdpateReferences(
                        currentReferencingStructure, oldVsNew, currentReferencingStructure.Version);
                sdmxObjects.AddIdentifiable(updatedMaintainable);
            }
        }
        /// <summary>
        /// Validates all the Maintainable Artefacts in the beans container are supported by the SDMX v1.0 syntax
        /// </summary>
        /// <param name="beans">
        /// The beans.
        /// </param>
        /// <exception cref="SdmxNotImplementedException">
        /// Structure not supported by SDMX-EDI
        /// </exception>
        private static void ValidateSupport(ISdmxObjects beans)
        {
            IList<SdmxStructureEnumType> supportedStructres = new List<SdmxStructureEnumType>();
            supportedStructres.Add(SdmxStructureEnumType.AgencyScheme);
            supportedStructres.Add(SdmxStructureEnumType.Dsd);
            supportedStructres.Add(SdmxStructureEnumType.ConceptScheme);
            supportedStructres.Add(SdmxStructureEnumType.CodeList);

            foreach (var maintainableBean in beans.GetAllMaintainables())
            {
                if (!supportedStructres.Contains(maintainableBean.StructureType.EnumType))
                {
                    throw new SdmxNotImplementedException(ExceptionCode.Unsupported, maintainableBean.StructureType.StructureType + " is not a supported by SDMX-EDI");
                }
            }
        }
        /// <summary>
        /// Build success response.
        /// </summary>
        /// <param name="buildFrom">
        /// The source sdmx objects.
        /// </param>
        /// <param name="warningMessage">
        /// The warning message.
        /// </param>
        /// <returns>
        /// The <see cref="RegistryInterface"/>.
        /// </returns>
        public RegistryInterface BuildSuccessResponse(ISdmxObjects buildFrom, string warningMessage)
        {

            // PLEASE NOTE. The code here is slightly different than in Java.
            // That is because of the differences between Java XmlBeans and .NET Linq2Xsd generated classes.
            // Please consult GIT log before making any changes.
            var responseType = new RegistryInterface();

            RegistryInterfaceType regInterface = responseType.Content;
            HeaderType headerType;

            if (buildFrom.Header != null)
            {
                headerType = this._headerXmlsBuilder.Build(buildFrom.Header);
                regInterface.Header = headerType;
            }
            else
            {
                headerType = new HeaderType();
                regInterface.Header = headerType;
                V2Helper.SetHeader(headerType, buildFrom);
            }
            
            var returnType = new QueryStructureResponseType();
            regInterface.QueryStructureResponse = returnType;

            var statusMessage = new StatusMessageType();
            returnType.StatusMessage = statusMessage;

            if (!string.IsNullOrWhiteSpace(warningMessage) || !ObjectUtil.ValidCollection(buildFrom.GetAllMaintainables()))
            {
                statusMessage.status = StatusTypeConstants.Warning;
                var tt = new TextType();
                statusMessage.MessageText.Add(tt);
                tt.TypedValue = !string.IsNullOrWhiteSpace(warningMessage)
                                    ? warningMessage
                                    : "No Structures Match The Query Parameters";
            }
            else
            {
                statusMessage.status = StatusTypeConstants.Success;
            }

            ISet<ICategorisationObject> categorisations = buildFrom.Categorisations;

            // GET CATEGORY SCHEMES
            if (buildFrom.CategorySchemes.Count > 0)
            {
                var catSchemesType = new CategorySchemesType();
                returnType.CategorySchemes = catSchemesType;

                /* foreach */
                foreach (ICategorySchemeObject cateogrySchemeBean in buildFrom.CategorySchemes)
                {
                    ISet<ICategorisationObject> matchingCategorisations = new HashSet<ICategorisationObject>();

                    /* foreach */
                    foreach (ICategorisationObject cat in categorisations)
                    {
                        if (MaintainableUtil<ICategorySchemeObject>.Match(cateogrySchemeBean, cat.CategoryReference))
                        {
                            matchingCategorisations.Add(cat);
                        }
                    }

                    catSchemesType.CategoryScheme.Add(
                        this._categorySchemeXmlBuilder.Build(cateogrySchemeBean, categorisations));
                }
            }

            // GET CODELISTS
            if (buildFrom.Codelists.Count > 0)
            {
                CodeListsType codeListsType = new CodeListsType();
                returnType.CodeLists = codeListsType;
                //CodeListsType codeListsType = returnType.CodeLists;

                /* foreach */
                foreach (ICodelistObject codelistBean in buildFrom.Codelists)
                {
                    codeListsType.CodeList.Add(this._codelistXmlBuilder.Build(codelistBean));
                }
            }

            // CONCEPT SCHEMES
            if (buildFrom.ConceptSchemes.Count > 0)
            {
                ConceptsType conceptsType =  new ConceptsType();
                returnType.Concepts = conceptsType;

                /* foreach */
                foreach (IConceptSchemeObject conceptSchemeBean in buildFrom.ConceptSchemes)
                {
                    conceptsType.ConceptScheme.Add(this._conceptSchemeXmlBuilder.Build(conceptSchemeBean));
                }
            }

            // DATAFLOWS
            if (buildFrom.Dataflows.Count > 0)
            {
                
                var dataflowsType =  new DataflowsType();
                returnType.Dataflows = dataflowsType;

                /* foreach */
                foreach (IDataflowObject currentBean in buildFrom.Dataflows)
                {
                    dataflowsType.Dataflow.Add(
                        this._dataflowXmlBuilder.Build(currentBean, GetCategorisations(currentBean, categorisations)));
                }
            }

            // HIERARCIC CODELIST
            if (buildFrom.HierarchicalCodelists.Count > 0)
            {
                HierarchicalCodelistsType hierarchicalCodelistsType = new HierarchicalCodelistsType();
                returnType.HierarchicalCodelists = hierarchicalCodelistsType;

                /* foreach */
                foreach (IHierarchicalCodelistObject currentBean0 in buildFrom.HierarchicalCodelists)
                {
                    hierarchicalCodelistsType.HierarchicalCodelist.Add(
                        this._hierarchicalCodelistXmlBuilder.Build(currentBean0));
                }
            }

            // KEY FAMILY
            if (buildFrom.DataStructures.Count > 0)
            {
                var keyFamiliesType = new KeyFamiliesType();
                returnType.KeyFamilies = keyFamiliesType;

                /* foreach */
                foreach (IDataStructureObject currentBean1 in buildFrom.DataStructures)
                {
                    keyFamiliesType.KeyFamily.Add(this._dataStructureXmlBuilder.Build(currentBean1));
                }
            }

            // METADATA FLOW
            if (buildFrom.Metadataflows.Count > 0)
            {
                var metadataflowsType = new MetadataflowsType();
                returnType.Metadataflows = metadataflowsType;

                /* foreach */
                foreach (IMetadataFlow currentBean2 in buildFrom.Metadataflows)
                {
                    metadataflowsType.Metadataflow.Add(
                        this._metadataflowXmlBuilder.Build(
                            currentBean2, GetCategorisations(currentBean2, categorisations)));
                }
            }

            // METADATA STRUCTURE
            if (buildFrom.MetadataStructures.Count > 0)
            {
                var msdsType = new MetadataStructureDefinitionsType();
                returnType.MetadataStructureDefinitions = msdsType;

                /* foreach */
                foreach (IMetadataStructureDefinitionObject currentBean3 in buildFrom.MetadataStructures)
                {
                    msdsType.MetadataStructureDefinition.Add(
                        this._metadataStructureDefinitionXmlsBuilder.Build(currentBean3));
                }
            }

            OrganisationSchemesType orgSchemesType = null;

            // AGENCY SCHEMES
            if (buildFrom.AgenciesSchemes.Count > 0)
            {
                orgSchemesType = new OrganisationSchemesType();
                returnType.OrganisationSchemes = orgSchemesType;

                /* foreach */
                foreach (IAgencyScheme currentBean4 in buildFrom.AgenciesSchemes)
                {
                    orgSchemesType.OrganisationScheme.Add(this._organisationSchemeXmlBuilder.Build(currentBean4));
                }
            }

            // DATA CONSUMER SCHEMES
            if (buildFrom.DataConsumerSchemes.Count > 0)
            {
                if (orgSchemesType == null)
                {
                    orgSchemesType = new OrganisationSchemesType();
                    returnType.OrganisationSchemes = orgSchemesType;
                }

                /* foreach */
                foreach (IDataConsumerScheme currentBean5 in buildFrom.DataConsumerSchemes)
                {
                    orgSchemesType.OrganisationScheme.Add(this._organisationSchemeXmlBuilder.Build(currentBean5));
                }
            }

            // DATA PROVIDER SCHEMES
            if (buildFrom.DataProviderSchemes.Count > 0)
            {
                if (orgSchemesType == null)
                {
                    orgSchemesType = new OrganisationSchemesType();
                    returnType.OrganisationSchemes = orgSchemesType;
                }

                /* foreach */
                foreach (IDataProviderScheme currentBean6 in buildFrom.DataProviderSchemes)
                {
                    orgSchemesType.OrganisationScheme.Add(this._organisationSchemeXmlBuilder.Build(currentBean6));
                }
            }

            // PROCESSES
            if (buildFrom.Processes.Count > 0)
            {
                var processesType = new ProcessesType();
                returnType.Processes = processesType;

                /* foreach */
                foreach (IProcessObject currentBean7 in buildFrom.Processes)
                {
                    processesType.Process.Add(this._processXmlBuilder.Build(currentBean7));
                }
            }

            // STRUCTURE SETS
            if (buildFrom.StructureSets.Count > 0)
            {
                var structureSetsType = new StructureSetsType();
                returnType.StructureSets = structureSetsType;

                /* foreach */
                foreach (IStructureSetObject currentBean8 in buildFrom.StructureSets)
                {
                    structureSetsType.StructureSet.Add(this._structureSetXmlBuilder.Build(currentBean8));
                }
            }

            // REPORTING TAXONOMIES
            if (buildFrom.ReportingTaxonomys.Count > 0)
            {
                var reportingTaxonomiesType = new ReportingTaxonomiesType();
                returnType.ReportingTaxonomies = reportingTaxonomiesType;

                /* foreach */
                foreach (IReportingTaxonomyObject currentBean9 in buildFrom.ReportingTaxonomys)
                {
                    reportingTaxonomiesType.ReportingTaxonomy.Add(this._reportingTaxonomyXmlBuilder.Build(currentBean9));
                }
            }

            if (buildFrom.AttachmentConstraints.Count > 0)
            {
                throw new SdmxNotImplementedException(
                    ExceptionCode.Unsupported, "Attachment Constraint at SMDX v2.0 - please use SDMX v2.1");
            }

            if (buildFrom.ContentConstraintObjects.Count > 0)
            {
                throw new SdmxNotImplementedException(
                    ExceptionCode.Unsupported, "Content Constraint at SMDX v2.0 - please use SDMX v2.1");
            }

            return responseType;
        }
        /// <summary>
        /// The build success response.
        /// </summary>
        /// <param name="beans">
        /// The beans.
        /// </param>
        /// <returns>
        /// The <see cref="RegistryInterface"/>.
        /// </returns>
        public RegistryInterface BuildSuccessResponse(ISdmxObjects beans)
        {
            var responseType = new RegistryInterface();
            RegistryInterfaceType regInterface = responseType.Content;

            HeaderType headerType;
            if (beans.Header != null)
            {
                headerType = this._headerXmlsBuilder.Build(beans.Header);
                regInterface.Header = headerType;
            }
            else
            {
                headerType = new HeaderType();
                regInterface.Header = headerType;
                V2Helper.SetHeader(headerType, beans);
            }

            var returnType = new SubmitStructureResponseType();
            regInterface.SubmitStructureResponse = returnType;
            ProcessMaintainables(returnType, beans.GetAllMaintainables());
            return responseType;
        }
 /// <summary>
 /// Add the specified <paramref name="sdmxObjects"/> to map.
 /// </summary>
 /// <param name="sdmxObjects">
 /// The SDMX objects.
 /// </param>
 private void AddObjectsToMap(ISdmxObjects sdmxObjects)
 {
     foreach (IMaintainableObject maint in sdmxObjects.GetAllMaintainables())
     {
         this.AddMaintainableToMap(maint);
     }
 }
        /// <summary>
        ///   The resolve references internal.
        /// </summary>
        /// <param name="sdmxObjects"> The sdmxObjects. </param>
        /// <param name="retrievalManager"> The retrieval manager. </param>
        /// <param name="populateMissingMap"> The populate missing map. </param>
        /// <returns> The <see cref="IIdentifiableObject" /> dictionary. </returns>
        /// <exception cref="CrossReferenceException">Reference error</exception>
        private IDictionaryOfSets<IIdentifiableObject, IIdentifiableObject> ResolveReferencesInternal(
            ISdmxObjects sdmxObjects,
            IIdentifiableRetrievalManager retrievalManager,
            IDictionary<IIdentifiableObject, ISet<ICrossReference>> populateMissingMap)
        {
            _log.Info("Resolve References, bean retrieval manager: " + retrievalManager);

            /* foreach */
            foreach (IAgency currentAgency in sdmxObjects.Agencies)
            {
                this._agencies.Add(currentAgency.FullId, currentAgency);
            }

            // Add all the top level sdmxObjects to the maintainables list
            this.AddObjectsToMap(sdmxObjects);

            // LOOP THROUGH ALL THE BEANS AND RESOLVE ALL THE REFERENCES
            if (this._resolveAgencies)
            {
                /* foreach */
                foreach (IMaintainableObject currentBean in sdmxObjects.GetAllMaintainables())
                {
                    try
                    {
                        this.ResolveAgency(currentBean, retrievalManager);
                    }
                    catch (CrossReferenceException e)
                    {
                        throw new SdmxReferenceException(e,
                            AgencyRef(currentBean.AgencyId));
                    }
                }
            }

            ISet<IMaintainableObject> loopSet = new HashSet<IMaintainableObject>();
            loopSet.AddAll(sdmxObjects.GetAllMaintainables());
            ISdmxObjectRetrievalManager retMan = new InMemoryRetrievalManager(sdmxObjects);

            /* foreach */
            foreach (IMaintainableObject currentMaintainable in loopSet)
            {
                this._log.Debug("Resolving References For : " + currentMaintainable.Urn);
                ISet<ICrossReference> crossReferences0;
                if (_maintainableCrossReferenceRetrieverEngine != null)
                {
                    crossReferences0 = _maintainableCrossReferenceRetrieverEngine.GetCrossReferences(retMan, currentMaintainable);
                }
                else
                {
                    crossReferences0 = currentMaintainable.CrossReferences;
                }
                this._log.Debug("Number of References : " + crossReferences0.Count);
                int i = 0;

                /* foreach */
                foreach (ICrossReference crossReference in crossReferences0)
                {
                    i++;
                    if (this._log.IsDebugEnabled)
                    {
                        this._log.Debug(
                            "Resolving Reference " + i + ": " + crossReference + " - referenced from -"
                            + crossReference.ReferencedFrom.StructureType);
                    }

                    try
                    {
                        this.StoreRef(
                            crossReference.ReferencedFrom, this.ResolveCrossReference(crossReference, retrievalManager));
                    }
                    catch (CrossReferenceException e)
                    {
                        if (populateMissingMap == null)
                        {
                            throw;
                        }
                        
                        HandleMissingReference(e, populateMissingMap);
                        //throw new ReferenceException(e, "Reference from structure '" + currentMaintainable.Urn + "' can not be resolved");
                    }
                }
            }

            return this._crossReferences;
        }
        /// <summary>
        ///   For the included <paramref name="sdmxObjects" />, returns a map of agency URN to maintainable Bean that references the agency
        /// </summary>
        /// <param name="sdmxObjects"> The included <c>SDMX</c> objects </param>
        /// <param name="retrievalManager"> The <see cref="ISdmxObjectRetrievalManager" /> </param>
        /// <returns> The included <paramref name="sdmxObjects" /> , returns a map of agency URN to maintainable Bean that references the agency </returns>
        public virtual IDictionary<string, ISet<IMaintainableObject>> GetMissingAgencies(ISdmxObjects sdmxObjects,
                                    IIdentifiableRetrievalManager identifiableRetrievalManager)
        {
            ISet<string> agencyIds = new HashSet<string>();

            /* foreach */
            ISet<IAgency> agencies = sdmxObjects.Agencies;
            foreach (IAgency acy in agencies)
            {
                agencyIds.Add(acy.FullId);
            }

            IDictionary<string, ISet<IMaintainableObject>> returnMap =
                new Dictionary<string, ISet<IMaintainableObject>>();

            /* foreach */
            ISet<IMaintainableObject> maintainableObjects = sdmxObjects.GetAllMaintainables();
            foreach (IMaintainableObject currentMaint in maintainableObjects)
            {
                string referencedAgencyId = currentMaint.AgencyId;
                if (!agencyIds.Contains(referencedAgencyId))
                {
                    if (identifiableRetrievalManager != null)
                    {
                        try
                        {
                            IAgency acy0 = ResolveAgency(referencedAgencyId, identifiableRetrievalManager);
                            if (acy0 != null)
                            {
                                agencyIds.Add(acy0.FullId);
                                continue;
                            }
                        }
                        catch (Exception th)
                        {
                            Console.Error.WriteLine(th.StackTrace);
                        }
                    }

                    ISet<IMaintainableObject> maintainables;
                    if (!returnMap.TryGetValue(referencedAgencyId, out maintainables))
                    {
                        maintainables = new HashSet<IMaintainableObject>();
                        returnMap.Add(referencedAgencyId, maintainables);
                    }

                    maintainables.Add(currentMaint);
                }
            }

            return returnMap;
        }