public void TestGetDataDataWriterEngineEmptyAttr(string query, string name) { var connectionString = ConfigurationManager.ConnectionStrings [name]; var dataQuery = new DataQueryImpl(new RESTDataQueryCore(query), new MappingStoreSdmxObjectRetrievalManager(connectionString)); const string EmptyAttributeXML = "empty-attribute.xml"; using (XmlWriter writer = XmlWriter.Create(EmptyAttributeXML, new XmlWriterSettings() {Indent = true})) { IDataWriterEngine dataWriter = new CompactDataWriterEngine(writer, SdmxSchema.GetFromEnum(SdmxSchemaEnumType.VersionTwoPointOne)); ISdmxDataRetrievalWithWriter sdmxDataRetrievalWithWriter = new DataRetrieverCore(new HeaderImpl("TestEmptyConditionalAttribute", "ZZ9"), connectionString, SdmxSchemaEnumType.VersionTwoPointOne); sdmxDataRetrievalWithWriter.GetData(dataQuery, dataWriter); writer.Flush(); } var fileInfo = new FileInfo(EmptyAttributeXML); Assert.IsTrue(fileInfo.Exists); using (var fileStream = fileInfo.OpenRead()) using (var reader = XmlReader.Create(fileStream)) { while (reader.Read()) { switch (reader.NodeType) { case XmlNodeType.Element: { var localName = reader.LocalName; if (localName.Equals("Group")) { Assert.IsTrue(reader.HasAttributes); var dateStr = reader.GetAttribute("NAT_TITLE"); Assert.IsNull(dateStr); } else if (localName.Equals("Obs")) { Assert.IsTrue(reader.HasAttributes); var attribute = reader.GetAttribute("OBS_COM"); Assert.IsTrue(attribute == null || !string.IsNullOrWhiteSpace(attribute)); } } break; } } } }
public void TestDimensionAtObservation() { IDataStructureMutableObject dsd = new DataStructureMutableCore() { Id = "TEST", AgencyId = "TEST_AGENCY", Version = "1.0" }; dsd.AddName("en", "Test name"); IDimensionMutableObject dimension = new DimensionMutableCore(); dimension.ConceptRef = new StructureReferenceImpl("TEST_AGENCY", "TEST_CONCEPTS", "1.0", SdmxStructureEnumType.Concept, "TEST_DIM"); dimension.Representation = new RepresentationMutableCore { Representation = new StructureReferenceImpl("TEST_AGENCY", "CL_TEST", "2.0", SdmxStructureEnumType.CodeList) }; dsd.AddDimension(dimension); dsd.AddPrimaryMeasure(new StructureReferenceImpl("TEST_AGENCY", "TEST_CONCEPTS", "1.0", SdmxStructureEnumType.Concept, "OBS_VALUE")); var immutableDsd = dsd.ImmutableInstance; var dataflowMutable = new DataflowMutableCore { Id = "TEST_DF", AgencyId = "TEST_AGENCY", Version = "1.2" }; dataflowMutable.AddName("en", "Test"); dataflowMutable.DataStructureRef = immutableDsd.AsReference; var dataflow = dataflowMutable.ImmutableInstance; IDataQuery query = new DataQueryImpl(immutableDsd, null, DataQueryDetail.GetFromEnum(DataQueryDetailEnumType.Full),null,null, null, dataflow, "AllDimensions", new HashSet<IDataQuerySelection>(), null, null); Assert.AreEqual("AllDimensions", query.DimensionAtObservation); }
/// <summary> /// Execute the rest query, write the response out to the output stream based on the data format /// </summary> /// <param name="dataQuery"> /// The data query /// </param> /// <param name="dataFormat"> /// The data format /// </param> /// <param name="outPutStream"> /// The output stream /// </param> public void ExecuteQuery(IRestDataQuery dataQuery, IDataFormat dataFormat, Stream outPutStream) { IDataQuery query = new DataQueryImpl(dataQuery, this._objectRetrievalManager); using (IDataWriterEngine dataWriterEngine = this._dataWriterManager.GetDataWriterEngine(dataFormat, outPutStream)) { this._dataRetrievalWithWriter.GetData(query, dataWriterEngine); } }