* @param root node
* @throws java.lang.IllegalStateException if vehicle id is missing OR if neither start location id nor start location
* coordinate are set
*/
private void parse_vehicles(JsonNode root) {
JsonNode vehicles = root.path(JsonConstants.VEHICLES);
for(JsonNode vehicleNode : vehicles){
//vehicle id
JsonNode vehicle_id_node = vehicleNode.path(JsonConstants.Vehicle.ID);
if(vehicle_id_node.isMissingNode()) throw new IllegalStateException("vehicle id missing");
VehicleImpl.Builder vehicleBuilder = VehicleImpl.Builder.newInstance(vehicle_id_node.asText());
//vehicle type
VehicleType type = vehicle_type_map.get(vehicleNode.path(JsonConstants.Vehicle.TYPE_ID).asText());
vehicleBuilder.setType(type);
//earliest start
JsonNode earliestStartNode = vehicleNode.path(JsonConstants.Vehicle.EARLIEST_START);
if(!earliestStartNode.isMissingNode()) vehicleBuilder.setEarliestStart(earliestStartNode.asDouble());
//latest end
JsonNode latestEndNode = vehicleNode.path(JsonConstants.Vehicle.LATEST_END);
if(!latestEndNode.isMissingNode()) vehicleBuilder.setLatestArrival(latestEndNode.asDouble());
//start
//location id
boolean either_id_or_coord = false;
JsonNode startAddressId = vehicleNode.path(JsonConstants.Vehicle.START_ADDRESS).path(JsonConstants.Address.ID);
if(!startAddressId.isMissingNode()){
vehicleBuilder.setStartLocationId(startAddressId.asText());
either_id_or_coord = true;
}
//location coordinate
{
JsonNode lonNode = vehicleNode.path(JsonConstants.Vehicle.START_ADDRESS).path(JsonConstants.Address.LON);
JsonNode latNode = vehicleNode.path(JsonConstants.Vehicle.START_ADDRESS).path(JsonConstants.Address.LAT);
if (!lonNode.isMissingNode() && !latNode.isMissingNode()) {
vehicleBuilder.setStartLocationCoordinate(Coordinate.newInstance(lonNode.asDouble(), latNode.asDouble()));
either_id_or_coord = true;
}
}
if(!either_id_or_coord) throw new IllegalStateException("start location of vehicle missing. either id or coordinate required");
//end
//location id
JsonNode endAddressId = vehicleNode.path(JsonConstants.Vehicle.END_ADDRESS).path(JsonConstants.Address.ID);
if(!endAddressId.isMissingNode()){
if(!startAddressId.asText().equals(endAddressId.asText())){
vehicleBuilder.setEndLocationId(endAddressId.asText());
}
}
//location coordinate
{
JsonNode lonNode = vehicleNode.path(JsonConstants.Vehicle.END_ADDRESS).path(JsonConstants.Address.LON);
JsonNode latNode = vehicleNode.path(JsonConstants.Vehicle.END_ADDRESS).path(JsonConstants.Address.LAT);
if (!lonNode.isMissingNode() && !latNode.isMissingNode()) {
vehicleBuilder.setEndLocationCoordinate(Coordinate.newInstance(lonNode.asDouble(), latNode.asDouble()));
}
}
//skills
JsonNode skillsNode = vehicleNode.path(JsonConstants.Vehicle.SKILLS);
for(JsonNode skillNode : skillsNode){
String skill = skillNode.asText();
vehicleBuilder.addSkill(skill);
}