public static MetaTable GetTableMeta(this IPXModelBuilder builder) { builder.DoNotApplyCurrentValueSet = true; // DoNotApplyCurrentValueSet means the "client that made the request" is an api(, not a GUI) so that // CNMM2.4 property DefaultInGUI (for Valueset/grouping) should not be used builder.BuildForSelection(); return(new MetaTable { Title = builder.Model.Meta.Title, Variables = builder.Model.Meta.Variables.Select(variable => new MetaVariable { Code = variable.Code, Text = variable.Name, Elimination = variable.Elimination, Time = variable.IsTime, Map = string.IsNullOrEmpty(variable.Map) ? null : variable.Map, Values = variable.Values.Select(value => value.Code).ToArray(), ValueTexts = variable.Values.Select(value => value.Value).ToArray() }).ToArray() }); }
/// <summary> /// Calls BuildForPresentation and handles special case when we have the following condition: /// 1. Redirect to the selection page is demanded for the saved query using the ?select switch /// 2. The setting "Remove single content" is set to True /// 3. There is only one value selected for the content variable /// </summary> /// <param name="builder"></param> /// <param name="selection"></param> private void BuildModelForPresentation(IPXModelBuilder builder, PCAxis.Paxiom.Selection[] selection) { if (_format.Equals(PxUrl.PAGE_SELECT) && PCAxis.Paxiom.Settings.Metadata.RemoveSingleContent && (builder.Model.Meta.ContentVariable != null)) { // Handle the special case... Variable contentVar = builder.Model.Meta.ContentVariable.CreateCopyWithValues(); bool inHeading = (builder.Model.Meta.Heading.GetByCode(contentVar.Code) != null); bool addContent = false; PCAxis.Paxiom.Selection selCont = selection.First(s => s.VariableCode.Equals(contentVar.Code)); if (selCont.ValueCodes.Count == 1) { // Remove all values except the one selected contentVar.Values.RemoveAll(x => x.Code != selCont.ValueCodes[0]); addContent = true; } // The content variable will be eliminated in BuildForPresentation ... builder.BuildForPresentation(selection); // ... but we need it on the selection page so we add it manually to the model after the call to BuildForPresentation if (addContent) { builder.Model.Meta.Variables.Add(contentVar); if (inHeading) { builder.Model.Meta.Heading.Add(contentVar); } else { builder.Model.Meta.Stub.Add(contentVar); } } } else { builder.BuildForPresentation(selection); } }
private PXModel LoadData(PCAxis.Query.SavedQuery sq) { //Only loads the first table source otherwise redirects to a page if (sq.Sources.Count != 1) { //TODO redirect to error page incopatable query for PX-Web } TableSource src = sq.Sources[0]; IPXModelBuilder builder = null; if (src.Type == "CNMM") { if (RouteInstance.RouteExtender == null) { DatabaseInfo db = PXWeb.Settings.Current.General.Databases.GetCnmmDatabase(src.DatabaseId); if (db == null) { //TODO Redirect database does not exist return(null); } var tableName = QueryHelper.GetTableName(src); builder = PxContext.CreatePaxiomBuilder(src.DatabaseId, tableName); } else { DatabaseInfo db = PXWeb.Settings.Current.General.Databases.GetCnmmDatabase(RouteInstance.RouteExtender.GetDatabase()); var tableName = QueryHelper.GetTableName(src); builder = PxContext.CreatePaxiomBuilder(RouteInstance.RouteExtender.Db.Database.id, tableName); } } else if (src.Type == "PX") { DatabaseInfo db = PXWeb.Settings.Current.General.Databases.GetPxDatabase(src.DatabaseId); if (db == null) { } else { if (!db.HasLanguage(src.Language)) { //TODO Redirect that the database is missing return(null); } if (src.Source.StartsWith("-/")) { src.Source = src.DatabaseId + src.Source.Substring(1); } builder = PxContext.CreatePaxiomBuilder(src.DatabaseId, src.Source); } } else { //TODO redirect to error page incompatible datasource type return(null); } builder.SetPreferredLanguage(src.Language); //If languefe set in reques we must read all langauges to be able to run workflow operations if (_language != null) { builder.ReadAllLanguages = true; } builder.BuildForSelection(); var model = builder.Model; List <PCAxis.Paxiom.Selection> sel = new List <PCAxis.Paxiom.Selection>(); foreach (var variable in model.Meta.Variables) { var query = src.Quieries.FirstOrDefault(q => q.Code == variable.Code); PCAxis.Paxiom.Selection s = null; if (query == null) { //Selects all values for the variable if it can't be eliminated s = new PCAxis.Paxiom.Selection(variable.Code); if (variable.IsContentVariable || !variable.Elimination) { s.ValueCodes.AddRange(variable.Values.Select(v => v.Code).ToArray()); } } else { if (PCAxis.Query.QueryHelper.IsAggregation(query.Selection.Filter)) { s = QueryHelper.SelectAggregation(variable, query, builder); } else if (query.Selection.Filter.StartsWith("vs:", StringComparison.InvariantCultureIgnoreCase)) { s = QueryHelper.SelectValueSet(variable, query, builder); } else { switch (query.Selection.Filter) { case "item": s = QueryHelper.SelectItem(variable, query); break; case "top": s = QueryHelper.SelectTop(variable, query); break; case "from": s = QueryHelper.SelectFrom(variable, query); break; case "all": s = QueryHelper.SelectAll(variable, query); break; default: //TODO unsupported filter break; } } } if (s != null) { sel.Add(s); } } var selection = sel.ToArray(); //TODO fixa till //if (sq.Output.Type == "SCREEN") PCAxis.Query.TableQuery tbl = new PCAxis.Query.TableQuery(builder.Model, selection); PaxiomManager.QueryModel = tbl; BuildModelForPresentation(builder, selection); return(builder.Model); }