ViewService
import io.skipcheck.tm1.client.service.cube.ViewService; 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: list with tm1.NativeView/Columns/Subset,
or getNative, 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 getNative 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.
ODataPath dimensions = ODataPath.of("Dimensions");
ODataPath months = dimensions.key("Month").nav("Hierarchies").key("Month").nav("Subsets").key("Quarters");
ODataPath regions = dimensions.key("Region").nav("Hierarchies").key("Region").nav("Subsets").key("Leaves");
ODataPath versions = dimensions.key("Version").nav("Hierarchies").key("Version");
ODataPath measures = dimensions.key("Measure").nav("Hierarchies").key("Measure");
return tm1.views()
.create("Sales", ViewScope.PUBLIC,
NativeViewPatch.builder()
.name("Revenue by Region")
.columns(List.of(ViewAxisSelectionPatch.builder().bindSubset(months).build()))
.rows(List.of(ViewAxisSelectionPatch.builder().bindSubset(regions).build()))
.titles(List.of(
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
String 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 tm1.views()
.create("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().list("Sales", ViewScope.PUBLIC, ODataQuery.none()).map(view -> {
if (view instanceof MDXView mdxView) {
return view.name() + ": " + mdxView.mdx();
}
if (view instanceof NativeView) {
return view.name() + ": native";
}
return 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
return tm1.views()
.getNative("Sales", ViewScope.PUBLIC, "Revenue by Region",
ODataQuery.none().expand("Columns/Subset").expand("Rows/Subset"))
.flatMapMany(view -> Flux.concat(Flux.fromIterable(view.columns()), Flux.fromIterable(view.rows())))
.map(axis -> axis.subset().uniqueName());
Members
ViewService constructor | A service sending its requests through session. |
list | GET Cubes('c')/Views (or the private ones), streamed. |
get | GET Cubes('c')/Views('v'). |
getNative | Reads a native view through its type, so its axes can be expanded. |
create | Creates a view; the patch's type says which kind (MDXViewPatch, NativeViewPatch), and a native view's axes bind subsets. |
update | Changes the properties the patch sets, such as an MDX view's MDX. |
update | PATCH Cubes('c')/Views('v') with If-Match. |
delete | DELETE Cubes('c')/Views('v'); its subsets stay. |
cube | GET Cubes('c')/Views('v')/Cube. |
ViewService
constructorViewService(Tm1Session session) A service sending its requests through session.
Parameters
session- the session
list
Flux<View> list(String cube, ViewScope scope, ODataQuery query) GET Cubes('c')/Views (or the private ones), streamed.
Parameters
cube- the cube's name
scope- which views
query- what to select, expand, filter and order; a native view's axes expand
through its type, as
tm1.NativeView/Columns/Subset
Returns
- the views, each as its own type
get
Mono<View> get(String cube, ViewScope scope, String view, ODataQuery query) GET Cubes('c')/Views('v').
Parameters
cube- the cube's name
scope- where the view is
view- the view's name
query- what to select and expand
Returns
- the view as its own type, or a
Tm1NotFoundExceptionif there's none
getNative
Mono<NativeView> getNative(String cube, ViewScope scope, String view, ODataQuery query) 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.
Parameters
cube- the cube's name
scope- where the view is
view- the view's name
query- what to select and expand
Returns
- the native view, or an error if it's an MDX view
create
Mono<View> create(String cube, ViewScope scope, ViewPatch view) 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").
Parameters
cube- the cube's name
scope- where to create it
view- the new view; it needs a name
Returns
- the view as created
update
Mono<Void> update(String cube, ViewScope scope, String view, ViewPatch patch) PATCH Cubes('c')/Views('v'): changes the properties the patch sets, such as
an MDX view's MDX.
Parameters
cube- the cube's name
scope- where the view is
view- the view's name
patch- the changes, of the view's kind
Returns
- completes when the view is changed
update
Mono<Void> update(String cube, ViewScope scope, String view, ViewPatch patch, String etag) PATCH Cubes('c')/Views('v') with If-Match.
Parameters
cube- the cube's name
scope- where the view is
view- the view's name
patch- the changes, of the view's kind
etag- the ETag the view was read with
Returns
- completes when the view is changed, or a
Tm1PreconditionFailedExceptionif it had changed
delete
Mono<Void> delete(String cube, ViewScope scope, String view) DELETE Cubes('c')/Views('v'); its subsets stay.
Parameters
cube- the cube's name
scope- where the view is
view- the view's name
Returns
- completes when the view is deleted
cube
Mono<Cube> cube(String cube, ViewScope scope, String view, ODataQuery query) GET Cubes('c')/Views('v')/Cube.
Parameters
cube- the cube's name
scope- where the view is
view- the view's name
query- what to select and expand
Returns
- the view's cube
TM1 REST Navigation View/Cube
Also in the Javadoc.