openapi: 3.0.1
info:
  title: Audit
  version: 1.0.0
paths:
  /:
    get:
      operationId: getHome
      responses:
        default:
          description: default response
          content:
            text/html:
              schema:
                type: object
  /audits/{auditId}:
    get:
      summary: Retrieves a specific audit
      operationId: getAudit
      parameters:
      - name: auditId
        in: path
        description: the identifier of the desired audit
        required: true
        schema:
          type: string
      responses:
        default:
          description: the desired audit object
    post:
      summary: Replaces the identified audit with the given one
      operationId: replaceAudit
      parameters:
      - name: auditId
        in: path
        description: the identifier of the audit
        required: true
        schema:
          type: string
      requestBody:
        description: the new audit that will replace the old saved one
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/Audit'
      responses:
        default:
          description: default response
          content:
            text/plain: {}
  /audits/{auditId}/pdf:
    get:
      summary: Generates the pdf of a given audit
      operationId: getAuditPDF
      parameters:
      - name: auditId
        in: path
        description: the identifier of the audit
        required: true
        schema:
          type: string
      responses:
        default:
          description: the PDF generated from the audit
  /audits/{auditId}/score:
    get:
      summary: Retrieves the score object of a given audit
      operationId: getAuditScores
      parameters:
      - name: auditId
        in: path
        description: the identifier of the audit
        required: true
        schema:
          type: string
      responses:
        default:
          description: the score object of the audit
  /audits/{auditId}/status:
    get:
      summary: Retrieves the status of a given audit
      operationId: getAuditStatus
      parameters:
      - name: auditId
        in: path
        description: the identifier of the audit
        required: true
        schema:
          type: string
      responses:
        default:
          description: the status of the audit
    post:
      summary: Sets the status of a given audit
      operationId: setAuditStatus
      parameters:
      - name: auditId
        in: path
        description: the identifier of the audit
        required: true
        schema:
          type: string
      requestBody:
        description: the new status for the audit
        content:
          application/json:
            schema:
              type: string
              enum:
              - AUTOVALUTAZIONE
              - RICHIESTA_VALUTAZIONE
              - GESTITO
      responses:
        default:
          description: default response
          content:
            text/plain: {}
  /cbs:
    get:
      summary: Retrieves all certification bodies saved in database
      operationId: getAllCBs
      responses:
        default:
          description: a collection of all the certification body objects in the database
    post:
      summary: Creates a new certification body in the database
      operationId: newCB
      requestBody:
        description: the certification body object to save
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CertificationBody'
      responses:
        default:
          description: default response
          content:
            text/plain: {}
  /cbs/{cbId}:
    get:
      summary: Retrieves the certification body with the given identifier
      operationId: getCBById
      parameters:
      - name: cbId
        in: path
        description: the identifier of the desired certification body
        required: true
        schema:
          type: string
      responses:
        default:
          description: the desired certification body object
  /cbs/{cbId}/audits:
    get:
      summary: Retrieves audits assigned to the given certification body
      operationId: getAssignedAudits
      parameters:
      - name: cbId
        in: path
        description: the identifier of the certification body
        required: true
        schema:
          type: string
      responses:
        default:
          description: the collection of audits assigned to the given certification
            body
    post:
      summary: Assigns an audit to a given certification body
      operationId: assignAudit
      parameters:
      - name: cbId
        in: path
        description: the identifier of the certification body
        required: true
        schema:
          type: string
      requestBody:
        description: the identifier of the audit
        content:
          text/plain:
            schema:
              type: string
      responses:
        default:
          description: default response
          content:
            text/plain: {}
  /cbs/{cbId}/firms:
    get:
      summary: Retrieves firms managed by the given certification body
      operationId: getAssignedFirms
      parameters:
      - name: cbId
        in: path
        description: the identifier of the certification body
        required: true
        schema:
          type: string
      responses:
        default:
          description: the collection of firms managed by the given certification
            body
    post:
      summary: Assigns a firm to a given certification body
      operationId: assignFirm
      parameters:
      - name: cbId
        in: path
        description: the identifier of the certification body
        required: true
        schema:
          type: string
      requestBody:
        description: the vat number of the firm
        content:
          text/plain:
            schema:
              type: string
      responses:
        default:
          description: default response
          content:
            text/plain: {}
  /certification-schemas:
    get:
      summary: Retrieves all certification schemas saved in database
      operationId: getCertificationSchemas
      responses:
        default:
          description: a collection of all the certification schema objects in the
            database
    post:
      summary: Creates a new certification schema in the database
      operationId: newCertificationSchema
      requestBody:
        description: the certification schema object to save
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CertificationSchema'
      responses:
        default:
          description: default response
          content:
            text/plain: {}
  /certification-schemas/{schemaId}:
    get:
      summary: Retrieves a given certification schema saved in database
      operationId: getCertificationSchema
      parameters:
      - name: schemaId
        in: path
        description: the identifier of the desired certification schema
        required: true
        schema:
          type: string
      responses:
        default:
          description: the desired certification schema object
  /firms:
    get:
      summary: Retrieves all firms saved in database
      operationId: getAllFirms
      responses:
        default:
          description: a collection of all the firm objects in the database
    post:
      summary: Creates a new firm in the database
      operationId: newFirm
      requestBody:
        description: the firm object to save
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/Firm'
      responses:
        default:
          description: default response
          content:
            text/plain: {}
  /firms/{vat}:
    get:
      summary: Retrieves the firm with the given VAT number
      operationId: getFirmByVAT
      parameters:
      - name: vat
        in: path
        description: the VAT number of the desired firm
        required: true
        schema:
          type: string
      responses:
        default:
          description: the desired firm object
  /firms/{vat}/audits:
    get:
      summary: Retrieves audits submitted for this firm
      operationId: getSubmittedAudits_1
      parameters:
      - name: vat
        in: path
        description: the VAT number of the firm
        required: true
        schema:
          type: string
      responses:
        default:
          description: a collection of audits submitted for this firm
    post:
      summary: Submits an audit for a given firm
      operationId: submitAudit
      parameters:
      - name: vat
        in: path
        description: the VAT number of the related firm
        required: true
        schema:
          type: string
      requestBody:
        description: the audit object to submit
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/Audit'
      responses:
        default:
          description: default response
          content:
            text/plain: {}
  /firms/{vat}/audits/latest:
    get:
      summary: Retrieves the latest audit submitted for this firm
      operationId: getLatestAudit
      parameters:
      - name: vat
        in: path
        description: the VAT number of the firm
        required: true
        schema:
          type: string
      responses:
        default:
          description: the desired audit
  /firms/{vat}/audits/{auditId}:
    get:
      summary: Retrieves a given audit submitted for this firm
      operationId: getAudit_1
      parameters:
      - name: vat
        in: path
        description: the VAT number of the firm
        required: true
        schema:
          type: string
      - name: auditId
        in: path
        description: the id of the desired audit
        required: true
        schema:
          type: string
      responses:
        default:
          description: the desired audit
  /firms/{vat}/latest-score:
    get:
      summary: Retrieves the score object of the latest audit submitted for this firm
      operationId: getLatestAuditScores
      parameters:
      - name: vat
        in: path
        description: the VAT number of the firm
        required: true
        schema:
          type: string
      responses:
        default:
          description: the desired audit score
  /firms/{vat}/schemas:
    get:
      summary: Retrieves all certification schemas assigned to the given firm
      operationId: getAssignedSchemas
      parameters:
      - name: vat
        in: path
        description: the VAT number of the firm
        required: true
        schema:
          type: string
      responses:
        default:
          description: a collection of all the certification schemas assigned to the
            given firm
    post:
      summary: Assigns a certification schema to a given firm
      operationId: assignSchema
      parameters:
      - name: vat
        in: path
        description: the VAT number of the firm
        required: true
        schema:
          type: string
      requestBody:
        description: the id of the certification schema to assign
        content:
          text/plain:
            schema:
              type: string
      responses:
        default:
          description: default response
          content:
            text/plain: {}
  /firms/{vat}/schemas/{schemaId}:
    get:
      summary: Retrieves the certification schema assigned to the given firm with
        the given id
      operationId: getAssignedSchemaById
      parameters:
      - name: vat
        in: path
        description: the VAT number of the firm
        required: true
        schema:
          type: string
      - name: schemaId
        in: path
        description: the id of the certification schema
        required: true
        schema:
          type: string
      responses:
        default:
          description: the certification schema
  /firms/{vat}/schemas/{schemaId}/audits:
    get:
      summary: Retrieves audits submitted for this firm related to the given schema
      operationId: getSubmittedAudits
      parameters:
      - name: vat
        in: path
        description: the VAT number of the firm
        required: true
        schema:
          type: string
      - name: schemaId
        in: path
        description: the id of the certification schema
        required: true
        schema:
          type: string
      responses:
        default:
          description: a collection of audits submitted for this firm
  /firms/{vat}/schemas/{schemaId}/audits/latest:
    get:
      summary: Retrieves the latest audit submitted for this firm related to the given
        schema
      operationId: getLatestAuditForSchema
      parameters:
      - name: vat
        in: path
        description: the VAT number of the firm
        required: true
        schema:
          type: string
      - name: schemaId
        in: path
        description: the id of the certification schema
        required: true
        schema:
          type: string
      responses:
        default:
          description: the desired audit
  /firms/{vat}/schemas/{schemaId}/audits/{auditId}:
    get:
      summary: Retrieves a given audit submitted for this firm related to the given
        schema
      operationId: getAuditForSchema
      parameters:
      - name: vat
        in: path
        description: the VAT number of the firm
        required: true
        schema:
          type: string
      - name: schemaId
        in: path
        description: the id of the certification schema
        required: true
        schema:
          type: string
      - name: auditId
        in: path
        description: the id of the desired audit
        required: true
        schema:
          type: string
      responses:
        default:
          description: the desired audit
  /firms/{vat}/suppliers:
    post:
      summary: Adds a supplier firm to the given focal firm
      operationId: addSupplier
      parameters:
      - name: vat
        in: path
        description: the VAT number of the focal firm
        required: true
        schema:
          type: string
      requestBody:
        description: the supplier vat number
        content:
          application/json:
            schema:
              type: string
      responses:
        default:
          description: default response
          content:
            text/plain: {}
  /rating/attributes/edges:
    get:
      summary: Retrieves edge attributes
      operationId: getEA
      responses:
        default:
          description: the array of edge attributes
  /rating/attributes/nodes:
    get:
      summary: Retrieves node attributes
      operationId: getNA
      responses:
        default:
          description: the array of node attributes
  /rating/login:
    post:
      summary: Login user
      operationId: userLogin
      requestBody:
        description: login information
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/UserLogin'
      responses:
        default:
          description: default response
          content:
            application/json: {}
  /rating/ne/{scId}:
    get:
      summary: Retrieves nodes and edges associated to a given supply chain
      operationId: getSCNE
      parameters:
      - name: scId
        in: path
        description: the identifier of the desired supply chain
        required: true
        schema:
          type: string
      responses:
        default:
          description: the desired list of nodes and edges
  /rating/project:
    post:
      summary: Create project
      operationId: createProject
      requestBody:
        description: project info
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/Project'
      responses:
        default:
          description: default response
          content:
            application/json: {}
  /rating/project/{projectId}:
    get:
      summary: Retrieves detail of the given project
      operationId: getProjectDetail
      parameters:
      - name: projectId
        in: path
        description: the identifier of the desired project
        required: true
        schema:
          type: string
      responses:
        default:
          description: the desired project detail
  /rating/project/{projectId}/scenarioresults:
    get:
      summary: Retrieves scenario results for the given project
      operationId: getProjectScenarioResults
      parameters:
      - name: projectId
        in: path
        description: the identifier of the desired project
        required: true
        schema:
          type: string
      responses:
        default:
          description: the list of scenario results
  /rating/project/{projectId}/scenarios:
    get:
      summary: Retrieves scenarios for the given project
      operationId: getProjectScenarios
      parameters:
      - name: projectId
        in: path
        description: the identifier of the desired project
        required: true
        schema:
          type: string
      responses:
        default:
          description: the list of scenarios
  /rating/sc/{firmId}:
    get:
      summary: Retrieves supply chains associated to a given firm
      operationId: getSC
      parameters:
      - name: firmId
        in: path
        description: the identifier of the desired firm
        required: true
        schema:
          type: string
      responses:
        default:
          description: the desired array of supply chains
  /rating/scenario:
    post:
      summary: Create scenario
      operationId: createScenario
      requestBody:
        description: scenario info
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/Scenario'
      responses:
        default:
          description: default response
          content:
            application/json: {}
  /rating/scenario/result:
    post:
      summary: Retrieve scenario result
      operationId: scenarioResult
      requestBody:
        description: scenario id
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/Id'
      responses:
        default:
          description: default response
          content:
            application/json: {}
  /rating/scenario/seal:
    post:
      summary: Seal scenario
      operationId: sealScenario
      requestBody:
        description: scenario id
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/Id'
      responses:
        default:
          description: default response
          content:
            application/json: {}
components:
  schemas:
    Audit:
      type: object
      properties:
        auditId:
          type: string
        schemaId:
          type: string
        schemaName:
          type: string
        certificationSchema:
          $ref: '#/components/schemas/CertificationSchema'
        indicatorValues:
          type: array
          items:
            $ref: '#/components/schemas/IndicatorValue'
        score:
          type: integer
          format: int32
        status:
          type: string
          enum:
          - AUTOVALUTAZIONE
          - RICHIESTA_VALUTAZIONE
          - GESTITO
        date:
          type: string
          format: date-time
        numberOfAnswers:
          type: integer
          format: int32
        latestInSchema:
          type: boolean
        registered:
          type: boolean
        firmVat:
          type: string
        firmName:
          type: string
    CertificationSchema:
      type: object
      properties:
        schemaId:
          type: string
        name:
          type: string
        version:
          type: string
        introduction:
          type: string
        image:
          type: string
        indicatorSchemas:
          type: array
          items:
            $ref: '#/components/schemas/IndicatorSchema'
        maximumScore:
          type: integer
          format: int32
        numberOfQuestions:
          type: integer
          format: int32
    IndicatorSchema:
      type: object
      properties:
        indicatorId:
          type: string
        name:
          type: string
        description:
          type: string
        indicatorType:
          type: string
          enum:
          - NUMERIC
          - TEXT
          - CHOICE
          - LIST
          - NONE
        options:
          type: array
          items:
            $ref: '#/components/schemas/Option'
        maximumScore:
          type: integer
          format: int32
        numberOfQuestions:
          type: integer
          format: int32
        singleMaxScore:
          type: integer
          format: int32
          writeOnly: true
    IndicatorValue:
      type: object
      properties:
        indicatorId:
          type: string
        value:
          type: object
        score:
          type: integer
          format: int32
        partialScore:
          type: integer
          format: int32
        numberOfAnswers:
          type: integer
          format: int32
    Option:
      type: object
      properties:
        ordering:
          type: string
        value:
          type: string
        score:
          type: integer
          format: int32
        textInput:
          type: boolean
    CertificationBody:
      type: object
      properties:
        cbId:
          type: string
        name:
          type: string
        assignedFirms:
          type: array
          items:
            $ref: '#/components/schemas/Firm'
        assignedAudits:
          type: array
          items:
            $ref: '#/components/schemas/Audit'
    Firm:
      type: object
      properties:
        vatNumber:
          type: string
        name:
          type: string
        audits:
          type: array
          items:
            $ref: '#/components/schemas/Audit'
        schemas:
          type: array
          items:
            $ref: '#/components/schemas/CertificationSchema'
        suppliers:
          type: array
          items:
            $ref: '#/components/schemas/Firm'
        latestAudit:
          $ref: '#/components/schemas/Audit'
    Attribute:
      type: object
      properties:
        id:
          type: integer
          format: int64
        name:
          type: string
    Project:
      type: object
      properties:
        id:
          type: string
        name:
          type: string
        date:
          type: string
        supply_chain:
          type: string
        nodes_attributes:
          type: array
          items:
            $ref: '#/components/schemas/Attribute'
        edges_attributes:
          type: array
          items:
            $ref: '#/components/schemas/Attribute'
    Id:
      type: object
      properties:
        id:
          type: string
    Scenario:
      type: object
      properties:
        scenarioId:
          type: string
        name:
          type: string
        date:
          type: string
        project:
          type: string
        focalFirm:
          type: string
        sealed:
          type: boolean
        nodes:
          uniqueItems: true
          type: array
          items:
            $ref: '#/components/schemas/ValuedNode'
        edges:
          uniqueItems: true
          type: array
          items:
            $ref: '#/components/schemas/ValuedEdge'
    ValuedAttribute:
      type: object
      properties:
        name:
          type: string
        value:
          type: number
          format: double
    ValuedEdge:
      type: object
      properties:
        firm1:
          type: string
        firm2:
          type: string
        values:
          uniqueItems: true
          type: array
          items:
            $ref: '#/components/schemas/ValuedAttribute'
    ValuedNode:
      type: object
      properties:
        firm:
          type: string
        values:
          uniqueItems: true
          type: array
          items:
            $ref: '#/components/schemas/ValuedAttribute'
    UserLogin:
      type: object
      properties:
        username:
          type: string
        password:
          type: string
