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 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;
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);
25 this.priority = priority;
26 this.actions = actions;
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);
37 if (priority != null) {
38 operationJs.put("priority", priority);
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);
51 operationJs.put("action", actionJsArray);