Class Tm1Request<T>

java.lang.Object
io.skipcheck.tm1.client.Tm1Request<T>
Type Parameters:
T - the type the response is read as: an entity or value for a single response, the item type for a collection, String for text, or Void for no content

public final class Tm1Request<T> extends Object
One TM1 REST call, described but not sent: the method, path, query, headers and body, and how to read the response.

Every service method is built on one of these. The same request can be sent on its own (the service's ordinary methods do that) or added to a $batch, so anything the client can do one request at a time, it can also batch. Requests are immutable.

// A cube's name, read as plain JSON
Tm1Request<JsonNode> cube = Tm1Request.get(ODataPath.of("Cubes").key("Sales"), ODataQuery.none().select("Name"),
		JsonNode.class);
// An action with no answer
Tm1Request<Void> reserve = Tm1Request.post(ODataPath.of("Cubes").key("Sales").action("tm1.Reserve"), Map.of(),
		Void.class);
  • Method Details

    • get

      public static <T> Tm1Request<T> get(ODataPath path, ODataQuery query, Class<T> type)
      GET of one entity or value.
      Type Parameters:
      T - the type the response is read as
      Parameters:
      path - the resource path
      query - the query options
      type - the class the response is read as
      Returns:
      the request
    • list

      public static <T> Tm1Request<T> list(ODataPath path, ODataQuery query, Class<T> itemType)
      GET of a collection, read item by item as itemType.
      Type Parameters:
      T - the type each item is read as
      Parameters:
      path - the collection's path
      query - the query options
      itemType - the class each item is read as
      Returns:
      the request
    • bytes

      public static Tm1Request<DataBuffer> bytes(ODataPath path)
      GET of raw bytes, such as a document's Content, streamed with Tm1Session.stream. Each buffer is the subscriber's to release (DataBufferUtils.release), or to hand on to something that does, such as DataBufferUtils.write.
      Parameters:
      path - the resource path
      Returns:
      the request
    • put

      public static Tm1Request<Void> put(ODataPath path, org.reactivestreams.Publisher<DataBuffer> content)
      PUT of raw bytes, as application/octet-stream, such as a document's Content. TM1 (11.8) refuses a chunked body (400, with no message), so the bytes are gathered and sent with their Content-Length: the whole content is held in memory while it's sent. If the session has to log in again, the request is sent once more and content subscribed again, so it should be one that can be: DataBufferUtils.read of a file is.
      Parameters:
      path - the resource path
      content - the bytes
      Returns:
      the request
    • text

      public static Tm1Request<String> text(ODataPath path)
      GET of plain text, such as Configuration/ProductVersion/$value.
      Parameters:
      path - the resource path
      Returns:
      the request
    • postList

      public static <T> Tm1Request<T> postList(ODataPath path, Object body, Class<T> itemType)
      POST whose response is a collection, read item by item as itemType: an action returning Collection(...), such as tm1.CheckRules.
      Type Parameters:
      T - the type each item is read as
      Parameters:
      path - the action's path
      body - the parameters, written as JSON
      itemType - the class each item is read as
      Returns:
      the request
    • post

      public static <T> Tm1Request<T> post(ODataPath path, @Nullable Object body, Class<T> type)
      POST: create an entity, or invoke an action. Actions always get a JSON body (an empty object if there are no parameters), since TM1 refuses an action without a JSON content type. With Void.class the response is ignored.
      Type Parameters:
      T - the type the response is read as
      Parameters:
      path - the collection or action path
      body - the entity or action parameters, or null for an empty object
      type - the class the response is read as: Void.class to ignore it, String.class to read it as text
      Returns:
      the request
    • patch

      public static Tm1Request<Void> patch(ODataPath path, Object body)
      PATCH: change the properties in body, leaving the rest as they are.
      Parameters:
      path - the entity's path
      body - the properties to change
      Returns:
      the request
    • delete

      public static Tm1Request<Void> delete(ODataPath path)
      DELETE.
      Parameters:
      path - the path of the entity to delete
      Returns:
      the request
    • withQuery

      public Tm1Request<T> withQuery(ODataQuery query)
      A copy with these query options instead.
      Parameters:
      query - the query options
      Returns:
      the copy
    • withHeader

      public Tm1Request<T> withHeader(String name, String value)
      A copy with a header added or replaced, such as If-Match.
      Parameters:
      name - the header name
      value - the header value
      Returns:
      the copy
    • withTimeout

      public Tm1Request<T> withTimeout(Duration timeout)
      A copy that may go timeout without receiving any data before it fails, instead of the session's request timeout. For calls TM1 only answers when the work is done, such as a long process run.
      Parameters:
      timeout - the longest wait for data; must be positive
      Returns:
      the copy
    • requires

      public Tm1Request<T> requires(Tm1Capability capability)
      A copy that's only sent if the server defines capability: before sending, the session checks the server's $metadata and otherwise fails with Tm1UnsupportedOperationException, without calling the server. Service methods for newer endpoints declare it.
      Parameters:
      capability - what the request needs the server to define
      Returns:
      the copy
    • requirement

      public Optional<Tm1Capability> requirement()
      What this request needs the server to define, if anything.
      Returns:
      the capability, or empty
    • ifMatch

      public Tm1Request<T> ifMatch(String etag)
      A copy sent with If-Match: etag, failing with 412 if the entity has changed since.
      Parameters:
      etag - the entity's ETag
      Returns:
      the copy
    • method

      public HttpMethod method()
      The HTTP method.
      Returns:
      the method
    • path

      public ODataPath path()
      The resource path, relative to the service root.
      Returns:
      the path
    • query

      public ODataQuery query()
      The query options.
      Returns:
      the query, possibly ODataQuery.none()
    • headers

      public Map<String,String> headers()
      The headers this request adds, in the order they were added.
      Returns:
      an unmodifiable map of header names to values
    • body

      public @Nullable Object body()
      The body, serialized as JSON when sent, or null for none.
      Returns:
      the body, or null
    • response

      public Tm1Request.Response response()
      How the response body is read.
      Returns:
      the response kind
    • type

      public Class<T> type()
      The class the response, or each item of a collection, is read as.
      Returns:
      the type
    • timeout

      public Optional<Duration> timeout()
      This request's own timeout, if it has one; otherwise the session's applies.
      Returns:
      the timeout, or empty
    • isIdempotent

      public boolean isIdempotent()
      Whether sending this twice has the same effect as sending it once: GET, PUT and DELETE are; POST (process runs, cell writes, creates) and PATCH aren't. The client never retries a non-idempotent request by itself.
      Returns:
      true for GET, PUT, DELETE and HEAD
    • relativeUri

      public String relativeUri()
      The encoded path and query relative to the service root, e.g. Cubes('Sales')?$select=Name.
      Returns:
      the relative URI
    • toString

      public String toString()
      METHOD relative-uri, unencoded, for logs.
      Overrides:
      toString in class Object