Skip to content

Commit

Permalink
fix: JSON Schema for block
Browse files Browse the repository at this point in the history
  • Loading branch information
rhwood committed May 24, 2019
1 parent a170aa6 commit a46fb7e
Show file tree
Hide file tree
Showing 7 changed files with 139 additions and 19 deletions.
2 changes: 1 addition & 1 deletion java/src/jmri/jmrit/operations/trains/JsonManifest.java
Expand Up @@ -162,7 +162,7 @@ public ArrayNode getLocations() {

if (routeLocation != train.getRoute().getTerminatesRouteLocation()) {
jsonLocation.set(JsonOperations.TRACK, this.getTrackComments(routeLocation, carList));
jsonLocation.put(JSON.DIRECTION, routeLocation.getTrainDirection());
jsonLocation.put(JSON.TRAIN_DIRECTION, routeLocation.getTrainDirection());
ObjectNode length = this.mapper.createObjectNode();
length.put(JSON.LENGTH, train.getTrainLength(routeLocation));
length.put(JSON.UNIT, Setup.getLengthUnit());
Expand Down
8 changes: 6 additions & 2 deletions java/src/jmri/server/json/JSON.java
Expand Up @@ -113,6 +113,10 @@ public final class JSON {
* {@value #SPEED}
*/
public static final String SPEED = "speed"; // NOI18N
/**
* {@value #DIRECTION}
*/
public static final String DIRECTION = "direction"; // NOI18N

/* JSON hello and metadata */
/**
Expand Down Expand Up @@ -382,9 +386,9 @@ public final class JSON {

/* JSON route (operations) tokens */
/**
* {@value #DIRECTION}
* {@value #TRAIN_DIRECTION}
*/
public static final String DIRECTION = "trainDirection"; // NOI18N
public static final String TRAIN_DIRECTION = "trainDirection"; // NOI18N
/**
* {@value #SEQUENCE}
*/
Expand Down
46 changes: 44 additions & 2 deletions java/src/jmri/server/json/block/block-client.json
Expand Up @@ -19,8 +19,50 @@
"value": {
"type": "string",
"description": "If present, sets the value of the block"
},
"speed": {
"type": [
"string"
],
"description": "The authorized speed through the block; authorized values depend on signal system in use"
},
"curvature": {
"type": "integer",
"enum": [
0,
1,
2,
4
],
"description": "Curvature of block; allowed values correspond to NONE, GRADUAL, TIGHT, SEVERE in that order"
},
"direction": {
"type": "integer",
"description": "Direction of block; see http://jmri.org/JavaDoc/doc/jmri/Path.html for possible values"
},
"length": {
"type": "number",
"description": "Length of block in millimeters"
},
"permissive": {
"type": "boolean",
"description": "true if block allows a train to enter it while occupied; false otherwise"
},
"speedLimit": {
"type": "number",
"description": "The maximum allowed speed for the block"
},
"denied": {
"type": "array",
"description": "List of names of blocks that trains cannot enter this block from",
"items": {
"type": "string",
"description": "Name of a block that trains cannot enter this block from"
}
}
},
"additionalProperties": false,
"required": ["name"]
}
"required": [
"name"
]
}
93 changes: 84 additions & 9 deletions java/src/jmri/server/json/block/block-server.json
Expand Up @@ -9,11 +9,17 @@
"description": "System name of the block"
},
"userName": {
"type": ["string", "null"],
"type": [
"string",
"null"
],
"description": "User name of the block"
},
"comment": {
"type": ["string", "null"],
"type": [
"string",
"null"
],
"description": "Comment for the block"
},
"properties": {
Expand All @@ -27,31 +33,100 @@
"description": "Key by which property is accessed"
},
"value": {
"type": ["string", "null"],
"type": [
"string",
"null"
],
"description": "String value of property or null"
}
}
},
"additionalProperties": false,
"required": ["name", "value"]
"required": [
"name",
"value"
]
},
"state": {
"type": "integer",
"description": "The state of the block"
},
"value": {
"type": ["string", "null"],
"type": [
"string",
"null"
],
"description": "The value of the block"
},
"sensor": {
"type": ["string", "null"],
"type": [
"string",
"null"
],
"description": "The system name of the sensor associated with the block"
},
"speed": {
"type": [
"string"
],
"description": "The authorized speed through the block; authorized values depend on signal system in use"
},
"curvature": {
"type": "integer",
"enum": [
0,
1,
2,
4
],
"description": "Curvature of block; allowed values correspond to NONE, GRADUAL, TIGHT, SEVERE in that order"
},
"direction": {
"type": "integer",
"description": "Direction of block; see http://jmri.org/JavaDoc/doc/jmri/Path.html for possible values"
},
"length": {
"type": "number",
"description": "Length of block in millimeters"
},
"permissive": {
"type": "boolean",
"description": "true if block allows a train to enter it while occupied; false otherwise"
},
"speedLimit": {
"type": "number",
"description": "The maximum allowed speed for the block"
},
"denied": {
"type": "array",
"description": "List of names of blocks that trains cannot enter this block from",
"items": {
"type": "string",
"description": "Name of a block that trains cannot enter this block from"
}
},
"reporter": {
"type": ["string", "null"],
"type": [
"string",
"null"
],
"description": "The system name of the reporter associated with the block"
}
},
"additionalProperties": false,
"required": ["name", "userName", "comment", "sensor", "reporter", "value"]
}
"required": [
"name",
"userName",
"comment",
"sensor",
"reporter",
"value",
"speed",
"curvature",
"direction",
"length",
"permissive",
"speedLimit",
"denied"
]
}
4 changes: 2 additions & 2 deletions java/src/jmri/server/json/operations/JsonUtil.java
Expand Up @@ -2,7 +2,7 @@

import static jmri.server.json.JSON.COLOR;
import static jmri.server.json.JSON.COMMENT;
import static jmri.server.json.JSON.DIRECTION;
import static jmri.server.json.JSON.TRAIN_DIRECTION;
import static jmri.server.json.JSON.EXPECTED_ARRIVAL;
import static jmri.server.json.JSON.EXPECTED_DEPARTURE;
import static jmri.server.json.JSON.LENGTH;
Expand Down Expand Up @@ -451,7 +451,7 @@ private ArrayNode getRouteLocationsForTrain(Train train, Locale locale) {
RouteLocation rl = route;
root.put(NAME, rl.getId());
root.put(USERNAME, rl.getName());
root.put(DIRECTION, rl.getTrainDirectionString());
root.put(TRAIN_DIRECTION, rl.getTrainDirectionString());
root.put(COMMENT, rl.getComment());
root.put(SEQUENCE, rl.getSequenceNumber());
root.put(EXPECTED_ARRIVAL, train.getExpectedArrivalTime(rl));
Expand Down
4 changes: 2 additions & 2 deletions java/src/jmri/web/servlet/operations/HtmlManifest.java
Expand Up @@ -137,7 +137,7 @@ public String getLocations() throws IOException {
// Message format: Train departs Boston Westbound with 12 cars, 450 feet, 3000 tons
builder.append(String.format(strings.getProperty("TrainDepartsCars"), routeLocationName,
strings.getProperty("Heading"
+ Setup.getDirectionString(location.path(JSON.DIRECTION).intValue())),
+ Setup.getDirectionString(location.path(JSON.TRAIN_DIRECTION).intValue())),
location.path(JSON.LENGTH).path(JSON.LENGTH).intValue(), location.path(JSON.LENGTH)
.path(JSON.UNIT).asText().toLowerCase(), location.path(JsonOperations.WEIGHT)
.intValue(), location.path(JsonOperations.CARS).path(JSON.TOTAL).intValue()));
Expand All @@ -146,7 +146,7 @@ public String getLocations() throws IOException {
// tons
builder.append(String.format(strings.getProperty("TrainDepartsLoads"), routeLocationName,
strings.getProperty("Heading"
+ Setup.getDirectionString(location.path(JSON.DIRECTION).intValue())),
+ Setup.getDirectionString(location.path(JSON.TRAIN_DIRECTION).intValue())),
location.path(JSON.LENGTH).path(JSON.LENGTH).intValue(), location.path(JSON.LENGTH)
.path(JSON.UNIT).asText().toLowerCase(), location.path(JsonOperations.WEIGHT)
.intValue(), location.path(JsonOperations.CARS).path(JSON.LOADS).intValue(), location
Expand Down
Expand Up @@ -124,7 +124,6 @@ public void testOnMessage() throws Exception {
instance.onMessage(JsonLayoutBlock.LAYOUTBLOCK, message, JSON.DELETE, locale, 42);
fail("Expected exception not thrown");
} catch (JsonException ex) {
System.out.println(ex.getJsonMessage());
assertEquals(409, ex.getCode());
assertEquals(1, ex.getAdditionalData().path(JSON.CONFLICT).size());
assertEquals("Manager", ex.getAdditionalData().path(JSON.CONFLICT).path(0).asText());
Expand Down

0 comments on commit a46fb7e

Please sign in to comment.