/// <summary>
        /// Handles the component mapping except for the TimeDimension when TRANSCODING is used
        /// </summary>
        /// <param name="reader">The IDataReader to read data from DDB</param>
        /// <param name="componentValues">The collection to store the component values</param>
        /// <param name="componentMappings">Component mappings list</param>
        /// <param name="info">The data retrieval information.</param>
        /// <returns>
        /// True all components were mapped - false when an unmapped code was found
        /// </returns>
        protected static bool HandleComponentMapping(IDataReader reader, IMappedValues componentValues, IList<IComponentMapping> componentMappings, DataRetrievalInfo info)
        {
            var dimensionAtObservationMapping = info.DimensionAtObservationMapping;
            for (int index = 0; index < componentMappings.Count; index++)
            {
                var componentMapping = componentMappings[index];

                var val = componentMapping.MapComponent(reader);
                if (val != null)
                {
                    componentValues.Add(index, val);
                    if (componentMapping.Component.FrequencyDimension)
                    {
                        componentValues.FrequencyValue = val;
                    }

                    if (componentMapping.Equals(dimensionAtObservationMapping))
                    {
                        componentValues.DimensionAtObservationValue = val;
                    }
                }
                else
                {
                    return false;
                }
            }

            return true;
        }
        protected override int StoreResults(IMappedValues componentValues, DataRetrievalInfo info)
        {
            var row = componentValues as MappedValues;
            if (row == null)
            {
                throw new ArgumentException("mappedValues not of MappedValues type");
            }

            var seriesInfo = info as DataRetrievalInfoSeries;

            RDFWriteSeries(seriesInfo, row);
            return RDFWriteObservation(seriesInfo, row, row.PrimaryMeasureValue.Value);
        }
 /// <summary>
 /// Read data from DDB, perfom mapping and transcoding and store it in the writer specified <see cref="DataRetrievalInfo"/>
 /// </summary>
 /// <param name="info">
 ///   The current Data Retrieval state 
 /// </param>
 /// <param name="reader">
 ///   The <see cref="IDataReader"/> to read data from DDB 
 /// </param>
 /// <param name="componentValues">
 ///   The component Values. 
 /// </param>
 /// <param name="mappings">
 ///   The collection of component mappings 
 /// </param>
 protected override void ReadData(DataRetrievalInfo info, IDataReader reader, IMappedValues componentValues, IList<IComponentMapping> mappings)
 {
     base.ReadData(info, reader, componentValues, mappings);
     var mappedValues = componentValues as MappedValues;
     if (mappedValues != null)
     {
         WriteXsMeasureCache(info as DataRetrievalInfoSeries, mappedValues.XSMeasureCaches);
     }
 }
        public void SetJsonStructure(IMappedValues componentValues)
        {
            if (_dsd == null)
                this._dsd = SdmxJsonSeriesDataQueryEngine.Instance._dsd;

            var row = componentValues as MappedValues;


            if (this.JsonStruct.Observation.ID == null)
            {
                this.JsonStruct.Observation.Role = "time";
                this.JsonStruct.Observation.ID = row.TimeDimensionValue.Key.Id;
            }

            AddObsValue(row.TimeValue);
            
            
            foreach (ComponentValue c in row.DimensionValues)
            {
                AddSerie(c.Key.Id, c.Value, GetKeyPosition(_dsd, c.Key.Id) , c.Key.FrequencyDimension);                
            }

            foreach (ComponentValue c in row.AttributeDataSetValues)
            {
                AddAttribute(c.Key.Id, c.Value, "DataSet");
            }
            foreach (ComponentValue c in row.AttributeGroupValues)
            {
                AddAttribute(c.Key.Id, c.Value, "Group");
            }
            foreach (ComponentValue c in row.AttributeSeriesValues)
            {
                AddAttribute(c.Key.Id, c.Value, "Series");
            }
            foreach (ComponentValue c in row.AttributeObservationValues)
            {
                AddAttribute(c.Key.Id, c.Value, "Observation");
            } 

        }
 /// <summary>
 /// Store the SDMX compliant data for each component entity in the store
 /// </summary>
 /// <param name="componentValues">
 /// The map between components and their values 
 /// </param>
 /// <param name="limit">
 /// The limit. 
 /// </param>
 /// <param name="info">
 /// The current Data Retrieval state 
 /// </param>
 /// <returns>
 /// The number of observations stored 
 /// </returns>
 protected override int StoreResults(IMappedValues componentValues, int limit, DataRetrievalInfo info)
 {
     return this.StoreResults(componentValues, info);
 }
        private static bool HandleTimeDimensionMapping(
            IDataReader reader, DataRetrievalInfo info, IMappedValues mappedValues)
        {
            if (info.TimeMapping != null)
            {
                string val = info.TimeTranscoder.MapComponent(reader, mappedValues.FrequencyValue);
                if (val != null)
                {
                    mappedValues.TimeValue = val;
                    if (info.IsTimePeriodAtObservation)
                    {
                        mappedValues.DimensionAtObservationValue = val;
                    }
                }
                else
                {
                    return false; // null value found at time dimension
                }
            }

            return true;
        }
 private static bool HandleMappings(IDataReader reader, DataRetrievalInfo info, IMappedValues componentValues, IList<IComponentMapping> mappings)
 {
     return HandleComponentMapping(reader, componentValues, mappings, info)
            && HandleTimeDimensionMapping(reader, info, componentValues); // MAT-262
 }
        protected override void ReadData(DataRetrievalInfo info, IDataReader reader, IMappedValues componentValues, IList<IComponentMapping> mappings)
        {
            int count = 0;

            while (reader.Read())
            {
                if (HandleMappings(reader, info, componentValues, mappings))
                {
                    count += this.StoreResults(componentValues, info);
                }
            }
            var seriesInfo = info as DataRetrievalInfoSeries;

            info.RecordsRead = count;

            if (count > 0)
            {                
                ((SdmxJsonBaseDataWriter)seriesInfo.SeriesWriter).WriteSDMXJsonStructure(this._dfo);                
            }

            
        }
        /// <summary>
        /// Write the columns
        /// </summary>
        /// <param name="info">
        /// The current Data Retrieval state 
        /// </param>
        /// <param name="componentValues">
        /// The component Values. 
        /// </param>
        /// <param name="mappings">
        /// The collection of component mappings 
        /// </param>
        /// <exception cref="ArgumentException">
        /// <paramref name="info"/>
        ///   not
        ///   <see cref="DataRetrievalInfoTabular"/>
        ///   type
        ///   -or-
        ///   <paramref name="componentValues"/>
        ///   not
        ///   <see cref="MappedValuesFlat"/>
        ///   type
        /// </exception>
        private void WriteColumns(
            DataRetrievalInfo info, IMappedValues componentValues, ICollection<IComponentMapping> mappings)
        {
            var mappedValues = componentValues as MappedValuesFlat;
            if (mappedValues == null)
            {
                throw new ArgumentException(Resources.ErrorComponentValuesNotMappedValuesFlaType, "componentValues");
            }

            var tabularInfo = info as DataRetrievalInfoTabular;
            if (tabularInfo == null)
            {
                throw new ArgumentException(Resources.ErrorInfoNotDataRetrievalInfoTabularType, "info");
            }

            for (int i = 0; i < mappings.Count; i++)
            {
                mappedValues.Add(i, null);
            }

            this.WriteColumns(mappedValues, tabularInfo);
        }
        /// <summary>
        /// Store the SDMX compliant data for each component entity in the store
        /// </summary>
        /// <param name="componentValues">
        /// The map between components and their values 
        /// </param>
        /// <param name="info">
        /// The current Data Retrieval state 
        /// </param>
        /// <returns>
        /// The number of observations stored 
        /// </returns>
        /// <exception cref="ArgumentException">
        /// <paramref name="info"/>
        ///   not
        ///   <see cref="DataRetrievalInfoTabular"/>
        ///   type
        ///   -or-
        ///   <paramref name="componentValues"/>
        ///   not
        ///   <see cref="MappedValuesFlat"/>
        ///   type
        /// </exception>
        protected override int StoreResults(IMappedValues componentValues, DataRetrievalInfo info)
        {
            var mappedValues = componentValues as MappedValuesFlat;
            if (mappedValues == null)
            {
                throw new ArgumentException(Resources.ErrorComponentValuesNotMappedValuesFlaType);
            }

            var tabularInfo = info as DataRetrievalInfoTabular;
            if (tabularInfo == null)
            {
                throw new ArgumentException(Resources.ErrorInfoNotDataRetrievalInfoTabularType);
            }

            this.WriteData(mappedValues, tabularInfo);

            return 1;
        }
Esempio n. 11
0
 /// <summary>
 /// Store the SDMX compliant data for each component entity in the store
 /// </summary>
 /// <param name="componentValues">
 /// The map between components and their values 
 /// </param>
 /// <param name="limit">
 /// The limit. 
 /// </param>
 /// <param name="info">
 /// The current Data Retrieval state 
 /// </param>
 /// <returns>
 /// The number of observations stored 
 /// </returns>
 protected abstract int StoreResults(IMappedValues componentValues, int limit, DataRetrievalInfo info);
Esempio n. 12
0
        /// <summary>
        /// Read data from DDB up the specified number of observations, perform mapping and transcoding and store it in the writer specified <see cref="DataRetrievalInfo"/>
        /// </summary>
        /// <param name="info">
        ///   The current Data Retrieval state 
        /// </param>
        /// <param name="reader">
        ///   The <see cref="IDataReader"/> to read data from DDB 
        /// </param>
        /// <param name="componentValues">
        ///   The component Values. 
        /// </param>
        /// <param name="limit">
        ///   The maximum number of observations, should be greater than 0 
        /// </param>
        /// <param name="mappings">
        ///   The collection of component mappings 
        /// </param>
        protected virtual void ReadData(DataRetrievalInfo info, IDataReader reader, IMappedValues componentValues, int limit, IList<IComponentMapping> mappings)
        {
            int count = 0;

            // note that setting the limit to SQL query doesn't help because a row might be ignored (see below) or a row might have multiple observations
            while ((count < limit) && reader.Read())
            {
                if (HandleMappings(reader, info, componentValues, mappings))
                {
                    count += this.StoreResults(componentValues, limit, info);
                }
            }

            // set the is truncated header flag
            info.IsTruncated = count >= limit;
            info.RecordsRead = count;
        }
Esempio n. 13
0
        /// <summary>
        /// Read data from DDB, perform mapping and transcoding and store it in the writer specified <see cref="DataRetrievalInfo"/>
        /// </summary>
        /// <param name="info">
        ///   The current Data Retrieval state 
        /// </param>
        /// <param name="reader">
        ///   The <see cref="IDataReader"/> to read data from DDB 
        /// </param>
        /// <param name="componentValues">
        ///   The component Values. 
        /// </param>
        /// <param name="mappings">
        ///   The collection of component mappings 
        /// </param>
        protected virtual void ReadData(DataRetrievalInfo info, IDataReader reader, IMappedValues componentValues, IList<IComponentMapping> mappings)
        {
            int count = 0;

            while (reader.Read())
            {
                if (HandleMappings(reader, info, componentValues, mappings))
                {
                    count += this.StoreResults(componentValues, info);
                }
            }
            //Pi
            info.RecordsRead = count;
        }
 /// <summary>
 /// Read data from DDB up the specified number of observations, perfom mapping and transcoding and store it in the writer specified <see cref="DataRetrievalInfo"/>
 /// </summary>
 /// <param name="info">
 ///   The current Data Retrieval state 
 /// </param>
 /// <param name="reader">
 ///   The <see cref="IDataReader"/> to read data from DDB 
 /// </param>
 /// <param name="componentValues">
 ///   The component Values. 
 /// </param>
 /// <param name="limit">
 ///   The maximum number of observations, should be greater than 0 
 /// </param>
 /// <param name="mappings">
 ///   The collection of component mappings 
 /// </param>
 protected override void ReadData(DataRetrievalInfo info, IDataReader reader, IMappedValues componentValues, int limit, IList<IComponentMapping> mappings)
 {
     this.WriteColumns(info, componentValues, mappings);
     base.ReadData(info, reader, componentValues, limit, mappings);
 }
        /// <summary>
        /// Store the SDMX compliant data for each component entity in the store
        /// </summary>
        /// <param name="componentValues">
        /// The map between components and their values 
        /// </param>
        /// <param name="limit">
        /// The limit. 
        /// </param>
        /// <param name="info">
        /// The current Data Retrieval state 
        /// </param>
        /// <returns>
        /// The number of observations stored 
        /// </returns>
        protected override int StoreResults(IMappedValues componentValues, int limit, DataRetrievalInfo info)
        {
            var row = componentValues as MappedValues;
            if (row == null)
            {
                throw new ArgumentException("mappedValues not of MappedValues type");
            }

            int maxMeasures = Math.Min(info.CrossSectionalMeasureMappings.Count, limit);
            int count = WriteXsMeasures(info as DataRetrievalInfoSeries, maxMeasures, row);
            return count;
        }
        /// <summary>
        /// Store the SDMX compliant data for each component entity in the store
        /// </summary>
        /// <param name="componentValues">
        /// The map between components and their values 
        /// </param>
        /// <param name="limit">
        /// The limit. 
        /// </param>
        /// <param name="info">
        /// The current Data Retrieval state 
        /// </param>
        /// <returns>
        /// The number of observations stored 
        /// </returns>
        protected override int StoreResults(IMappedValues componentValues, int limit, DataRetrievalInfo info)
        {
            var row = componentValues as MappedXsValues;
            if (row == null)
            {
                throw new ArgumentException("mappedValues not of MappedXsValues type");
            }

            var xsInfo = info as DataRetrievalInfoXS;
            if (xsInfo == null)
            {
                throw new ArgumentException("info not of DataRetrievalInfoXS type");
            }

            WriteDataSet(row, xsInfo);

            if (row.IsNewGroupKey())
            {
                WriteGroup(row, xsInfo);
            }

            if (row.IsNewSectionKey())
            {
                WriteSection(row, xsInfo);
            }

            return WriteObservation(row, xsInfo, limit);
        }
        /// <summary>
        /// Store the SDMX compliant data for each component entity in the store
        /// </summary>
        /// <param name="componentValues">
        /// The map between components and their values 
        /// </param>
        /// <param name="info">
        /// The current Data Retrieval state 
        /// </param>
        /// <returns>
        /// The number of observations stored 
        /// </returns>
        
        protected override int StoreResults(IMappedValues componentValues, DataRetrievalInfo info)
        {
            
            var row = componentValues as MappedValues;
            
            if (row == null)
            {
                throw new ArgumentException("mappedValues not of MappedValues type");
            }
            
            var seriesInfo = info as DataRetrievalInfoSeries;
            
            ((SdmxJsonBaseDataWriter)seriesInfo.SeriesWriter).SetJsonStructure(componentValues);

            if (row.IsNewKey())
            {
                if (((SdmxJsonBaseDataWriter)seriesInfo.SeriesWriter).StartedObservations) 
                {
                    ((SdmxJsonBaseDataWriter)seriesInfo.SeriesWriter).CloseObject();
                    ((SdmxJsonBaseDataWriter)seriesInfo.SeriesWriter).CloseObject();
                    ((SdmxJsonBaseDataWriter)seriesInfo.SeriesWriter)._startedObservations = false;
                }
                TryWriteDataSet(row, seriesInfo);
                WriteSdmxJsonSeries(seriesInfo, row);
                
            }

            return WriteObservation(seriesInfo, row, row.PrimaryMeasureValue.Value);
        }