-
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.
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()
URL: {{base_url}}/{{smartdata}}/smartdata/collection/testcollection_geometries?storage=teststorage
Method: GET
- Sending GET request
- Respons with an list of attributes and their definition (JSON) including advanced info about geometry columns
- Response state: 200 OK
In this case attributes have always type "geometry" with additional informations:
- subtype: POINT, POINTZ, ...
- dimension: 2,3 (2D/3D)
- srid: A number identifying the coordinate system
Testcase:
- testGetGeoAttributes()
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()
URL: {{base_url}}/{{smartdata}}/smartdata/collection/testcollection_ts/addAttributes?storage=teststorage
Method: PUT
Body: New attribut(s) definition in array
- Sending PUT request
- New attributes are added
- Response state: 201 CREATED
Testcases:
- testAddAttributes()
Exceptions:
- New attribute has invalid definition:
- Response with error message
- Response state: PRECONDITION_FAILED
- One on the new attributes allready exists
- Response with error message
- Response state: CONFLICT
URL: {{base_url}}/{{smartdata}}/smartdata/collection/testcollection_ts/addAttributes?storage=teststorage
Method: PUT
Body: New attribut(s) definition in array
- Sending PUT request
- New attributes are added
- Response state: 201 CREATED
Testcase:
- testAddGeoAttributes()
Exceptions:
- New attribute has invalid definition:
- Response with error message
- Response state: PRECONDITION_FAILED
- One on the new attributes allready exists
- Response with error message
- Response state: CONFLICT
URL: {{base_url}}/{{smartdata}}/smartdata/collection/testcollection_ts/changeAttribute?storage=teststorage
Method: PUT
Body: Changed column definition
- Sending PUT request
- Attribute changes it's type, length, defaultValue or any other information
- Response state: 200 OK
Exceptions:
- New information is invalid definition:
- Response with error message
- Response state: PRECONDITION_FAILED
URL: {{base_url}}/{{smartdata}}/smartdata/collection/testcollection_geometries/changeAttribute?storage=teststorage
Method: PUT
Body: Changed column definition
- Sending PUT request
- Attribute changes its SRID, existing coordinates are converted
- Response state: 200 OK
Testcases:
- testChangeSRID()
Exceptions:
- New srid is invalid definition:
- Response with error message
- Response state: PRECONDITION_FAILED
URL: {{base_url}}/{{smartdata}}/smartdata/collection/testcollection_geometries/changeAttribute?storage=teststorage
Method: PUT
Body: JSON array with one object for each deleteable attribut with it's name.
- Sending PUT request
- Attributes are removed from collection
- Response state: 200 OK
Use function 3 and function 1 for this. This works even over different storages and different SmartData instances.
- Get the collection definition via GET /collection/TABLE_NAME
- Send the recived Json via POST /collection/TABLE_NAME
You can change the storage and collection name within url and json.
Testcase: * testGetAttributesAndCreateTable()
URL:
Method: POST
Body: Attribute definitions with forign key attributes
Additional attributes for references:
| Name | Description | Possible Values | Default value | Optional |
|---|---|---|---|---|
| refCollection | Referenced collections name | any collection name | - | false |
| refAttribute | Referenced attributes name | any attribute name | - | false |
| refName | References name | varchar | db-system generated | true |
| refStorage | Referenced storage name | any storage name | - | true |
| refOnDelete | CASCADE | - | true | |
| refOnUpdate | CASCADE | - | true |
- Send POST request
- Collection is created with refernces
Exception:
- Referenced attribute / collection / storage does not exists.
- Error message
- Response state: 500 INTERNAL SERVER ERROR (subject to change)
- 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"
},
...
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"
}