///////////////////////////////////////////////////////////////////////////////////////////////////
		////////////BUILD FROM MUTABLE OBJECTS              //////////////////////////////////////////////////
		///////////////////////////////////////////////////////////////////////////////////////////////////
		#region Constructors and Destructors

        /// <summary>
        /// Initializes a new instance of the <see cref="ComponentCore" /> class.
        /// </summary>
        /// <param name="itemMutableObject">The agencyScheme.</param>
        /// <param name="parent">The parent.</param>
        /// <param name="validateComponentAttributes">if set to <c>true</c> [validate component attributes].</param>
        /// <exception cref="SdmxException">Throws Validate exception.</exception>
		protected internal ComponentCore(IComponentMutableObject itemMutableObject, IIdentifiableObject parent, bool validateComponentAttributes = true)
			: base(itemMutableObject, parent)
		{
			try
			{
				if (itemMutableObject.Representation != null)
				{
					this.LocalRepresentation = new RepresentationCore(itemMutableObject.Representation, this);
				}

				if (itemMutableObject.ConceptRef != null)
				{
					this._conceptRef = new CrossReferenceImpl(this, itemMutableObject.ConceptRef);
				}
			}
			catch (Exception th)
			{
                throw new SdmxException("IsError creating component: " + this, th);
			}

            if (validateComponentAttributes)
            {
                this.ValidateComponentAttributes();
            }
        }
Example #2
0
        /// <summary>
        /// Retrieve the concept reference.
        /// </summary>
        /// <param name="dataReader">
        /// The data reader.
        /// </param>
        /// <param name="component">
        /// The component.
        /// </param>
        private static void RetrieveConceptRef(IDataRecord dataReader, IComponentMutableObject component)
        {
            //// TODO cache category references
            string conceptRef           = DataReaderHelper.GetString(dataReader, "CONCEPTREF");
            string conceptSchemeRef     = DataReaderHelper.GetString(dataReader, "CONCEPTSCHEME_ID");
            string conceptSchemeVersion = DataReaderHelper.GetString(dataReader, "CONCEPT_VERSION");
            string conceptSchemeAgency  = DataReaderHelper.GetString(dataReader, "CONCEPT_AGENCY");

            component.ConceptRef = new StructureReferenceImpl(conceptSchemeAgency, conceptSchemeRef, conceptSchemeVersion, SdmxStructureEnumType.Concept, conceptRef);
        }
Example #3
0
 /// <summary>
 /// Add references to <paramref name="structureReferences"/>
 /// </summary>
 /// <param name="component">
 /// The component.
 /// </param>
 /// <param name="structureReferences">
 /// The structure references.
 /// </param>
 private static void AddReferences(IComponentMutableObject component, ICollection <IStructureReference> structureReferences)
 {
     if (component != null)
     {
         structureReferences.Add(component.ConceptRef);
         if (component.Representation != null && component.Representation.Representation != null)
         {
             structureReferences.Add(component.Representation.Representation);
         }
     }
 }
Example #4
0
        /// <summary>
        /// Fill the components of a KeyFamilyBean object
        /// </summary>
        /// <param name="parent">
        /// The KeyFamilyBean to populate
        /// </param>
        /// <param name="parentSysId">
        /// The DSD.DSD_ID PrimaryKey
        /// </param>
        /// <returns>
        /// The <see cref="IDataStructureMutableObject"/> which will be the same as <paramref name="parent"/> unless the DSD
        ///     is cross sectional.
        /// </returns>
        private IDataStructureMutableObject FillComponents(IDataStructureMutableObject parent, long parentSysId)
        {
            var crossSectionalMeasures = new List <ICrossSectionalMeasureMutableObject>();
            var crossDataSet           = new HashSet <string>();
            var crossGroup             = new HashSet <string>();
            var crossSection           = new HashSet <string>();
            var crossObs     = new HashSet <string>();
            var componentMap = new Dictionary <long, IComponentMutableObject>();
            IStructureReference measureCodelistRepresentation = null;

            using (DbCommand command = this._commandBuilder.Build(new ItemSqlQuery(this._componentQueryInfo, parentSysId)))
                using (IDataReader dataReader = this.MappingStoreDb.ExecuteReader(command))
                {
                    var idIdx     = dataReader.GetOrdinal("ID");
                    var compIdIdx = dataReader.GetOrdinal("COMP_ID");

                    while (dataReader.Read())
                    {
                        IComponentMutableObject component = RetrieveComponentType(parent, dataReader, crossSectionalMeasures);
                        componentMap.Add(dataReader.GetInt64(compIdIdx), component);

                        component.Id = DataReaderHelper.GetString(dataReader, idIdx);

                        measureCodelistRepresentation = RetrieveRepresentationReference(dataReader, component);
                        RetrieveConceptRef(dataReader, component);

                        RetrieveCrossSectionalAttachments(dataReader, crossDataSet, component.Id, crossGroup, crossSection, crossObs);
                    }
                }

            if (parent.AttributeList != null)
            {
                this.SetupGroupAttributes(parent, parentSysId);

                SetupAttributeAttachmentLevel(parent, this.GetAttributeDimensionRefs(parentSysId));
            }

            parent = SetupCrossSectionalDsd(parent, crossDataSet, crossGroup, crossSection, crossObs, crossSectionalMeasures, measureCodelistRepresentation);
            this.SetupAttributesAttachmentCrossMeasures(parent as ICrossSectionalDataStructureMutableObject, parentSysId);

            this.GetTextFormatInformation(parentSysId, componentMap);

            this._componentAnnotationRetrieverEngine.RetrieveAnnotations(parentSysId, componentMap);

            return(parent);
        }
Example #5
0
        /// <summary>
        /// Gets the text format information.
        /// </summary>
        /// <param name="parentSysId">
        /// The parent system unique identifier.
        /// </param>
        /// <param name="componentMap">
        /// The component map.
        /// </param>
        private void GetTextFormatInformation(long parentSysId, IDictionary <long, IComponentMutableObject> componentMap)
        {
            var textFormats = new Dictionary <long, ITextFormatMutableObject>();

            using (var command = this.MappingStoreDb.GetSqlStringCommandFormat(DsdConstant.TextFormatQueryFormat, this.MappingStoreDb.CreateInParameter("dsdId", DbType.Int64, parentSysId)))
                using (var reader = this.MappingStoreDb.ExecuteReader(command))
                {
                    var compIdIdx     = reader.GetOrdinal("COMP_ID");
                    var enumNameIdx   = reader.GetOrdinal("ENUM_NAME");
                    var enumValueIdx  = reader.GetOrdinal("ENUM_VALUE");
                    var facetValueIdx = reader.GetOrdinal("FACET_VALUE");

                    while (reader.Read())
                    {
                        var compId = reader.GetInt64(compIdIdx);

                        ITextFormatMutableObject textFormat;
                        if (!textFormats.TryGetValue(compId, out textFormat))
                        {
                            textFormat = new TextFormatMutableCore();
                            textFormats.Add(compId, textFormat);
                        }

                        var enumName   = DataReaderHelper.GetString(reader, enumNameIdx);
                        var enumValue  = DataReaderHelper.GetString(reader, enumValueIdx);
                        var facetValue = DataReaderHelper.GetString(reader, facetValueIdx);
                        PopulateTextFormat(enumName, enumValue, textFormat, facetValue);
                    }
                }

            foreach (var textFormat in textFormats)
            {
                IComponentMutableObject component = componentMap[textFormat.Key];
                if (component.Representation == null)
                {
                    component.Representation = new RepresentationMutableCore();
                }

                component.Representation.TextFormat = textFormat.Value;
            }
        }
Example #6
0
        /// <summary>
        /// The populate attributes.
        /// </summary>
        /// <param name="parent">
        /// The parent.
        /// </param>
        /// <param name="dataReader">
        /// The data reader.
        /// </param>
        /// <returns>
        /// The <see cref="IComponentMutableObject"/>.
        /// </returns>
        /// <exception cref="SdmxNotImplementedException">
        /// Unsupported attachment level at COMPONENT.ATT_ASS_LEVEL
        /// </exception>
        private static IComponentMutableObject PopulateAttributes(IDataStructureMutableObject parent, IDataRecord dataReader)
        {
            var attribute = new AttributeMutableCore {
                AssignmentStatus = DataReaderHelper.GetString(dataReader, "ATT_STATUS")
            };

            // TODO pending support already in Java
            ////attribute.TimeFormat = DataReaderHelper.GetBoolean(dataReader, "ATT_IS_TIME_FORMAT")
            ////                           ? "true"
            ////                           : "false";
            string attachmentLevel = DataReaderHelper.GetString(dataReader, "ATT_ASS_LEVEL");

            switch (attachmentLevel)
            {
            case AttachmentLevelConstants.DataSet:
                attribute.AttachmentLevel = AttributeAttachmentLevel.DataSet;
                break;

            case AttachmentLevelConstants.Group:
                attribute.AttachmentLevel = AttributeAttachmentLevel.Group;
                break;

            case AttachmentLevelConstants.Observation:
                attribute.AttachmentLevel = AttributeAttachmentLevel.Observation;
                break;

            case AttachmentLevelConstants.Series:
                attribute.AttachmentLevel = AttributeAttachmentLevel.DimensionGroup;

                break;

            default:
                throw new SdmxNotImplementedException(ExceptionCode.Unsupported, "Attachment:" + attachmentLevel);
            }

            IComponentMutableObject component = attribute;

            parent.AddAttribute(attribute);
            return(component);
        }
            /// <summary>
            /// The write cross component attributes.
            /// </summary>
            /// <param name="component">
            /// The component.
            /// </param>
            /// <param name="tryWriteAttribute">
            /// The try write attribute.
            /// </param>
            public void WriteCrossComponentAttributes(
                IComponentMutableObject component, Action<AttributeNameTable, bool> tryWriteAttribute)
            {
                if (this._crossSectional == null)
                {
                    return;
                }

                string item = component.ConceptRef.ChildReference.Id;
                tryWriteAttribute(AttributeNameTable.crossSectionalAttachDataSet, this._crossDataSet.Contains(item));

                tryWriteAttribute(AttributeNameTable.crossSectionalAttachGroup, this._crossGroup.Contains(item));
                tryWriteAttribute(AttributeNameTable.crossSectionalAttachSection, this._crossSection.Contains(item));
                tryWriteAttribute(AttributeNameTable.crossSectionalAttachObservation, this._crossObs.Contains(item));
            }
        /// <summary>
        /// Write the common element of a Component
        /// </summary>
        /// <param name="component">
        /// The IComponentMutableObject object
        /// </param>
        private void WriteComponentContent(IComponentMutableObject component)
        {
            if (component.Representation != null && component.Representation.TextFormat != null)
            {
                this.WriteTextFormat(component.Representation.TextFormat);
            }

            this.WriteAnnotations(ElementNameTable.Annotations, component.Annotations);
        }
        /// <summary>
        /// Write the common xml attribute of a Component
        /// </summary>
        /// <param name="component">
        /// The IComponentMutableObject object
        /// </param>
        private void WriteComponentAttributes(IComponentMutableObject component)
        {
            IStructureReference concept = component.ConceptRef;
            this.TryWriteAttribute(AttributeNameTable.conceptRef, concept.ChildReference.Id);
            this.TryWriteAttribute(AttributeNameTable.conceptSchemeRef, concept.MaintainableReference.MaintainableId);
            this.TryWriteAttribute(AttributeNameTable.conceptSchemeAgency, concept.MaintainableReference.AgencyId);

            //// TODO -- use either MT or ESTAT extensions. NSI Client needs those extensions either.
            ////if (this.TargetSchema == SdmxSchema.VersionTwoPointZeroEuroStat)
            ////{
            ////TryWriteAttribute(AttributeNameTable.conceptSchemeVersion, concept.MaintainableReference.Version);
            TryWriteAttribute(AttributeNameTable.conceptSchemeVersion, concept.MaintainableReference.Version);
            ////}
        }
Example #10
0
        /// <summary>
        /// Retrieve the component representation reference.
        /// </summary>
        /// <param name="dataReader">
        /// The data reader.
        /// </param>
        /// <param name="component">
        /// The component.
        /// </param>
        /// <returns>
        /// The <see cref="IStructureReference"/> of the representation.
        /// </returns>
        private static IStructureReference RetrieveRepresentationReference(IDataRecord dataReader, IComponentMutableObject component)
        {
            IStructureReference measureCodelistRepresentation = null;
            string codelist = DataReaderHelper.GetString(dataReader, "CODELIST_ID");

            if (!string.IsNullOrWhiteSpace(codelist))
            {
                string codelistAgency         = DataReaderHelper.GetString(dataReader, "CODELIST_AGENCY");
                string codelistVersion        = DataReaderHelper.GetString(dataReader, "CODELIST_VERSION");
                var    codelistRepresentation = new StructureReferenceImpl(codelistAgency, codelist, codelistVersion, SdmxStructureEnumType.CodeList);
                component.Representation = new RepresentationMutableCore {
                    Representation = codelistRepresentation
                };
            }

            // Important. Concept scheme must be checked *after* codelist.
            var conceptSchemeRepresentation = DataReaderHelper.GetString(dataReader, "REP_CS_ID");

            if (!string.IsNullOrWhiteSpace(conceptSchemeRepresentation))
            {
                var measureDimension = component as IDimensionMutableObject;
                if (measureDimension != null && measureDimension.MeasureDimension)
                {
                    string agency  = DataReaderHelper.GetString(dataReader, "REP_CS_AGENCY");
                    string version = DataReaderHelper.GetString(dataReader, "REP_CS_VERSION");
                    if (component.Representation != null)
                    {
                        measureCodelistRepresentation = component.Representation.Representation;
                    }

                    measureDimension.Representation = new RepresentationMutableCore
                    {
                        Representation =
                            new StructureReferenceImpl(
                                agency,
                                conceptSchemeRepresentation,
                                version,
                                SdmxStructureEnumType.ConceptScheme)
                    };
                }
            }

            return(measureCodelistRepresentation);
        }
        /// <summary>
        /// Handles the Component element child elements
        /// </summary>
        /// <param name="parent">
        /// The parent IComponentMutableObject object
        /// </param>
        /// <param name="localName">
        /// The name of the current xml element
        /// </param>
        /// <returns>
        /// The <see cref="StructureReaderBaseV20.ElementActions"/>.
        /// </returns>
        private ElementActions HandleChildElements(IComponentMutableObject parent, object localName)
        {
            if (NameTableCache.IsElement(localName, ElementNameTable.TextFormat))
            {
                parent.Representation = new RepresentationMutableCore { TextFormat = HandleTextFormat(this.Attributes) };

                //// TextFormatType has only attributes so we do not expect anything else.
                return ElementActions.Empty;
            }

            return null;
        }
        /// <summary>
        /// Populates the properties of the given IComponentMutableObject object from the given xml attributes dictionary
        /// </summary>
        /// <param name="parent">
        /// The <see cref="ICrossSectionalDataStructureMutableObject"/>
        /// </param>
        /// <param name="component">
        /// The given IComponentMutableObject object
        /// </param>
        /// <param name="attributes">
        /// The dictionary contains the attributes of the element
        /// </param>
        private static void ParseComponentBaseAttributes(ICrossSectionalDataStructureMutableObject parent, IComponentMutableObject component, IDictionary<string, string> attributes)
        {
            var conceptRef = ParseComponentConceptAttributes(component, attributes);

            // code list attributes
            string codelist = Helper.TrySetFromAttribute(attributes, AttributeNameTable.codelist, string.Empty);
            if (!string.IsNullOrEmpty(codelist))
            {
                component.Representation = new RepresentationMutableCore();
                string codelistVersion = Helper.TrySetFromAttribute(attributes, AttributeNameTable.codelistVersion, string.Empty);
                string codelistAgency = Helper.TrySetFromAttribute(attributes, AttributeNameTable.codelistAgency, string.Empty);
                component.Representation.Representation = new StructureReferenceImpl(codelistAgency, codelist, codelistVersion, SdmxStructureEnumType.CodeList);
            }

            // XS
            var id = component.Id ?? conceptRef;
            AddCrossSectionalAttach(id, parent.CrossSectionalAttachDataSet, AttributeNameTable.crossSectionalAttachDataSet, attributes);
            AddCrossSectionalAttach(id, parent.CrossSectionalAttachGroup, AttributeNameTable.crossSectionalAttachGroup, attributes);
            AddCrossSectionalAttach(id, parent.CrossSectionalAttachSection, AttributeNameTable.crossSectionalAttachSection, attributes);
            AddCrossSectionalAttach(id, parent.CrossSectionalAttachObservation, AttributeNameTable.crossSectionalAttachObservation, attributes);
        }
Example #13
0
 /// <summary>
 /// Gets the enumerated representation.
 /// </summary>
 /// <param name="component">The component.</param>
 /// <returns>The representation <see cref="IStructureReference"/> of the <paramref name="component"/>; otherwise null.</returns>
 public static IStructureReference GetEnumeratedRepresentation(this IComponentMutableObject component)
 {
     return(component.Representation != null ? component.Representation.Representation : null);
 }