-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adds SchemaViolation construct, validationutils to return set of viol…
…ations instead of boolean
- Loading branch information
Gunda Abhishek
committed
Dec 10, 2024
1 parent
152cb5f
commit 77b18d0
Showing
6 changed files
with
238 additions
and
132 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
7 changes: 7 additions & 0 deletions
7
leia-common/src/main/java/com/grookage/leia/common/violation/LeiaSchemaViolation.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,7 @@ | ||
package com.grookage.leia.common.violation; | ||
|
||
public interface LeiaSchemaViolation { | ||
String message(); | ||
|
||
String fieldPath(); | ||
} |
30 changes: 30 additions & 0 deletions
30
leia-common/src/main/java/com/grookage/leia/common/violation/LeiaSchemaViolationImpl.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,30 @@ | ||
package com.grookage.leia.common.violation; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Data | ||
@Builder | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class LeiaSchemaViolationImpl implements LeiaSchemaViolation { | ||
private String message; | ||
private String fieldPath; | ||
|
||
@Override | ||
public String message() { | ||
return message; | ||
} | ||
|
||
@Override | ||
public String fieldPath() { | ||
return fieldPath; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return String.format("[Violation] %s: %s", fieldPath, message); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
leia-common/src/main/java/com/grookage/leia/common/violation/ViolationContext.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,34 @@ | ||
package com.grookage.leia.common.violation; | ||
|
||
import lombok.Builder; | ||
import lombok.Data; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
import java.util.HashSet; | ||
import java.util.LinkedList; | ||
import java.util.Set; | ||
|
||
@Data | ||
@Builder | ||
@NoArgsConstructor | ||
public class ViolationContext { | ||
@Getter | ||
private final Set<LeiaSchemaViolation> violations = new HashSet<>(); | ||
private final LinkedList<String> path = new LinkedList<>(); | ||
|
||
public void addViolation(final String message) { | ||
String fullPath = String.join(".", path); | ||
violations.add(new LeiaSchemaViolationImpl(message, fullPath)); | ||
} | ||
|
||
public void pushPath(final String element) { | ||
path.addLast(element); | ||
} | ||
|
||
public void popPath() { | ||
if (!path.isEmpty()) { | ||
path.removeLast(); | ||
} | ||
} | ||
} |
Oops, something went wrong.