appschema.rst 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. .. _rest_App-Schema:
  2. App Schema
  3. ==========
  4. .. _appschema_upload_create:
  5. Uploading an app-schema mapping file
  6. ------------------------------------
  7. **Create a new app-schema store and update the feature type mappings of an existing app-schema store by uploading a mapping configuration file**
  8. The following request uploads an app-schema mapping file called ``LandCoverVector.xml`` to a data store called ``LandCoverVector``. If no ``LandCoverVector`` data store existed in workspace ``lcv`` prior to the request, it would be created.
  9. *Request*
  10. .. admonition:: curl
  11. ::
  12. curl -v -X PUT -d @LandCoverVector.xml -H "Content-Type: text/xml"
  13. -u admin:geoserver http://localhost:8080/geoserver/rest/workspaces/lcv/datastores/LandCoverVector/file.appschema?configure=all
  14. *Response*
  15. ::
  16. 201 Created
  17. Listing app-schema store details
  18. --------------------------------
  19. *Request*
  20. .. admonition:: curl
  21. ::
  22. curl -v -u admin:geoserver -X GET
  23. http://localhost:8080/geoserver/rest/workspaces/lcv/datastores/LandCoverVector.xml
  24. *Response*
  25. .. code-block:: xml
  26. <dataStore>
  27. <name>LandCoverVector</name>
  28. <type>Application Schema DataAccess</type>
  29. <enabled>true</enabled>
  30. <workspace>
  31. <name>lcv</name>
  32. <atom:link xmlns:atom="http://www.w3.org/2005/Atom" rel="alternate" href="http://localhost:8080/geoserver/rest/workspaces/lcv.xml" type="application/xml"/>
  33. </workspace>
  34. <connectionParameters>
  35. <entry key="dbtype">app-schema</entry>
  36. <entry key="namespace">http://inspire.ec.europa.eu/schemas/lcv/3.0</entry>
  37. <entry key="url">file:/path/to/data_dir/data/lcv/LandCoverVector/LandCoverVector.appschema</entry>
  38. </connectionParameters>
  39. <__default>false</__default>
  40. <featureTypes>
  41. <atom:link xmlns:atom="http://www.w3.org/2005/Atom" rel="alternate" href="http://localhost:8080/geoserver/rest/workspaces/lcv/datastores/LandCoverVector/featuretypes.xml" type="application/xml"/>
  42. </featureTypes>
  43. </dataStore>
  44. Uploading a new app-schema mapping configuration file
  45. -----------------------------------------------------
  46. **Upload a new mapping configuration, stored in the mapping file "`LandCoverVector_alternative.xml", to the "LandCoverVector" data store**
  47. *Request*
  48. .. admonition:: curl
  49. ::
  50. curl -v -X PUT -d @LandCoverVector_alternative.xml -H "Content-Type: text/xml"
  51. -u admin:geoserver http://localhost:8080/geoserver/rest/workspaces/lcv/datastores/LandCoverVector/file.appschema?configure=none
  52. *Response*
  53. ::
  54. 200 OK
  55. .. note:: This time the ``configure`` parameter is set to ``none``, because we don't want to configure again the feature types, just replace their mapping configuration.
  56. .. note:: If the set of feature types mapped in the new configuration file differs from the set of feature types mapped in the old one (either some are missing, or some are new, or both), the best way to proceed is to delete the data store and create it anew issuing another PUT request, :ref:`as shown above <appschema_upload_create>`.
  57. Uploading multiple app-schema mapping files
  58. -------------------------------------------
  59. **Create a new app-schema data store based on a complex mapping configuration split into multiple files, and show how to upload application schemas (i.e. XSD files) along with the mapping configuration.**
  60. .. note:: In the previous example, we have seen how to create a new app-schema data store by uploading a mapping configuration stored in a single file; this time, things are more complicated, since the mappings have been spread over two configuration files: the main configuration file is called ``geosciml.appschema`` and contains the mappings for three feature types: ``GeologicUnit``, ``MappedFeature`` and ``GeologicEvent``; the second file is called ``cgi_termvalue.xml`` and contains the mappings for a single non-feature type, ``CGI_TermValue``.
  61. .. note:: As explained in the :ref:`REST API reference documentation for data stores <rest_api_datastores_file_put_appschema>`, when the mapping configuration is spread over multiple files, the extension of the main configuration file must be ``.appschema``.
  62. The main configuration file includes the second file:
  63. .. code-block:: xml
  64. ...
  65. <includedTypes>
  66. <Include>cgi_termvalue.xml</Include>
  67. </includedTypes>
  68. ...
  69. We also want to upload to GeoServer the schemas required to define the mapping, instead of having GeoServer retrieve them from the internet (which is especially useful in case our server doesn't have access to the web). The main schema is called ``geosciml.xsd`` and is referred to in ``geosciml.appschema`` as such:
  70. .. code-block:: xml
  71. ...
  72. <targetTypes>
  73. <FeatureType>
  74. <schemaUri>geosciml.xsd</schemaUri>
  75. </FeatureType>
  76. </targetTypes>
  77. ...
  78. In this case, the main schema depends on several other schemas:
  79. .. code-block:: xml
  80. <include schemaLocation="geologicUnit.xsd"/>
  81. <include schemaLocation="borehole.xsd"/>
  82. <include schemaLocation="vocabulary.xsd"/>
  83. <include schemaLocation="geologicRelation.xsd"/>
  84. <include schemaLocation="fossil.xsd"/>
  85. <include schemaLocation="value.xsd"/>
  86. <include schemaLocation="geologicFeature.xsd"/>
  87. <include schemaLocation="geologicAge.xsd"/>
  88. <include schemaLocation="earthMaterial.xsd"/>
  89. <include schemaLocation="collection.xsd"/>
  90. <include schemaLocation="geologicStructure.xsd"/>
  91. They don't need to be listed in the ``targetTypes`` section of the mapping configuration, but they must be included in the ZIP archive that will be uploaded.
  92. .. note:: The GeoSciML schemas listed above, as pretty much any application schema out there, reference the base GML schemas (notably, ``http://schemas.opengis.net/gml/3.1.1/base/gml.xsd``) and a few other remotely hosted schemas (e.g. ``http://www.geosciml.org/cgiutilities/1.0/xsd/cgiUtilities.xsd``).
  93. For the example to work in a completely offline environment, one would have to either replace all remote references with local ones, or pre-populate the app-schema cache with a copy of the remote schemas. :ref:`GeoServer's user manual <app-schema-cache>` contains more information on the app-schema cache.
  94. To summarize, we'll upload to GeoServer a ZIP archive with the following contents:
  95. .. code-block:: console
  96. geosciml.appschema # main mapping file
  97. cgi_termvalue.xml # secondary mapping file
  98. geosciml.xsd # main schema
  99. borehole.xsd
  100. collection.xsd
  101. earthMaterial.xsd
  102. fossil.xsd
  103. geologicAge.xsd
  104. geologicFeature.xsd
  105. geologicRelation.xsd
  106. geologicStructure.xsd
  107. geologicUnit.xsd
  108. value.xsd
  109. vocabulary.xsd
  110. *Request*
  111. .. admonition:: curl
  112. ::
  113. curl -X PUT --data-binary @geosciml.zip -H "Content-Type: application/zip"
  114. -u admin:geoserver http://localhost:8080/geoserver/rest/workspaces/gsml/datastores/geosciml/file.appschema?configure=all
  115. *Response*
  116. ::
  117. 200 OK
  118. A new ``geosciml`` data store will be created with three feature types in it:
  119. .. code-block:: xml
  120. <featureTypes>
  121. <featureType>
  122. <name>MappedFeature</name>
  123. <atom:link xmlns:atom="http://www.w3.org/2005/Atom" rel="alternate" href="http://localhost:8080/geoserver/rest/workspaces/gsml/datastores/geosciml/featuretypes/MappedFeature.xml" type="application/xml"/>
  124. </featureType>
  125. <featureType>
  126. <name>GeologicEvent</name>
  127. <atom:link xmlns:atom="http://www.w3.org/2005/Atom" rel="alternate" href="http://localhost:8080/geoserver/rest/workspaces/gsml/datastores/geosciml/featuretypes/GeologicEvent.xml" type="application/xml"/>
  128. </featureType>
  129. <featureType>
  130. <name>GeologicUnit</name>
  131. <atom:link xmlns:atom="http://www.w3.org/2005/Atom" rel="alternate" href="http://localhost:8080/geoserver/rest/workspaces/gsml/datastores/geosciml/featuretypes/GeologicUnit.xml" type="application/xml"/>
  132. </featureType>
  133. </featureTypes>
  134. Cleaning schemas on internal MongoDB stores
  135. -------------------------------------------
  136. **Clean persisted schema on an internal MongoDB Store, allowing it to generate a new one from data.**
  137. *Request template*
  138. .. admonition:: curl
  139. ::
  140. curl -v -X POST
  141. -u admin:geoserver http://localhost:8080/geoserver/rest/workspaces/{WORKSPACE}/appschemastores/{APP_SCHEMA_STORE_NAME}/datastores/{INTERNAL_STORE_ID}/cleanSchemas
  142. *Request*
  143. .. admonition:: curl
  144. ::
  145. curl -v -X POST
  146. -u admin:geoserver http://localhost:8080/geoserver/rest/workspaces/st/appschemastores/AppSchemaStoreName/datastores/store_id/cleanSchemas
  147. *Response*
  148. ::
  149. 200 OK
  150. **Clean persisted schema on all internal MongoDB Stores, allowing it to generate them from data.**
  151. *Request template*
  152. .. admonition:: curl
  153. ::
  154. curl -v -X POST
  155. -u admin:geoserver http://localhost:8080/geoserver/rest/workspaces/{WORKSPACE}/appschemastores/{APP_SCHEMA_STORE_NAME}/cleanSchemas
  156. *Request*
  157. .. admonition:: curl
  158. ::
  159. curl -v -X POST
  160. -u admin:geoserver http://localhost:8080/geoserver/rest/workspaces/st/appschemastores/AppSchemaStoreName/cleanSchemas
  161. *Response*
  162. ::
  163. 200 OK
  164. **Rebuild persisted schema on internal MongoDB Store, allowing it to generate them from data and query parameters.**
  165. *Request template*
  166. .. admonition:: curl
  167. ::
  168. curl -v -X POST
  169. -u admin:geoserver http://localhost:8080/geoserver/rest/workspaces/{WORKSPACE}/appschemastores/{APP_SCHEMA_STORE_NAME}/datastores/{INTERNAL_STORE_ID}/rebuildMongoSchemas?ids={ID_1},{ID_2}&max={MAX_OBJECTS}
  170. - ids: Comma separated MongoDB JSON objects ids to query for generating schemas. Not required if the 'max' is setted.
  171. - max: Max number of MongoDB JSON objects to get for generating schemas. Not required if the 'ids' is setted.
  172. *Request*
  173. .. admonition:: curl
  174. ::
  175. curl -v -X POST
  176. -u admin:geoserver http://localhost:8080/geoserver/rest/workspaces/st/appschemastores/AppSchemaStoreName/datastores/store_id/rebuildMongoSchemas?ids=58e5889ce4b02461ad5af081,58e5889ce4b02461ad5af080&max=5
  177. *Response*
  178. ::
  179. 200 OK
  180. **Rebuild persisted schema on all internal MongoDB Stores, allowing it to generate them from data and query parameters.**
  181. *Request template*
  182. .. admonition:: curl
  183. ::
  184. curl -v -X POST
  185. -u admin:geoserver http://localhost:8080/geoserver/rest/workspaces/{WORKSPACE}/appschemastores/{APP_SCHEMA_STORE_NAME}/rebuildMongoSchemas?ids={ID_1},{ID_2}&max={MAX_OBJECTS}
  186. - ids: Comma separated MongoDB JSON objects ids to query for generating schemas. Not required if the 'max' is setted.
  187. - max: Max number of MongoDB JSON objects to get for generating schemas. Not required if the 'ids' is setted.
  188. *Request*
  189. .. admonition:: curl
  190. ::
  191. curl -v -X POST
  192. -u admin:geoserver http://localhost:8080/geoserver/rest/workspaces/st/appschemastores/AppSchemaStoreName/rebuildMongoSchemas?ids=58e5889ce4b02461ad5af081,58e5889ce4b02461ad5af080&max=5
  193. *Response*
  194. ::
  195. 200 OK
  196. .. note:: This endpoins are only available when App-Schema and MongoDB modules are installed on Geoserver, and involved app-schema store have internal MongoDB stores in mappings definition.