Modidy a package name of nemo
[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 / Operation.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 Operation implements INemoItem {
13         private String operation_id;
14         private String operation_name;
15         private String target_object;
16         private String priority = "0";
17         private List<Action> actions;
18
19         public Operation(String operation_id, String operation_name,
20                         String target_object, String priority, List<Action> actions) {
21                 this.operation_id = operation_id;
22                 this.operation_name = operation_name;
23                 this.target_object = UUIDUtils.getUUId(target_object);
24                 if (priority != null)
25                         this.priority = priority;
26                 this.actions = actions;
27         }
28
29         @Override
30         public JSONObject toJSONObject() {
31                 JSONObject operationJs = new JSONObject();
32                 operationJs.put("operation-id", operation_id);
33                 operationJs.put("operation-name", operation_name);
34                 if (target_object != null) {
35                         operationJs.put("target-object", target_object);
36                 }
37                 if (priority != null) {
38                         operationJs.put("priority", priority);
39                 }
40
41                 if (actions != null && actions.size() > 0) {
42                         // JS array,actions array.
43                         JSONArray actionJsArray = new JSONArray();
44                         // remember add order to each action;
45                         for (int i = 0; i < actions.size(); i++) {
46                                 Action action = actions.get(i);
47                                 JSONObject actionJs = action.toJSONObject();
48                                 actionJs.put("order", i + "");
49                                 actionJsArray.put(i, actionJs);
50                         }
51                         operationJs.put("action", actionJsArray);
52                 }
53
54                 return operationJs;
55         }
56 }