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 / Connection.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 Connection implements INemoItem {
13     private String connection_id;
14     private String connection_name;
15     private String connection_type;
16     private List<String> end_nodes;
17     private List<Property> properties;
18
19     public Connection(String connection_id, String connection_name, String connection_type, List<String> end_nodes, List<Property> properties) {
20         this.connection_id = connection_id;
21         this.connection_name = connection_name;
22         this.connection_type = connection_type;
23         this.end_nodes = end_nodes;
24         this.properties = properties;
25     }
26
27     @Override
28     public JSONObject toJSONObject() {
29         JSONObject jsonConnection = new JSONObject();
30         jsonConnection.put("connection-id", connection_id);
31         jsonConnection.put("connection-name", connection_name);
32         jsonConnection.put("connection-type", connection_type);
33
34         if(end_nodes!=null&&end_nodes.size()>0){
35             //JS array,sub nodes
36             JSONArray jsonEndNodeArray = new JSONArray();
37             for (int i=0;i<end_nodes.size();i++){
38                 String value = end_nodes.get(i);
39                 
40                 JSONObject jsonEndNode = new JSONObject();
41                 jsonEndNode.put("order", i + "");
42                 jsonEndNode.put("node-id", value);
43                 jsonEndNodeArray.put(i, jsonEndNode);
44             }
45             jsonConnection.put("end-node", jsonEndNodeArray);
46         }
47
48
49         if(properties!=null&&properties.size()>0){
50             //JS array,properties
51             JSONArray jsonPropertyArray = new JSONArray();
52             for (int i=0;i<properties.size();i++){
53                 JSONObject jsonProperty= properties.get(i).toJSONObject();
54                 jsonPropertyArray.put(i,jsonProperty);
55             }
56             jsonConnection.put("property", jsonPropertyArray);
57         }
58
59
60         return jsonConnection;
61     }
62 }