-
Notifications
You must be signed in to change notification settings - Fork 4.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
JSON configuration persistence 2 #39
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
11 changes: 11 additions & 0 deletions
11
...fig-persistence/src/main/java/io/dataline/config/persistence/ConfigNotFoundException.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,11 @@ | ||
package io.dataline.config.persistence; | ||
|
||
public class ConfigNotFoundException extends Exception { | ||
public ConfigNotFoundException(String message) { | ||
super(message); | ||
} | ||
|
||
public ConfigNotFoundException(String message, Throwable cause) { | ||
super(message, cause); | ||
} | ||
} |
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
43 changes: 43 additions & 0 deletions
43
...config-persistence/src/main/java/io/dataline/config/persistence/JsonSchemaValidation.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,43 @@ | ||
package io.dataline.config.persistence; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.networknt.schema.*; | ||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
|
||
public class JsonSchemaValidation { | ||
private final SchemaValidatorsConfig schemaValidatorsConfig; | ||
private final JsonSchemaFactory jsonSchemaFactory; | ||
|
||
private static final JsonSchemaValidation INSTANCE = new JsonSchemaValidation(); | ||
|
||
public static JsonSchemaValidation getInstance() { | ||
return INSTANCE; | ||
} | ||
|
||
private JsonSchemaValidation() { | ||
this.schemaValidatorsConfig = new SchemaValidatorsConfig(); | ||
this.jsonSchemaFactory = JsonSchemaFactory.getInstance(SpecVersion.VersionFlag.V7); | ||
} | ||
|
||
public Set<ValidationMessage> validate(JsonNode schemaJson, JsonNode configJson) { | ||
JsonSchema schema = jsonSchemaFactory.getSchema(schemaJson, schemaValidatorsConfig); | ||
|
||
return schema.validate(configJson); | ||
} | ||
|
||
public void validateThrow(JsonNode schemaJson, JsonNode configJson) | ||
throws JsonValidationException { | ||
final Set<ValidationMessage> validationMessages = validate(schemaJson, configJson); | ||
if (validationMessages.size() > 0) { | ||
throw new JsonValidationException( | ||
String.format( | ||
"json schema validation failed. \nerrors: %s \nschema: \n%s \nobject: \n%s", | ||
validationMessages.stream() | ||
.map(ValidationMessage::toString) | ||
.collect(Collectors.joining(",")), | ||
schemaJson.toPrettyString(), | ||
configJson.toPrettyString())); | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
...fig-persistence/src/main/java/io/dataline/config/persistence/JsonValidationException.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,11 @@ | ||
package io.dataline.config.persistence; | ||
|
||
public class JsonValidationException extends Exception { | ||
public JsonValidationException(String message) { | ||
super(message); | ||
} | ||
|
||
public JsonValidationException(String message, Throwable cause) { | ||
super(message, cause); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
...e-config-persistence/src/main/java/io/dataline/config/persistence/WorkspaceConstants.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,8 @@ | ||
package io.dataline.config.persistence; | ||
|
||
import java.util.UUID; | ||
|
||
public class WorkspaceConstants { | ||
// for MVP we only support one workspace per deployment and we hard code its id. | ||
public static UUID DEFAULT_WORKSPACE_ID = UUID.fromString("5ae6b09b-fdec-41af-aaf7-7d94cfc33ef6"); | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this looks like a premature refactor here, but it get immediately used in a PR that i'm about to put up.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
proof: file: dataline-server/src/main/java/io/dataline/server/validation/IntegrationSchemaValidation.java in #42.