1 package org.opendaylight.nemo.tool.eclipse.plugin.rest.actions.model;
3 import org.json.JSONArray;
4 import org.json.JSONObject;
5 import org.opendaylight.nemo.tool.eclipse.plugin.rest.actions.UUIDUtils;
10 * Created by hj on 10/29/15.
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;
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;
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);
34 if(end_nodes!=null&&end_nodes.size()>0){
36 JSONArray jsonEndNodeArray = new JSONArray();
37 for (int i=0;i<end_nodes.size();i++){
38 String value = end_nodes.get(i);
40 JSONObject jsonEndNode = new JSONObject();
41 jsonEndNode.put("order", i + "");
42 jsonEndNode.put("node-id", value);
43 jsonEndNodeArray.put(i, jsonEndNode);
45 jsonConnection.put("end-node", jsonEndNodeArray);
49 if(properties!=null&&properties.size()>0){
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);
56 jsonConnection.put("property", jsonPropertyArray);
60 return jsonConnection;