Class SandboxService

java.lang.Object
io.skipcheck.tm1.client.service.data.SandboxService

public final class SandboxService extends Object
Sandboxes: private copies of the data a user writes to before publishing. They belong to the user the session is for.

Reading and writing in a sandbox go through a session view: Tm1Session.withSandbox or Tm1Client.withSandbox, which add TM1's !sandbox option to every request. This service manages the sandboxes themselves.

Create a sandbox, write to it, and publish the changes to base data:

// Write to a new sandbox, leaving base data alone until the changes are published
Map<String, String> cell = new LinkedHashMap<>();
cell.put("Version", "Budget");
cell.put("Region", "North");
cell.put("Month", "Jan");
cell.put("Measure", "Revenue");
Tm1Client whatIf = tm1.withSandbox("What If");
return tm1.sandboxes()
	.create(SandboxPatch.builder().name("What If").build())
	.then(whatIf.cells().update("Sales", cell, 1500))
	.then(tm1.sandboxes().publish("What If"));

Read a cell in base data and in a sandbox:

// The same cell read in base data and in a sandbox: the same query, through a
// client for each
String mdx = "SELECT {[Month].[Month].[Jan]} ON 0, {[Region].[Region].[North]} ON 1 FROM [Sales]"
		+ " WHERE ([Version].[Version].[Budget], [Measure].[Measure].[Revenue])";
ODataQuery values = ODataQuery.none().select(CellsetCell.VALUE);
Mono<JsonNode> base = tm1.cellsets()
	.stream(mdx, values, 1, (cellset, cells) -> cells.map(CellsetCell::value))
	.next();
Mono<JsonNode> whatIf = tm1.withSandbox("What If")
	.cellsets()
	.stream(mdx, values, 1, (cellset, cells) -> cells.map(CellsetCell::value))
	.next();
return Mono.zip(base, whatIf, (b, w) -> "base " + b + ", what-if " + w);
  • Constructor Details

    • SandboxService

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

    • list

      @Tm1Endpoint("EntitySet Sandboxes") public reactor.core.publisher.Flux<Sandbox> list(ODataQuery query)
      GET Sandboxes, streamed: the session user's sandboxes.
      Parameters:
      query - what to select, filter and order
      Returns:
      the sandboxes
    • get

      @Tm1Endpoint("EntitySet Sandboxes") public reactor.core.publisher.Mono<Sandbox> get(String name, ODataQuery query)
      GET Sandboxes('name').
      Parameters:
      name - the sandbox's name
      query - what to select
      Returns:
      the sandbox, or a Tm1NotFoundException if there's none
    • create

      @Tm1Endpoint("EntitySet Sandboxes") public reactor.core.publisher.Mono<Sandbox> create(SandboxPatch sandbox)
      POST Sandboxes: creates an empty sandbox.
      Parameters:
      sandbox - the new sandbox; it needs a name
      Returns:
      the sandbox as created
    • update

      @Tm1Endpoint("EntitySet Sandboxes") public reactor.core.publisher.Mono<Void> update(String name, SandboxPatch patch)
      PATCH Sandboxes('name'): changes the properties the patch sets, such as IncludeInSandboxDimension.
      Parameters:
      name - the sandbox's name
      patch - the changes
      Returns:
      completes when the sandbox is changed
    • delete

      @Tm1Endpoint("EntitySet Sandboxes") public reactor.core.publisher.Mono<Void> delete(String name)
      DELETE Sandboxes('name'), with its unpublished changes.
      Parameters:
      name - the sandbox's name
      Returns:
      completes when the sandbox is deleted
    • load

      @Tm1Endpoint("Action Sandbox/Load") public reactor.core.publisher.Mono<Void> load(String name)
      tm1.Load: loads the sandbox into memory.
      Parameters:
      name - the sandbox's name
      Returns:
      completes when it's loaded
    • unload

      @Tm1Endpoint("Action Sandbox/Unload") public reactor.core.publisher.Mono<Void> unload(String name)
      tm1.Unload: frees the sandbox's memory, keeping its changes.
      Parameters:
      name - the sandbox's name
      Returns:
      completes when it's unloaded
    • discardChanges

      @Tm1Endpoint("Action Sandbox/DiscardChanges") public reactor.core.publisher.Mono<Void> discardChanges(String name)
      tm1.DiscardChanges: throws away the sandbox's changes, keeping the sandbox.
      Parameters:
      name - the sandbox's name
      Returns:
      completes when they're discarded
    • publish

      @Tm1Endpoint("Action Sandbox/Publish") public reactor.core.publisher.Mono<Void> publish(String name)
      tm1.Publish: writes the sandbox's changes to base data.
      Parameters:
      name - the sandbox's name
      Returns:
      completes when they're published
    • publish

      @Tm1Endpoint("Action Sandbox/Publish") public reactor.core.publisher.Mono<Void> publish(String name, ConflictResolution conflicts, boolean allowQueueing, boolean cleanAfter)
      tm1.Publish with options.
      Parameters:
      name - the sandbox's name
      conflicts - what to do with cells changed in base data since the sandbox's changes
      allowQueueing - whether to wait for a lock rather than fail
      cleanAfter - whether to empty the sandbox once published
      Returns:
      completes when they're published
    • merge

      @Tm1Endpoint("Action Sandbox/Merge") public reactor.core.publisher.Mono<Void> merge(String name, String target)
      tm1.Merge: copies the sandbox's changes into another sandbox.
      Parameters:
      name - the sandbox's name
      target - the name of the sandbox to merge into
      Returns:
      completes when they're merged
    • merge

      @Tm1Endpoint("Action Sandbox/Merge") public reactor.core.publisher.Mono<Void> merge(String name, String target, ConflictResolution conflicts, boolean allowQueueing, boolean cleanAfter)
      tm1.Merge with options.
      Parameters:
      name - the sandbox's name
      target - the name of the sandbox to merge into
      conflicts - what to do with cells the target changed too
      allowQueueing - whether to wait for a lock rather than fail
      cleanAfter - whether to empty this sandbox once merged
      Returns:
      completes when they're merged