openapi: 3.0.1
info:
  title: SensLog
  description: 'ASWI semestral project of CodeBakers.'
  version: 1.0.0
externalDocs:
  description: Find out more about Swagger
  url: https://swagger.io

tags:
- name: login
  description: Login process
  externalDocs:
    description: Find out more
    url: https://www.senslog.org/api/v1/
- name: group
  description: Groups endpoints
- name: data
  description: Data endpoints
- name: observation
  description: Observations endpoints
- name: analytics
  description: Analitics endpoints
- name: management
  description: Insert endpoints
- name: sensors
  description: Sensor service
- name: administration
  description: Administration service

paths:
  /senslog15/ControllerServlet:
    post:
      tags:
      - login
      summary: Authorize login
      operationId: login
      parameters:
        - in: query
          name: username
          schema:
            type: string
          description: User login
        - in: query
          name: password
          schema:
            type: string
          description: User password
      responses:
        200:
          description: successful operation
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/UserCookie'
        401:
          description: Wrong username or password
          content:
            text/plain:
              schema:
                type: string

  /senslog15/rest/user:
    get:
      tags:
        - login
      summary: User information
      operationId: getUserInfo
      responses:
        200:
          description: successful operation
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/UserInfo'
    post:
      tags:
        - administration
      summary: Create User
      operationId: createUser
      responses:
        200:
          description: created
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/UserInfo'

  /senslog15/SensorService?Operation=GetSensors:
    get:
      tags:
        - sensors
      summary: Get unit sensors
      operationId: getUnitSensors
      parameters:
        - in: query
          name: unit_id
          required: true
          schema:
            type: integer
      responses:
        200:
          description: successful
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/Sensor'


  /senslog15/SensorService?Operation=GetObservations:
    get:
      tags:
        - observation
      summary: Get observation
      operationId: getObservation
      parameters:
        - in: query
          name: unit_id
          required: true
          schema:
            type: integer
        - in: query
          name: sensor_id
          required: true
          schema:
            type: integer
        - in: query
          name: from
          schema:
            type: string
        - in: query
          name: to
          schema:
            type: string
      responses:
        200:
          description: Get observation for unitId and sensorId
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/OldObservation'
        500:
          description: Internal server error

  /senslog15/GroupService:
    get:
      tags:
      - group
      summary: Get groups
      operationId: getGroups
      parameters:
        - in: query
          name: Operation
          required: true
          schema:
            type: string
            default: GetGroups
            enum:
            - GetGroups
            - GetSuperGroups
            - GetSubGroups
          description: Group operation
        - in: query
          name: parent_group
          schema:
            type: integer
      responses:
        200:
          description: successful operation
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/Group'

  /senslog15/DataService?Operation=GetUnits:
    get:
      tags:
        - data
      summary: Get data
      operationId: getData
      responses:
        200:
          description: successful operation
          content:
            application/json:
              schema:
                type: array
                items:
                  oneOf:
                    - type: object
                      properties:
                        drivers:
                          $ref: '#/components/schemas/Drivers'
                        generalInfo:
                          $ref: '#/components/schemas/GeneralInfo'
                        holder:
                          nullable: true
                        lastpos:
                          $ref: '#/components/schemas/Lastpos'
                        sensors:
                          type: array
                          items:
                            $ref: '#/components/schemas/Sensor'
                        unit:
                          $ref: '#/components/schemas/Unit'

  /analytics/analytics:
    get:
      tags:
        - analytics
      summary: Get analytics
      operationId: getAnalytics
      parameters:
        - in: query
          name: unit_id
          required: true
          schema:
            type: integer
        - in: query
          name: sensor_id
          required: false
          schema:
            type: integer
        - in: query
          name: from
          schema:
            type: string
        - in: query
          name: to
          schema:
            type: string
        - in: query
          name: interval
          schema:
            type: string
      responses:
        200:
          description: Get observation for unit
          content:
            application/json:
              schema:
                type: array
                properties:
                  sensor:
                    $ref: '#/components/schemas/Sensors'
        400:
          description: wrong request
          content:
            application/json:
              schema:
                type: object
                properties:
                  message:
                    type: string
                  path:
                    type: string
                  timestamp:
                    type: number

  /senslog15/ManagementService?Operation=InsertUnit:
    post:
      tags:
        - management
      summary: Insert Unit
      operationId: insertUnit
      responses:
        200:
          description: inserted
          content:
            application/json:
              schema:
                type: object
                properties:
                  unit:
                    $ref: '#/components/schemas/InsertUnit'
                  sensors:
                    type: array
                    items:
                      $ref: '#/components/schemas/InsertSensor'
        400:
          description: wrong request
          content:
            application/json:
              schema:
                type: object
                properties:
                  message:
                    type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                unit:
                  $ref: '#/components/schemas/InsertUnit'
                sensors:
                  type: array
                  items:
                    $ref: '#/components/schemas/InsertSensor'

  /senslog15/ManagementService?Operation=InsertSensor:
    post:
      tags:
        - management
      summary: Insert Sensor
      operationId: insertSensor
      responses:
        200:
          description: inserted
          content:
            application/json:
              schema:
                type: object
                properties:
                  unit:
                    $ref: '#/components/schemas/InsertUnit'
                  sensors:
                    type: array
                    items:
                      $ref: '#/components/schemas/InsertSensor'
        400:
          description: wrong request
          content:
            application/json:
              schema:
                type: object
                properties:
                  message:
                    type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                unit:
                  $ref: '#/components/schemas/InsertUnit'
                sensors:
                  type: array
                  items:
                    $ref: '#/components/schemas/InsertSensor'

  /senslog15/SensorService?Operation=GetAllPhenomenons:
    get:
      tags:
        - sensors
      summary: Get phenomenons
      operationId: getPhenomenons
      responses:
        200:
          description: Getting all Phenomenons
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/Phenomenon'

  /senslog15/SensorService?Operation=GetAllSensorTypes:
    get:
      tags:
        - sensors
      summary: Get sensor types
      operationId: getSensorTypes
      responses:
        200:
          description: Getting all Sensor types
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/SensorType'

  /senslog15/ManagementService?Operation=UpdateUnit:
    put:
      tags:
        - management
      summary: Update Unit
      operationId: updateUnit
      responses:
        200:
          description: updated
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                unit:
                  $ref: '#/components/schemas/InsertUnit'

  /senslog15/ManagementService?Operation=DeleteUnit:
    delete:
      tags:
        - management
      summary: Delete Unit
      operationId: deleteUnit
      responses:
        200:
          description: deleted
          content:
            application/json:
              schema:
                type: object
                properties:
                  message:
                    type: string
        400:
          description: wrong request
          content:
            application/json:
              schema:
                type: object
                properties:
                  message:
                    type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                unit:
                  $ref: '#/components/schemas/InsertUnit'

  /senslog15/ManagementService?Operation=DeleteSensor:
    delete:
      tags:
        - management
      summary: Delete Sensor
      operationId: deleteSensor
      responses:
        200:
          description: deleted
          content:
            application/json:
              schema:
                type: object
                properties:
                  unit:
                    $ref: '#/components/schemas/InsertUnit'
                  sensors:
                    type: array
                    items:
                      $ref: '#/components/schemas/InsertSensor'
        400:
          description: wrong request
          content:
            application/json:
              schema:
                type: object
                properties:
                  message:
                    type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                unit:
                  $ref: '#/components/schemas/InsertUnit'
                sensors:
                  type: array
                  items:
                    $ref: '#/components/schemas/InsertSensor'

  /senslog15/ManagementService?Operation=UpdateSensor:
    put:
      tags:
        - management
      summary: Update Sensor
      operationId: updateSensor
      responses:
        200:
          description: updated
          content:
            application/json:
              schema:
                type: object
                properties:
                  unit:
                    $ref: '#/components/schemas/InsertUnit'
                  sensors:
                    type: array
                    items:
                      $ref: '#/components/schemas/InsertSensor'
        400:
          description: wrong request
          content:
            application/json:
              schema:
                type: object
                properties:
                  message:
                    type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                unit:
                  $ref: '#/components/schemas/InsertUnit'
                sensors:
                  type: array
                  items:
                    $ref: '#/components/schemas/InsertSensor'

  /senslog15/rest/user/rights:
    get:
      tags:
        - administration
      summary: Get rights
      operationId: getRights
      responses:
        200:
          description: success
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/Right'

  /senslog15/FeederServlet?Operation=InsertPosition:
    get:
      tags:
        - sensors
      parameters:
        - in: query
          name: lat
          required: true
          schema:
            type: number
        - in: query
          name: lon
          required: true
          schema:
            type: number
        - in: query
          name: unit_id
          required: true
          schema:
            type: integer
        - in: query
          name: date
          required: true
          schema:
            type: string
        - in: query
          name: alt
          required: false
          schema:
            type: string
        - in: query
          name: speed
          required: false
          schema:
            type: number
        - in: query
          name: dop
          required: false
          schema:
            type: number
      summary: Insert position to unit
      operationId: insertPosition
      responses:
        200:
          description: success

components:
  schemas:
    Right:
      type: object
      properties:
        rightsId:
          type: integer
        userRole:
          type: string
        note:
          type: string

    InsertUnit:
      type: object
      properties:
        unit_id:
          type: integer
        description:
          type: string

    InsertSensor:
      type: object
      properties:
        sensor_id:
          type: integer
        sensor_name:
          type: string
        sensor_type:
          type: string
        phenomenon:
          $ref: '#/components/schemas/InsertPhenomenon'

    InsertPhenomenon:
      type: object
      properties:
        phenomenon_id:
          type: integer

    UserCookie:
      type: object
      properties:
        sessionid:
          type: string
        language:
          type: string
        audio:
          type: boolean
        rightsID:
          type: integer

    UserInfo:
      type: object
      properties:
        userId:
          type: integer
        userName:
          type: string
        userPass:
          type: string
        userRealName:
          type: string
        groupId:
          type: integer
        "rightsId":
          type: integer

    Group:
      type: object
      properties:
        id:
          type: integer
        parent_group_id:
          type: integer
        group_name:
          type: string
        has_children:
          type: boolean

    Unit:
      type: object
      properties:
        description:
          type: string
        holderId:
          type: integer
        unitId:
          type: integer

    Phenomenon:
      type: object
      properties:
        phenomenonId:
          type: string
        phenomenonName:
          type: string
        unit:
          type: string

    Sensor:
      type: object
      properties:
        firstObservationTime:
          type: string
          format: date-time
        lastObservationTime:
          type: string
          format: date-time
        phenomenon:
          $ref: '#/components/schemas/Phenomenon'
        sensorId:
          type: integer
        sensorName:
          type: string
        sensorType:
          type: string

    Position:
      type: object
      properties:
        SRID:
          type: string
        gid:
          type: integer
        group_id:
          type: integer
        postgisGeomString:
          type: string
        postgisString:
          type: string
        speed:
          type: integer
        time_stamp:
          type: string
          format: date-time
        unit_id:
          type: integer
        x:
          type: number
        y:
          type: number

    Attributes:
      type: object
      properties:
        is_online:
          type: boolean
        is_moving:
          type: boolean

    AlertEvents:
      type: array

    Lastpos:
      type: object
      properties:
        alertEvents:
          $ref: '#/components/schemas/AlertEvents'
        attributes:
          $ref: '#/components/schemas/Attributes'
        position:
          $ref: '#/components/schemas/Position'

    GeneralInfo:
      type: array

    Drivers:
      type: array

    Sensors:
      type: object
      properties:
        sensorsData:
          $ref: '#/components/schemas/SensorsData'

    SensorsData:
      type: object
      properties:
        interval:
          type: number
        data:
          $ref: '#/components/schemas/Data'
        statistics:
          $ref: '#/components/schemas/Statistics'

    Data:
      type: object
      properties:
        observation:
          $ref: '#/components/schemas/Observation'

    Observation:
      type: object
      properties:
        min:
          type: number
        max:
          type: number
        avg:
          type: number
        sum:
          type: number
        timestamp:
          type: string
          format: date-time

    Statistics:
      type: object
      properties:
        min:
          type: number
        max:
          type: number
        avg:
          type: number
        sum:
          type: number

    OldObservation:
      type: object
      properties:
        gid:
          type: integer
        time:
          type: string
          format: date-time
        value:
          type: number

    SensorType:
      type: object
      properties:
        phenomenon:
          $ref: '#/components/schemas/Phenomenon'
        sensorId:
          type: integer
        sensorName:
          type: string
        sensorType:
          type: string





