SHARE
TWEET

Untitled

a guest Oct 21st, 2019 83 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import org.springframework.stereotype.Component;
  2. import org.springframework.batch.core.*;
  3. import javax.validation.*;
  4.  
  5. @Component
  6. public class ValidationTasklet implements Tasklet {
  7.  
  8.   private final ReadService readService;
  9.   private final WriteService writeService;
  10.   private final Validator validator;
  11.  
  12.   @Override
  13.   public RepeatStatus execute(StepContribution sc, ChunkContext cc){
  14.    
  15.     // read the input file
  16.     List<User> userList = readService.readFile("/path/to/input/file");
  17.    
  18.     // validate the input
  19.     List<User> validUserList = userList.stream()
  20.      .map( user -> {
  21.        Set<ConstraintViolation<User> violations = validator.validate(user);
  22.        return violations.isEmpty() ? user : null;
  23.      })
  24.      .filter(Objects::nonNull)
  25.      .collect(Collectors.toList());
  26.    
  27.    // write the output file
  28.    writeService.writeFile(validUserList,"/path/to/output/file");
  29.    
  30.    return RepeatStatus.FINISHED;
  31.    }
  32.  
  33.   // Constructor
  34. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top