-
Notifications
You must be signed in to change notification settings - Fork 2
Funktionen_CollectionResource
Here you find documentation for working with collections. Collections are spaces in database that contain records (datasets). Postgres: collection = table
URL: {{base_url}}/{{smartdata}}/smartdata/collection/testcollection_ts?storage=teststorage
Method: POST
Body: JSON with attribute definition (see examples)
- Send POST request with attribute definitions
- Creates the collection. Identity attribute "id" is automatically added.
- Response state: 201 CREATED
A attribute definition consists of the following informations:
| Name | Description | Possible Values | Default value | Optional |
|---|---|---|---|---|
| isIdentity | If that attribute is an identity attribute | true / false | false | yes |
| isAutoIncrement | If that attribute has auto incremention values | true / false | false | yes |
| isNullable | It attribute can be null | true / false | true | yes |
| name | attributes name | all chars | - | no |
| type | attributes datatype | all supported by underlying db | - | no |
| defaultValue | default value for atribute | every matching to datatype | yes | yes |
Common types: bigserial, timestamp, float8, int8, varchar, bool
Common attributes:
- id (Id attributes default name for id based functions)
- ts (Timestamp values default name used for time based functions)
Testcases:
- testCreateCollection()
Exceptions:
- Try to create a collection that allready exists
- Response state: NOT_MODIFIED
- testCreateCollectionAllreadyExists()
- A autoincrementing attribut is given with the definition
- Collection will be created with autoincrementation attribute
- testCreateCollectionGivingAutoId()
- A non autoincrementing attribut is given with the definition
- Collection will be created with non autoincrementation attribute
- testCreateCollectionGivingId()
This is only supported on systems with geospatial ability.
URL: {{base_url}}/{{smartdata}}/smartdata/collection/testcollection_ts?storage=teststorage
Method: POST
Body: JSON with attribute definition (see examples)
- Send POST request with attribute definitions
- Creates the collection with given geometry attributes
- Response state: 201 CREATED
A attribute definition can use the following informations additionaly to the base informations:
| Name | Description | Possible Values | Default value | Optional |
|---|---|---|---|---|
| type | attributes datatype | geometry(Point,4326), geometry(PointZ,4326) | - | false |
Geometry types are database depending. postgres: You can use every geometry type that is supported by postgis.
URL: {{base_url}}/{{smartdata}}/smartdata/collection/testcollection_ts?storage=teststorage
Method: GET
- Sending GET request
- Respons with an list of attributes and their definition (JSON)
- Response state: 200 OK
The returned JSON can be used to create a new table with the same attributes.
In case of geometries response has always type "geometry" with additional informations:
- subtype: POINT, POINTZ, ...
- dimension: 2,3 (2D/3D)
- srid: A number identifying the coordinate system
Testcases:
- testGetAttributes()
Exceptions:
- There are no attributes in the collection
- Response with an empty list
- Response state: 200 OK
- The collection or storage used does not exist
- Response with error message
- Response state: 404 NOT FOUND
- testGetAttributesNoExSchema()
- Es wird eine Liste der verfügbaren Geo-Attribute mit ihren Eigenschaften ausgegeben
- testGetGeoAttributes()
Ausnahmen:
- Es gibt keine Attribute in der Collection
- Es wird mit Status OK und einer leeren Liste geantwortet
- Es werden neue Attribute zur Collection hinzugefügt
- testAddAttributes()
Ausnahmen:
- Das Attribut kann nicht angelegt werden wegen ungültiger Eigenschaften
- Es wird mit Status PRECONDITION_FAILED geantwortet
- Es werden neue Geo-Attribute zur Collection hinzugefügt
- testAddGeoAttributes()
Ausnahmen:
- Das Attribut kann nicht angelegt werden wegen ungültiger Eigenschaften
- Es wird mit Status PRECONDITION_FAILED geantwortet
- Es werden neue Geo-Attribute zur Collection hinzugefügt
- testChangeSRID()
Ausnahmen:
- Das Attribut kann nicht angelegt werden wegen ungültiger Eigenschaften
- Es wird mit Status PRECONDITION_FAILED geantwortet
- Es wird über die CollectionRessource.getAttributes() die Definition einer Collection abgerufen. Diese wird dann an ein anderen Storage / Collection geschickt, um die Collection dort ebenfalls zu erzeugen.
- testGetAttributesAndCreateTable()
- Die Collection wird mit den entsprechenden Eigenschaften im neuen Storage unter dem neuen Collection-Namen angelegt
- Es wird mit Status 201 CREATED geantwortet
- Es wird über die CollectionResource.delAttributes() eine Liste von Attributen übergeben, die gelöscht werden sollen.
- Die Attribute werden aus der Collection gelöscht
- Es wird mit Status 200 OK geantwortet
- Es sollen die Fremdschlüssel einer Collection aufgelistet werden
- Es muss eine Collection, die Fremdschlüssel kennt abgefragt werden
- In der Auflistung der Attribute werden mit refName, refStorage, refAttribute, refOnUpdate, refOnDelete die Eigenschaften des Fremdschlüssels ausgegeben
Ausnahmen: Es werden dieselben Ausnahmen angewendet, wie beim Abfragen von Collections ohne Fremdschlüssel
Beispiel Antwort:
"name": "tbl_file_join_oo",
"attributes": [
{
"isAutoIncrement": false,
"refCollection": "tbl_observedobject",
"refOnDelete": "CASCADE",
"isNullable": true,
"name": "oo_id",
"isIdentity": false,
"refAttribute": "id",
"type": "int8",
"refName": "tbl_file_join_oo_fk",
"refStorage": "smartmonitoring",
"refOnUpdate": "CASCADE"
},
...
- Es soll eine neue Collection inkl. Fremdschlüsseln angelegt werden
- Das Definitions-JSON muss die Angaben refCollection und refAttribute enthalten. Mit refName, refStorage, refOnDelete und refOnUpdate können weitere Eigenschaften gesetzt werden
Ausnahmen:
- Existiert die zu referenzierende Collection nicht, wird mit Status 500 geantwortet
Fragt die Referenzen von und zu einer Collection ab und listet sie auf.
Antwort:
{"references": [
{
"from_storage" : "smartmonitoring",
"from_collection" : "schemes_visuals",
"from_attr" : "observedobject_id",
"to_storage" : "smartmonitoring",
"to_collection" : "tbl_observedobject",
"to_attr" : "id"
}, {
"from_storage" : "smartmonitoring",
"from_collection" : "schemes_activity",
"from_attr" : "observedobject_id",
"to_storage" : "smartmonitoring",
"to_collection" : "tbl_observedobject",
"to_attr" : "id"
}, {
"from_storage" : "smartmonitoring",
"from_collection" : "tbl_location_join_oo",
"from_attr" : "oo_id",
"to_storage" : "smartmonitoring",
"to_collection" : "tbl_observedobject",
"to_attr" : "id"
}, {
"from_storage" : "smartmonitoring",
"from_collection" : "tbl_observedobject",
"from_attr" : "parent_id",
"to_storage" : "smartmonitoring",
"to_collection" : "tbl_observedobject",
"to_attr" : "id"
}
],
"name": "tbl_observedobject",
"storage": "smartmonitoring"
}