/// <summary> /// Returns true if the specified <paramref name="currentType"/> has SDMX v2.0 cross sectional information. /// </summary> /// <param name="currentType"> /// The KeyFamily instance /// </param> /// <returns> /// true if the specified <paramref name="currentType"/> has at least some SDMX v2.0 cross sectional information. /// </returns> public static bool IsCrossSectional(KeyFamilyType currentType) { bool isCrossSectional = currentType.Components.Dimension.All( component => component.isFrequencyDimension || component.isMeasureDimension || (component.crossSectionalAttachDataSet.HasValue && component.crossSectionalAttachDataSet.Value) || (component.crossSectionalAttachGroup.HasValue && component.crossSectionalAttachGroup.Value) || (component.crossSectionalAttachSection.HasValue && component.crossSectionalAttachSection.Value) || (component.crossSectionalAttachObservation.HasValue && component.crossSectionalAttachObservation.Value)); if (currentType.Components.Attribute.Count > 0) { isCrossSectional = isCrossSectional && currentType.Components.Attribute.All( component => (component.crossSectionalAttachDataSet.HasValue && component.crossSectionalAttachDataSet.Value) || (component.crossSectionalAttachGroup.HasValue && component.crossSectionalAttachGroup.Value) || (component.crossSectionalAttachSection.HasValue && component.crossSectionalAttachSection.Value) || (component.crossSectionalAttachObservation.HasValue && component.crossSectionalAttachObservation.Value)); } return isCrossSectional; }
/////////////////////////////////////////////////////////////////////////////////////////////////// ////////////BUILD FROM V2 SCHEMA ////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////// /// <summary> /// Initializes a new instance of the <see cref="DimensionListCore"/> class. /// </summary> /// <param name="keyFamily"> /// The agencyScheme. /// </param> /// <param name="parent"> /// The parent. /// </param> /// <exception cref="SdmxSemmanticException"> Throws SdmxSemmanticException. /// </exception> public DimensionListCore(KeyFamilyType keyFamily, IMaintainableObject parent) : base( DimensionList.FixedId, SdmxStructureType.GetFromEnum(SdmxStructureEnumType.DimensionDescriptor), parent) { this.dimensions = new List<IDimension>(); int pos = 1; ComponentsType components = keyFamily.Components; try { if (components != null) { foreach (DimensionType currentDimension in components.Dimension) { this.dimensions.Add(new DimensionCore(currentDimension, this, pos)); pos++; } if (components.TimeDimension != null) { this.dimensions.Add(new DimensionCore(components.TimeDimension, this, pos)); } } } catch (SdmxSemmanticException ex) { throw new SdmxSemmanticException(ex, ExceptionCode.ObjectStructureConstructionError, this.Urn); } catch (Exception th) { throw new SdmxException(th, ExceptionCode.ObjectStructureConstructionError, this.Urn); } this.ValidateDimensionList(); }
static StructureType createStructure(PXModel model) { // Create structure StructureType structure = new StructureType(); // Create concepts container ConceptsType concepts = new ConceptsType(); structure.Concepts = concepts; // Concept Schemes List <ConceptSchemeType> conceptSchemes = new List <ConceptSchemeType>(); //Create Common Concept Scheme conceptSchemes.Add(createCommonConcepts()); // Create instance concept scheme ConceptSchemeType conceptScheme = new ConceptSchemeType(); conceptScheme.agencyID = model.Meta.Agency().CleanID(); conceptScheme.id = "DEFAULT"; conceptScheme.version = "1.0"; List <TextType> name = new List <TextType>(); { TextType enName = new TextType(); enName.lang = "en"; enName.Value = "Default Concept Scheme"; name.Add(enName); } conceptScheme.Name = name.ToArray(); List <ConceptType> schemeConcepts = new List <ConceptType>(); // Create fixed concepts (not contained in CDC) // Stock/flow/average indicator { ConceptType concept = new ConceptType(); concept.id = "SFA_INDICATOR"; name = new List <TextType>(); { TextType enName = new TextType(); enName.lang = "en"; enName.Value = "Stock, flow, average indicator"; name.Add(enName); } concept.Name = name.ToArray(); schemeConcepts.Add(concept); } // Seasonal adjustement { ConceptType concept = new ConceptType(); concept.id = "SEAS_ADJ"; name = new List <TextType>(); { TextType enName = new TextType(); enName.lang = "en"; enName.Value = "Seasonally adjustement"; name.Add(enName); } concept.Name = name.ToArray(); schemeConcepts.Add(concept); } // Daily adjustement { ConceptType concept = new ConceptType(); concept.id = "DAY_ADJ"; name = new List <TextType>(); { TextType enName = new TextType(); enName.lang = "en"; enName.Value = "Daily adjustement"; name.Add(enName); } concept.Name = name.ToArray(); schemeConcepts.Add(concept); } // Price basis { ConceptType concept = new ConceptType(); concept.id = "PRICE_BASIS"; name = new List <TextType>(); { TextType enName = new TextType(); enName.lang = "en"; enName.Value = "Price basis"; name.Add(enName); } concept.Name = name.ToArray(); schemeConcepts.Add(concept); } // Create codelists container List <CodeListType> codeLists = new List <CodeListType>(); //Create Common Code Lists codeLists.AddRange(createCommonCodes(model)); // Create key family KeyFamilyType keyFamily = new KeyFamilyType(); keyFamily.agencyID = model.Meta.Agency().CleanID(); keyFamily.id = model.Meta.Matrix.CleanID(); keyFamily.version = "1.0"; name = new List <TextType>(); { TextType enName = new TextType(); enName.lang = "en"; enName.Value = model.Meta.Matrix; name.Add(enName); } keyFamily.Name = name.ToArray(); ComponentsType components = new ComponentsType(); keyFamily.Components = components; // Create attributes List <AttributeType> attributes = new List <AttributeType>(); if (model.Meta.ContentVariable == null) { //Any non-null key words will be data set level attributes //Unit of measure attributes.Add(createUnitsAttribute(false, model.Meta.Agency().CleanID())); if (model.Meta.ContentInfo != null) { // Stock, flow, average if (model.Meta.ContentInfo.StockFa != null) { attributes.Add(createStockFlowAttribute(false, model.Meta.Agency().CleanID())); } // Seasonal adjustement if (model.Meta.ContentInfo.SeasAdj != null) { attributes.Add(createSeasAdjAttribute(false, model.Meta.Agency().CleanID())); } // Daily adjustment if (model.Meta.ContentInfo.DayAdj != null) { attributes.Add(createDayAdjAttribute(false, model.Meta.Agency().CleanID())); } // Base period if (model.Meta.ContentInfo.Baseperiod != null) { attributes.Add(createBasePeriodAttribute(false)); } // Reference period if (model.Meta.ContentInfo.RefPeriod != null) { attributes.Add(createReferencePeriodAttribute(false)); } // Current / fixed prices if (model.Meta.ContentInfo.CFPrices != null) { attributes.Add(createPriceBasisAttribute(false, model.Meta.Agency().CleanID())); } } } else { //Any non-null key words will be series level attributes //Unit of measure attributes.Add(createUnitsAttribute(true, model.Meta.Agency().CleanID())); if (model.Meta.ContentInfo != null) { // Stock, flow, average if (model.Meta.ContentInfo.StockFa != null) { attributes.Add(createStockFlowAttribute(true, model.Meta.Agency().CleanID())); } // Seasonal adjustement if (model.Meta.ContentInfo.SeasAdj != null) { attributes.Add(createSeasAdjAttribute(true, model.Meta.Agency().CleanID())); } // Daily adjustment if (model.Meta.ContentInfo.DayAdj != null) { attributes.Add(createDayAdjAttribute(true, model.Meta.Agency().CleanID())); } // Base period if (model.Meta.ContentInfo.Baseperiod != null) { attributes.Add(createBasePeriodAttribute(true)); } // Reference period if (model.Meta.ContentInfo.RefPeriod != null) { attributes.Add(createReferencePeriodAttribute(true)); } // Current / fixed prices if (model.Meta.ContentInfo.CFPrices != null) { attributes.Add(createPriceBasisAttribute(true, model.Meta.Agency().CleanID())); } } } attributes.Add(createObsStatusAttribute()); attributes.Add(createDecimalsAttribute()); // Add attributes to key family components components.Attribute = attributes.ToArray(); // Create dimensions List <DimensionType> dimensions = new List <DimensionType>(); // Create frequency dimension DimensionType freq = new DimensionType(); freq.conceptAgency = "SDMX"; freq.conceptSchemeRef = "CROSS_DOMAIN_CONCEPTS"; freq.conceptRef = "FREQ"; freq.conceptVersion = "1.0"; freq.codelistAgency = "SDMX"; freq.codelist = "CL_FREQ"; freq.codelistVersion = "1.0"; freq.isFrequencyDimension = true; dimensions.Add(freq); // Loop through variables to create concepts, codelists, and dimensions foreach (Variable var in model.Meta.Variables) { if (!isStandardConcept(var)) { // Create concept schemeConcepts.Add(createConcept(var)); // Create codelist codeLists.Add(createCodelist(var)); // Create dimension dimensions.Add(createDimension(var, model.Meta.Agency().CleanID())); } } // Create time dimension TimeDimensionType time = new TimeDimensionType(); time.conceptAgency = "SDMX"; time.conceptSchemeRef = "CROSS_DOMAIN_CONCEPTS"; time.conceptRef = "TIME_PERIOD"; time.conceptVersion = "1.0"; TextFormatType timeFormat = new TextFormatType(); timeFormat.textType = TextTypeType.ObservationalTimePeriod; time.TextFormat = timeFormat; components.TimeDimension = time; // Add dimensions to key family components components.Dimension = dimensions.ToArray(); // Create primary measure PrimaryMeasureType obsValue = new PrimaryMeasureType(); obsValue.conceptSchemeAgency = "SDMX"; obsValue.conceptSchemeRef = "CROSS_DOMAIN_CONCEPTS"; obsValue.conceptRef = "OBS_VALUE"; obsValue.conceptVersion = "1.0"; TextFormatType obsFormat = new TextFormatType(); obsFormat.textType = TextTypeType.Decimal; obsValue.TextFormat = obsFormat; components.PrimaryMeasure = obsValue; // Add key family to structure List <KeyFamilyType> keyFamilies = new List <KeyFamilyType>(); keyFamilies.Add(keyFamily); structure.KeyFamilies = keyFamilies.ToArray(); // Add concepts to scheme conceptScheme.Concept = schemeConcepts.ToArray(); conceptSchemes.Add(conceptScheme); concepts.ConceptScheme = conceptSchemes.ToArray(); // Add codelists to structure structure.CodeLists = codeLists.ToArray(); structure.Header = createHeader(model, false); return(structure); }
/////////////////////////////////////////////////////////////////////////////////////////////////// ////////////BUILD FROM V2.0 SCHEMA ////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////// /// <summary> /// Initializes a new instance of the <see cref="AttributeListCore"/> class. /// </summary> /// <param name="keyFamily"> /// The sdmxObject. /// </param> /// <param name="parent"> /// The parent. /// </param> public AttributeListCore(KeyFamilyType keyFamily, IMaintainableObject parent) : base( AttributeListObject.FixedId, SdmxStructureType.GetFromEnum(SdmxStructureEnumType.AttributeDescriptor), parent) { this.attributes = new List<IAttributeObject>(); if (keyFamily.Components != null && keyFamily.Components.Attribute != null) { foreach (AttributeType currentAttribute in keyFamily.Components.Attribute) { this.attributes.Add(new AttributeObjectCore(currentAttribute, this)); } } }
/// <summary> /// Initializes a new instance of the <see cref="CrossSectionalDataStructureObjectCore"/> class. /// </summary> /// <param name="keyFamilyType"> /// The itemMutableObject. /// </param> /// <exception cref="SdmxSemmanticException"> /// Throws Validate exception. /// </exception> public CrossSectionalDataStructureObjectCore(KeyFamilyType keyFamilyType) : base(keyFamilyType) { this._crossSectionalMeasures = new List<ICrossSectionalMeasure>(); this._crossSectionalAttachDataSet = new List<IComponent>(); this._crossSectionalAttachGroup = new List<IComponent>(); this._crossSectionalAttachSection = new List<IComponent>(); this._crossSectionalAttachObservation = new List<IComponent>(); this._attributeToMeasuresMap = new Dictionary<string, IList<ICrossSectionalMeasure>>(); this._measureDimensions = new List<string>(); this._codelistMap = new Dictionary<string, ICrossReference>(); //// TODO java 0.9.9 bug. XS DSD may not have any XS Measures //// Reverted changes that were made during sync //// Please do not change unless you are sure. if (keyFamilyType.Components == null || !CrossSectionalUtil.IsCrossSectional(keyFamilyType)) { throw new SdmxSemmanticException("Can not create ICrossSectionalDataStructureObject as there are no CrossSectional Measures defined"); } foreach (CrossSectionalMeasureType xsMeasureType in keyFamilyType.Components.CrossSectionalMeasure) { this._crossSectionalMeasures.Add(new CrossSectionalMeasureCore(xsMeasureType, this)); } foreach (DimensionType currentComponent in keyFamilyType.Components.Dimension) { string componentId = currentComponent.conceptRef; if (currentComponent.isMeasureDimension) { this._measureDimensions.Add(componentId); string codelistAgency = currentComponent.codelistAgency; if (string.IsNullOrWhiteSpace(codelistAgency)) { codelistAgency = this.BaseAgencyId; } ICrossReference codelistRef = new CrossReferenceImpl( this, codelistAgency, currentComponent.codelist, currentComponent.codelistVersion, SdmxStructureType.GetFromEnum(SdmxStructureEnumType.CodeList)); this._codelistMap.Add(componentId, codelistRef); } if (currentComponent.crossSectionalAttachDataSet != null && currentComponent.crossSectionalAttachDataSet.Value) { this.AddComponentToList(componentId, this._crossSectionalAttachDataSet); } if (currentComponent.crossSectionalAttachGroup != null && currentComponent.crossSectionalAttachGroup.Value) { this.AddComponentToList(componentId, this._crossSectionalAttachGroup); } if (currentComponent.crossSectionalAttachObservation != null && currentComponent.crossSectionalAttachObservation.Value) { this.AddComponentToList(componentId, this._crossSectionalAttachObservation); } if (currentComponent.crossSectionalAttachSection != null && currentComponent.crossSectionalAttachSection.Value) { this.AddComponentToList(componentId, this._crossSectionalAttachSection); } } foreach (AttributeType currentComponent0 in keyFamilyType.Components.Attribute) { string componentId1 = currentComponent0.conceptRef; if (currentComponent0.crossSectionalAttachDataSet != null && currentComponent0.crossSectionalAttachDataSet.Value) { this.AddComponentToList(componentId1, this._crossSectionalAttachDataSet); } if (currentComponent0.crossSectionalAttachGroup != null && currentComponent0.crossSectionalAttachGroup.Value) { this.AddComponentToList(componentId1, this._crossSectionalAttachGroup); } if (currentComponent0.crossSectionalAttachObservation != null && currentComponent0.crossSectionalAttachObservation.Value) { this.AddComponentToList(componentId1, this._crossSectionalAttachObservation); } if (currentComponent0.crossSectionalAttachSection != null && currentComponent0.crossSectionalAttachSection.Value) { this.AddComponentToList(componentId1, this._crossSectionalAttachSection); } this.SetAttributeMeasures(componentId1, currentComponent0.AttachmentMeasure); } if (keyFamilyType.Components.TimeDimension != null) { TimeDimensionType timeDimensionType = keyFamilyType.Components.TimeDimension; if (timeDimensionType.crossSectionalAttachDataSet != null && timeDimensionType.crossSectionalAttachDataSet.Value) { this.AddComponentToList(DimensionObject.TimeDimensionFixedId, this._crossSectionalAttachDataSet); } if (timeDimensionType.crossSectionalAttachGroup != null && timeDimensionType.crossSectionalAttachGroup.Value) { this.AddComponentToList(DimensionObject.TimeDimensionFixedId, this._crossSectionalAttachGroup); } if (timeDimensionType.crossSectionalAttachObservation != null && timeDimensionType.crossSectionalAttachObservation.Value) { this.AddComponentToList(DimensionObject.TimeDimensionFixedId, this._crossSectionalAttachObservation); } if (timeDimensionType.crossSectionalAttachSection != null && timeDimensionType.crossSectionalAttachSection.Value) { this.AddComponentToList(DimensionObject.TimeDimensionFixedId, this._crossSectionalAttachSection); } } try { this.Validate(); } catch (SdmxSemmanticException ex) { throw new SdmxSemmanticException(ex, ExceptionCode.ObjectStructureConstructionError, this.Urn); } catch (Exception th) { throw new SdmxException(th, ExceptionCode.ObjectStructureConstructionError, this.Urn); } }