rest-batch-op.rst 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. .. _rest_api_geofence_server_batch:
  2. Batch Rest API
  3. ===================
  4. Batch operations allow to run multiple insert, update and delete at the same time over rules and admin rules. All the operations are executed in a single transaction: this means that either all of them are successful or all the operations are rolled back.
  5. Security
  6. --------
  7. The Geofence REST API is only accessible to users with the role ``ROLE_ADMIN``.
  8. Input/Output
  9. ------------
  10. Data Object Transfer
  11. ~~~~~~~~~~~~~~~~~~~~
  12. Both XML and JSON are supported for transfer of data objects. The default is XML. Alternatively, JSON may be used by setting the ``Content-Type`` and ``Accept`` HTTP headers to ``application/json`` in your requests.
  13. A ``Batch`` data object transfer must declare a list of ``operations``. Each operation needs to declare:
  14. * The ``service`` name (``rules`` for a Rule operation or ``adminrules`` for an AdminRule operation).
  15. * The ``type`` of the operation (``insert``, ``update``, ``delete``).
  16. * The ``id`` of the entity over which the operation is being performed in case of an ``update`` or ``delete`` types.
  17. * The ``Rule`` or ``AdminRule`` data object transfer in case of ``insert`` or ``update`` operation.
  18. Encoding of a Batch in XML::
  19. <Batch>
  20. <operations service="rules" id="2" type="update">
  21. <Rule id="2">
  22. <access>ALLOW</access>
  23. <layer>layer</layer>
  24. <priority>5</priority>
  25. <request>GETMAP</request>
  26. <roleName>ROLE_AUTHENTICATED</roleName>
  27. <service>WMS</service>
  28. <workspace>ws</workspace>
  29. </Rule>
  30. </operations>
  31. <operations service="rules" id="5" type="delete" />
  32. <operations service="adminrules" type="insert">
  33. <RuleAdmin>
  34. <priority>2</priority>
  35. <roleName>ROLE_USER</roleName>
  36. <workspace>ws</workspace>
  37. <access>ADMIN</access>
  38. </RuleAdmin>
  39. </operations>
  40. </Batch>
  41. Encoding of a Batch in JSON::
  42. {
  43. "Batch":{
  44. "operations":[
  45. {
  46. "@service":"adminrules",
  47. "@type":"update",
  48. "@id":"3",
  49. "Rule":{
  50. "access":"ALLOW",
  51. "layer":"layer",
  52. "priority":5,
  53. "request":"GETMAP",
  54. "service":"WMS",
  55. "roleName":"ROLE_AUTHENTICATED",
  56. "workspace":"ws"
  57. }
  58. },
  59. {
  60. "@service":"rules",
  61. "@type":"delete",
  62. "@id":5
  63. },
  64. {
  65. "@service":"adminrules",
  66. "@type":"insert",
  67. "AdminRule":{
  68. "priority":2,
  69. "roleName":"ROLE_USER",
  70. "workspace":"ws",
  71. "access":"ADMIN"
  72. }
  73. }
  74. ]
  75. }
  76. }
  77. Requests
  78. --------
  79. ``/rest/geofence/batch/exec``
  80. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  81. Issue a Batch operation executing all the declared operations.
  82. +------------+-----------------+--------------+-------------------------------------------------------------+
  83. | Method | Action | Response code| Response |
  84. +============+=================+==============+=============================================================+
  85. | POST | Execute a batch | 200 | OK |
  86. | | +--------------+-------------------------------------------------------------+
  87. | | | 400 | BadRequest: malformed request body, duplicate rule addition |
  88. | | +--------------+-------------------------------------------------------------+
  89. | | | 404 | NotFound: rule not found |
  90. | | +--------------+-------------------------------------------------------------+
  91. | | | 500 | InternalServerError: unexpected error |
  92. +------------+-----------------+--------------+-------------------------------------------------------------+