Skip to content
This repository has been archived by the owner on Nov 9, 2022. It is now read-only.

Support for temporal #847

Open
grtjn opened this issue Sep 22, 2017 · 5 comments
Open

Support for temporal #847

grtjn opened this issue Sep 22, 2017 · 5 comments

Comments

@grtjn
Copy link
Contributor

grtjn commented Sep 22, 2017

Involves creating indexes (metadata fields?), temporal axis, and collection.

@grtjn
Copy link
Contributor Author

grtjn commented Sep 22, 2017

Bit long, but this worked in app_specific:

  alias_method :original_bootstrap, :bootstrap

  def bootstrap
    original_bootstrap

    logger.info ""
    logger.info "Bootstrapping hidden metadata fields:"
    r = execute_query(
      %Q{
        xquery version "1.0-ml";

        import module namespace admin = "http://marklogic.com/xdmp/admin"
          at "/MarkLogic/admin.xqy";

        let $metadata-fields := (
          (: Temporal fields :)
          "validStart:dateTime",
          "validEnd:dateTime",
          "systemStart:dateTime",
          "systemEnd:dateTime",
          "temporalProtectLevel:string",
          "temporalProtectExTime:dateTime",
          "temporalArchivePaths:string"
        )
        let $config := admin:get-configuration()
        let $dbid := xdmp:database()
        let $fieldspecs :=
          for $field in $metadata-fields
          let $name := substring-before($field, ":")
          return
            admin:database-metadata-field($name)
        let $config := admin:database-add-field($config, $dbid, $fieldspecs)
        let $rangespecs :=
          for $field in $metadata-fields
          let $name := substring-before($field, ":")
          let $type := substring-after($field, ":")
          return
            admin:database-range-field-index($type,
              $name, "http://marklogic.com/collation/codepoint", fn:true() )
        let $config :=
          admin:database-add-range-field-index($config, $dbid, $rangespecs)
        let $_ :=
          admin:save-configuration($config)
        return $metadata-fields
      },
      { :app_name => @properties["ml.app-name"] }
    )
    r.body = parse_body r.body
    logger.info r.body
    logger.info ""

    logger.info "Bootstrapping temporal axes:"
    r = execute_query(
      %Q{
        xquery version "1.0-ml";
        declare namespace html = "http://www.w3.org/1999/xhtml";
        import module namespace temporal = "http://marklogic.com/xdmp/temporal" at "/MarkLogic/temporal.xqy";

        for $coll in ('uni-temporal', 'bi-temporal')
        return
          if (temporal:collections() = $coll) then
            temporal:collection-set-options($coll, "updates-admin-override")
          else ();

        xquery version "1.0-ml";
        
        for $coll in ('uni-temporal', 'bi-temporal')
        return
          xdmp:collection-delete($coll);

        xquery version "1.0-ml";
        declare namespace html = "http://www.w3.org/1999/xhtml";
        import module namespace temporal = "http://marklogic.com/xdmp/temporal" at "/MarkLogic/temporal.xqy";

        for $coll in ('uni-temporal', 'bi-temporal')
        return
          if (temporal:collections() = $coll) then
            temporal:collection-set-options($coll, "updates-safe")
          else ();

        xquery version "1.0-ml";
        import module namespace temporal = "http://marklogic.com/xdmp/temporal" 
             at "/MarkLogic/temporal.xqy";
        
        for $coll in ('uni-temporal', 'bi-temporal')
        return
          if (temporal:collections() = $coll) then
            temporal:collection-remove($coll)
          else ();

        xquery version "1.0-ml"; 
        import module namespace temporal = "http://marklogic.com/xdmp/temporal" 
            at "/MarkLogic/temporal.xqy";

        for $axis in ('valid', 'system')
        return
          if (temporal:axes() = $axis) then
            temporal:axis-remove($axis)
          else ();

        xquery version "1.0-ml"; 
        import module namespace temporal = "http://marklogic.com/xdmp/temporal" 
            at "/MarkLogic/temporal.xqy";

        temporal:axis-create(
            "valid",
            cts:field-reference("validStart", "type=dateTime"),
            cts:field-reference("validEnd", "type=dateTime")),
        temporal:axis-create(
            "system",
            cts:field-reference("systemStart", "type=dateTime"),
            cts:field-reference("systemEnd", "type=dateTime"))
      },
      { :app_name => @properties["ml.app-name"] }
    )
    r.body = parse_body r.body
    logger.info r.body
    logger.info ""

    logger.info "Bootstrapping temporal collections:"
    r = execute_query(
      %Q{
        xquery version "1.0-ml";
        import module namespace temporal = "http://marklogic.com/xdmp/temporal" 
             at "/MarkLogic/temporal.xqy";

        temporal:collection-create("bi-temporal", "system", "valid"),
        temporal:collection-create("uni-temporal", "system")
      },
      { :app_name => @properties["ml.app-name"] }
    )
    r.body = parse_body r.body
    logger.info r.body
    logger.info ""
  end

@grtjn
Copy link
Contributor Author

grtjn commented Sep 22, 2017

Nothing needed for wipe if I recall correctly..

@grtjn
Copy link
Contributor Author

grtjn commented Sep 22, 2017

#834 covers the metadata fields part

@rlouapre
Copy link
Contributor

rlouapre commented Apr 5, 2018

Any plan to integrate it in Roxy?

@grtjn
Copy link
Contributor Author

grtjn commented Apr 5, 2018

You asking for it is a good argument to do so.. :)

Pondering about how that should look like in terms of configs. Probably something that looks a little like how management rest api expects it I guess. Or close to SEC xml perhaps?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants