Connecting RecordsDaoEndpoint

To write data to RecordsDao in the Camel DSL context content, you need to describe the RecordsDaoEndpoint. For this, the beans section is described before the routes. For example:

- beans:
    - name: "recordsDaoEndpoint"
      type: ru.citeck.ecos.integrations.domain.cameldsl.service.RecordsDaoEndpoint
      properties:
        sourceId: testDao
        pkProp: id
        columnMap:
          name: content
          state: currentState
          type: type
        valueConvertMap: |
          {"type": {"*": "YAML"}, "state": {"1":"STARTED", "*": "STOPPED"}}
- route:
    from:
      uri: "timer:start?delay=-1&repeatCount=1"
      steps:
        - setBody:
            constant: "select * from actions"
        - to: "jdbc:datasource"
        - split:
            simple: "${body}"
            steps:
              - to: "bean:recordsDaoEndpoint"

Where

  • recordsDaoEndpoint – the name of the RecordsDaoEndpoint; when using it in a route, the prefix “bean:” must be added;

  • type – the bean class, always specified as ru.citeck.ecos.integrations.domain.cameldsl.service.RecordsDaoEndpoint

  • in the properties section, the settings of the RecordsDaoEndpoint are described:

    • appName - target application identifier

    • sourceId - target data source identifier where the data will be placed. Mandatory property;

    • pkProp – attribute of the source that is the primary key;

    • columnMap – correspondence between attributes of the source and target attributes. In the given example, the value of the name attribute from the source will be mapped to the content attribute of the target, state to currentState, type to type. General form of the map:

      sourcePropName1: targetPropName1
      sourcePropName2: targetPropName2
      …
      sourcePropNameN: targetPropNameN
      чтоБерем: кудаКладем
      
    • valueConvertMap – a map for converting source values before writing them to the target database. The map is written in JSON format, the symbol ‘*’ means any attribute value. In the given example, before writing to the currentState attribute, the value of the state field will be replaced with STARTED if it equals 1, and with STOPPED in all other cases. Thus, the currentState attribute in the resulting table will contain only two values: STARTED or STOPPED. General form of the map:

      {“sourcePropName1”:
      {“value1”:”resultValue1”,
          “value2”:”resultValue2”,
          …
          “valueN”:”resultValueN”},
      “sourcePropName2”:
      {“value21”:”resultValue21”,
          “value22”:”resultValue22”,
          …
          “value2N”:”resultValue2N”},
      …
      “sourcePropNameM”:
      {“valueM1”:”resultValueM1”,
          “valueM2”:”resultValueM2”,
          …
          “valueMN”:”resultValueMN”}}
      

Since valueConvertMap is a multi-line property, the symbol “|” must be specified before the value.

Multiple RecordsDaoEndpoint can be described in one context.

- beans:
  - name: "recordsTestDaoEndpoint"
    type: ru.citeck.ecos.integrations.domain.cameldsl.service.RecordsDaoEndpoint
    properties:
      sourceId: recordsTestDao
      pkProp: id
  - name: "testDaoEndpoint"
    type: ru.citeck.ecos.integrations.domain.cameldsl.service.RecordsDaoEndpoint
    properties:
      sourceId: testDao
      pkProp: id
      columnMap:
        name: content
        state: currentState
        type: type
      valueConvertMap: |
        {"type": {"*": "YAML"}}
  - name: "…"
    

RecordsDaoEndpoint can also process data obtained from an XML file, CSV file, or a text file containing string representations of Map.

Example of a context containing routes for processing RecordsDaoEndpoint data from files:

- beans:
    - name: "recordsDaoEndpoint"
      type: ru.citeck.ecos.integrations.domain.cameldsl.service.RecordsDaoEndpoint
      properties:
        sourceId: testDao
        pkProp: id
        columnMap:
          name: content
          state: currentState
        delimiter: ","
- route:
    id: "fromXmlFileToDb"
    from:
      uri: "direct:fromXmlFileToDb"
      steps:
        - split:
            xpath: "//someObject"
            steps:
              - to: "bean:recordsDaoEndpoint"
- route:
    id: "fromTxtFileToDb"
    from:
      uri: "direct:fromTxtFileToDb"
      steps:
        - split:
            tokenize: "\n"
            steps:
              - to: "bean:recordsDaoEndpoint"

The fromXmlFileToDb route splits the input XML stream from the file into someObject elements and passes them to the RecordsDaoEndpoint.

Example input XML file:

<?xml version="1.0" encoding="UTF-8"?>
<messages>
  <someObject id="50" usage ="Additional">
    <name>Test route name James</name>
    <purpose>Test endpoint</purpose>
  </someObject>
  <someObject id="210" usage ="Standard">
    <name>Route 61</name>
    <purpose>Test</purpose>
    <city>Moscow</city>
  </someObject>
</messages>

In the given example, the record attributes id, usage, name, and purpose are available for setting values.

The fromTxtFileToDb route splits the input text stream from the file into lines. Example CSV file:

id,name,value
10,SomeName,
908,- route:,additional
77,,

Example file with string representations of Map:

id=15, name=Test
id=64, name=Route, value=null
id=48, name=Open route, value=null

For working with string data, the RecordsDaoEndpoint settings delimiter and keyValueSeparator are used.

  • delimiter – defines the string delimiter for values in a line for a CSV file and for key-value pairs for a string representation of Map, default value is “,”

  • keyValueSeparator – defines the string separator for key and value in the string representation of Map, default value is “=”