1 /*******************************************************************************
2 * Copyright (c) 2017 Politecnico di Torino and others.
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Apache License, Version 2.0
6 * which accompanies this distribution, and is available at
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *******************************************************************************/
9 package it.polito.verigraph.validation;
11 import com.fasterxml.jackson.databind.JsonNode;
13 import it.polito.verigraph.model.Configuration;
14 import it.polito.verigraph.model.Graph;
15 import it.polito.verigraph.model.Node;
16 import it.polito.verigraph.validation.exception.ValidationException;
18 public class VpnaccessValidator implements ValidationInterface {
21 public void validate(Graph graph, Node node, Configuration configuration) throws ValidationException {
22 JsonNode configurationNode = configuration.getConfiguration();
24 if (!configurationNode.isArray())
25 throw new ValidationException("configuration must be an array");
27 for (JsonNode object : configurationNode) {
28 JsonNode vpnexit = object.get("vpnexit");
29 if (!vpnexit.isTextual())
30 throw new ValidationException("value corresponding to the key 'vpnexit' must be a string");
31 validateObject(graph, node, vpnexit.asText());
36 private void validateObject(Graph g, Node node, String field) throws ValidationException {
37 boolean isValid = false;
38 for (Node n : g.getNodes().values()) {
39 if ((n.getFunctional_type().equals("vpnexit")) && (n.getName().equals(field)))
44 throw new ValidationException("'"+ field + "' is not a valid value for the configuration of a type '"
45 + node.getFunctional_type()
46 + "'. Please use the name of an existing node of type 'vpnexit'.");