Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import org.springframework.stereotype.Component;
- import org.springframework.batch.core.*;
- import javax.validation.*;
- @Component
- public class ValidationTasklet implements Tasklet {
- private final ReadService readService;
- private final WriteService writeService;
- private final Validator validator;
- @Override
- public RepeatStatus execute(StepContribution sc, ChunkContext cc){
- // read the input file
- List<User> userList = readService.readFile("/path/to/input/file");
- // validate the input
- List<User> validUserList = userList.stream()
- .map( user -> {
- Set<ConstraintViolation<User> violations = validator.validate(user);
- return violations.isEmpty() ? user : null;
- })
- .filter(Objects::nonNull)
- .collect(Collectors.toList());
- // write the output file
- writeService.writeFile(validUserList,"/path/to/output/file");
- return RepeatStatus.FINISHED;
- }
- // Constructor
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement