-
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.
Merge pull request #14 from abhigun/schema_violations
Schema Violations and Marshaller bug fix
- Loading branch information
Showing
31 changed files
with
757 additions
and
155 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
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
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
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
222 changes: 117 additions & 105 deletions
222
leia-common/src/main/java/com/grookage/leia/common/utils/SchemaValidationUtils.java
Large diffs are not rendered by default.
Oops, something went wrong.
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
19 changes: 19 additions & 0 deletions
19
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,19 @@ | ||
package com.grookage.leia.common.violation; | ||
|
||
public interface LeiaSchemaViolation { | ||
|
||
/** | ||
* @return Error message for the violation | ||
*/ | ||
String message(); | ||
|
||
/** | ||
* @return Relative path of the field being validated from the {@code rootKlass} | ||
*/ | ||
String fieldPath(); | ||
|
||
/** | ||
* @return Class of the field being validated | ||
*/ | ||
Class<?> rootKlass(); | ||
} |
41 changes: 41 additions & 0 deletions
41
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,41 @@ | ||
package com.grookage.leia.common.violation; | ||
|
||
import com.google.common.base.Joiner; | ||
import com.google.common.base.Strings; | ||
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; | ||
private Class<?> rootKlass; | ||
|
||
@Override | ||
public String message() { | ||
return message; | ||
} | ||
|
||
@Override | ||
public String fieldPath() { | ||
return fieldPath; | ||
} | ||
|
||
@Override | ||
public Class<?> rootKlass() { | ||
return rootKlass; | ||
} | ||
|
||
public String toString() { | ||
if (Strings.isNullOrEmpty(fieldPath)) { | ||
return String.format("[LeiaSchemaViolation] %s, message = %s", rootKlass, message); | ||
} | ||
return String.format("[LeiaSchemaViolation] %s, fieldPath = %s, message = %s", rootKlass, | ||
fieldPath, message); | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
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,38 @@ | ||
package com.grookage.leia.common.violation; | ||
|
||
import lombok.Builder; | ||
import lombok.Data; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
import java.util.ArrayList; | ||
import java.util.LinkedList; | ||
import java.util.List; | ||
|
||
@Data | ||
@Builder | ||
@NoArgsConstructor | ||
public class ViolationContext { | ||
@Getter | ||
private final List<LeiaSchemaViolation> violations = new ArrayList<>(); | ||
private final LinkedList<Class<?>> klassPath = new LinkedList<>(); | ||
|
||
public void addViolation(final String message) { | ||
violations.add(new LeiaSchemaViolationImpl(message, null, klassPath.peekLast())); | ||
} | ||
|
||
public void addViolation(final String message, | ||
final String path) { | ||
violations.add(new LeiaSchemaViolationImpl(message, path, klassPath.peekLast())); | ||
} | ||
|
||
public void pushClass(final Class<?> klass) { | ||
klassPath.addLast(klass); | ||
} | ||
|
||
public void popClass() { | ||
if (!klassPath.isEmpty()) { | ||
klassPath.removeLast(); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.