/**
* @param root node
* @throws java.lang.IllegalStateException if service id is missing OR neither location id nor location coordinate are set
*/
private void parse_services(JsonNode root) {
JsonNode services = root.path(JsonConstants.SERVICES);
for(JsonNode serviceNode : services){
//type
JsonNode typeNode = serviceNode.path(JsonConstants.Job.TYPE);
//service id
JsonNode jobIdNode = serviceNode.path(JsonConstants.Job.ID);
if(jobIdNode.isMissingNode()) throw new IllegalStateException("service-id is missing");
Service.Builder serviceBuilder;
if(typeNode.isMissingNode()) serviceBuilder = Service.Builder.newInstance(jobIdNode.asText());
else if(typeNode.asText().equals(JsonConstants.Job.SERVICE)) serviceBuilder = Service.Builder.newInstance(jobIdNode.asText());
else if(typeNode.asText().equals(JsonConstants.Job.PICKUP)) serviceBuilder = Pickup.Builder.newInstance(jobIdNode.asText());
else if(typeNode.asText().equals(JsonConstants.Job.DELIVERY)) serviceBuilder = Delivery.Builder.newInstance(jobIdNode.asText());
else throw new IllegalStateException("type of service ("+typeNode.asText()+") is not supported");
//service address
JsonNode addressIdNode = serviceNode.path(JsonConstants.Job.ADDRESS).path(JsonConstants.Address.ID);
boolean either_locationId_or_coord = false;
if(!addressIdNode.isMissingNode()){
serviceBuilder.setLocationId(addressIdNode.asText());
either_locationId_or_coord = true;
}
{
JsonNode lonNode = serviceNode.path(JsonConstants.Job.ADDRESS).path(JsonConstants.Address.LON);
JsonNode latNode = serviceNode.path(JsonConstants.Job.ADDRESS).path(JsonConstants.Address.LAT);
if (!lonNode.isMissingNode() && !latNode.isMissingNode()) {
serviceBuilder.setCoord(Coordinate.newInstance(lonNode.asDouble(), latNode.asDouble()));
either_locationId_or_coord = true;
}
}
if(!either_locationId_or_coord) throw new IllegalStateException("location missing. either locationId or locationCoordinate is required");
//service name
JsonNode nameNode = serviceNode.path(JsonConstants.Job.NAME);
if(!nameNode.isMissingNode()) serviceBuilder.setName(nameNode.asText());
//service duration
serviceBuilder.setServiceTime(serviceNode.path(JsonConstants.Job.SERVICE_DURATION).asDouble());
//service tw
JsonNode start_tw_node = serviceNode.path(JsonConstants.Job.TIME_WINDOW).path(JsonConstants.TimeWindow.START);
JsonNode end_tw_node = serviceNode.path(JsonConstants.Job.TIME_WINDOW).path(JsonConstants.TimeWindow.END);
if(!start_tw_node.isMissingNode() && !end_tw_node.isMissingNode()){
serviceBuilder.setTimeWindow(TimeWindow.newInstance(start_tw_node.asDouble(),end_tw_node.asDouble()));
}
//service size
JsonNode sizeNode = serviceNode.path(JsonConstants.Job.SIZE);
int size_index = 0;
for(JsonNode sizeValNode : sizeNode){
int size_value = sizeValNode.intValue();
serviceBuilder.addSizeDimension(size_index,size_value);
size_index++;
}
//service skills
JsonNode reqSkills = serviceNode.path(JsonConstants.Job.SKILLS);
for(JsonNode skillNode : reqSkills){
serviceBuilder.addRequiredSkill(skillNode.asText());
}
//add service
vrpBuilder.addJob(serviceBuilder.build());