public string ComponentSave(string concept, string[] ids, SessionQuery query)
        {
            //SessionQuery query = SessionQueryManager.GetSessionQuery(HttpContext.Current.Session);
            if (query == null || query.KeyFamily == null)
            {
                throw new InvalidOperationException("query is not set");
            }

            IDimension component = Utils.GetComponentByName(query.KeyFamily, concept);

            ICodelistObject codes = query.GetCachedCodelist(component);
            query.ClearCodeListAfter(component);
            if (ids.Length == 0)
            {
                query.RemoveComponent(component);
                return _emptyJSON;
            }

               // try
            //{
                if (codes == null)
                {
                    //QueryBuilder queryBuilder = new QueryBuilder(query);
                    //INsiClient nsiClient = GetNSIClient(this.Context);
                    //codes = nsiClient.GetCodelist(query.Dataflow, query.KeyFamily, component, queryBuilder.CreateConstraintBean(component.ConceptRef.ChildReference.Id));
                    codes = this.GetCodeListCostraint(query.Dataflow, query.KeyFamily, component);
                    query.UpdateCodelistMap(codes, component);
                }

                var codesList = new List<ICode>();

                //time dimensione with region period
                if (component.TimeDimension && ids.Length == 1)
                {
                    {
                        int offsetTime = int.Parse(ids.First());
                        int lengthTime = codes.Items.Count;

                        if ((lengthTime - offsetTime) >= 0)
                        {
                            var _codes = codes.Items.Reverse().Take(offsetTime);// codMap[kf.TimeDimension.Id].Reverse().Take(offsetTime);
                            List<string> _criteriaTime = (from c in _codes select c.Id).ToList<string>();

                            codesList.Add((ICode)codes.GetCodeById(_criteriaTime.Last()));
                            codesList.Add((ICode)codes.GetCodeById(_criteriaTime.First()));
            /*
                            this.DataObj.Criteria[kf.TimeDimension.Id] = new List<string>();
                            this.DataObj.Criteria[kf.TimeDimension.Id].Add(_criteriaTime.Last());
                            this.DataObj.Criteria[kf.TimeDimension.Id].Add(_criteriaTime.First());
             * */
                        }
                        else
                        {
                            /*
                            this.DataObj.Criteria[kf.TimeDimension.Id] = new List<string>();
                            this.DataObj.Criteria[kf.TimeDimension.Id].Add(codemap[kf.TimeDimension.Id].First().Key);
                            this.DataObj.Criteria[kf.TimeDimension.Id].Add(codemap[kf.TimeDimension.Id].Last().Key);
                             */
                            var _codes = codes.Items.Reverse().Take(lengthTime);// codMap[kf.TimeDimension.Id].Reverse().Take(offsetTime);
                            List<string> _criteriaTime = (from c in _codes select c.Id).ToList<string>();

                            codesList.Add((ICode)codes.GetCodeById(_criteriaTime.First()));
                            codesList.Add((ICode)codes.GetCodeById(_criteriaTime.Last()));

                        }
                    }
                }
                else
                {
                    foreach (string id in ids)
                    {
                        codesList.Add((ICode)codes.GetCodeById(id));
                    }
                }

                    query.SaveComponent(component, codesList);
                return _emptyJSON;
              //  }
        }
        /*NUOVO SESSION QUERY*/
        /// <summary>
        /// Get a CodeList for the specified component from either <see cref="INsiClient"/> or from <see cref="SessionQuery"/> cache.
        /// </summary>
        /// <param name="query">
        /// The SessionQuery holding the current dataflow and possibly the artefact cache
        /// </param>
        /// <param name="component">
        /// The SDMX DSD component to retrieve the artefact for
        /// </param>
        /// <returns>
        /// A artefact or null
        /// </returns>
        private ICodelistObject GetCodeList(SessionQuery query, IComponent component)
        {
            //INsiClient nsiClient = GetNSIClient(this.Context);
            ICodelistObject codes = query.GetCachedCodelist(component);
            if (codes == null)
            {
                //QueryBuilder queryBuilder = new QueryBuilder(query);
                //codes = IGetSDMX.GetCodelist(query.Dataflow, query.KeyFamily, component, queryBuilder.CreateConstraintBean(component.ConceptRef.ChildReference.Id),true);
                codes = this.GetCodeListCostraint(query.Dataflow, query.KeyFamily, component);
                query.UpdateCodelistMap(codes, component);
                //NEL CASO DI CODE TIME LIST VENGONO RIPARSATE
                codes = query.GetCachedCodelist(component);
            }
            /*cort code @order@
            var sortedCodes = codes.Items.OrderBy<ICode, int>(
                 o =>
                 {
                     var corder = o.Annotations.FirstOrDefault(mutableObject => string.Equals(mutableObject.Type, "@ORDER@"));
                     return corder != null ? int.Parse(corder.Text[0].Value) : 0;
                 }).ToArray();

            foreach (ICode obj in codes.Items)
                codes.Items.Remove(obj);

            foreach (ICode obj in sortedCodes)
                codes.Items.Add(obj);
            */

            return codes;
        }