/*
         * internal List<DataCriteria> InitCriteria(IDataStructureObject kf, Dictionary<string, List<string>> Criteria)
         * {
         *  List<DataCriteria> criterias = new List<DataCriteria>();
         *  foreach (IComponent comp in kf.Components.Where(c => Criteria.ContainsKey(c.Id)))
         *  {
         *      criterias.Add(new DataCriteria() { component = comp.Id, values = Criteria[comp.Id] });
         *  }
         *
         *  foreach (IComponent comp in kf.DimensionList.Dimensions.Where(c => !Criteria.ContainsKey(c.Id)))
         *  {
         *      criterias.Add(new DataCriteria() { component = comp.Id, values = Criteria[comp.Id] });
         *  }
         *  return criterias;
         * }
         */


        public IDataQuery CreateQueryBean(IDataflowObject df, IDataStructureObject kf, List <DataCriteria> Criterias)
        {
            ISet <IDataQuerySelection> selections = new HashSet <IDataQuerySelection>();
            string startTime = String.Empty;
            string endTime   = String.Empty;

            // Under the DataWhere only one child MUST reside.
            foreach (var queryComponent in Criterias)
            {
                if (queryComponent != null)
                {
                    if (!string.IsNullOrEmpty(queryComponent.component) && queryComponent.component != kf.TimeDimension.Id)
                    {
                        //if (queryComponent.values.Count > 0) baco 25/11/2015
                        if (queryComponent.values.Count > 0 && !string.IsNullOrEmpty(queryComponent.values[0]))
                        {
                            ISet <string> valuern = new HashSet <string>();
                            foreach (string c in queryComponent.values)
                            {
                                if (!string.IsNullOrEmpty(c))
                                {
                                    valuern.Add((c));
                                }
                            }
                            IDataQuerySelection selection = new DataQueryDimensionSelectionImpl(queryComponent.component, valuern);
                            selections.Add(selection);
                        }
                    }
                    else if (!string.IsNullOrEmpty(queryComponent.component) && queryComponent.component == kf.TimeDimension.Id)
                    {
                        if (queryComponent.values.Count > 0 && !string.IsNullOrEmpty(queryComponent.values[0]))
                        {
                            startTime = queryComponent.values[0];
                            //if (queryComponent.values.Count > 1 && !string.IsNullOrEmpty(queryComponent.values[1]))
                            if (queryComponent.values.Count > 1 && !string.IsNullOrEmpty(queryComponent.values[queryComponent.values.Count - 1]))
                            {
                                endTime = queryComponent.values[queryComponent.values.Count - 1];
                            }
                        }
                    }
                }
            }
            IDataQuerySelectionGroup sel = new DataQuerySelectionGroupImpl(selections, null, null);

            if ((string.IsNullOrEmpty(startTime)) && (!string.IsNullOrEmpty(endTime)))
            {
                sel = new DataQuerySelectionGroupImpl(selections, new SdmxDateCore(endTime), new SdmxDateCore(endTime));
            }
            else if ((!string.IsNullOrEmpty(startTime)) && (string.IsNullOrEmpty(endTime)))
            {
                sel = new DataQuerySelectionGroupImpl(selections, new SdmxDateCore(startTime), new SdmxDateCore(startTime));
            }
            else if ((!string.IsNullOrEmpty(startTime)) && (!string.IsNullOrEmpty(endTime)))
            {
                sel = new DataQuerySelectionGroupImpl(selections, new SdmxDateCore(startTime), new SdmxDateCore(endTime));
            }
            IList <IDataQuerySelectionGroup> selGroup = new List <IDataQuerySelectionGroup>();

            selGroup.Add(sel);
            IDataQuery query;

            if (DataObjConfiguration._TypeEndpoint == EndpointType.REST)
            {
                query = new DataQueryFluentBuilder().Initialize(kf, df).
                        WithDataQuerySelectionGroup(selGroup).Build();
            }
            else
            {
                query = new DataQueryFluentBuilder().Initialize(kf, df).
                        WithOrderAsc(true).
                        WithMaxObservations(MaximumObservations).
                        WithDataQuerySelectionGroup(selGroup).Build();
            }
            return(query);
        }
Exemple #2
0
        /// <summary>
        /// Create a SDMX Model Query for <see cref="SessionQuery.Dataflow"/> from the criteria at <see cref="SessionQuery._queryComponentIndex"/>
        /// </summary>
        /// <returns>
        /// A QueryBean object
        /// </returns>
        public IDataQuery CreateQueryBean()
        {
            if (!this._sessionQuery.IsDataflowSet)
            {
                throw new InvalidOperationException("Dataflow is not set");
            }

            ISet <IDataQuerySelection> selections = new HashSet <IDataQuerySelection>();
            string startTime = String.Empty;
            string endTime   = String.Empty;

            // Under the DataWhere only one child MUST reside.
            foreach (var queryComponent in this._sessionQuery.GetQueryComponents())
            {
                if (queryComponent != null)
                {
                    IComponent component = queryComponent.GetKeyFamilyComponent();
                    var        dimension = component as IDimension;

                    if (dimension != null && !dimension.TimeDimension)
                    {
                        IDataQuerySelection selection = this.AddDimensionToQuery(queryComponent, component);
                        selections.Add(selection);
                    }
                    else if (dimension != null && dimension.TimeDimension)
                    {
                        if (!string.IsNullOrEmpty(queryComponent.StartDate))
                        {
                            startTime = queryComponent.StartDate;
                            endTime   = queryComponent.EndDate;
                        }
                    }
                }
            }
            IDataQuerySelectionGroup sel = new DataQuerySelectionGroupImpl(selections, null, null);

            if ((string.IsNullOrEmpty(startTime)) && (!string.IsNullOrEmpty(endTime)))
            {
                sel = new DataQuerySelectionGroupImpl(selections, null, new SdmxDateCore(endTime));
            }
            else if ((!string.IsNullOrEmpty(startTime)) && (string.IsNullOrEmpty(endTime)))
            {
                sel = new DataQuerySelectionGroupImpl(selections, new SdmxDateCore(startTime), null);
            }
            else if ((!string.IsNullOrEmpty(startTime)) && (!string.IsNullOrEmpty(endTime)))
            {
                sel = new DataQuerySelectionGroupImpl(selections, new SdmxDateCore(startTime), new SdmxDateCore(endTime));
            }
            IList <IDataQuerySelectionGroup> selGroup = new List <IDataQuerySelectionGroup>();

            selGroup.Add(sel);
            IDataQuery query;

            if (_sessionQuery.EndPointType == EndpointType.REST)
            {
                query = new DataQueryFluentBuilder().Initialize(_sessionQuery.KeyFamily, _sessionQuery.Dataflow).
                        WithDataQuerySelectionGroup(selGroup).Build();
            }
            else
            {
                query = new DataQueryFluentBuilder().Initialize(_sessionQuery.KeyFamily, _sessionQuery.Dataflow).
                        WithOrderAsc(true).
                        WithMaxObservations(_sessionQuery.MaximumObservations).
                        WithDataQuerySelectionGroup(selGroup).Build();
            }
            return(query);
        }