Announcement Announcement Module
Collapse
No announcement yet.
Where shall i call the Validation Component? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Where shall i call the Validation Component?

    File Data:
    Column: Price,PromoDate(yyyy-mm-dd)
    Rec-1 -> 0.23,2008-05-08
    Rec-2 -> 0,2008-04-07

    Validation Component Rules:
    Price should be greater than zero.
    PromoDate should be greater than 2008-04-08

    Results:
    table A -> Rec-1 (No validation error)
    table B -> Rec-2 (Two validation errors. Price and PromoDate not valid)

    Requirement:
    -We need to validate the file data, using the Validation Component (already built using java), before inserting data into the table A.
    -Valid records should go to table A
    -Invalid records should go to table B

    Questions:
    1. Shall i call the Validation Component in the transformer?
    2. Do i need two separate writers (CustomWriter extends AbstractItemWriter) to write to the table A and B?

  • #2
    It really depends upon how you want to split it up. I've had clients that assumed everything would be good and when a validation error happened, they threw an exception from within the ItemReader (using ValidatingItemReader) They then applied an ItemReaderListener that would log out the bad item (your table B) It's important that it's in the reader, since exceptions thrown from there won't cause a rollback if you use skip (SkipLimitStepFactoryBean)

    You could also use a transformer that when given an input, sets a flag for good or bad,(or even returns separate object types for each) and write to one table or another depending on the flag. I wouldn't say one approach is really right or wrong, but it depends on how you want to do it. I'm tempted to say the transformer approach is better so that you could use skip to account for parsing exceptions separately. For example, if the promo date was formatted incorrectly, a FlatFileParsingException would be thrown, which you could want to log separately.

    Comment

    Working...
    X