/// <summary> /// Gets the enumerated representation. /// </summary> /// <param name="dimension">The dimension.</param> /// <param name="dsd">The DSD.</param> /// <returns>The representation <see cref="IStructureReference"/> of the <paramref name="dimension"/>; otherwise null.</returns> public static IStructureReference GetEnumeratedRepresentation(this IDimensionMutableObject dimension, IDataStructureMutableObject dsd) { if (dimension.MeasureDimension) { var crossDsd = dsd as ICrossSectionalDataStructureMutableObject; if (crossDsd != null) { IStructureReference reference = crossDsd.MeasureDimensionCodelistMapping[dimension.Id]; return(reference); } } return(dimension.GetEnumeratedRepresentation()); }
/// <summary> /// Setup cross sectional DSD. /// </summary> /// <param name="parent"> /// The parent. /// </param> /// <param name="crossDataSet"> /// The list of components attached to cross-sectional data set. /// </param> /// <param name="crossGroup"> /// The list of components attached to cross-sectional group. /// </param> /// <param name="crossSection"> /// The list of components attached to cross-sectional section. /// </param> /// <param name="crossObs"> /// The list of components attached to cross-sectional observation level /// </param> /// <param name="crossSectionalMeasures"> /// The cross sectional measures. /// </param> /// <param name="measureCodelistRepresentation"> /// The SDMX v2.0 measure dimension codelist representation; otherwise null /// </param> /// <returns> /// The <see cref="IDataStructureMutableObject"/>. /// </returns> private static IDataStructureMutableObject SetupCrossSectionalDsd( IDataStructureMutableObject parent, ICollection <string> crossDataSet, ICollection <string> crossGroup, ICollection <string> crossSection, ICollection <string> crossObs, IEnumerable <ICrossSectionalMeasureMutableObject> crossSectionalMeasures, IStructureReference measureCodelistRepresentation) { if ( parent.Dimensions.All( o => o.FrequencyDimension || o.TimeDimension || o.MeasureDimension || crossDataSet.Contains(o.Id) || crossGroup.Contains(o.Id) || crossSection.Contains(o.Id) || crossObs.Contains(o.Id))) { if (parent.AttributeList == null || parent.AttributeList.Attributes.All(o => crossDataSet.Contains(o.Id) || crossGroup.Contains(o.Id) || crossSection.Contains(o.Id) || crossObs.Contains(o.Id))) { ICrossSectionalDataStructureMutableObject crossDsd = _crossDsdBuilder.Build(parent); crossDsd.CrossSectionalAttachDataSet.AddAll(crossDataSet); crossDsd.CrossSectionalAttachSection.AddAll(crossSection); crossDsd.CrossSectionalAttachGroup.AddAll(crossGroup); crossDsd.CrossSectionalAttachObservation.AddAll(crossObs); IDimensionMutableObject measure = crossDsd.Dimensions.FirstOrDefault(o => o.MeasureDimension); if (measure != null) { foreach (ICrossSectionalMeasureMutableObject crossSectionalMeasureMutableObject in crossSectionalMeasures) { crossSectionalMeasureMutableObject.MeasureDimension = measure.Id; crossDsd.CrossSectionalMeasures.Add(crossSectionalMeasureMutableObject); } if (measureCodelistRepresentation == null) { DataStructureUtil.ConvertMeasureRepresentation(crossDsd); } } return(crossDsd); } } return(parent); }
/////////////////////////////////////////////////////////////////////////////////////////////////// ////////////BUILD FROM MUTABLE OBJECTS ////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////// #region Constructors and Destructors /// <summary> /// Initializes a new instance of the <see cref="DimensionCore"/> class. /// </summary> /// <param name="itemMutableObject"> /// The sdmxObject. /// </param> /// <param name="position0"> /// The position 0. /// </param> /// <param name="parent"> /// The parent. /// </param> /// <exception cref="SdmxSemmanticException"> /// Throws Validate exception. /// </exception> public DimensionCore(IDimensionMutableObject itemMutableObject, int position0, IDimensionList parent) : base(itemMutableObject, parent) { this.conceptRole = new List<ICrossReference>(); try { this.position = position0; this.measureDimension = itemMutableObject.MeasureDimension; this.timeDimension = itemMutableObject.TimeDimension; if (itemMutableObject.ConceptRole != null) { foreach (IStructureReference currentConceptRole in itemMutableObject.ConceptRole) { this.conceptRole.Add(new CrossReferenceImpl(this, currentConceptRole)); } } this.ValidateDimension(); } catch (Exception e) { throw new SdmxSemmanticException("IsError creating structure: " + this.ToString(), e); } }
/// <summary> /// Write a KeyFamily/Components/Dimensions element from a IDimensionMutableObject object /// </summary> /// <param name="dimension"> /// The IDimensionMutableObject object to write /// </param> /// <param name="helper"> /// Helper class for SDMX v2.0 cross-sectional /// </param> private void WriteComponent(IDimensionMutableObject dimension, CrossSectionalDsdHelper helper) { if (dimension.TimeDimension) { this.WriteStartElement(this.DefaultPrefix, ElementNameTable.TimeDimension); } else { this.WriteStartElement(this.DefaultPrefix, ElementNameTable.Dimension); this.TryWriteAttribute(AttributeNameTable.isMeasureDimension, dimension.MeasureDimension); this.TryWriteAttribute(AttributeNameTable.isFrequencyDimension, dimension.FrequencyDimension); } this.WriteComponentAttributes(dimension); if (dimension.MeasureDimension) { this.WriteRepresentation(helper.GetRepresentation(dimension)); } else { this.WriteRepresentation(dimension.Representation); } helper.WriteCrossComponentAttributes(dimension, this.TryWriteAttribute); //// TODO not supported by the Common API 0.9.9 ////this.TryWriteAttribute(AttributeNameTable.isCountDimension, dimension.CountDimension); ////this.TryWriteAttribute(AttributeNameTable.isEntityDimension, dimension.IsEntityDimension); ////this.TryWriteAttribute(AttributeNameTable.isIdentityDimension, dimension.IsIdentityDimension); ////this.TryWriteAttribute( //// AttributeNameTable.isNonObservationTimeDimension, dimension.IsNonObservationTimeDimension); this.WriteComponentContent(dimension); this.WriteEndElement(); }
/// <summary> /// Returns the representation of the <paramref name="dimension"/> if it is measure and the parent DSD is <see cref="ICrossSectionalDataStructureMutableObject"/> /// </summary> /// <param name="dimension"> /// The measure dimension. /// </param> /// <returns> /// The <see cref="IRepresentationMutableObject"/>. /// </returns> public IRepresentationMutableObject GetRepresentation(IDimensionMutableObject dimension) { IStructureReference codelistRef; if (this._crossSectional == null || !dimension.MeasureDimension || !this._crossSectional.MeasureDimensionCodelistMapping.TryGetValue(dimension.ConceptRef.ChildReference.Id, out codelistRef)) { return dimension.Representation; } return new RepresentationMutableCore { Representation = codelistRef }; }
/// <summary> /// Builds the data structure object. /// </summary> /// <param name="dimension">The dimension.</param> /// <returns> /// The <see cref="IDataStructureObject"/> /// </returns> private static IDataStructureObject BuildDataStructureObject(IDimensionMutableObject dimension) { IDataStructureMutableObject dsd = new DataStructureMutableCore() { Id = "TEST_DSD", AgencyId = "TEST", Version = "1.0" }; dsd.AddName("en", "TEST_DSD"); dsd.AddPrimaryMeasure(new StructureReferenceImpl("TEST_AGENCY", "TEST_CONCEPTS", "1.0", SdmxStructureEnumType.Concept, "OBS_VALUE")); dsd.AddDimension(dimension); var immutable = dsd.ImmutableInstance; return immutable; }
private IDataStructureMutableObject ReOrderDimension(IDataStructureMutableObject dsMut, IDimensionMutableObject dimMut, int inputOrder) { var sortedDimension = dsMut.DimensionList.Dimensions.OrderBy( o => { var corder = o.Annotations.FirstOrDefault(mutableObject => string.Equals(mutableObject.Type, "@ORDER@")); return corder != null ? int.Parse(corder.Text[0].Value) : 0; }).ToArray(); dsMut.Dimensions.Clear(); int orderID = 1; IAnnotationMutableObject annOrder; foreach (IDimensionMutableObject dim in sortedDimension) { if (orderID == inputOrder) { annOrder = dimMut.Annotations.Where(a => a.Type == "@ORDER@").FirstOrDefault(); if (annOrder != null) dimMut.Annotations.Remove(annOrder); dimMut.Annotations.Add(CreateAnnotation("order" + orderID.ToString(), "", "@ORDER@", "", new List<ITextTypeWrapperMutableObject>(){ new TextTypeWrapperMutableCore("en",orderID.ToString()) } ) ); dsMut.AddDimension(dimMut); ++orderID; } annOrder = dim.Annotations.Where(a => a.Type == "@ORDER@").FirstOrDefault(); if (annOrder != null) dim.Annotations.Remove(annOrder); dim.Annotations.Add(CreateAnnotation("order" + orderID.ToString(), "", "@ORDER@", "", new List<ITextTypeWrapperMutableObject>(){ new TextTypeWrapperMutableCore("en",orderID.ToString()) } ) ); dsMut.AddDimension(dim); ++orderID; } if (orderID <= inputOrder) { annOrder = dimMut.Annotations.Where(a => a.Type == "@ORDER@").FirstOrDefault(); if (annOrder != null) dimMut.Annotations.Remove(annOrder); dimMut.Annotations.Add(CreateAnnotation("order" + orderID.ToString(), "", "@ORDER@", "", new List<ITextTypeWrapperMutableObject>(){ new TextTypeWrapperMutableCore("en",orderID.ToString()) } ) ); dsMut.AddDimension(dimMut); } return dsMut; }
/// <summary> /// The add dimension. /// </summary> /// <param name="dimension"> /// The dimension. /// </param> public void AddDimension(IDimensionMutableObject dimension) { if (this.dimensions == null) { this.dimensions = new List<IDimensionMutableObject>(); } this.dimensions.Add(dimension); }
///// <summary> ///// Populates the proporties of the given IDimensionMutableObject object from the given xml attributes dictionary ///// </summary> ///// <param name="timeDimension">The given IDimensionMutableObject object</param> ///// <param name="attributes">The dictionary contains the attributes of the element</param> // private static void ParseAttributes(IDimensionMutableObject timeDimension, IDictionary<string, string> attributes) { // ParseAttributes((IComponentMutableObject) timeDimension, attributes); // } /// <summary> /// Populates the properties of the given IDimensionMutableObject object from the given xml attributes dictionary /// </summary> /// <param name="artefact"> /// The <see cref="ICrossSectionalDataStructureMutableObject"/> /// </param> /// <param name="dimension"> /// The given IDimensionMutableObject object /// </param> /// <param name="attributes"> /// The dictionary contains the attributes of the element /// </param> private static void ParseAttributes(ICrossSectionalDataStructureMutableObject artefact, IDimensionMutableObject dimension, IDictionary<string, string> attributes) { //// TODO java not supported by the Common API as in Java version 0.9.9 ////dimension.IsCountDimension = Helper.TrySetFromAttribute( //// attributes, AttributeNameTable.isCountAttribute, dimension.IsCountDimension); dimension.MeasureDimension = Helper.TrySetFromAttribute(attributes, AttributeNameTable.isMeasureDimension, dimension.MeasureDimension); dimension.FrequencyDimension = Helper.TrySetFromAttribute(attributes, AttributeNameTable.isFrequencyDimension, dimension.FrequencyDimension); //// TODO java not supported by the Common API as in Java version 0.9.9 ////dimension.IsEntityDimension = Helper.TrySetFromAttribute( //// attributes, AttributeNameTable.isEntityDimension, dimension.IsEntityDimension); ////dimension.IsNonObservationTimeDimension = Helper.TrySetFromAttribute( //// attributes, AttributeNameTable.isNonObservationTimeDimension, dimension.IsNonObservationTimeDimension); ////dimension.IsIdentityDimension = Helper.TrySetFromAttribute( //// attributes, AttributeNameTable.isIdentityAttribute, dimension.IsIdentityDimension); ParseComponentBaseAttributes(artefact, dimension, attributes); }