-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Throw exception if lazy validation processing detects any errors
- Loading branch information
Showing
4 changed files
with
79 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
src/main/java/com/github/joschi/jadconfig/LazyValidationException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package com.github.joschi.jadconfig; | ||
|
||
import com.github.joschi.jadconfig.response.ProcessingOutcome; | ||
import com.github.joschi.jadconfig.response.ProcessingResponse; | ||
|
||
import java.util.LinkedList; | ||
import java.util.List; | ||
import java.util.stream.Stream; | ||
|
||
public class LazyValidationException extends ValidationException { | ||
private final ProcessingResponse processingResponse; | ||
|
||
public LazyValidationException(ProcessingResponse result) { | ||
super(toMessage(result)); | ||
this.processingResponse = result; | ||
} | ||
|
||
private static String toMessage(ProcessingResponse result) { | ||
final List<String> stringBuilder = new LinkedList<>(); | ||
stringBuilder.add("Following errors ocurred during configuration processing:"); | ||
result.getOutcomes().stream() | ||
.filter(ProcessingOutcome::hasProblems) | ||
.flatMap(processingOutcome -> Stream.concat( | ||
processingOutcome.getFieldProcessingProblems().values().stream().map(e -> toMessage(processingOutcome, e)), | ||
processingOutcome.getValidationMethodsProblems().values().stream().map(e -> toMessage(processingOutcome, e)) | ||
)).forEach(stringBuilder::add); | ||
return String.join("\n", stringBuilder); | ||
} | ||
|
||
private static String toMessage(ProcessingOutcome processingOutcome, Exception exception) { | ||
// TODO: should we distinct between field processing problem and validation method? | ||
// TODO: should we include class name of the bean or not? | ||
return exception.getMessage(); | ||
} | ||
|
||
public ProcessingResponse getProcessingResponse() { | ||
return processingResponse; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters