Exemple #1
0
        public IDataQuerySelection AddDimensionToQuery(QueryComponent queryComponent, IComponent component)
        {
            ISet <string> valuern = new HashSet <string>();

            foreach (ICode c in queryComponent.RetrieveCodes())
            {
                if (!string.IsNullOrEmpty(c.Id))
                {
                    valuern.Add((c.Id));
                }
            }
            IDataQuerySelection selection = new DataQueryDimensionSelectionImpl(component.Id, valuern);

            return(selection);
        }
        /*
         * 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);
        }