# ---------------------------------------------------------------------------
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements.  See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License.  You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ---------------------------------------------------------------------------
apiVersion: camel.apache.org/v1
kind: Kamelet
metadata:
  name: oracle-database-sink
  annotations:
    camel.apache.org/kamelet.support.level: "Stable"
    camel.apache.org/catalog.version: "4.10.2"
    camel.apache.org/kamelet.icon: "data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4KPCEtLSBHZW5lcmF0b3I6IEFkb2JlIElsbHVzdHJhdG9yIDIyLjEuMCwgU1ZHIEV4cG9ydCBQbHVnLUluIC4gU1ZHIFZlcnNpb246IDYuMDAgQnVpbGQgMCkgIC0tPgo8c3ZnIHZlcnNpb249IjEuMSIgaWQ9IkxheWVyXzEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIHg9IjBweCIgeT0iMHB4IgoJIHZpZXdCb3g9IjAgMCA1MTIgNTEyIiBzdHlsZT0iZW5hYmxlLWJhY2tncm91bmQ6bmV3IDAgMCA1MTIgNTEyOyIgeG1sOnNwYWNlPSJwcmVzZXJ2ZSI+CjxnPgoJPHBhdGggZD0iTTI1NiwzMUMxMzEuNywzMSwzMSw2Mi41LDMxLDEwMS4zdjU2LjJjMCwzOC44LDEwMC43LDcwLjMsMjI1LDcwLjNzMjI1LTMxLjUsMjI1LTcwLjN2LTU2LjJDNDgxLDYyLjUsMzgwLjMsMzEsMjU2LDMxeiIvPgoJPHBhdGggZD0iTTI1NiwyNzAuMWMtMTI0LjMsMC0yMjUtMzEuNS0yMjUtNzAuM3Y4NC40YzAsMzguOCwxMDAuNyw3MC4zLDIyNSw3MC4zczIyNS0zMS41LDIyNS03MC4zdi04NC40CgkJQzQ4MSwyMzguNiwzODAuMywyNzAuMSwyNTYsMjcwLjF6Ii8+Cgk8cGF0aCBkPSJNMjU2LDM5Ni42Yy0xMjQuMywwLTIyNS0zMS41LTIyNS03MC4zdjg0LjRjMCwzOC44LDEwMC43LDcwLjMsMjI1LDcwLjNzMjI1LTMxLjUsMjI1LTcwLjN2LTg0LjQKCQlDNDgxLDM2NS4yLDM4MC4zLDM5Ni42LDI1NiwzOTYuNnoiLz4KPC9nPgo8L3N2Zz4K"
    camel.apache.org/provider: "Apache Software Foundation"
    camel.apache.org/kamelet.group: "SQL"
    camel.apache.org/kamelet.namespace: "Database"
  labels:
    camel.apache.org/kamelet.type: "sink"
spec:
  definition:
    title: "Oracle Database Sink"
    description: |-
      Send data to an Oracle Database.

      In your Pipe file, you must explicitly declare the Oracle Database driver dependency in spec->integration->dependencies.

      - "mvn:com.oracle.database.jdbc:ojdbc11:<version>"

      This Kamelet expects a JSON-formatted body. Use key:value pairs to map the JSON fields and parameters. For example, here is a query:

      'INSERT INTO accounts (username,city) VALUES (:#username,:#city)'

      Here is example input for the example query:

      '{ "username":"oscerd", "city":"Rome"}'
    required:
      - serverName
      - username
      - password
      - query
      - databaseName
    type: object
    properties:
      serverName:
        title: Server Name
        description: The server name for the data source.
        type: string
        example: localhost
      serverPort:
        title: Server Port
        description: The server port for the data source.
        type: string
        default: 1521
      username:
        title: Username
        description: The username to access a secured Oracle Database.
        type: string
        x-descriptors:
        - urn:camel:group:credentials
      password:
        title: Password
        description: The password to access a secured Oracle Database.
        type: string
        format: password
        x-descriptors:
        - urn:camel:group:credentials
      query:
        title: Query
        description: The query to execute against the Oracle Database.
        type: string
        example: 'INSERT INTO accounts (username,city) VALUES (:#username,:#city)'
      databaseName:
        title: Database Name
        description: The name of the Oracle Database.
        type: string
  types:
    in:
      mediaType: application/json
  dependencies:
  - "camel:jackson"
  - "camel:kamelet"
  - "camel:sql"
  - "mvn:org.apache.commons:commons-dbcp2:2.13.0"
  template:
    beans:
      - name: local-sql-oracle-sink
        type: "#class:org.apache.camel.component.sql.SqlComponent"
        properties:
          autowiredEnabled: "false"
      - name: dsBean
        type: "#class:org.apache.commons.dbcp2.BasicDataSource"
        properties:
          username: '{{username}}'
          password: '{{password}}'
          url: 'jdbc:oracle:thin:@{{serverName}}:{{serverPort}}/{{databaseName}}'
          driverClassName: 'oracle.jdbc.driver.OracleDriver'
    from:
      uri: "kamelet:source"
      steps:
      - unmarshal:
          json: 
            library: Jackson
      - to: 
          uri: "{{local-sql-oracle-sink}}:{{query}}"
          parameters:
            dataSource: "#bean:{{dsBean}}"