1 package org.opendaylight.nemo.tool.eclipse.plugin.rest.actions.model;
3 import org.json.JSONArray;
4 import org.json.JSONObject;
7 * Created by hj on 10/29/15.
9 public class NemoInput implements INemoInput {
11 private INemoItem iNemoItem;
12 private boolean begin;
14 public NemoInput(User user, INemoItem iNemoItem) {
16 this.iNemoItem = iNemoItem;
18 public NemoInput(User user) {
20 this.iNemoItem = null;
24 public String toJsonFormatString() {
25 JSONObject dataJs = new JSONObject();
26 JSONObject inputValueJson = new JSONObject();
27 inputValueJson.put("user-id", user.getUser_id());
29 if (iNemoItem == null&&begin) {
30 inputValueJson.put("user-name", user.getUser_name());
31 inputValueJson.put("user-password", user.getUser_password());
32 inputValueJson.put("user-role", user.getUser_role());
33 dataJs.put("input", inputValueJson);
34 return dataJs.toString();
36 if (iNemoItem == null) {
37 dataJs.put("input", inputValueJson);
38 return dataJs.toString();
41 JSONArray itemJsArray = new JSONArray();
43 if (iNemoItem instanceof Node) {
46 if (iNemoItem instanceof Connection) {
49 if (iNemoItem instanceof Flow) {
52 if (iNemoItem instanceof Operation) {
55 itemJsArray.put(0, iNemoItem.toJSONObject());
56 JSONObject objectsJs = new JSONObject();
57 objectsJs.put(key, itemJsArray);
58 if (iNemoItem instanceof Operation)
59 inputValueJson.put("operations", objectsJs);
61 inputValueJson.put("objects", objectsJs);
62 dataJs.put("input", inputValueJson);
63 return dataJs.toString();