public SessionImplObject GetSpecificCodemap(bool firstDimension, ConnectionStringSettings connectionStringSetting, SessionQuery query)
        {
            try
            {
                ISdmxObjects structure;
                //ISdmxObjects structure = query._structure;
                if (query.Structure == null)
                { structure = GetDsd(); }
                else
                { structure =
                    query.Structure; }

                IDataflowObject df = structure.Dataflows.First();
                IDataStructureObject kf = structure.DataStructures.First();

                query.Structure = structure;
                query.Dataflow = df;

                if (kf == null)
                    throw new InvalidOperationException("DataStructure is not set");

                TemplateWidget templateWidget = new TemplateWidget();
                var template = new TemplateObject();
                //if (connectionStringSetting.ConnectionString !=null && connectionStringSetting.ConnectionString.ToLower() != "file")
                if (connectionStringSetting.ConnectionString != null)
                {
                    templateWidget = new TemplateWidget(connectionStringSetting.ConnectionString);
                    template = templateWidget.GetSingle(new GetTemplateObject()
                    {
                        Template = new TemplateObject()
                        {
                            Dataflow = CodemapObj.Dataflow,
                            Configuration = CodemapObj.Configuration,
                        }
                    });
                }
                else
                { template = null; }

                string dimension = null;
                Dictionary<string, ICodelistObject> ConceptCodelists = null;

                // Se ha una template forzo il retrive di tutte le codelist per evitare problemi in stampa tabella
                if (template!=null)
                {
                    ConceptCodelists = this.GetCodelistMap(query, false);
                    query.Criteria = template.Criteria;

                    if (template.Criteria.ContainsKey(kf.TimeDimension.Id))
                    {
                        List<string> typeCheck = template.Criteria[kf.TimeDimension.Id] as List<string>;
                        if (typeCheck != null)
                            typeCheck.Sort();
                        query.SetCriteriaTime(typeCheck);
                    }
                }
                else
                 {
                    dimension = (firstDimension) ? kf.DimensionList.Dimensions.FirstOrDefault().Id : CodemapObj.Codelist;
                    IComponent component = kf.GetComponent(dimension);
                    ICodelistObject ConceptCodelistsComponent = GetCodeList(query, component);
                    //se chiedo tutte le codelist insieme
                    //ConceptCodelists = GetCodelistMap(query, false);
                    //se chiedo una codelist alla volta
                    //ConceptCodelists = GetCodelistMap(component.Id, df, kf;
                    ConceptCodelists = GetCodelistMap(component.Id, df, kf,query);

                  }

                CodemapSpecificResponseObject codemapret = new CodemapSpecificResponseObject()
                {
                    codemap = ParseCodelist(ConceptCodelists,kf,query),
                    costraint = (template != null) ? template.Criteria : null,
                    hideDimension = (template != null) ? template.HideDimension : null,
                    //enabledVar = (template != null) ? template.EnableVaration : true,
                    enabledVar = (template != null) ? template.EnableVaration : false,
                    enabledCri = (template != null) ? template.EnableCriteria : true,
                    enabledDec = (template != null) ? template.EnableDecimal : true,
                    codelist_target = dimension,
                    key_time_dimension = kf.TimeDimension.Id,
                    freq_dimension = kf.FrequencyDimension.Id,
                    dataflow = new MaintenableObj()
                    {
                        id = df.Id,
                        agency = df.AgencyId,
                        version = df.Version,
                        name = TextTypeHelper.GetText(df.Names, this.CodemapObj.Configuration.Locale),
                        description = TextTypeHelper.GetText(df.Descriptions, this.CodemapObj.Configuration.Locale)
                    }
                };

                this.SessionObj.SavedCodemap = new JavaScriptSerializer().Serialize(codemapret);
                return this.SessionObj;
            }
            catch (Exception ex)
            {
                Logger.Warn(ex.Message, ex);
                throw ex;
            }
        }
        public SessionImplObject GetCodemap(SessionQuery query, ConnectionStringSettings connectionStringSetting)
        {
            try
            {
                ISdmxObjects structure = query.Structure;// GetDsd();
                IDataflowObject df = structure.Dataflows.First();
                IDataStructureObject kf = structure.DataStructures.First();

                if (kf == null)
                    throw new InvalidOperationException("DataStructure is not set");
                if (df == null)
                    throw new InvalidOperationException("Dataflow is not set");

                Dictionary<string, ICodelistObject> ConceptCodelists = GetCodelistMap(query, false);

                if (this.SessionObj.SdmxObject!=null )
                { this.SessionObj.SdmxObject.Codelists.Clear();

                foreach (ICodelistObject codelist in ConceptCodelists.Values)
                    this.SessionObj.SdmxObject.AddCodelist(codelist);
                }

                /*check if exist connection and one template*/
                TemplateWidget templateWidget = new TemplateWidget();
                var template = new TemplateObject();

                ///if (connectionStringSetting.ConnectionString!=null && connectionStringSetting.ConnectionString.ToLower() != "file")
                if (connectionStringSetting.ConnectionString != null)
                {
                    templateWidget = new TemplateWidget(connectionStringSetting.ConnectionString);
                    template = templateWidget.GetSingle(new GetTemplateObject()
                    {
                        Template = new TemplateObject()
                        {
                            Dataflow = CodemapObj.Dataflow,
                            Configuration = CodemapObj.Configuration,
                        }
                    });
                }
                else
                { template = null; }

                CodemapSpecificResponseObject codemapret = new CodemapSpecificResponseObject()
                {
                    codemap = ParseCodelist(ConceptCodelists),
                    costraint = (template != null) ? template.Criteria : null,
                    hideDimension = (template != null) ? template.HideDimension : null,
                    //enabledVar = (template != null) ? template.EnableVaration : true,
                    enabledVar = (template != null) ? template.EnableVaration : false,
                    enabledCri = (template != null) ? template.EnableCriteria : true,
                    enabledDec = (template != null) ? template.EnableDecimal : true,
                    key_time_dimension = kf.TimeDimension.Id,
                    freq_dimension = kf.FrequencyDimension.Id,
                    dataflow = new MaintenableObj()
                    {
                        id = df.Id,
                        agency = df.AgencyId,
                        version = df.Version,
                        name = TextTypeHelper.GetText(df.Names, this.CodemapObj.Configuration.Locale),
                        description = TextTypeHelper.GetText(df.Descriptions, this.CodemapObj.Configuration.Locale)
                    }
                };

                this.SessionObj.SavedCodemap = new JavaScriptSerializer().Serialize(codemapret);
                return this.SessionObj;
            }
            catch (Exception ex)
            {
                Logger.Warn(ex.Message, ex);
                throw ex;
            }
        }