public void TestFreqWithFreqConcept() { IDimensionMutableObject dimension = new DimensionMutableCore(); dimension.ConceptRef = new StructureReferenceImpl("TEST_AGENCY", "TEST_CONCEPTS", "1.0", SdmxStructureEnumType.Concept, "FREQ"); var immutable = BuildDataStructureObject(dimension); Assert.NotNull(immutable.FrequencyDimension); }
public void TestWriteCodedTimeDimensionV20() { IDimensionMutableObject dimension = new DimensionMutableCore(); dimension.TimeDimension = true; dimension.Id = DimensionObject.TimeDimensionFixedId; dimension.ConceptRef = new StructureReferenceImpl("TEST_AGENCY", "TEST_CONCEPTS", "1.0", SdmxStructureEnumType.Concept, "TIME_PERIOD"); var structureReference = new StructureReferenceImpl("TEST_AGENCY", "CL_TIME_PERIOD", "1.0", SdmxStructureEnumType.CodeList); dimension.Representation = new RepresentationMutableCore() { Representation = structureReference }; var immutable = BuildDataStructureObject(dimension); using (var stream = new MemoryStream()) { this._writerManager.WriteStructure(immutable, new HeaderImpl("TEST", "TEST"), new SdmxStructureFormat(StructureOutputFormat.GetFromEnum(StructureOutputFormatEnumType.SdmxV2StructureDocument)), stream); stream.Position = 0; using (var location = new MemoryReadableLocation(stream.ToArray())) { var workspace = _parsingManager.ParseStructures(location); var dsd = workspace.GetStructureObjects(false).DataStructures.First(); var timeDimension = dsd.TimeDimension; Assert.IsTrue(timeDimension.HasCodedRepresentation()); Assert.AreEqual(timeDimension.Representation.Representation.AgencyId, structureReference.AgencyId); Assert.AreEqual(timeDimension.Representation.Representation.MaintainableId, structureReference.MaintainableId); Assert.AreEqual(timeDimension.Representation.Representation.Version, structureReference.Version); } } }
public void TestCodedTimeDimension() { IDimensionMutableObject dimension = new DimensionMutableCore(); dimension.TimeDimension = true; dimension.Id = DimensionObject.TimeDimensionFixedId; dimension.ConceptRef = new StructureReferenceImpl("TEST_AGENCY", "TEST_CONCEPTS", "1.0", SdmxStructureEnumType.Concept, "TIME_PERIOD"); dimension.Representation = new RepresentationMutableCore() {Representation = new StructureReferenceImpl("TEST_AGENCY", "CL_TIME_PERIOD", "1.0", SdmxStructureEnumType.CodeList) }; var immutable = BuildDataStructureObject(dimension); var timeDimension = immutable.TimeDimension; Assert.NotNull(timeDimension); Assert.IsTrue(timeDimension.HasCodedRepresentation()); var structureReference = dimension.Representation.Representation; Assert.AreEqual(timeDimension.Representation.Representation.AgencyId, structureReference.AgencyId); Assert.AreEqual(timeDimension.Representation.Representation.MaintainableId, structureReference.MaintainableId); Assert.AreEqual(timeDimension.Representation.Representation.Version, structureReference.Version); }
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); }
protected void btnAddDimension_Click(object sender, EventArgs e) { if (!ValidateDimensionData()) { OpenAddDimensionPopUp(); return; } IDimensionMutableObject dim = new DimensionMutableCore(); dim.Id = txtDimID.Text; switch (cmbDimType.SelectedValue) { case "FREQUENCY": dim.FrequencyDimension = true; break; case "MEASURE": dim.MeasureDimension = true; break; case "TIME": dim.TimeDimension = true; break; } #region "***** Concept Reference ******" ArtefactIdentity csIdentity = new ArtefactIdentity(); string[] conceptData = txtDimConcept.Text.Split(','); if (conceptData.Length > 0) { csIdentity.ID = conceptData[0]; csIdentity.Agency = conceptData[1]; csIdentity.Version = conceptData[2].Substring(0, conceptData[2].IndexOf(' ')); string conceptID = conceptData[2].Substring(conceptData[2].LastIndexOf(' ') + 1); IStructureReference conceptRef = new StructureReferenceImpl(csIdentity.Agency, csIdentity.ID, csIdentity.Version, SdmxStructureType.GetFromEnum(SdmxStructureEnumType.Concept), new string[] { conceptID }); dim.ConceptRef = conceptRef; } #endregion switch (cmbDimType.SelectedValue) { case "NORMAL": case "FREQUENCY": // Remove NTD Normal Dimension foreach (IDimensionMutableObject dimF in _dsdMutable.Dimensions) { if (dimF.ConceptRef.MaintainableId == _ntdNRName) { _dsdMutable.Dimensions.Remove(dimF); break; } } #region "***** Codelist Reference ******" if (txtDimCodelist.Text != string.Empty) { ArtefactIdentity clIdentity = new ArtefactIdentity(); string[] clData = txtDimCodelist.Text.Split(','); clIdentity.ID = clData[0]; clIdentity.Agency = clData[1]; clIdentity.Version = clData[2]; IStructureReference codelistRef = new StructureReferenceImpl(clIdentity.Agency, clIdentity.ID, clIdentity.Version, SdmxStructureType.GetFromEnum(SdmxStructureEnumType.CodeList), null); IRepresentationMutableObject representationRef = new RepresentationMutableCore(); representationRef.Representation = codelistRef; dim.Representation = representationRef; } #endregion break; case "MEASURE": #region "***** ConceptScheme Reference ******" if (txtDimConceptScheme.Text != string.Empty) { ArtefactIdentity cSchemeIdentity = new ArtefactIdentity(); string[] clData = txtDimConceptScheme.Text.Split(','); cSchemeIdentity.ID = clData[0]; cSchemeIdentity.Agency = clData[1]; cSchemeIdentity.Version = clData[2]; IStructureReference cSchemeRef = new StructureReferenceImpl(cSchemeIdentity.Agency, cSchemeIdentity.ID, cSchemeIdentity.Version, SdmxStructureType.GetFromEnum(SdmxStructureEnumType.ConceptScheme), null); IRepresentationMutableObject representationRef = new RepresentationMutableCore(); representationRef.Representation = cSchemeRef; dim.Representation = representationRef; } #endregion break; case "TIME": // Remove NTD Time Dimensione foreach (IDimensionMutableObject dimF in _dsdMutable.Dimensions) { if (dimF.ConceptRef.MaintainableId == _ntdTDName) { _dsdMutable.Dimensions.Remove(dimF); break; } } break; } try { _dsdMutable.AddDimension(dim); SetDsdToSession(); SetDimensionTab(_dsdMutable.ImmutableInstance); PopulateLBDimensionList(_dsdMutable, lbAttachmentDimension); PopulateLBDimensionList(_dsdMutable, lbGroupDimension); txtDimID.Text = ""; txtDimConcept.Text = ""; txtDimCodelist.Text = ""; txtDimConceptScheme.Text = ""; cmbDimType.SelectedIndex = 0; Utils.ForceBlackClosing(); } catch (Exception ex) { _dsdMutable.Dimensions.Remove(dim); OpenAddDimensionPopUp(); Utils.ShowDialog(ex.Message, 600, Resources.Messages.err_add_dimension); } }
private void CreateEmptyDSD() { IDataStructureMutableObject dsdMutable; dsdMutable = _sdmxUtils.buildDataStructure(_ntdString + "DSD_ID", _ntdString + "AGENCY", _ntdDSDVersion); dsdMutable.AddName("en", _ntdString + "DSD_NAME"); //AnnotationGeneralControl.ClearAnnotationsSession(); #region NormalDimension IDimensionMutableObject dim = new DimensionMutableCore(); dim.Id = _ntdNRName; IStructureReference conceptRef = new StructureReferenceImpl(_ntdNRName, _ntdNRName, "1.0", SdmxStructureType.GetFromEnum(SdmxStructureEnumType.Concept), new string[] { _ntdNRName }); dim.ConceptRef = conceptRef; dsdMutable.AddDimension(dim); #endregion #region TimeDimension IDimensionMutableObject dim2 = new DimensionMutableCore(); dim2.Id = _ntdTDName; dim2.TimeDimension = true; IStructureReference conceptRef2 = new StructureReferenceImpl(_ntdTDName, _ntdTDName, "1.0", SdmxStructureType.GetFromEnum(SdmxStructureEnumType.Concept), new string[] { _ntdTDName }); dim2.ConceptRef = conceptRef2; dsdMutable.AddDimension(dim2); #endregion dsdMutable.AddPrimaryMeasure(new StructureReferenceImpl(_ntdPMName, _ntdPMName, "1.0", SdmxStructureEnumType.Concept, _ntdPMName)); _dsdMutable = dsdMutable; SetDsdToSession(); }
public void TestUnCodeTimeDimension() { IDimensionMutableObject dimension = new DimensionMutableCore(); dimension.TimeDimension = true; dimension.Id = DimensionObject.TimeDimensionFixedId; dimension.ConceptRef = new StructureReferenceImpl("TEST_AGENCY", "TEST_CONCEPTS", "1.0", SdmxStructureEnumType.Concept, "TIME_PERIOD"); dimension.Representation = new RepresentationMutableCore() { TextFormat = new TextFormatMutableCore() { TextType = TextType.GetFromEnum(TextEnumType.TimePeriod) } }; var immutable = BuildDataStructureObject(dimension); Assert.NotNull(immutable.TimeDimension); Assert.IsFalse(immutable.TimeDimension.HasCodedRepresentation()); Assert.NotNull(immutable.TimeDimension.Representation); Assert.NotNull(immutable.TimeDimension.Representation.TextFormat); }
/// <summary> /// Handles the KeyFamily element child elements /// </summary> /// <param name="parent"> /// The parent IDataStructureMutableObject object /// </param> /// <param name="localName"> /// The name of the current xml element /// </param> /// <returns> /// The <see cref="StructureReaderBaseV20.ElementActions"/>. /// </returns> private ElementActions HandleChildElements(ICrossSectionalDataStructureMutableObject parent, object localName) { ElementActions actions = null; if (NameTableCache.IsElement(localName, ElementNameTable.Dimension)) { var dimension = new DimensionMutableCore(); ParseAttributes(parent, dimension, this.Attributes); parent.AddDimension(dimension); actions = this.BuildElementActions(dimension, this.HandleChildElements, DoNothing); } else if (NameTableCache.IsElement(localName, ElementNameTable.TimeDimension)) { var timeDimension = new DimensionMutableCore { TimeDimension = true, Id = DimensionObject.TimeDimensionFixedId }; ParseAttributes(parent, timeDimension, this.Attributes); parent.AddDimension(timeDimension); actions = this.BuildElementActions(timeDimension, this.HandleChildElements, DoNothing); } else if (NameTableCache.IsElement(localName, ElementNameTable.PrimaryMeasure)) { var measure = new PrimaryMeasureMutableCore(); ParseComponentBaseAttributes(parent, measure, this.Attributes); parent.PrimaryMeasure = measure; actions = this.BuildElementActions(measure, this.HandleChildElements, DoNothing); } else if (NameTableCache.IsElement(localName, ElementNameTable.CrossSectionalMeasure)) { var measure = new CrossSectionalMeasureMutableCore(); ParseAttributes(parent, measure, this.Attributes); parent.AddCrossSectionalMeasures(measure); actions = this.BuildElementActions(measure, this.HandleChildElements, DoNothing); } else if (NameTableCache.IsElement(localName, ElementNameTable.Attribute)) { var attribute = new AttributeMutableCore(); ParseAttributes(parent, attribute, this.Attributes); parent.AddAttribute(attribute); actions = this.BuildElementActions(attribute, this.HandleChildElements, this.HandleTextChildElement); } else if (NameTableCache.IsElement(localName, ElementNameTable.Components)) { //// Component element contains the rest of elements so we use the same action again. actions = this.BuildElementActions(parent, this.HandleChildElements, DoNothing); } else if (NameTableCache.IsElement(localName, ElementNameTable.Group)) { var groupMutableCore = new GroupMutableCore(); ParseAttributes(groupMutableCore, this.Attributes); parent.AddGroup(groupMutableCore); actions = this.BuildElementActions(groupMutableCore, this.HandleAnnotableChildElements, this.HandleTextChildElement); } return actions; }