Class DataSourceDef

java.lang.Object
org.apache.juneau.console.freemarker.DataSourceDef

public final class DataSourceDef extends Object
Declares a console data source: a browser loader that fetches rows from a same-origin URL, builds a columnar frame and publishes it on the topic data:<id>, which chart cards read with ChartDef.source(...).

Add it to a page with PageSpec.data(...). The declaration is checked when it is added: a bad URL, mode, chunking, column type or subscription role is E-76, and a bad parser or builder name is E-74.

Example:

page.data(DataSourceDef.create("orgRequests") .url("/rest/orgRequests/series").format(Format.CSV) .params(Subscription.to(Topics.filter("range")).as("params") .map("start", "start").map("end", "end")) .chunk(Chunking.byDay("start", "end")).cache(Cache.indexedDb()));

Since:
10.0.0
  • Method Details

    • create

      public static DataSourceDef create(String id)
      Parameters:
      id - The source id; unique across cards, data sources and dashboard sections. The topic is data:<id>.
      Returns:
      A new declaration.
      Throws:
      IllegalArgumentException - E-40 if the id is not a valid topic key.
    • id

      public String id()
      Returns:
      The source id.
    • url

      public DataSourceDef url(String value)
      Parameters:
      value - A same-origin path; {token}s are filled from params. @return This object.
    • format

      Parameters:
      value - The wire format; sets the built-in parser. @return This object.
    • parser

      public DataSourceDef parser(String name)
      Parameters:
      name - A registered parser: a bare built-in name or a dotted app name. Only the name's shape is checked here; a bare name other than the built-ins (csv, ndjson, json) is resolved only in the browser, where an unknown one is E-JS-92.
      Returns:
      This object.
    • builder

      public DataSourceDef builder(String name)
      Parameters:
      name - A registered builder: a bare built-in name or a dotted app name. Only the name's shape is checked here; a bare name other than the built-in columnar is resolved only in the browser, where an unknown one is E-JS-93.
      Returns:
      This object.
    • columns

      public DataSourceDef columns(String... specs)
      Parameters:
      specs - Columns as name:type, type one of number, time, string, bool. @return This object.
    • params

      public DataSourceDef params(Subscription... subs)
      Parameters:
      subs - Subscriptions with role params or refresh. @return This object.
    • chunk

      Parameters:
      value - The chunking; DataSourceDef.Chunking.none() by default.
      Returns:
      This object.
      Throws:
      IllegalArgumentException - E-76 if the value is null, or the window param names are blank or equal.
    • concurrency

      public DataSourceDef concurrency(int value)
      Parameters:
      value - Parallel chunk requests, 1..6 (default 1). @return This object.
    • debounceMs

      public DataSourceDef debounceMs(int value)
      Parameters:
      value - The params-change debounce in ms (default 250). @return This object.
    • cache

      Parameters:
      value - The cache; DataSourceDef.Cache.memory() by default. @return This object.
    • epoch

      public DataSourceDef epoch(String epochUrl, String path)
      Parameters:
      epochUrl - A same-origin path probed once per load.
      path - The dotted path of the epoch value in the JSON response.
      Returns:
      This object.
    • mode

      Parameters:
      value - The mode; DataSourceDef.Mode.RAW by default. @return This object.
    • maxRows

      public DataSourceDef maxRows(long value)
      Parameters:
      value - The row count past which AUTO switches to AGGREGATE. @return This object.
    • aggregateUrl

      Parameters:
      value - A same-origin path answering the aggregate request. @return This object.
    • aggregate

      Parameters:
      value - The aggregate request. @return This object.
    • toMap

      public JsonMap toMap()
      The contract.dataSources[] entry; checks the cross-field rules.
      Returns:
      A new map.
      Throws:
      IllegalArgumentException - E-76 if the declaration is incomplete or inconsistent.