swagger: '2.0'

info:
  version: "0.1.0"
  title: workflow-manager

host: haleconnect.com
schemes:
  - https
basePath: /workflows

paths:

  /{workflowType}/{resourceType}/{resourceId}/descriptor:
    parameters:
      - $ref: '#/parameters/workflowType'
      - $ref: '#/parameters/resourceType'
      - $ref: '#/parameters/resourceId'

    get:
      tags:
        - Workflows (generic)
      summary: Get the descriptor for a workflow
      responses:
        200:
          description: OK
          schema:
            $ref: '#/definitions/WorkflowDescriptor'
        default:
          $ref: '#/responses/Error'

  # manual trigger
  /{workflowType}/{resourceType}/{resourceId}/run:
    parameters:
      - $ref: '#/parameters/workflowType'
      - $ref: '#/parameters/resourceType'
      - $ref: '#/parameters/resourceId'

      - $ref: '#/parameters/limitToTargetIds'
      - $ref: '#/parameters/limitToResources'
      - $ref: '#/parameters/storeMetadata'
      - $ref: '#/parameters/replaceDefaults'
      - $ref: '#/parameters/limit'

    get:
      tags:
        - Workflows (generic)
      summary: Manually trigger a resource workflow
      responses:
        200:
          $ref: '#/responses/Success'
        default:
          $ref: '#/responses/Error'


# manual trigger
  /{workflowType}/{resourceType}/{resourceId}/cancelWorkflow:
    parameters:
      - $ref: '#/parameters/workflowType'
      - $ref: '#/parameters/resourceType'
      - $ref: '#/parameters/resourceId'
      - in: body
        name: additional params
        description: Additional params to filter the cancelWorkflow provided as a valid Json. For e.g. "limitToTargetIds"=["wms_1.3.0", "direct_download_2.0"] when "limitToResource"=["service"])
        schema:
          type: object
          required:
            - body
          properties:
            limitToTargetIds:
              type: array
              items:
                type: string
            limitToResources:
              type: array
              items:
                type: string
    delete:
          tags:
            - Workflows (generic)
          summary: Manually trigger a call to cancel a resource workflow
          responses:
            204:
              $ref: '#/responses/Success'
            default:
              $ref: '#/responses/Error'


  # manual trigger
  /{jobId}/cancelWorkflow:
    parameters:
      - $ref: '#/parameters/jobId'

    delete:
          tags:
            - Workflows (generic)
          summary: Manually trigger a call to cancel a cancellable resource workflow
          responses:
            204:
              $ref: '#/responses/Success'
            default:
              $ref: '#/responses/Error'


  # manual trigger
  /{workflowType}/{resourceType}/{resourceId}/{subresourceId}/run:
    parameters:
      - $ref: '#/parameters/workflowType'
      - $ref: '#/parameters/resourceType'
      - $ref: '#/parameters/resourceId'
      - $ref: '#/parameters/subresourceId'

      - $ref: '#/parameters/limitToTargetIds'
      - $ref: '#/parameters/limitToResources'
      - $ref: '#/parameters/storeMetadata'
      - $ref: '#/parameters/replaceDefaults'
      - $ref: '#/parameters/limit'
    get:
      tags:
        - Workflows (generic)
      summary: Manually trigger a resource workflow
      responses:
        200:
          $ref: '#/responses/Success'
        default:
          $ref: '#/responses/Error'


  /{workflowType}/{resourceType}/{resourceId}/invalidateRunningWorkflow:
    parameters:
      - $ref: '#/parameters/workflowType'
      - $ref: '#/parameters/resourceType'
      - $ref: '#/parameters/resourceId'
    get:
      tags:
        - Workflows (generic)
      summary: Invalidate a running workflow
      responses:
        200:
          $ref: '#/responses/Success'
        default:
          $ref: '#/responses/Error'

  # get recent results
  /{workflowType}/{resourceType}/{resourceId}/results:
    parameters:
      - $ref: '#/parameters/workflowType'
      - $ref: '#/parameters/resourceType'
      - $ref: '#/parameters/resourceId'
    get:
      tags:
        - Workflows (generic)
      summary: Get recent resource workflow execution results
      responses:
        200:
          description: OK
          schema:
            type: array
            items:
              $ref: '#/definitions/WorkflowResult'
        default:
          $ref: '#/responses/Error'

    # get recent results
  /{workflowType}/{resourceType}/{resourceId}/{subresourceId}/results:
    parameters:
      - $ref: '#/parameters/workflowType'
      - $ref: '#/parameters/resourceType'
      - $ref: '#/parameters/resourceId'
      - $ref: '#/parameters/subresourceId'
    get:
      tags:
        - Workflows (generic)
      summary: Get recent resource workflow execution results
      responses:
        200:
          description: OK
          schema:
            type: array
            items:
              $ref: '#/definitions/WorkflowResult'
        default:
          $ref: '#/responses/Error'

    # get recent results associated to a subresource
  /{workflowType}/{resourceType}/sub/{subresourceId}/results:
    parameters:
      - $ref: '#/parameters/workflowType'
      - $ref: '#/parameters/resourceType'
      - $ref: '#/parameters/subresourceId'
    get:
      tags:
        - Workflows (generic)
      summary: Get recent resource workflow execution results associated to a subresource
      responses:
        200:
          description: OK
          schema:
            type: array
            items:
              $ref: '#/definitions/WorkflowResult'
        default:
          $ref: '#/responses/Error'

    # put recent results
  /{workflowType}/{resourceType}/{resourceId}/results/{jobId}:
    parameters:
      - $ref: '#/parameters/workflowType'
      - $ref: '#/parameters/resourceType'
      - $ref: '#/parameters/resourceId'
      - $ref: '#/parameters/jobId'
      - $ref: '#/parameters/externalResult'
    put:
      tags:
        - Workflows (generic)
      summary: Add a workflow execution result for a job id
      responses:
        200:
          $ref: '#/responses/Success'
        default:
          $ref: '#/responses/Error'

    # get status details for an active workflow execution
  /status/{jobId}:
    parameters:
      - $ref: '#/parameters/jobId'
    get:
      tags:
        - Workflows (generic)
      summary: Get status details for an active workflow execution
      responses:
        200:
          description: OK
          schema:
            $ref: '#/definitions/WorkflowStatus'
        default:
          $ref: '#/responses/Error'

  # ETF Validator workflow

  /api/etfvalidator/tests:
    get:
      tags:
        - ETF Validator
      summary: Get the available tests with classification information
      responses:
        200:
          description: OK
          schema:
            type: array
            items:
              type: object
        default:
          $ref: '#/responses/Error'

  /api/etfvalidator/defaults/settings/theme/{themeId}:
    parameters:
      - $ref: '#/parameters/themeId'
    get:
      tags:
        - ETF Validator
      summary: Get the default settings that would be applied to the given theme if no explicit configuration is set.
      responses:
        200:
          description: OK
          schema:
            type: object
        default:
          $ref: '#/responses/Error'

  /api/etfvalidator/defaults/tests/theme/{themeId}:
    parameters:
      - $ref: '#/parameters/themeId'
    get:
      tags:
        - ETF Validator
      summary: Get the default test configuration that would be applied to the given theme if no explicit configuration is set.
      responses:
        200:
          description: OK
          schema:
            type: array
            items:
              type: object
        default:
          $ref: '#/responses/Error'

  # Spatineo Workflow

  /api/spatineo/availability/{resourceId}/{serviceId}:
    parameters:
      - $ref: '#/parameters/resourceId'
    get:
      tags:
        - Spatineo Update Workflow
      summary: Get the availabiltiy for a service
      parameters:
        - name: serviceId
          in: path
          description: Spatineo Service Identifier
          required: true
          type: string
      responses:
        200:
          description: OK
          schema:
            type: object
        default:
          $ref: '#/responses/Error'

  /api/spatineo/supported/{resourceId}:
    parameters:
      - $ref: '#/parameters/resourceId'
    get:
      tags:
        - Spatineo Update Workflow
      summary: Checks if monitoring with Spatineo is supported for a Bucket
      responses:
        200:
          $ref: '#/responses/Success'
        default:
          $ref: '#/responses/Error'

securityDefinitions:
  bearer:
    type: apiKey
    name: Authorization
    in: header

parameters:
  resourceId:
    name: resourceId
    in: path
    description: Resource identifier
    required: true
    type: string
  resourceType:
    name: resourceType
    in: path
    description: Resource type
    required: true
    type: string
  workflowType:
    name: workflowType
    in: path
    description: Type of the workflow to address
    required: true
    type: string
    enum:
      - transformation
      - publishing
      - autofill
      - deletion
      - checkcrs
      - usage
      - coverage
      - spatineo
      - etfvalidator
      - etftest
      - xmlvalidation
      - files-update
      - placeholder
      - service-purge
      - series-deletion
      - series-root-bucket-setup
  subresourceId:
    name: subresourceId
    in: path
    description: The identifier of the subresource
    required: true
    type: string
  jobId:
    name: jobId
    in: path
    description: The workflow job id
    required: true
    type: string
  limitToTargetIds:
    name: limitToTargetIds
    in: query
    description: (Etfvalidator only) TargetID(s) (for e.g. wms_1.3.0 or direct_download_2.0 when limitToResource=service) should only be provided if you want to re-run tests for a particular resource with its target Id.
    required: false
    type: array
    items:
      type: string
    collectionFormat: multi
  limitToResources:
    name: limitToResources
    in: query
    description: (Etfvalidator only) If you want to re-run tests for a particular resource.
    required: false
    type: string
    enum:
      - datasetMetadata
      - serviceMetadata
      - service
      - data
  storeMetadata:
    name: storeMetadata
    in: query
    description: (Autofill only) If updated metadata should be stored.
    required: false
    type: boolean
  replaceDefaults:
    name: replaceDefaults
    in: query
    description: (Autofill only) If default values should replace existing ones.
    required: false
    type: boolean
  limit:
    name: limit
    in: query
    description: (Usage only) Determines the number of daily usage records to get.
    required: false
    type: integer
  externalResult:
    name: externalResult
    in: body
    required: true
    schema:
      $ref: '#/definitions/ExternalWorkflowResult'
  themeId:
    name: themeId
    in: path
    description: The identifier of the theme
    required: true
    type: string
definitions:

  Feedback:
    type: object
    required:
      - code
      - message
      - error
    properties:
      code:
        type: integer
        format: int32
      message:
        type: string
      error:
        type: boolean

  WorkflowDescriptor:
    description: The workflow descriptor
    type: object

  WorkflowID:
    type: object
    description: Resource workflow identifier
    required:
      - workflowType
      - resourceType
      - resourceId
    properties:
      workflowType:
        type: string
        description: Workflow type
      resourceType:
        type: string
        description: Resource type
      resourceId:
        type: string
        description: Resource identifier

  ExternalWorkflowResult:
    type: object
    description: A result from an external workflow execution
    required:
      - success
    properties:
      success:
        type: boolean
        description: Whether or not the workflow exectuion has been successful
      properties:
        type: object
        description: Optional additional workflow result properties

  WorkflowResult:
    type: object
    description: Report/result of a resource workflow execution
    required:
      - success
      - completed
      - workflow
      - jobId
    properties:
      workflow:
        $ref: '#/definitions/WorkflowID'
      jobId:
        type: string
        description: The identifier of the related workflow execution job
      started:
        type: integer
        description: Timestamp when the operation was started
      completed:
        type: integer
        description: Timestamp when the operation was completed
      success:
        type: boolean
        description: If the operation was a success
      descriptor:
        $ref: '#/definitions/WorkflowDescriptor'
      result:
        type: object
        description: The workflow type specific workflow result

  WorkflowStatus:
    type: object
    description: Workflow execution status details
    required:
      - jobId
      - workflowId
      - status
    properties:
      jobId:
        type: string
        description: The identifier of the related workflow execution job
      workflowId:
        $ref: '#/definitions/WorkflowID'
      status:
        type: string
        enum:
          - scheduled
          - running
        description: The status of the workflow execution
      queuePosition:
        type: integer
        description: The position in the execution queue when scheduled

responses:

  Success:
    description: OK
    schema:
      $ref: '#/definitions/Feedback'

  Error:
    description: Internal error processing request
    schema:
      $ref: '#/definitions/Feedback'
