Disable syslog in heat-translator for functest integration
[parser.git] / verigraph / src / main / java / it / polito / escape / verify / validation / VpnexitValidator.java
1 /*******************************************************************************
2  * Copyright (c) 2017 Politecnico di Torino and others.
3  *
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
10 package it.polito.escape.verify.validation;
11
12 import com.fasterxml.jackson.databind.JsonNode;
13
14 import it.polito.escape.verify.model.Configuration;
15 import it.polito.escape.verify.model.Graph;
16 import it.polito.escape.verify.model.Node;
17 import it.polito.escape.verify.validation.exception.ValidationException;
18
19 public class VpnexitValidator implements ValidationInterface {
20
21         @Override
22         public void validate(Graph graph, Node node, Configuration configuration) throws ValidationException {
23                 JsonNode configurationNode = configuration.getConfiguration();
24
25                 if (!configurationNode.isArray())
26                         throw new ValidationException("configuration must be an array");
27
28                 for (JsonNode object : configurationNode) {
29                         JsonNode vpnexit = object.get("vpnaccess");
30                         if (!vpnexit.isTextual())
31                                 throw new ValidationException("value corresponding to the key 'vpnaccess' must be a string");
32                         validateObject(graph, node, vpnexit.asText());
33                 }
34
35         }
36
37         private void validateObject(Graph g, Node node, String field) throws ValidationException {
38                 boolean isValid = false;
39                 for (Node n : g.getNodes().values()) {
40                         if ((n.getFunctional_type().equals("vpnaccess")) && (n.getName().equals(field)))
41                                 isValid = true;
42                 }
43
44                 if (!isValid)
45                         throw new ValidationException("'"       + field + "' is not a valid value for the configuration of a type '"
46                                                                                         + node.getFunctional_type()
47                                                                                         + "'. Please use the name of an existing node of type 'vpnaccess'.");
48
49         }
50
51 }