# ---------------------------------------------------------------------------
# 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/v1alpha1
kind: Kamelet
metadata:
  name: solr-source
  annotations:
    camel.apache.org/kamelet.support.level: "Stable"
    camel.apache.org/catalog.version: "3.21.0"
    camel.apache.org/kamelet.icon: "data:image/svg+xml;base64,[encoded data, 5296 characters]"
    camel.apache.org/provider: "Apache Software Foundation"
    camel.apache.org/kamelet.group: "Solr"
    camel.apache.org/kamelet.namespace: "Search"
  labels:
    camel.apache.org/kamelet.type: "source"
spec:
  definition:
    title: "Solr Source"
    description: |-
      Query for documents to Solr Collection.
    required:
      - period
      - servers
      - collection
      - query
    type: object
    properties:
      period:
        title: Period between Polls
        description: The interval between fetches to the Solr collection
        type: integer
        default: 10000
      collection:
        title: Collection
        description: Solr Collection name
        type: string
      servers:
        title: Servers
        description: Comma separated list of Solr Servers and ports
        type: string
      query:
        title: Query
        description: The query to submit to Solr
        type: string
      username:
        title: Username
        description: Username to connect to Solr.
        type: string
        x-descriptors:
        - urn:camel:group:credentials
      password:
        title: Password
        description: Password to connect to Solr.
        type: string
        format: password
        x-descriptors:
        - urn:alm:descriptor:com.tectonic.ui:password
        - urn:camel:group:credentials
  types:
    in:
      mediaType: application/json
  dependencies:
  - "camel:solr"
  - "camel:core"
  - "camel:timer"
  - "camel:jackson"
  - "camel:kamelet"
  template:
    from:
      uri: "timer:solr-stream"
      parameters:
        period: "{{period}}"
      steps:
      - set-header:
          name: "SolrOperation"
          constant: "QUERY"
      - set-header:
          name: "CamelSolrQueryString"
          constant: "{{query}}"
      - remove-header:
          name: "content-type"
      - to:
          uri: "solr:{{servers}}/solr/{{collection}}"
          parameters:
            username: "{{?username}}"
            password: "{{?password}}"
      - marshal:
          json:
            library: Jackson
      - to: "kamelet:sink"