ViewService
using Skipcheck.Tm1.Client.Services; Views: a cube's public and private views (ViewScope), native
(NativeView: subsets on columns, rows and titles) or MDX (MDXView).
They're read as View, so each comes back as its own type.
A native view's subsets are in complex properties, reached by expanding through the
tm1.NativeView type: ListAsync with tm1.NativeView/Columns/Subset,
or GetNativeAsync, which reads one view through the type. On TM1 11.8.35 the
type-cast expand works on a list holding MDX views too; an older server was reported to
fail it, and GetNativeAsync doesn't depend on it.
Create a native view: each axis binds a subset, and every dimension of the cube has to be on one.
// Months across, regions down, and the cube's other dimensions as titles: every
// dimension of the cube must be on an axis. Each axis binds an existing subset.
var dimensions = ODataPath.Of("Dimensions");
var months = dimensions.Key("Month").Nav("Hierarchies").Key("Month").Nav("Subsets").Key("Quarters");
var regions = dimensions.Key("Region").Nav("Hierarchies").Key("Region").Nav("Subsets").Key("Leaves");
var versions = dimensions.Key("Version").Nav("Hierarchies").Key("Version");
var measures = dimensions.Key("Measure").Nav("Hierarchies").Key("Measure");
return await tm1.Views.CreateAsync(
"Sales",
ViewScope.Public,
NativeViewPatch
.Builder()
.Name("Revenue by Region")
.Columns([ViewAxisSelectionPatch.Builder().BindSubset(months).Build()])
.Rows([ViewAxisSelectionPatch.Builder().BindSubset(regions).Build()])
.Titles([
ViewTitlePatch.Builder().BindSubset(versions.Nav("Subsets").Key("All")).BindSelected(versions.Nav("Elements").Key("Actual")).Build(),
ViewTitlePatch.Builder().BindSubset(measures.Nav("Subsets").Key("All")).BindSelected(measures.Nav("Elements").Key("Revenue")).Build(),
])
.SuppressEmptyRows(true)
.Build()
);
Create an MDX view from its query:
// An MDX view is its query
var mdx =
"SELECT {[Month].[Month].[Jan], [Month].[Month].[Feb]} ON 0,"
+ " {TM1FILTERBYLEVEL({TM1SUBSETALL([Region].[Region])}, 0)} ON 1 FROM [Sales]"
+ " WHERE ([Version].[Version].[Actual], [Measure].[Measure].[Revenue])";
return await tm1.Views.CreateAsync("Sales", ViewScope.Private, MDXViewPatch.Builder().Name("My Revenue").Mdx(mdx).Build());
List a cube's views, telling the kinds apart by type:
// Each view comes back as its own type
return tm1
.Views.ListAsync("Sales", ViewScope.Public)
.Select(view =>
view switch
{
MDXView mdxView => $"{view.Name}: {mdxView.Mdx}",
NativeView => $"{view.Name}: native",
_ => $"{view.Name}: unknown kind",
}
);
Read the subsets on a native view's axes:
// A native view's axes are complex properties: expand them by path, through the
// view's type
var view = await tm1.Views.GetNativeAsync(
"Sales",
ViewScope.Public,
"Revenue by Region",
ODataQuery.None().Expand("Columns/Subset").Expand("Rows/Subset")
);
return view.Columns!.Concat(view.Rows!).Select(axis => axis.Subset!.UniqueName!).ToList();
Members
ViewService constructor | A service that sends its requests through session. |
ListAsync | GET Cubes('c')/Views (or the private ones), streamed; a native view's axes expand through its type, as tm1.NativeView/Columns/Subset. |
GetAsync | The view as its own type, or a Tm1NotFoundException if there's none. |
GetNativeAsync | Reads a native view through its type, so its axes can be expanded. |
CreateAsync | Creates a view; the patch's type says which kind (MDXViewPatch, NativeViewPatch), and a native view's axes bind subsets. |
UpdateAsync | Changes the properties the patch sets, such as an MDX view's MDX. |
DeleteAsync | DELETE Cubes('c')/Views('v'); its subsets stay. |
CubeAsync | The view's cube. |
ViewService
constructorViewService(Tm1Session session)A service that sends its requests through session.
ListAsync
IAsyncEnumerable<View> ListAsync(string cube, ViewScope scope, ODataQuery? query = null, CancellationToken cancellationToken = default)GET Cubes('c')/Views (or the private ones), streamed; a native view's axes
expand through its type, as tm1.NativeView/Columns/Subset.
TM1 REST Navigation Cube/Views Navigation Cube/PrivateViews
GetAsync
Task<View> GetAsync(string cube, ViewScope scope, string view, ODataQuery? query = null, CancellationToken cancellationToken = default)GET Cubes('c')/Views('v'): the view as its own type, or a
Tm1NotFoundException if there's none.
TM1 REST Navigation Cube/Views Navigation Cube/PrivateViews
GetNativeAsync
Task<NativeView> GetNativeAsync( string cube, ViewScope scope, string view, ODataQuery? query = null, CancellationToken cancellationToken = default )GET Cubes('c')/Views('v')/tm1.NativeView: reads a native view through its type,
so its axes can be expanded: Columns/Subset, Rows/Subset, Titles/Subset,
Titles/Selected. They're complex properties, so TM1 wants paths, not nested options.
An MDX view is an error.
TM1 REST Navigation Cube/Views Navigation Cube/PrivateViews Navigation ViewAxisSelection/Subset Navigation ViewTitle/Subset Navigation ViewTitle/Selected
CreateAsync
Task<View> CreateAsync(string cube, ViewScope scope, ViewPatch view, CancellationToken cancellationToken = default)POST Cubes('c')/Views: creates a view; the patch's type says which kind
(MDXViewPatch, NativeViewPatch), and a native view's axes bind subsets. TM1
(11.8) refuses a native view that leaves any of the cube's dimensions off its columns, rows
and titles (400, "All cube dimensions must be placed on an axis").
TM1 REST Navigation Cube/Views Navigation Cube/PrivateViews
UpdateAsync
Task UpdateAsync( string cube, ViewScope scope, string view, ViewPatch patch, string? etag = null, CancellationToken cancellationToken = default )PATCH Cubes('c')/Views('v'): changes the properties the patch sets, such as an
MDX view's MDX. With etag, sent as If-Match: a
Tm1PreconditionFailedException if the view had changed.
TM1 REST Navigation Cube/Views Navigation Cube/PrivateViews
DeleteAsync
Task DeleteAsync(string cube, ViewScope scope, string view, CancellationToken cancellationToken = default)DELETE Cubes('c')/Views('v'); its subsets stay.
TM1 REST Navigation Cube/Views Navigation Cube/PrivateViews
CubeAsync
Task<Cube> CubeAsync(string cube, ViewScope scope, string view, ODataQuery? query = null, CancellationToken cancellationToken = default)GET Cubes('c')/Views('v')/Cube: the view's cube.
TM1 REST Navigation View/Cube