/// <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; }
/// <summary> /// Returns a set of <see cref="IMaintainableMutableObject"/> that the IMaintainableMutableObject cross references /// </summary> /// <param name="artefact"> /// The bean. /// </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> /// <exception cref="SdmxReferenceException"> /// - if any of the references could not be resolved /// </exception> /// <exception cref="ArgumentNullException"><paramref name="artefact"/> is null.</exception> /// <returns> /// a set of <see cref="IMaintainableMutableObject"/> that the IMaintainableMutableObject cross references /// </returns> public ISet <IMaintainableMutableObject> ResolveReferences(IMaintainableMutableObject artefact, int numberLevelsDeep, Func <IStructureReference, IMaintainableMutableObject> retrievalManager) { if (artefact == null) { throw new ArgumentNullException("artefact"); } IMutableObjects objects = new MutableObjectsImpl(); objects.AddIdentifiable(artefact); IDictionaryOfSets <IMaintainableMutableObject, IMaintainableMutableObject> dictionaryOfSets = this.ResolveReferences(objects, numberLevelsDeep, retrievalManager); ISet <IMaintainableMutableObject> set; if (!dictionaryOfSets.TryGetValue(artefact, out set)) { set = new HashSet <IMaintainableMutableObject>(); } return(set); }
/// <summary> /// Handle QueryStructureResponse Child elements /// </summary> /// <param name="parent"> /// The parent QueryStructureResponseBean object /// </param> /// <param name="localName"> /// The name of the current xml element /// </param> /// <returns> /// The <see cref="StructureReaderBaseV20.ElementActions"/>. /// </returns> private ElementActions HandleChildElements(IQueryStructureResponseInfo parent, object localName) { ElementActions actions = null; if (NameTableCache.IsElement(localName, ElementNameTable.StatusMessage)) { IStatusMessageInfo status = this.CreateStatusMessage(); parent.StatusMessage = status; actions = this.AddSimpleAction(status, this.HandleTextChildElement); } else { if (parent.Structure == null) { var structure = new MutableObjectsImpl(); parent.Structure = structure; } this.HandleTopLevelBase(parent.Structure, localName); } return actions; }
/// <summary> /// Returns a set of maintainable that match the given query parameters /// </summary> /// <param name="structureQuery"> /// The structure Query. /// </param> /// <param name="allowedDataflows"> /// The allowed Dataflows. /// </param> /// <exception cref="ArgumentNullException"> /// <paramref name="structureQuery"/> is null /// </exception> /// <returns> /// The <see cref="IMutableObjects"/>. /// </returns> public virtual IMutableObjects GetMaintainables(IRestStructureQuery structureQuery, IList<IMaintainableRefObject> allowedDataflows) { _log.InfoFormat(CultureInfo.InvariantCulture, "Query for maintainable artefact(s): {0}", structureQuery); if (structureQuery == null) { throw new ArgumentNullException("structureQuery"); } IMutableObjects mutableObjects = new MutableObjectsImpl(); var cachedRetrievalManager = this._advancedMutableRetrievalManagerFactory.GetRetrievalManager(this._retrievalAdvancedManager); var crossReferenceMutableRetrievalManager = this._crossReferenceManager.GetCrossRetrievalManager(this._database, cachedRetrievalManager); this.PopulateMutables( cachedRetrievalManager, mutableObjects, new[] { structureQuery.StructureReference }, structureQuery.StructureQueryMetadata.IsReturnLatest, structureQuery.StructureQueryMetadata.StructureQueryDetail, allowedDataflows, crossReferenceMutableRetrievalManager); GetDetails(structureQuery, mutableObjects, crossReferenceMutableRetrievalManager, allowedDataflows); if (mutableObjects.AllMaintainables.Count == 0) { throw new SdmxNoResultsException("No structures found for the specific query"); } return mutableObjects; }
/// <summary> /// Returns the latest version of the maintainable for the given maintainable input /// </summary> /// <param name="maintainableObject"> /// The maintainable Object. /// </param> /// <param name="allowedDataflows"> /// The allowed Dataflows. /// </param> /// <returns> /// The <see cref="IMaintainableMutableObject"/>. /// </returns> public virtual IMaintainableMutableObject GetLatest(IMaintainableMutableObject maintainableObject, IList<IMaintainableRefObject> allowedDataflows) { if (maintainableObject == null) { return null; } // Create a reference *without* the version, because we want the latest. IStructureReference reference = new StructureReferenceImpl(maintainableObject.AgencyId, maintainableObject.Id, null, maintainableObject.StructureType); IMutableObjects objects = new MutableObjectsImpl(); this.PopulateMutables(objects, new[] { reference }, true, StructureQueryDetailEnumType.Full, allowedDataflows); var maintainable = objects.GetMaintainables(maintainableObject.StructureType).FirstOrDefault(); if (maintainable == null) { throw new SdmxNoResultsException("No structures found for the specific query"); } return maintainable; }
private ISdmxObjects GetSdmxObjects() { WSModel wsModel = new WSModel(); ISdmxObjects sdmxInput; ISdmxObjects sdmxFinal; IMutableObjects mutableObj = new MutableObjectsImpl(); LocalizedUtils localizedUtils = new LocalizedUtils(Utils.LocalizedCulture); sdmxFinal = new SdmxObjectsImpl(); try { sdmxInput = wsModel.GetOrganisationUnitScheme(new ArtefactIdentity(SearchBar1.ucID, SearchBar1.ucAgency, SearchBar1.ucVersion), true,true); if (SearchBar1.ucName.Trim() != string.Empty) { foreach (IOrganisationUnitSchemeObject ous in sdmxInput.OrganisationUnitSchemes) { if (localizedUtils.GetNameableName(ous).ToUpper().Contains(SearchBar1.ucName.Trim().ToUpper())) mutableObj.AddOrganisationUnitScheme(ous.MutableInstance); } sdmxFinal = mutableObj.ImmutableObjects; } else sdmxFinal = sdmxInput; } catch (Exception ex) { throw ex; } return sdmxFinal; }
/// <summary> /// Returns a set of <see cref="IMaintainableMutableObject"/> that the IMaintainableMutableObject cross references /// </summary> /// <param name="artefact"> /// The bean. /// </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> /// <exception cref="SdmxReferenceException"> /// - if any of the references could not be resolved /// </exception> /// <exception cref="ArgumentNullException"><paramref name="artefact"/> is null.</exception> /// <returns> /// a set of <see cref="IMaintainableMutableObject"/> that the IMaintainableMutableObject cross references /// </returns> public ISet<IMaintainableMutableObject> ResolveReferences(IMaintainableMutableObject artefact, int numberLevelsDeep, Func<IStructureReference, IMaintainableMutableObject> retrievalManager) { if (artefact == null) { throw new ArgumentNullException("artefact"); } IMutableObjects objects = new MutableObjectsImpl(); objects.AddIdentifiable(artefact); IDictionaryOfSets<IMaintainableMutableObject, IMaintainableMutableObject> dictionaryOfSets = this.ResolveReferences(objects, numberLevelsDeep, retrievalManager); ISet<IMaintainableMutableObject> set; if (!dictionaryOfSets.TryGetValue(artefact, out set)) { set = new HashSet<IMaintainableMutableObject>(); } return set; }
private ISdmxObjects GetSdmxObjects() { WSModel wsModel = new WSModel(); ISdmxObjects sdmxInput; ISdmxObjects sdmxFinal; IMutableObjects mutableObj = new MutableObjectsImpl(); LocalizedUtils localizedUtils = new LocalizedUtils(Utils.LocalizedCulture); sdmxFinal = new SdmxObjectsImpl(); try { sdmxInput = wsModel.GetDataFlow(new ArtefactIdentity(SearchBar1.ucID, SearchBar1.ucAgency, SearchBar1.ucVersion, ucIsFinalArtefact), true, true); if (SearchBar1.ucName.Trim() != string.Empty) { foreach (IDataflowObject df in sdmxInput.Dataflows) { if (localizedUtils.GetNameableName(df).Contains(SearchBar1.ucName.Trim())) mutableObj.AddDataflow(df.MutableInstance); } sdmxFinal = mutableObj.ImmutableObjects; } else sdmxFinal = sdmxInput; } catch (Exception ex) { throw ex; } return sdmxFinal; }
/// <summary> /// Parses a structure document OR a Registry document that contains structures. /// </summary> /// <param name="reader"> /// The reader. /// </param> /// <param name="settings"> /// - addition settings to perform when parsing /// </param> /// <param name="retrievalManager"> /// The retrieval manager. /// </param> /// <returns> /// StructureWorkspace - from this structures can be retrieved in any format required /// </returns> public IStructureWorkspace ParseStructures(ISdmxXmlStream reader, ResolutionSettings settings, ISdmxObjectRetrievalManager retrievalManager) { if (!reader.HasReader) { throw new ArgumentException("ISdmxXmlStream doesnt have a Reader", "reader"); } IMutableObjects objects = null; switch (reader.MessageType) { case MessageEnumType.RegistryInterface: IRegistryInfo registryInfo = this._registryReader.Read(reader.Reader); if (registryInfo.HasQueryStructureResponse && registryInfo.QueryStructureResponse.StatusMessage.Status != Status.Error) { objects = registryInfo.QueryStructureResponse.Structure; } break; case MessageEnumType.Structure: objects = this._structureReader.Read(reader.Reader); break; } if (objects == null) { objects = new MutableObjectsImpl(); } ISdmxObjects immutableBeans = objects.ImmutableObjects; return this.BuildWorkspace(immutableBeans, settings, retrievalManager); }
/// <summary> /// Writes the <paramref name="maintainableObject"/> out to the output location in the format specified by the implementation /// </summary> /// <param name="maintainableObject"> /// The maintainableObject. /// </param> public void WriteStructure(IMaintainableObject maintainableObject) { IMutableObjects mutableObjects = new MutableObjectsImpl(); mutableObjects.AddIdentifiable(maintainableObject.MutableInstance); this.WriteStructure(mutableObjects, null); }
public void TestWriteReadBigCodeList(int count) { string countStr = count.ToString(CultureInfo.InvariantCulture); ICodelistMutableObject codelist = new CodelistMutableCore(); codelist.Id = "CL_K" + countStr; codelist.AgencyId = "TEST"; codelist.AddName("en", "Test CL with " + countStr); for (int i = 0; i < count; i++) { ICodeMutableObject code = new CodeMutableCore(); code.Id = i.ToString(CultureInfo.InvariantCulture); code.AddName("en", "Code " + code.Id); codelist.AddItem(code); } IMutableObjects mutableObjects = new MutableObjectsImpl(); mutableObjects.AddCodelist(codelist); var sw = new Stopwatch(); string output = string.Format(CultureInfo.InvariantCulture, "big-codelist-{0}.xml", countStr); sw.Start(); using (XmlWriter writer = XmlWriter.Create(output, new XmlWriterSettings { CloseOutput = true, Indent = true })) { var structureWriter = new StructureWriterV2(writer); structureWriter.WriteStructure(mutableObjects, new HeaderImpl("ZZ9", "ZZ9")); } sw.Stop(); Trace.WriteLine(string.Format(CultureInfo.InvariantCulture, "Writing {0} took {1}", countStr, sw.Elapsed)); sw.Reset(); sw.Start(); XmlReaderSettings settings = XMLParser.GetSdmxXmlReaderSettings(SdmxSchemaEnumType.VersionTwo); settings.ValidationEventHandler += OnValidationEventHandler; var structureReader = new StructureReaderV2(); settings.NameTable = NameTableCache.Instance.NameTable; using (XmlReader reader = XmlReader.Create(output, settings)) { IMutableObjects res = structureReader.Read(reader); Assert.NotNull(res); } sw.Stop(); Trace.WriteLine(string.Format(CultureInfo.InvariantCulture, "Reading {0} took {1}", countStr, sw.Elapsed)); }
public void Test() { var s = new MutableObjectsImpl(); var s3 = new SdmxObjectsImpl(DatasetAction.GetFromEnum(DatasetActionEnumType.Append)); Assert.AreEqual(s3.Action.EnumType, DatasetActionEnumType.Append); Assert.IsNotNull(s.AllMaintainables); CollectionAssert.IsEmpty(s.AllMaintainables); Assert.AreNotSame(s.AllMaintainables, s.AllMaintainables); Assert.IsNotNull(s.Categorisations); CollectionAssert.IsEmpty(s.Categorisations); Assert.AreSame(s.Categorisations, s.Categorisations); Assert.IsNotNull(s.CategorySchemes); CollectionAssert.IsEmpty(s.CategorySchemes); Assert.AreSame(s.CategorySchemes, s.CategorySchemes); Assert.IsNotNull(s.Codelists); CollectionAssert.IsEmpty(s.Codelists); Assert.AreSame(s.Codelists, s.Codelists); Assert.IsNotNull(s.ConceptSchemes); CollectionAssert.IsEmpty(s.ConceptSchemes); Assert.AreSame(s.ConceptSchemes, s.ConceptSchemes); Assert.IsNotNull(s.DataStructures); CollectionAssert.IsEmpty(s.DataStructures); Assert.AreSame(s.DataStructures, s.DataStructures); Assert.IsNotNull(s.Dataflows); CollectionAssert.IsEmpty(s.Dataflows); Assert.AreSame(s.Dataflows, s.Dataflows); Assert.IsNotNull(s.HierarchicalCodelists); CollectionAssert.IsEmpty(s.HierarchicalCodelists); Assert.AreSame(s.HierarchicalCodelists, s.HierarchicalCodelists); Assert.IsNotNull(s.MetadataStructures); CollectionAssert.IsEmpty(s.MetadataStructures); Assert.AreSame(s.MetadataStructures, s.MetadataStructures); Assert.IsNotNull(s.Metadataflows); CollectionAssert.IsEmpty(s.Metadataflows); Assert.AreSame(s.Metadataflows, s.Metadataflows); Assert.IsNotNull(s.OrganisationUnitSchemes); CollectionAssert.IsEmpty(s.OrganisationUnitSchemes); Assert.AreSame(s.OrganisationUnitSchemes, s.OrganisationUnitSchemes); Assert.IsNotNull(s.Processes); CollectionAssert.IsEmpty(s.Processes); Assert.AreSame(s.Processes, s.Processes); Assert.IsNotNull(s.Registrations); CollectionAssert.IsEmpty(s.Registrations); Assert.AreSame(s.Registrations, s.Registrations); Assert.IsNotNull(s.ReportingTaxonomys); CollectionAssert.IsEmpty(s.ReportingTaxonomys); Assert.AreSame(s.ReportingTaxonomys, s.ReportingTaxonomys); Assert.IsNotNull(s.StructureSets); CollectionAssert.IsEmpty(s.StructureSets); Assert.AreSame(s.StructureSets, s.StructureSets); Assert.IsNotNull(s.Subscriptions); CollectionAssert.IsEmpty(s.Subscriptions); Assert.AreSame(s.Subscriptions, s.Subscriptions); var agencySchemeMock = new Mock<IAgencySchemeMutableObject>(); agencySchemeMock.Setup(o => o.StructureType).Returns(SdmxStructureType.GetFromEnum(SdmxStructureEnumType.AgencyScheme)); agencySchemeMock.Setup(o => o.AgencyId).Returns("TEST_AGENCY"); agencySchemeMock.Setup(o => o.Id).Returns("ID_AGENCYSCHEME"); agencySchemeMock.Setup(o => o.Version).Returns("1.2"); agencySchemeMock.Setup(o => o.StructureType).Returns(SdmxStructureType.GetFromEnum(SdmxStructureEnumType.AgencyScheme)); IAgencySchemeMutableObject agencyScheme = agencySchemeMock.Object; s.AddAgencyScheme(agencyScheme); CollectionAssert.IsNotEmpty(s.AgencySchemeMutableObjects); s.RemoveAgencySchemeMutableObjects(agencyScheme); CollectionAssert.IsEmpty(s.AgencySchemeMutableObjects); s.AddIdentifiable(agencyScheme); CollectionAssert.IsNotEmpty(s.AgencySchemeMutableObjects); var categorisationObjectMock = new Mock<ICategorisationMutableObject>(); categorisationObjectMock.Setup(o => o.StructureType).Returns(SdmxStructureType.GetFromEnum(SdmxStructureEnumType.Categorisation)); categorisationObjectMock.Setup(o => o.AgencyId).Returns("TEST_AGENCY"); categorisationObjectMock.Setup(o => o.Id).Returns("ID_CATEGORISATIONOBJECT"); categorisationObjectMock.Setup(o => o.Version).Returns("1.2"); ICategorisationMutableObject categorisationObject = categorisationObjectMock.Object; s.AddCategorisation(categorisationObject); CollectionAssert.IsNotEmpty(s.Categorisations); s.RemoveCategorisation(categorisationObject); CollectionAssert.IsEmpty(s.Categorisations); s.AddIdentifiable(categorisationObject); CollectionAssert.IsNotEmpty(s.Categorisations); var categorySchemeObjectMock = new Mock<ICategorySchemeMutableObject>(); categorySchemeObjectMock.Setup(o => o.StructureType).Returns(SdmxStructureType.GetFromEnum(SdmxStructureEnumType.CategoryScheme)); categorySchemeObjectMock.Setup(o => o.AgencyId).Returns("TEST_AGENCY"); categorySchemeObjectMock.Setup(o => o.Id).Returns("ID_CATEGORYSCHEMEOBJECT"); categorySchemeObjectMock.Setup(o => o.Version).Returns("1.2"); ICategorySchemeMutableObject categorySchemeObject = categorySchemeObjectMock.Object; s.AddCategoryScheme(categorySchemeObject); CollectionAssert.IsNotEmpty(s.CategorySchemes); s.RemoveCategoryScheme(categorySchemeObject); CollectionAssert.IsEmpty(s.CategorySchemes); s.AddIdentifiable(categorySchemeObject); CollectionAssert.IsNotEmpty(s.CategorySchemes); var codelistObjectMock = new Mock<ICodelistMutableObject>(); codelistObjectMock.Setup(o => o.StructureType).Returns(SdmxStructureType.GetFromEnum(SdmxStructureEnumType.CodeList)); codelistObjectMock.Setup(o => o.AgencyId).Returns("TEST_AGENCY"); codelistObjectMock.Setup(o => o.Id).Returns("ID_CODELISTOBJECT"); codelistObjectMock.Setup(o => o.Version).Returns("1.2"); ICodelistMutableObject codelistObject = codelistObjectMock.Object; s.AddCodelist(codelistObject); CollectionAssert.IsNotEmpty(s.Codelists); s.RemoveCodelist(codelistObject); CollectionAssert.IsEmpty(s.Codelists); s.AddIdentifiable(codelistObject); CollectionAssert.IsNotEmpty(s.Codelists); var conceptSchemeObjectMock = new Mock<IConceptSchemeMutableObject>(); conceptSchemeObjectMock.Setup(o => o.StructureType).Returns(SdmxStructureType.GetFromEnum(SdmxStructureEnumType.ConceptScheme)); conceptSchemeObjectMock.Setup(o => o.AgencyId).Returns("TEST_AGENCY"); conceptSchemeObjectMock.Setup(o => o.Id).Returns("ID_CONCEPTSCHEMEOBJECT"); conceptSchemeObjectMock.Setup(o => o.Version).Returns("1.2"); IConceptSchemeMutableObject conceptSchemeObject = conceptSchemeObjectMock.Object; s.AddConceptScheme(conceptSchemeObject); CollectionAssert.IsNotEmpty(s.ConceptSchemes); s.RemoveConceptScheme(conceptSchemeObject); CollectionAssert.IsEmpty(s.ConceptSchemes); s.AddIdentifiable(conceptSchemeObject); CollectionAssert.IsNotEmpty(s.ConceptSchemes); var dataConsumerSchemeMock = new Mock<IDataConsumerSchemeMutableObject>(); dataConsumerSchemeMock.Setup(o => o.StructureType).Returns(SdmxStructureType.GetFromEnum(SdmxStructureEnumType.DataConsumerScheme)); dataConsumerSchemeMock.Setup(o => o.AgencyId).Returns("TEST_AGENCY"); dataConsumerSchemeMock.Setup(o => o.Id).Returns("ID_DATACONSUMERSCHEME"); dataConsumerSchemeMock.Setup(o => o.Version).Returns("1.2"); IDataConsumerSchemeMutableObject dataConsumerScheme = dataConsumerSchemeMock.Object; s.AddDataConsumerScheme(dataConsumerScheme); CollectionAssert.IsNotEmpty(s.DataConsumberSchemeMutableObjects); s.RemoveDataConsumberSchemeMutableObjects(dataConsumerScheme); CollectionAssert.IsEmpty(s.DataConsumberSchemeMutableObjects); s.AddIdentifiable(dataConsumerScheme); CollectionAssert.IsNotEmpty(s.DataConsumberSchemeMutableObjects); var dataProviderSchemeMock = new Mock<IDataProviderSchemeMutableObject>(); dataProviderSchemeMock.Setup(o => o.StructureType).Returns(SdmxStructureType.GetFromEnum(SdmxStructureEnumType.DataProviderScheme)); dataProviderSchemeMock.Setup(o => o.AgencyId).Returns("TEST_AGENCY"); dataProviderSchemeMock.Setup(o => o.Id).Returns("ID_DATAPROVIDERSCHEME"); dataProviderSchemeMock.Setup(o => o.Version).Returns("1.2"); IDataProviderSchemeMutableObject dataProviderScheme = dataProviderSchemeMock.Object; s.AddDataProviderScheme(dataProviderScheme); CollectionAssert.IsNotEmpty(s.DataProviderSchemeMutableObjects); s.RemoveDataProviderSchemeMutableObjects(dataProviderScheme); CollectionAssert.IsEmpty(s.DataProviderSchemeMutableObjects); s.AddIdentifiable(dataProviderScheme); CollectionAssert.IsNotEmpty(s.DataProviderSchemeMutableObjects); var dataStructureObjectMock = new Mock<IDataStructureMutableObject>(); dataStructureObjectMock.Setup(o => o.StructureType).Returns(SdmxStructureType.GetFromEnum(SdmxStructureEnumType.Dsd)); dataStructureObjectMock.Setup(o => o.AgencyId).Returns("TEST_AGENCY"); dataStructureObjectMock.Setup(o => o.Id).Returns("ID_DATASTRUCTUREOBJECT"); dataStructureObjectMock.Setup(o => o.Version).Returns("1.2"); IDataStructureMutableObject dataStructureObject = dataStructureObjectMock.Object; s.AddDataStructure(dataStructureObject); CollectionAssert.IsNotEmpty(s.DataStructures); s.RemoveDataStructure(dataStructureObject); CollectionAssert.IsEmpty(s.DataStructures); s.AddIdentifiable(dataStructureObject); CollectionAssert.IsNotEmpty(s.DataStructures); var dataflowObjectMock = new Mock<IDataflowMutableObject>(); dataflowObjectMock.Setup(o => o.StructureType).Returns(SdmxStructureType.GetFromEnum(SdmxStructureEnumType.Dataflow)); dataflowObjectMock.Setup(o => o.AgencyId).Returns("TEST_AGENCY"); dataflowObjectMock.Setup(o => o.Id).Returns("ID_DATAFLOWOBJECT"); dataflowObjectMock.Setup(o => o.Version).Returns("1.2"); IDataflowMutableObject dataflowObject = dataflowObjectMock.Object; s.AddDataflow(dataflowObject); CollectionAssert.IsNotEmpty(s.Dataflows); s.RemoveDataflow(dataflowObject); CollectionAssert.IsEmpty(s.Dataflows); s.AddIdentifiable(dataflowObject); CollectionAssert.IsNotEmpty(s.Dataflows); var hierarchicalCodelistObjectMock = new Mock<IHierarchicalCodelistMutableObject>(); hierarchicalCodelistObjectMock.Setup(o => o.StructureType).Returns(SdmxStructureType.GetFromEnum(SdmxStructureEnumType.HierarchicalCodelist)); hierarchicalCodelistObjectMock.Setup(o => o.AgencyId).Returns("TEST_AGENCY"); hierarchicalCodelistObjectMock.Setup(o => o.Id).Returns("ID_HIERARCHICALCODELISTOBJECT"); hierarchicalCodelistObjectMock.Setup(o => o.Version).Returns("1.2"); IHierarchicalCodelistMutableObject hierarchicalCodelistObject = hierarchicalCodelistObjectMock.Object; s.AddHierarchicalCodelist(hierarchicalCodelistObject); CollectionAssert.IsNotEmpty(s.HierarchicalCodelists); s.RemoveHierarchicalCodelist(hierarchicalCodelistObject); CollectionAssert.IsEmpty(s.HierarchicalCodelists); s.AddIdentifiable(hierarchicalCodelistObject); CollectionAssert.IsNotEmpty(s.HierarchicalCodelists); var metadataFlowMock = new Mock<IMetadataFlowMutableObject>(); metadataFlowMock.Setup(o => o.StructureType).Returns(SdmxStructureType.GetFromEnum(SdmxStructureEnumType.MetadataFlow)); metadataFlowMock.Setup(o => o.AgencyId).Returns("TEST_AGENCY"); metadataFlowMock.Setup(o => o.Id).Returns("ID_METADATAFLOW"); metadataFlowMock.Setup(o => o.Version).Returns("1.2"); IMetadataFlowMutableObject metadataFlow = metadataFlowMock.Object; s.AddMetadataFlow(metadataFlow); CollectionAssert.IsNotEmpty(s.Metadataflows); s.RemoveMetadataFlow(metadataFlow); CollectionAssert.IsEmpty(s.Metadataflows); s.AddIdentifiable(metadataFlow); CollectionAssert.IsNotEmpty(s.Metadataflows); var metadataStructureDefinitionObjectMock = new Mock<IMetadataStructureDefinitionMutableObject>(); metadataStructureDefinitionObjectMock.Setup(o => o.StructureType).Returns(SdmxStructureType.GetFromEnum(SdmxStructureEnumType.Msd)); metadataStructureDefinitionObjectMock.Setup(o => o.AgencyId).Returns("TEST_AGENCY"); metadataStructureDefinitionObjectMock.Setup(o => o.Id).Returns("ID_METADATASTRUCTUREDEFINITIONOBJECT"); metadataStructureDefinitionObjectMock.Setup(o => o.Version).Returns("1.2"); IMetadataStructureDefinitionMutableObject metadataStructureDefinitionObject = metadataStructureDefinitionObjectMock.Object; s.AddMetadataStructure(metadataStructureDefinitionObject); CollectionAssert.IsNotEmpty(s.MetadataStructures); s.RemoveMetadataStructure(metadataStructureDefinitionObject); CollectionAssert.IsEmpty(s.MetadataStructures); s.AddIdentifiable(metadataStructureDefinitionObject); CollectionAssert.IsNotEmpty(s.MetadataStructures); var organisationUnitSchemeObjectMock = new Mock<IOrganisationUnitSchemeMutableObject>(); organisationUnitSchemeObjectMock.Setup(o => o.StructureType).Returns(SdmxStructureType.GetFromEnum(SdmxStructureEnumType.OrganisationUnitScheme)); organisationUnitSchemeObjectMock.Setup(o => o.AgencyId).Returns("TEST_AGENCY"); organisationUnitSchemeObjectMock.Setup(o => o.Id).Returns("ID_ORGANISATIONUNITSCHEMEOBJECT"); organisationUnitSchemeObjectMock.Setup(o => o.Version).Returns("1.2"); IOrganisationUnitSchemeMutableObject organisationUnitSchemeObject = organisationUnitSchemeObjectMock.Object; s.AddOrganisationUnitScheme(organisationUnitSchemeObject); CollectionAssert.IsNotEmpty(s.OrganisationUnitSchemes); s.RemoveOrganisationUnitScheme(organisationUnitSchemeObject); CollectionAssert.IsEmpty(s.OrganisationUnitSchemes); s.AddIdentifiable(organisationUnitSchemeObject); CollectionAssert.IsNotEmpty(s.OrganisationUnitSchemes); var processObjectMock = new Mock<IProcessMutableObject>(); processObjectMock.Setup(o => o.StructureType).Returns(SdmxStructureType.GetFromEnum(SdmxStructureEnumType.Process)); processObjectMock.Setup(o => o.AgencyId).Returns("TEST_AGENCY"); processObjectMock.Setup(o => o.Id).Returns("ID_PROCESSOBJECT"); processObjectMock.Setup(o => o.Version).Returns("1.2"); IProcessMutableObject processObject = processObjectMock.Object; s.AddProcess(processObject); CollectionAssert.IsNotEmpty(s.Processes); s.RemoveProcess(processObject); CollectionAssert.IsEmpty(s.Processes); s.AddIdentifiable(processObject); CollectionAssert.IsNotEmpty(s.Processes); var provisionAgreementObjectMock = new Mock<IProvisionAgreementMutableObject>(); provisionAgreementObjectMock.Setup(o => o.StructureType).Returns(SdmxStructureType.GetFromEnum(SdmxStructureEnumType.ProvisionAgreement)); provisionAgreementObjectMock.Setup(o => o.AgencyId).Returns("TEST_AGENCY"); provisionAgreementObjectMock.Setup(o => o.Id).Returns("ID_PROVISIONAGREEMENTOBJECT"); provisionAgreementObjectMock.Setup(o => o.Version).Returns("1.2"); IProvisionAgreementMutableObject provisionAgreementObject = provisionAgreementObjectMock.Object; s.AddProvision(provisionAgreementObject); CollectionAssert.IsNotEmpty(s.Provisions); s.RemoveProvision(provisionAgreementObject); CollectionAssert.IsEmpty(s.Provisions); s.AddIdentifiable(provisionAgreementObject); CollectionAssert.IsNotEmpty(s.Provisions); var registrationObjectMock = new Mock<IRegistrationMutableObject>(); registrationObjectMock.Setup(o => o.StructureType).Returns(SdmxStructureType.GetFromEnum(SdmxStructureEnumType.Registration)); registrationObjectMock.Setup(o => o.AgencyId).Returns("TEST_AGENCY"); registrationObjectMock.Setup(o => o.Id).Returns("ID_REGISTRATIONOBJECT"); registrationObjectMock.Setup(o => o.Version).Returns("1.2"); IRegistrationMutableObject registrationObject = registrationObjectMock.Object; s.AddRegistration(registrationObject); CollectionAssert.IsNotEmpty(s.Registrations); s.RemoveRegistration(registrationObject); CollectionAssert.IsEmpty(s.Registrations); s.AddIdentifiable(registrationObject); CollectionAssert.IsNotEmpty(s.Registrations); var reportingTaxonomyObjectMock = new Mock<IReportingTaxonomyMutableObject>(); reportingTaxonomyObjectMock.Setup(o => o.StructureType).Returns(SdmxStructureType.GetFromEnum(SdmxStructureEnumType.ReportingTaxonomy)); reportingTaxonomyObjectMock.Setup(o => o.AgencyId).Returns("TEST_AGENCY"); reportingTaxonomyObjectMock.Setup(o => o.Id).Returns("ID_REPORTINGTAXONOMYOBJECT"); reportingTaxonomyObjectMock.Setup(o => o.Version).Returns("1.2"); IReportingTaxonomyMutableObject reportingTaxonomyObject = reportingTaxonomyObjectMock.Object; s.AddReportingTaxonomy(reportingTaxonomyObject); CollectionAssert.IsNotEmpty(s.ReportingTaxonomys); s.RemoveReportingTaxonomy(reportingTaxonomyObject); CollectionAssert.IsEmpty(s.ReportingTaxonomys); s.AddIdentifiable(reportingTaxonomyObject); CollectionAssert.IsNotEmpty(s.ReportingTaxonomys); var structureSetObjectMock = new Mock<IStructureSetMutableObject>(); structureSetObjectMock.Setup(o => o.StructureType).Returns(SdmxStructureType.GetFromEnum(SdmxStructureEnumType.StructureSet)); structureSetObjectMock.Setup(o => o.AgencyId).Returns("TEST_AGENCY"); structureSetObjectMock.Setup(o => o.Id).Returns("ID_STRUCTURESETOBJECT"); structureSetObjectMock.Setup(o => o.Version).Returns("1.2"); IStructureSetMutableObject structureSetObject = structureSetObjectMock.Object; s.AddStructureSet(structureSetObject); CollectionAssert.IsNotEmpty(s.StructureSets); s.RemoveStructureSet(structureSetObject); CollectionAssert.IsEmpty(s.StructureSets); s.AddIdentifiable(structureSetObject); CollectionAssert.IsNotEmpty(s.StructureSets); var subscriptionObjectMock = new Mock<ISubscriptionMutableObject>(); subscriptionObjectMock.Setup(o => o.StructureType).Returns(SdmxStructureType.GetFromEnum(SdmxStructureEnumType.Subscription)); subscriptionObjectMock.Setup(o => o.AgencyId).Returns("TEST_AGENCY"); subscriptionObjectMock.Setup(o => o.Id).Returns("ID_SUBSCRIPTIONOBJECT"); subscriptionObjectMock.Setup(o => o.Version).Returns("1.2"); ISubscriptionMutableObject subscriptionObject = subscriptionObjectMock.Object; s.AddSubscription(subscriptionObject); CollectionAssert.IsNotEmpty(s.Subscriptions); s.RemoveSubscription(subscriptionObject); CollectionAssert.IsEmpty(s.Subscriptions); s.AddIdentifiable(subscriptionObject); CollectionAssert.IsNotEmpty(s.Subscriptions); var s5 = new MutableObjectsImpl(s.Dataflows); CollectionAssert.IsNotEmpty(s5.Dataflows); CollectionAssert.IsEmpty(s5.GetMaintainables(SdmxStructureType.GetFromEnum(SdmxStructureEnumType.HierarchicalCodelist))); CollectionAssert.IsNotEmpty(s5.GetMaintainables(SdmxStructureType.GetFromEnum(SdmxStructureEnumType.Dataflow))); }
private ISdmxObjects GetSdmxObjects() { WSModel wsModel = new WSModel(); ISdmxObjects sdmxInput; ISdmxObjects sdmxFinal; IMutableObjects mutableObj = new MutableObjectsImpl(); LocalizedUtils localizedUtils = new LocalizedUtils(Utils.LocalizedCulture); bool stub = true; sdmxFinal = new SdmxObjectsImpl(); if (hdnViewMode.Value == "Concept") stub = false; try { sdmxInput = wsModel.GetConceptScheme(new ArtefactIdentity(SearchBar1.ucID, SearchBar1.ucAgency, SearchBar1.ucVersion, ucIsFinalArtefact), stub, true); if (SearchBar1.ucName.Trim() != string.Empty) { foreach (IConceptSchemeObject cs in sdmxInput.ConceptSchemes) { if (localizedUtils.GetNameableName(cs).Contains(SearchBar1.ucName.Trim())) mutableObj.AddConceptScheme(cs.MutableInstance); } sdmxFinal = mutableObj.ImmutableObjects; } else sdmxFinal = sdmxInput; } catch (Exception ex) { throw ex; } return sdmxFinal; }
/// <summary> /// Retrieves all structures that match the given query parameters in the list of query objects. The list /// must contain at least one StructureQueryObject. /// </summary> /// <param name="queries"> /// The queries. /// </param> /// <param name="resolveReferences"> /// - if set to true then any cross referenced structures will also be available in the SdmxObjects container /// </param> /// <param name="returnStub"> /// - if set to true then only stubs of the returned objects will be returned. /// </param> /// <param name="allowedDataflows"> /// The allowed Dataflows. /// </param> /// <returns> /// The <see cref="IMutableObjects"/>. /// </returns> public virtual IMutableObjects RetrieveStructures(IList<IStructureReference> queries, bool resolveReferences, bool returnStub, IList<IMaintainableRefObject> allowedDataflows) { IMutableObjects mutableObjects = new MutableObjectsImpl(); var cachedRetrievalManager = this._advancedMutableRetrievalManagerFactory.GetRetrievalManager(this._retrievalAdvancedManager); var crossReferenceMutableRetrievalManager = this._crossReferenceManager.GetCrossRetrievalManager(this._database, cachedRetrievalManager); this.PopulateMutables(cachedRetrievalManager, mutableObjects, queries, false, returnStub.GetStructureQueryDetail(), allowedDataflows, crossReferenceMutableRetrievalManager); if (resolveReferences) { var resolver = _resolverFactory.GetResolver(StructureReferenceDetail.GetFromEnum(StructureReferenceDetailEnumType.Children), crossReferenceMutableRetrievalManager); resolver.ResolveReferences(mutableObjects, returnStub, allowedDataflows); } if (mutableObjects.AllMaintainables.Count == 0) { throw new SdmxNoResultsException("No structures found for the specific query"); } return mutableObjects; }
/// <summary> /// Writes the <paramref name="maintainableObject"/> out to the output location in the format specified by the implementation /// </summary> /// <param name="maintainableObject"> /// The maintainableObject. /// </param> public void WriteStructure(IMaintainableObject maintainableObject) { IMutableObjects mutableObjects = new MutableObjectsImpl(); mutableObjects.AddIdentifiable(maintainableObject.MutableInstance); IRegistryInfo registry = new RegistryInfo(); registry.QueryStructureResponse = new QueryStructureResponseInfo { Structure = mutableObjects }; this.WriteRegistryInterface(registry); }
/// <summary> /// Retrieve the <paramref name="queries"/> and populate the <paramref name="mutableObjects"/> /// </summary> /// <param name="retrievalManager"> /// The retrieval manager. /// </param> /// <param name="mutableObjects"> /// The mutable objects. /// </param> /// <param name="queries"> /// The structure queries /// </param> /// <param name="returnLatest"> /// Set to <c>true</c> to retrieve the latest; otherwise set to <c>false</c> to retrieve all versions /// </param> /// <param name="returnStub"> /// Set to <c>true</c> to retrieve artefacts as stubs; otherwise set to <c>false</c> to retrieve full artefacts. /// </param> /// <param name="allowedDataflows"> /// The allowed dataflows. /// </param> /// <param name="crossReferenceMutableRetrievalManager"> /// The cross-reference manager /// </param> protected override void PopulateMutables(IAuthAdvancedSdmxMutableObjectRetrievalManager retrievalManager, IMutableObjects mutableObjects, IList<IStructureReference> queries, bool returnLatest, StructureQueryDetailEnumType returnStub, IList<IMaintainableRefObject> allowedDataflows, IAuthCrossReferenceMutableRetrievalManager crossReferenceMutableRetrievalManager) { var dataflowLessQueries = new List<IStructureReference>(); var dataflowQueries = new List<IStructureReference>(); foreach (var query in queries) { if (query.MaintainableStructureEnumType.EnumType == SdmxStructureEnumType.Dataflow) { dataflowQueries.Add(query); } else { dataflowLessQueries.Add(query); } } base.PopulateMutables(retrievalManager, mutableObjects, dataflowLessQueries, returnLatest, returnStub, allowedDataflows, crossReferenceMutableRetrievalManager); // get the latest for dataflows to emulate the intermediate SR behavior. base.PopulateMutables(retrievalManager, mutableObjects, dataflowQueries, true, returnStub, allowedDataflows, crossReferenceMutableRetrievalManager); if (queries.NeedsCategorisation()) { _log.Info("SDMX v2.0 structure search manager used. Trying to retrieve categorisations all dataflows and categorisations."); IMutableObjects objects = new MutableObjectsImpl(mutableObjects.Dataflows); objects.AddIdentifiables(mutableObjects.CategorySchemes); // get categorisations IResolverFactory factory = new ResolverFactory(); var resolver = factory.GetResolver(StructureReferenceDetail.GetFromEnum(StructureReferenceDetailEnumType.Parents), crossReferenceMutableRetrievalManager); resolver.ResolveReferences(objects, returnStub == StructureQueryDetailEnumType.AllStubs, allowedDataflows); // add them to mutable objects mutableObjects.AddIdentifiables(objects.Categorisations); } }
/// <summary> /// Process the specified <paramref name="structureQuery"/> returning an /// <see cref="T:Org.Sdmxsource.Sdmx.Api.Model.Mutable.IMutableObjects"/> container which contains the Maintainable /// Structure hat correspond to the <paramref name="structureQuery"/> query parameters. /// </summary> /// <param name="structureQuery"> /// The structure query. /// </param> /// <param name="allowedDataflows"> /// The allowed Dataflows. /// </param> /// <returns> /// The <see cref="T:Org.Sdmxsource.Sdmx.Api.Model.Mutable.IMutableObjects"/>. /// </returns> public IMutableObjects GetMaintainables(IComplexStructureQuery structureQuery, IList<IMaintainableRefObject> allowedDataflows) { if (structureQuery == null) { throw new ArgumentNullException("structureQuery"); } IMutableObjects mutableObjects = new MutableObjectsImpl(); var cachedRetrievalManager = this._retrievalFactory.GetRetrievalManager(this._retrievalManager); var crossReferenceMutableRetrievalManager = this._crossReferenceManagerFactory.GetCrossRetrievalManager(this._database, cachedRetrievalManager); this.PopulateMutables(cachedRetrievalManager, mutableObjects, structureQuery, allowedDataflows, crossReferenceMutableRetrievalManager); GetDetails(structureQuery, mutableObjects, crossReferenceMutableRetrievalManager, allowedDataflows); mutableObjects.DataStructures.NormalizeSdmxv20DataStructures(); if (mutableObjects.AllMaintainables.Count == 0) { throw new SdmxNoResultsException("No structures found for the specific query"); } return mutableObjects; }