package org.slc.sli.ingestion.landingzone.handler;

import org.slc.sli.ingestion.landingzone.validation.IngestionValidator;

/**
 * Abstract class for all handlers.
 * 
 * @author dduran
 * 
 */
public abstract class AbstractIngestionHandler<T> implements Handler<T> {
    
    IngestionValidator<T> preValidator;
    IngestionValidator<T> postValidator;
    
    abstract void doHandling(T item);
    
    void pre(T item) {
        // TODO: fix after validators are refactored
        // preValidator.validate();
    };
    
    void post(T item) {
        // TODO: fix after validators are refactored
        // postValidator.validate();
    };
    
    @Override
    public void handle(T item) {
        
        pre(item);
        
        doHandling(item);
        
        post(item);
        
    };
    
}

@@ -78,40 +78,202 @@
 ion.
-landingzone.validation.Ingestion
+validation.DummyValidationReport;%0Aimport org.slc.sli.ingestion.validation.ValidationReport;%0Aimport org.slc.sli.ingestion.validation.ValidationReportAble;%0Aimport org.slc.sli.ingestion.validation.
 Vali
@@ -322,17 +322,16 @@
 lers.%0A *
- 
 %0A * @aut
@@ -343,17 +343,16 @@
 duran%0A *
- 
 %0A */%0Apub
@@ -426,26 +426,13 @@
 %3E %7B%0A
-    
 %0A    
-Ingestion
 Vali
@@ -458,21 +458,13 @@
 or;%0A
+%0A
     
-Ingestion
 Vali
@@ -487,20 +487,16 @@
 idator;%0A
-    
 %0A    abs
@@ -526,20 +526,16 @@
  item);%0A
-    
 %0A    voi
@@ -550,64 +550,82 @@
 item
-) %7B%0A        // TODO: fix after validators are refactored
+, ValidationReport validationReport) %7B%0A        if (preValidator != null) %7B
 %0A   
@@ -629,18 +629,19 @@
         
-//
+   
  preVali
@@ -646,39 +646,66 @@
 lidator.
-validate(
+isValid(item, validationReport
 );%0A    
+  
+  
 %7D
-;
 %0A    
+%7D;%0A
 %0A    voi
@@ -721,73 +721,94 @@
 item
-) %7B%0A        // TODO: fix after validators are refactored%0A
+, ValidationReport validationReport) %7B%0A        if (postValidator != null) %7B%0A  
         
 // p
@@ -807,15 +807,13 @@
     
-// post
+  pre
 Vali
@@ -822,27 +822,58 @@
 tor.
-validate();
+isValid(item, validationReport);%0A        %7D
 %0A    %7D;%0A
     
@@ -868,20 +868,16 @@
 %0A    %7D;%0A
-    
 %0A    @Ov
@@ -916,24 +916,25 @@
 item) %7B%0A
+%0A
         
 %0A       
@@ -929,36 +929,297 @@
     
-%0A        pr
+ValidationReport vr = (item instanceof ValidationReportAble) ? ((ValidationReportAble) item)%0A                .getValidationReport() : new DummyValidationReport();%0A%0A        handl
 e(item
+, vr
 );%0A    
+%7D%0A%0A
     
+@Override%0A    public void handle(T item, ValidationReport vr) %7B%0A%0A        pre(item, vr);%0A
 %0A   
@@ -1237,32 +1237,33 @@
 ling(item);%0A
+%0A
         
 %0A        pos
@@ -1254,48 +1254,252 @@
     
+post(item, vr);
 %0A    
+%7D%0A%0A
     p
-ost(item)
+ublic void setPreValidator(Validator%3CT%3E preValidator) %7B%0A        this.preValidator = preValidator
 ;%0A    
+%7D%0A%0A
     
-%0A    %7D
+public void setPostValidator(Validator%3CT%3E postValidator) %7B%0A        this.postValidator = postValidator
 ;%0A    
+%7D
 %0A%7D%0A

use Validator interface for pre and post validation