Class ViewService

java.lang.Object
io.skipcheck.tm1.client.service.cube.ViewService

public final class ViewService extends Object
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(String, ViewScope, String, ODataQuery), 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());
  • Constructor Details

    • ViewService

      public ViewService(Tm1Session session)
      A service sending its requests through session.
      Parameters:
      session - the session
  • Method Details

    • list

      @Tm1Endpoint("Navigation Cube/Views") @Tm1Endpoint("Navigation Cube/PrivateViews") public reactor.core.publisher.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

      @Tm1Endpoint("Navigation Cube/Views") @Tm1Endpoint("Navigation Cube/PrivateViews") public reactor.core.publisher.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 Tm1NotFoundException if there's none
    • getNative

      @Tm1Endpoint("Navigation Cube/Views") @Tm1Endpoint("Navigation Cube/PrivateViews") @Tm1Endpoint("Navigation ViewAxisSelection/Subset") @Tm1Endpoint("Navigation ViewTitle/Subset") @Tm1Endpoint("Navigation ViewTitle/Selected") public reactor.core.publisher.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

      @Tm1Endpoint("Navigation Cube/Views") @Tm1Endpoint("Navigation Cube/PrivateViews") public reactor.core.publisher.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

      @Tm1Endpoint("Navigation Cube/Views") @Tm1Endpoint("Navigation Cube/PrivateViews") public reactor.core.publisher.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

      @Tm1Endpoint("Navigation Cube/Views") @Tm1Endpoint("Navigation Cube/PrivateViews") public reactor.core.publisher.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 Tm1PreconditionFailedException if it had changed
    • delete

      @Tm1Endpoint("Navigation Cube/Views") @Tm1Endpoint("Navigation Cube/PrivateViews") public reactor.core.publisher.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

      @Tm1Endpoint("Navigation View/Cube") public reactor.core.publisher.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