Skip to content
Permalink
Browse files

fix: JSON Schema for block

  • Loading branch information...
rhwood committed May 24, 2019
1 parent a170aa6 commit a46fb7e5ac45a132e0593a98d6a83f1d7a23d9b6
@@ -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());
@@ -113,6 +113,10 @@
* {@value #SPEED}
*/
public static final String SPEED = "speed"; // NOI18N
/**
* {@value #DIRECTION}
*/
public static final String DIRECTION = "direction"; // NOI18N

/* JSON hello and metadata */
/**
@@ -382,9 +386,9 @@

/* 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}
*/
@@ -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"
]
}
@@ -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": {
@@ -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"
]
}
@@ -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;
@@ -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));
@@ -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()));
@@ -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
@@ -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());

0 comments on commit a46fb7e

Please sign in to comment.
You can’t perform that action at this time.