Class ChangeSetService

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

public final class ChangeSetService extends Object
Change sets: groups of cell writes that can be undone together.

A write joins a change set through TM1's !ChangeSet query option, which a session view from Tm1Session.withChangeSet(String) adds to every request ($metadata doesn't say how; TM1 11.8 does it this way). within(Function) does it all: begins a change set, gives the work a session that records into it, and ends it however the work finishes.

Make some writes in a change set, keeping its ID:

// Record some writes in a change set, and keep its ID to undo them later
Map<String, String> cell = new LinkedHashMap<>();
cell.put("Version", "Forecast");
cell.put("Region", "North");
cell.put("Month", "Jan");
cell.put("Measure", "Revenue");
return tm1.changeSets().within(session -> {
	String id = session.changeSet().orElseThrow();
	return Tm1Client.of(session).cells().update("Sales", cell, 1500).thenReturn(id);
}).single();

Undo them later:

// Revert every write recorded in the change set; writes outside it stay
return tm1.changeSets().undo(changeSet);
  • Constructor Summary

    Constructors
    Constructor
    Description
    A service sending its requests through session.
  • Method Summary

    Modifier and Type
    Method
    Description
    reactor.core.publisher.Mono<String>
    BeginChangeSet: starts a change set.
    reactor.core.publisher.Mono<Long>
    end(String id)
    EndChangeSet: stops recording into a change set; it can still be undone.
    reactor.core.publisher.Mono<Void>
    UndoChangeSet: reverts every write recorded in a change set.
    <R> reactor.core.publisher.Flux<R>
    within(Function<Tm1Session, org.reactivestreams.Publisher<R>> work)
    Runs work in a new change set: begins it, gives the work a view of the session that records into it (session.changeSet() has the ID, for a later undo(String)), and ends it when the work completes, fails or is cancelled.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • ChangeSetService

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

    • begin

      @Tm1Endpoint("ActionImport BeginChangeSet") public reactor.core.publisher.Mono<String> begin()
      BeginChangeSet: starts a change set. Needs schema 10.2.2.6.
      Returns:
      the change set's ID, for Tm1Session.withChangeSet(String)
    • end

      @Tm1Endpoint("ActionImport EndChangeSet") public reactor.core.publisher.Mono<Long> end(String id)
      EndChangeSet: stops recording into a change set; it can still be undone. Needs schema 10.2.2.6.
      Parameters:
      id - the change set's ID
      Returns:
      TM1's return code
    • undo

      @Tm1Endpoint("ActionImport UndoChangeSet") public reactor.core.publisher.Mono<Void> undo(String id)
      UndoChangeSet: reverts every write recorded in a change set. Needs schema 10.2.2.6.
      Parameters:
      id - the change set's ID
      Returns:
      completes when the writes are reverted
    • within

      @Tm1Endpoint("ActionImport BeginChangeSet") @Tm1Endpoint("ActionImport EndChangeSet") public <R> reactor.core.publisher.Flux<R> within(Function<Tm1Session, org.reactivestreams.Publisher<R>> work)
      Runs work in a new change set: begins it, gives the work a view of the session that records into it (session.changeSet() has the ID, for a later undo(String)), and ends it when the work completes, fails or is cancelled.
      // Record some writes in a change set, and keep its ID to undo them later
      Map<String, String> cell = new LinkedHashMap<>();
      cell.put("Version", "Forecast");
      cell.put("Region", "North");
      cell.put("Month", "Jan");
      cell.put("Measure", "Revenue");
      return tm1.changeSets().within(session -> {
      	String id = session.changeSet().orElseThrow();
      	return Tm1Client.of(session).cells().update("Sales", cell, 1500).thenReturn(id);
      }).single();
      
      Type Parameters:
      R - what the work gives
      Parameters:
      work - the writes to record, given the session to make them through
      Returns:
      what the work gives, with the change set ended at the end