-
Notifications
You must be signed in to change notification settings - Fork 48
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
Enable metadata schema validation #504
Changes from 4 commits
d8e40eb
6b25090
395d247
a8462ee
a359518
7593dbd
ddb3f9a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,6 @@ | |
"DWN-2" : "devices/DWN-2" | ||
}, | ||
"Version" : { | ||
"main" : "1.3.14-90-g266b9b3" | ||
"main" : "1.3.14-92-g6b250906" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,14 @@ | ||
{ | ||
"system": { | ||
"location": { | ||
"site": "AA-TEST-SITE" | ||
"site": "US-SFO-XYY" | ||
}, | ||
"physical_tag": { | ||
"asset": { | ||
"guid": "bim://04aEp5ymD_$u5IxhJN2aGi", | ||
"site": "US-SFO-XYY", | ||
"name": "AHU-1" | ||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
{ | ||
"version": "1.4.0", | ||
"timestamp": "2018-08-26T21:39:29.364Z", | ||
"description": "Generic test example metadata file", | ||
"cloud": { | ||
"auth_type": "ES256" | ||
}, | ||
"pointset": { | ||
"points": { | ||
"return_air_temperature_sensor": { | ||
"units": "Degrees-Celsius", | ||
"baseline_value": 20, | ||
"baseline_tolerance": 2 | ||
}, | ||
"room_setpoint": { | ||
"writable": true, | ||
"units": "Degrees-Celsius", | ||
"baseline_value": 20, | ||
"baseline_state": "applied" | ||
} | ||
} | ||
}, | ||
"discovery": { | ||
"families": { | ||
"bacnet": { | ||
} | ||
} | ||
}, | ||
"testing": { | ||
"targets": { | ||
"invalid": { | ||
"target_point": "return_air_temperature_sensor", | ||
"target_value": -20 | ||
}, | ||
"failure": { | ||
"target_point": "room_setpoint", | ||
"target_value": -20 | ||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
1 schema violations found | ||
object has missing required properties (["system"]) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -301,23 +301,28 @@ private Metadata readMetadataWithValidation(boolean validate) { | |
return null; | ||
} | ||
|
||
JsonNode mergedMetadata = getMergedMetadata(instance); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add unit tests for this function please. It might need to be broken up into pieces? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added class LocalDeviceTest with coverage for the two major caes |
||
|
||
try { | ||
ProcessingReport report = schemas.get(METADATA_JSON).validate(instance); | ||
ProcessingReport report = schemas.get(METADATA_JSON).validate(mergedMetadata); | ||
if (validate) { | ||
parseMetadataValidateProcessingReport(report); | ||
} | ||
} catch (ProcessingException | ValidationException e) { | ||
exceptionMap.put(EXCEPTION_VALIDATING, e); | ||
} | ||
return JsonUtil.convertTo(Metadata.class, mergedMetadata); | ||
} | ||
|
||
private JsonNode getMergedMetadata(JsonNode instance) { | ||
try { | ||
String intermediary = JsonUtil.stringify(instance); | ||
if (siteMetadata == null) { | ||
return JsonUtil.fromString(Metadata.class, intermediary); | ||
return instance; | ||
} else { | ||
Map<String, Object> mergedMetadata = GeneralUtils.deepCopy(siteMetadata); | ||
GeneralUtils.mergeObject(mergedMetadata, asMap(intermediary)); | ||
return JsonUtil.convertTo(Metadata.class, mergedMetadata); | ||
return JsonUtil.convertTo(JsonNode.class, mergedMetadata); | ||
} | ||
} catch (Exception e) { | ||
exceptionMap.put(EXCEPTION_READING, e); | ||
|
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.
Can we make this automatic?
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.
What do you mean by automatic?
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.
Automatic = Can we derive the 4 from a calculation based on the test inputs
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.
I'm semi ok with this if we make it less of a hunt to figure out why it's 3, instead of it just being a bare int by itself in a file that calculates the rest. For example
Clean devices are: SNS-4 GAT-123 AHU-22
[ "${clean_devices}" == 3 ].....
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.
I'm really not sure it's worth it in this case. The logic to calculate that
for just this one case would be relatively complicated (find all the files
that don't match a very specific pattern that just matches one file), and
then likely would end up bring more fragile than just having the raw
expected value -- and then you'd also have to worry about an inadvertent
change in the input data changing the expected and actual value for the
test...
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.
Ok -- added named constant with detail about why it is what it is!