Modify pom file
[nemo.git] / nemo-tools / eclipse-plugin / nemo-rest / org.opendaylight.nemo.tool.eclipse.plugin.rest / src / org / opendaylight / nemo / tool / eclipse / plugin / rest / actions / model / Node.java
1 package org.opendaylight.nemo.tool.eclipse.plugin.rest.actions.model;
2
3 import org.json.JSONArray;
4 import org.json.JSONObject;
5 import org.opendaylight.nemo.tool.eclipse.plugin.rest.actions.UUIDUtils;
6
7 import java.util.List;
8
9 /**
10  * Created by hj on 10/29/15.
11  */
12 public class Node implements INemoItem{
13     private String node_id;
14     private String node_name;
15     private String node_type;
16     private List<Property> properties;
17     private List<String> sub_nodes;
18
19     public Node(String node_id, String node_name, String node_type, List<Property> properties, List<String> sub_nodes) {
20         this.node_id = node_id;
21         this.node_name = node_name;
22         this.node_type = node_type;
23         this.properties = properties;
24         this.sub_nodes = sub_nodes;
25     }
26
27     @Override
28     public JSONObject toJSONObject() {
29         JSONObject jsonNode = new JSONObject();
30         jsonNode.put("node-id",node_id);
31         jsonNode.put("node-name",node_name);
32         if(node_type!=null){
33             jsonNode.put("node-type",node_type);
34         }
35         if(properties!=null&&properties.size()>0){
36             //JS array,properties
37             JSONArray jsonPropertyArray = new JSONArray();
38             for (int i=0;i<properties.size();i++){
39                 JSONObject jsonProperty= properties.get(i).toJSONObject();
40                 jsonPropertyArray.put(i,jsonProperty);
41             }
42             jsonNode.put("property",jsonPropertyArray);
43         }
44
45         if(sub_nodes!=null&&sub_nodes.size()>0){
46             //JS array,sub nodes
47             JSONArray jsonSubNodeArray = new JSONArray();
48             for (int i=0;i<sub_nodes.size();i++){
49                 String value = sub_nodes.get(i);
50                 
51                 JSONObject jsonSubNode = new JSONObject();
52                 jsonSubNode.put("order",i+"");
53                 jsonSubNode.put("node-id",value);
54                 jsonSubNodeArray.put(i,jsonSubNode);
55             }
56             jsonNode.put("sub-node",jsonSubNodeArray);
57         }
58
59         return jsonNode;
60     }
61
62     @Override
63     public boolean equals(Object o) {
64         if (this == o) return true;
65         if (o == null || getClass() != o.getClass()) return false;
66
67         Node node = (Node) o;
68
69         if (node_id != null ? !node_id.equals(node.node_id) : node.node_id != null) return false;
70
71         return true;
72     }
73
74     @Override
75     public int hashCode() {
76         return node_id != null ? node_id.hashCode() : 0;
77     }
78
79     @Override
80     public String toString() {
81         return "Node{" +
82                 "node_id='" + node_id + '\'' +
83                 ", node_name='" + node_name + '\'' +
84                 ", node_type='" + node_type + '\'' +
85                 ", properties=" + properties +
86                 ", sub_nodes=" + sub_nodes +
87                 '}';
88     }
89 }