0

I have the following requirements:

  1. For each record in a CSV file, read the value contained in three of its fields named startValue, endValue and change.
  2. Calculate the change as (endValue-startValue)/startValue
  3. Compare the calculated change to the change provided in the CSV file for the record. Log a warning if different to the same number of decimal places. Continue to step 4 in any case.
  4. Replace the change value in the CSV file with the change calculated in step 3. Leave the CSV file unaltered otherwise. Blank lines, line terminators, headers and all other field values should remain unchanged.

I'm aware of two approaches.

Approach 1

from("{{route.getCsvFile}}")
.unmarshal(new BindyCsvDataFormat(MyValueChange.class))`
.process(myProcessor) // calculates `change` and replaces CSV `change` value
.to("bean-validator:changeValidator") // does step 3
.marshal(new BindyCsvDataFormat(MyValueChange.class))
.to("{{route.putCsvFile}}");

The problem: I do not want to have to unmarshall all CSV fields into a Java object. I only need the three fields to work with change. The CSV file contains 75 other fields.

Approach 2

from("{{route.getCsvFile}}")
.unmarshal(new CsvDataFormat())
.process(myProcessor)
.marshal(new CsvDataFormat())
.to("{{route.putCsvFile}}");

The problem: myProcessor must now contain code to parse through a List of Strings and must contain code to validate the bean (instead of using Camel's call to bean validation).

Is there a way to use bindy for just three fields and then use that bean to replace only the change values within the original CSV data?

James
  • 2,876
  • 18
  • 72
  • 116

0 Answers0