Add verigraph code base
[parser.git] / verigraph / src / main / java / it / polito / escape / verify / model / Node.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.model;
11
12 import java.util.HashMap;
13 import java.util.HashSet;
14 import java.util.Map;
15 import java.util.Set;
16
17 import javax.xml.bind.annotation.XmlRootElement;
18 import javax.xml.bind.annotation.XmlTransient;
19
20 import com.fasterxml.jackson.annotation.JsonInclude;
21 import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
22 import com.fasterxml.jackson.databind.annotation.JsonSerialize;
23
24 import io.swagger.annotations.ApiModel;
25 import io.swagger.annotations.ApiModelProperty;
26 import it.polito.escape.verify.deserializer.NodeCustomDeserializer;
27 import it.polito.escape.verify.serializer.CustomMapSerializer;
28
29 @ApiModel(value = "Node")
30 @XmlRootElement
31 @JsonDeserialize(using = NodeCustomDeserializer.class)
32 @JsonInclude(JsonInclude.Include.NON_EMPTY)
33 public class Node {
34
35         @ApiModelProperty(required = false, hidden = true)
36         @XmlTransient
37         private long                                    id;
38
39         @ApiModelProperty(required = true, example = "ep", value = "The name of the node can be any string")
40         private String                                  name;
41
42         @ApiModelProperty(      required = true,
43                                                 example = "endpoint",
44                                                 value = "The functional types that are currently supported are: endpoint, firewall, nat, antispam, webclient, webserver, mailclient, mailserver")
45         private String                                  functional_type;
46
47         @ApiModelProperty(required = false, hidden = true)
48         @XmlTransient
49         private Configuration                   configuration   = new Configuration();
50
51         @ApiModelProperty(      name = "neighbours",
52                                                 notes = "Neighbours",
53                                                 dataType = "List[it.polito.escape.verify.model.Neighbour]")
54         private Map<Long, Neighbour>    neighbours              = new HashMap<Long, Neighbour>();
55
56         @ApiModelProperty(required = false, hidden = true)
57         @XmlTransient
58         private Set<Link>                               links                   = new HashSet<>();
59
60         public Node() {
61
62         }
63
64         public Node(long id, String name, String functional_type, Configuration configuration) {
65                 this.id = id;
66                 this.name = name;
67                 this.functional_type = functional_type;
68                 this.configuration = configuration;
69         }
70
71         public String getName() {
72                 return name;
73         }
74
75         public void setName(String name) {
76                 this.name = name;
77         }
78
79         public String getFunctional_type() {
80                 return functional_type;
81         }
82
83         public void setFunctional_type(String functional_type) {
84                 this.functional_type = functional_type;
85         }
86
87         // @XmlTransient
88         public Configuration getConfiguration() {
89                 return configuration;
90         }
91
92         public void setConfiguration(Configuration configuration) {
93                 this.configuration = configuration;
94         }
95
96         @JsonSerialize(using = CustomMapSerializer.class)
97         public Map<Long, Neighbour> getNeighbours() {
98                 return neighbours;
99         }
100
101         public void setNeighbours(Map<Long, Neighbour> neighbours) {
102                 this.neighbours = neighbours;
103         }
104
105         public long getId() {
106                 return this.id;
107         }
108
109         public void setId(long id) {
110                 this.id = id;
111         }
112
113         public Set<Link> getLinks() {
114                 return links;
115         }
116
117         public void setLinks(Set<Link> links) {
118                 this.links = links;
119         }
120
121         public void addLink(String url, String rel) {
122                 Link link = new Link();
123                 link.setLink(url);
124                 link.setRel(rel);
125                 links.add(link);
126         }
127
128         @Override
129         public int hashCode() {
130                 final int prime = 31;
131                 int result = 1;
132                 result = prime * result + ((name == null) ? 0 : name.hashCode());
133                 return result;
134         }
135
136         @Override
137         public boolean equals(Object obj) {
138                 if (this == obj)
139                         return true;
140                 else
141                         return false;
142         }
143
144         public Neighbour searchNeighbourByName(String name) {
145                 for (Neighbour neighbour : this.neighbours.values()) {
146                         if (neighbour.getName().equals(name))
147                                 return neighbour;
148                 }
149                 return null;
150         }
151
152 }