gid_storage.rst 3.89 KB
Newer Older
Marco Mariani's avatar
Marco Mariani committed
1 2 3

.. _gid-storage:

4
jIO GIDStorage
Marco Mariani's avatar
Marco Mariani committed
5 6 7 8 9
==============

A storage to enable interoperability between all kind of storages.

A global ID (GID) is a document id which represents a unique document. This ID
10
is then used to find this unique document on all types of backends.
Marco Mariani's avatar
Marco Mariani committed
11

Tristan Cavelier's avatar
Tristan Cavelier committed
12 13
This storage uses sub storage ``.allDocs()`` and queries to find unique
documents, and converts their ids to gids.
Marco Mariani's avatar
Marco Mariani committed
14

Marco Mariani's avatar
Marco Mariani committed
15 16
Where it can be used
--------------------
Marco Mariani's avatar
Marco Mariani committed
17

Marco Mariani's avatar
Marco Mariani committed
18
When you want to duplicate / synchronize / split / edit data in different kind of storages (ERP5 + XWiki + Dav + ...).
Marco Mariani's avatar
Marco Mariani committed
19 20 21 22 23 24

Storage Description
-------------------

* ``type`` - ``"gid"``
* ``sub_storage`` - the sub storage description.
Marco Mariani's avatar
Marco Mariani committed
25
* ``constraints`` - the constraints to use to generate a gid by defining metadata types for some kind of document.
Marco Mariani's avatar
Marco Mariani committed
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46

Example:

.. code-block:: javascript

  {
    "type": "gid",
    "sub_storage": {<storage description>},
    "constraints": {
      "default": { // constraints for all kind of documents
        // "document metadata": "type of metadata"
        "type": "list"
        "title": "string"
      },
      "Text": { // document of type 'Text' additional constraints
        "language": "string"
      }
    }
  }


47
This description tells the *GIDStorage* to use 2 metadata attributes (``type``, ``title``) to define a
Marco Mariani's avatar
Marco Mariani committed
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
document as unique in the default case. If the document is of type ``Text``, then
the handler will use 3 metadata (``type``, ``title``, ``language``).
If these constraints are not respected, then the storage returns an error telling us to
review the document metadata. Here are samples of document respecting the above
constraints:

.. code-block:: javascript

  {
    "type": "Text",
    "title": "Hello World!",
    "language": "en"
  }

  {
    "type": ["Text", "Web Page"],
    "title": "My Web Page Title",
    "language": "en-US",
    "format": "text/html"
  }

  {
    "type": "Image",
    "title": "My Image Title"
  }


Available metadata types are:
76

Marco Mariani's avatar
Marco Mariani committed
77 78 79 80 81 82 83 84 85 86 87 88 89 90
* ``"json"`` - The json value of the metadata.
* ``"string"`` - The value as string if it is not a list.
* ``"list"`` - The value as list.
* ``"date"`` - The value if it can be converted to a date (as string).
* ``"DCMIType"`` - A value matching one of the DCMIType Vocabulary (as string).
* ``"contentType"`` - A value which is a content type (as string).
* ``["DCMIType", "list"]`` - The value which contains a DCMIType (as list).
* ``[...]`` - make your own combination.



Document Requirements
---------------------

91 92 93
A metadata value must be a string. This string can be placed in an attribute within
a ``"content"`` key. The object can contains custom keys with string values. A
metadata object can contain several values. Example:
Marco Mariani's avatar
Marco Mariani committed
94 95 96 97 98 99 100 101

.. code-block:: javascript

  {
    "key": "value",
    // or
    "key": ["value1", "value2"],
    // or
102 103 104 105
    "key": {
      "attribute name": "attribute value",
      "content": "value"
    },
Marco Mariani's avatar
Marco Mariani committed
106 107 108 109 110 111 112 113 114 115 116
    // or
    "key": [
      {"scheme": "DCTERMS.URI", "content": "http://foo.com/bar"},
      "value2",
      "value3",
      ...
    ],
    ...
  }


117
Metadata attributes which names begin with an underscore can contain anything.
Marco Mariani's avatar
Marco Mariani committed
118 119 120 121 122 123 124 125 126 127 128

.. code-block:: javascript

  {
    "_key": {"whatever": ["blue", []], "a": null}
  }

Storage Requirements
--------------------

* This storage is not compatible with *RevisionStorage* and *ReplicateRevisionStorage*.
Tristan Cavelier's avatar
Tristan Cavelier committed
129
* Sub storages have to support options for queries and ``include_docs``.
130

Marco Mariani's avatar
Marco Mariani committed
131 132 133 134 135 136 137 138 139

Dependencies
------------

No dependency.

Suggested storage tree
----------------------

140
Replication between storages::
Marco Mariani's avatar
Marco Mariani committed
141 142 143 144 145 146 147 148 149 150 151

  Replicate Storage
  +-- GID Storage
  |   `-- Local Storage
  +-- GID Storage
  |   `-- Remote Storage 1
  `-- GID Storage
     `-- Remote Storage 2

**CAUTION: All gid storage must have the same description!**

152
Offline application usage::
Marco Mariani's avatar
Marco Mariani committed
153 154 155 156 157 158 159 160 161

  Replicate Storage
  +-- Index Storage with DB in Local Storage
  |   `-- GID Storage
  |       `-- ERP5 Storage
  `-- GID Storage
      `-- Local Storage

**CAUTION: All gid storage must have the same description!**