== Data
:Author:    Andreas Krantz
:Email:     totonga@gmail.com

****
ASAM ODS is about making measurement data persistent. So this is the most important chapter. Its is about writing and reading data (meta/bulk).
****

include::datamatrix.adoc[]


=== Read meta data

----
POST /con/{conI}/data/access
----

.get results from first entity derived from AoTest with all properties
================================
TIP: The server will have a default rowMaxCount setting.
     He will potentially not return all AoTest if there are more of them.
     
.request
[source,json]
----
curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/problem+json' -d '
{
    "AoTest": {}
}' 
'http://localhost:8081/con/c1/data/access'
----
.result
[source,json]
----
{
  "matrices": [
    {
      "name": "TestBed", 
      "baseName": "AoTest", 
      "objecttype": "2", 
      "columns": [
        {
          "name": "Name", 
          "baseName": "name", 
          "datatype": "DT_STRING", 
          "dtString": { "values": ["CFMA-L8","HAVC_PRT_KL EP","CFMA-L9"] }
        },
        {
          "name": "Id", 
          "baseName": "id", 
          "datatype": "DT_ID", 
          "dtLonglong": { "values": ["2","3","4"] } 
        },
        {
          "name": "Description", 
          "datatype": "DT_STRING", 
          "baseName": "description", 
          "dtString": { "values": ["Engine test bench","All-wheel flat-roadway test bench","All-wheel flat-roadway test bench"] }
        },
        {
          "name": "Version", 
          "datatype": "DT_STRING", 
          "baseName": "version", 
          "dtString": { "values": ["2.1","1.5","1.2"] }
        },
        {
          "name": "Location", 
          "datatype": "DT_STRING", 
          "baseName": "", 
          "dtString": { "values": ["Madrid","Austin","Milan"] }
        },
        {
          "name": "Environment", 
          "datatype": "DT_ID", 
          "baseName": "environment", 
          "dtLonglong": { "values": ["1","1","1"] }
        }
      ]
    }
  ]
}
----
================================

.get results from Project all properties
================================
TIP: The server will have a default rowMaxCount setting.
     He will potentially not return all AoTest if there are more of them.
     
.request
[source,json]
----
curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/problem+json' -d '
{
    "Project": {}
}' 
'http://localhost:8081/con/c1/data/access'
----
.result
[source,json]
----
----
================================

.get results from instances with objecttype 5 with all properties
================================
TIP: Using the objecttype will give no great speed improvement. It is not even readable.
     
.request
[source,json]
----
curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/problem+json' -d '
{
    "5": {}
}' 
'http://localhost:8081/con/c1/data/access'
----
.result
[source,json]
----
----
================================

.get results of instances with objecttype MeaQuantity and define the maximal number of rows to return
================================
.request
[source,json]
----
curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/problem+json' -d '
{
    "AoMeasurementQuantity": {},
    "$options": {
        "$rowlimit": 10
    }
}' 
'http://localhost:8081/con/c1/data/access'
----
.result
[source,json]
----
----
================================

.get id and name attribute of the given entity
================================
TIP: if an instance should be shown in a tree it is sufficient to retrieve name and id

.request
[source,json]
----
curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/problem+json' -d '
{
    "AoMeasurementQuantity": {},
    "$attributes": {
        "name": 1,
        "id": 1
    }
}' 
'http://localhost:8081/con/c1/data/access'
----
.result
[source,json]
----
----
================================

.get id and name attribute of the given entity and the name attribute of the related measurement
================================
TIP: if an instance should shown it might be usefult to retrieve some parent/related attributes. 
     Be aware of the fact that two DataMatrices are returned.

.request
[source,json]
----
curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/problem+json' -d '
{
    "AoMeasurementQuantity": {},
    "$attributes": {
        "name": 1,
        "id": 1,
        "measurement.name": 1
    }
}' 
'http://localhost:8081/con/c1/data/access'
----
.result
[source,json]
----
----
================================


.get all attributes if for a given instance
================================
.request
[source,json]
----
curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/problem+json' -d '
{
    "AoMeasurementQuantity": 1960
}' 
'http://localhost:8081/con/c1/data/access'
----
.result
[source,json]
----
----

Same result will show up with the following request

.request
[source,json]
----
curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/problem+json' -d '
{
    "AoMeasurementQuantity": {
        "id": 1960
    }
}' 
'http://localhost:8081/con/c1/data/access'
----
.result
[source,json]
----
----
================================

.get children MeasurementQuantities of the Measurement with id=4
================================
.request
[source,json]
----
curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/problem+json' -d '
{
    "AoMeasurementQuantity": {
        "measurement": 4
    },
    "$attributes": {
        "name": 1,
        "id": 1
    }
}' 
'http://localhost:8081/con/c1/data/access'
----
.result
[source,json]
----
----
================================

.Get information about all MeasurementQuantities of a the SubTest with id=10
================================
.request
[source,json]
----
curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/problem+json' -d '
{
    "AoMeasurementQuantity": {
        "measurement.test": 10
    },
    "$attributes": {
        "name": 1,
        "id": 1,
        "measurement.name": 1,
        "measurement.id": 1
    }
}' 
'http://localhost:8081/con/c1/data/access'
----
.result
[source,json]
----
----
================================

.get some measurementquantities and related info using a query
================================
.request
[source,json]
----
curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' -d '
{
    "AoMeasurementQuantity": {
        "$and": [
            {
                "measurement.measurement_begin": {
                    "$gt": "20071101115000"
                }
            },
            {
                "$or": [
                    {
                        "name": "7 Time Point10:+Z"
                    },
                    {
                        "name": "1 Time Point4:+Z"
                    }
                ]
            }
        ]
    },
    "$attributes": {
        "name": 1,
        "id": 1,
        "unit.name": 1,
        "measurement.name": 1,
        "measurement.id": 1,
        "measurement.test.name": 1,
        "measurement.test.id": 1
    }
}' 'http://localhost:8081/con/c2/data/access'
----
.result
[source,json]
----
----
================================

.get DISTINCT of all MeasurementQuantity names
================================
.request
[source,json]
----
curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/problem+json' -d '
{
    "AoMeasurementQuantity": {},
    "$attributes": {
        "name": {
            "$distinct": 1
        }
    }
}' 
'http://localhost:8081/con/c1/data/access'
----
.result
[source,json]
----
----
================================

.get names of given entity in descending order
================================
.request
[source,json]
----
curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/problem+json' -d '
{
    "AoMeasurementQuantity": {},
    "$attributes": {
        "name": 1
    },
    "$orderby": {
        "name": 0
    }
}' 
'http://localhost:8081/con/c1/data/access'
----
.result
[source,json]
----
----
================================

.get names of measurementquantities grouped and ordered by name
================================
.request
[source,json]
----
curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' -d '
{
    "AoMeasurementQuantity": {},
    "$attributes": {
        "name": 1
    },
    "$orderby": {
        "name": 1
    },
    "$groupby": {
        "name": 1
    }
}' 'http://localhost:8081/con/c1/data/access'
----
.result
[source,json]
----
----
================================

.Using normal joins will only return element where all relations are set
================================
.request
[source,json]
----
curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' -d '
{
    "AoMeasurementQuantity": {},
    "$attributes": {
        "name": 1,
        "unit.name": 1,
        "quantity.name": 1
    }
}' 'http://localhost:8081/con/c1/data/access'
----
.result
[source,json]
----
----
================================

.Use outer joins for sparse set relations
================================
.request
[source,json]
----
curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' -d '
{
    "AoMeasurementQuantity": {},
    "$attributes": {
        "name": 1,
        "unit:OUTER.name": 1,
        "quantity:OUTER.name": 1
    }
}' 'http://localhost:8081/con/c1/data/access'
----
.result
[source,json]
----
----
================================


=== Read bulk data

----
POST /con/{conI}/data/access
----

****
When bulk data is returned the AoLocalColumn::values attribute is used. It has type DT_UNKNOWN. So the values
will be returned in unkownSeq which allows different types for each result row.
****

.Get values, flags and generation_parameters of the given localcolumn
================================
.request
[source,json]
----
curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/problem+json' -d '
{
    "AoLocalColumn": 2263,
    "$attributes": {
        "id": 1,
        "generation_parameters": 1,
        "values": 1,
        "flags": 1
    }
}' 
'http://localhost:8081/con/c1/data/access'
----
.result
[source,json]
----
----
================================

.Get id, values, flags and generation_parameters of all local columns of the Submatrix with id=24, but return maximal 3 sequence rows
================================
.request
[source,json]
----
curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/problem+json' -d '
{
    "AoLocalColumn": {
        "submatrix": 24
    },
    "$attributes": {
        "id": 1,
        "generation_parameters": 1,
        "values": 1,
        "flags": 1
    },
    "$options": {
        "$seqlimit": 3
    }
}' 
'http://localhost:8081/con/c1/data/access'
----
.result
[source,json]
----
{
  "matrices": [
    {
      "name": "LocalColumn",
      "baseName": "AoLocalColumn", 
      "objecttype": "205", 
      "columns": [
        {
          "name": "Id", 
          "baseName": "id", 
          "datatype": "DT_ID", 
          "flags": [], 
          "dtLonglong": { "values": ["2262", "2263", "2264"] }
        }, 
        {
          "name": "iGeneration_Parameters", 
          "baseName": "generation_parameters", 
          "datatype": "DS_DOUBLE", 
          "dsDouble": {
            "values": [ 
              { "values": [] }, 
              { "values": [] }, 
              { "values": [0.0, 4.76171875] }
            ]
          }, 
          "flags": [false,false,true]
        }, 
        {
          "name": "iValues", 
          "baseName": "values", 
          "datatype": "DT_UNKNOWN", 
          "dtUnknown": {
            "values": [
              {
                "datatype": "DT_FLOAT", 
                "dtFloat": { "values": [-10000.0, -10000.0, -10000.0] }
              }, 
              {
                "datatype": "DT_FLOAT", 
                "dtFloat": { "values": [7.6884284019470215, 7.6887431144714355, 7.689032077789307] }
              }, 
              {
                "datatype": "DT_FLOAT", 
                "dtFloat": { "values": [0.0, 4.76171875] }
              }
            ]
          }, 
          "flags": []
        }, 
        {
          "name": "iFlags", 
          "baseName": "flags", 
          "datatype": "DS_SHORT", 
          "dsLong": {
            "values": [
              { "values": [] }, 
              { "values": [] }, 
              { "values": [16384, 16543] }
            ]
          }, 
          "flags": [false, false, true]
        }
      ]
    }
  ]
}
----
================================

.Get  chunk id, values and flags of all local columns with id=2263
================================
.request
[source,json]
----
curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/problem+json' -d '
{
    "AoLocalColumn": 2263,
    "$attributes": {
        "id": 1,
        "values": 1,
        "flags": 1
    },
    "$options": {
        "$seqlimit": 100,
        "$seqskip": 10
    }
}' 
'http://localhost:8081/con/c1/data/access'
----
.result
[source,json]
----
----
================================

.Get id, values, flags and generation_parameters of all local column Phoenix_02 and FFemAIF1_14 of the Submatrix with id=24
================================
.request
[source,json]
----
curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/problem+json' -d '
{
    "AoLocalColumn": {
        "submatrix": 24,
        "name": {
            "$in": [
                "Phoenix_02",
                "FFemAIF1_14"
            ]
        }
    },
    "$attributes": {
        "id": 1,
        "generation_parameters": 1,
        "values": 1,
        "flags": 1
    }
}' 
'http://localhost:8081/con/c1/data/access'
----
.result
[source,json]
----
----
================================


=== Write meta data

----
POST /con/{conI}/data/modify
PUT /con/{conI}/data/modify
DELETE /con/{conI}/data/modify
----

==== Create new instances

----
POST /con/{conI}/data/modify
----

==== Update instances

----
PUT /con/{conI}/data/modify
----

==== Delete Instances

----
DELETE /con/{conI}/data/modify
----


=== Write bulk data

----
PUT /con/{conI}/data/modify
----
