Skip to content

Funktionen_CollectionResource

Florian Fehring edited this page Apr 30, 2026 · 12 revisions

Here you find documentation for working with collections. Collections are spaces in database that contain records (datasets). Postgres: collection = table

Function 1: Create a Collection

URL: {{base_url}}/{{smartdata}}/smartdata/collection/testcollection_ts?storage=teststorage

Method: POST

Body: JSON with attribute definition (see examples)

  1. 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:

  1. Try to create a collection that allready exists
    • Response state: NOT_MODIFIED
    • testCreateCollectionAllreadyExists()
  2. A autoincrementing attribut is given with the definition
    • Collection will be created with autoincrementation attribute
    • testCreateCollectionGivingAutoId()
  3. A non autoincrementing attribut is given with the definition
    • Collection will be created with non autoincrementation attribute
    • testCreateCollectionGivingId()

Function 2: Create a Collection with geo information

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)

  1. 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.

Function 3: Getting request attributes

URL: {{base_url}}/{{smartdata}}/smartdata/collection/testcollection_ts?storage=teststorage

Method: GET

  1. 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:

  1. There are no attributes in the collection
    • Response with an empty list
    • Response state: 200 OK
  2. The collection or storage used does not exist
    • Response with error message
    • Response state: 404 NOT FOUND
    • testGetAttributesNoExSchema()

Funktion 3: Abfragen der Geo-Attribute einer Collection

  1. Es wird eine Liste der verfügbaren Geo-Attribute mit ihren Eigenschaften ausgegeben
    • testGetGeoAttributes()

Ausnahmen:

  1. Es gibt keine Attribute in der Collection
    • Es wird mit Status OK und einer leeren Liste geantwortet

Funktion 4: Ein neues Attribut hinzufügen

  1. Es werden neue Attribute zur Collection hinzugefügt
    • testAddAttributes()

Ausnahmen:

  1. Das Attribut kann nicht angelegt werden wegen ungültiger Eigenschaften
    • Es wird mit Status PRECONDITION_FAILED geantwortet

Funktion 5: Ein neues Geo-Attribut hinzufügen

  1. Es werden neue Geo-Attribute zur Collection hinzugefügt
    • testAddGeoAttributes()

Ausnahmen:

  1. Das Attribut kann nicht angelegt werden wegen ungültiger Eigenschaften
    • Es wird mit Status PRECONDITION_FAILED geantwortet

Funktion 6: Bei einem Geo-Attribut die SRID ändern

  1. Es werden neue Geo-Attribute zur Collection hinzugefügt
    • testChangeSRID()

Ausnahmen:

  1. Das Attribut kann nicht angelegt werden wegen ungültiger Eigenschaften
    • Es wird mit Status PRECONDITION_FAILED geantwortet

Funktion 7: Definition einer Collection kopieren

  1. 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

Funktion 8: Attribute löschen

  1. 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

Funktion 9: Abfragen der Fremdschlüssel einer Collection

  1. 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"
    },
    ...

Funktion 10: Eine Collection mit Fremdschlüsseln anlegen

  1. 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:

  1. Existiert die zu referenzierende Collection nicht, wird mit Status 500 geantwortet

Funktion 11: Abfragen aller Referenzen zu und von einer Collection

Fragt die Referenzen von und zu einer Collection ab und listet sie auf.

Beispiel: https://scl.fh-bielefeld.de/SmartDataAirquality/smartdata/collection/tbl_observedobject/references?storage=smartmonitoring

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"
}

Clone this wiki locally