Modify pom file
[nemo.git] / nemo-tools / eclipse-plugin-project / nemo-rest / org.opendaylight.nemo.tool.eclipse.plugin.rest / src / org / opendaylight / nemo / tool / eclipse / plugin / rest / actions / model / NemoInput.java
1 package org.opendaylight.nemo.tool.eclipse.plugin.rest.actions.model;
2
3 import org.json.JSONArray;
4 import org.json.JSONObject;
5
6 /**
7  * Created by hj on 10/29/15.
8  */
9 public class NemoInput implements INemoInput {
10         private User user;
11         private INemoItem iNemoItem;
12         private boolean begin;
13
14         public NemoInput(User user, INemoItem iNemoItem) {
15                 this.user = user;
16                 this.iNemoItem = iNemoItem;
17         }
18         public NemoInput(User user) {
19                 this.user = user;
20                 this.iNemoItem = null;
21                 begin = true;
22         }
23         @Override
24         public String toJsonFormatString() {
25                 JSONObject dataJs = new JSONObject();
26                 JSONObject inputValueJson = new JSONObject();
27                 inputValueJson.put("user-id", user.getUser_id());
28                 
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();
35                 }
36                 if (iNemoItem == null) {
37                         dataJs.put("input", inputValueJson);
38                         return dataJs.toString();
39                 }
40                 // item js array;
41                 JSONArray itemJsArray = new JSONArray();
42                 String key = "node";
43                 if (iNemoItem instanceof Node) {
44                         key = "node";
45                 }
46                 if (iNemoItem instanceof Connection) {
47                         key = "connection";
48                 }
49                 if (iNemoItem instanceof Flow) {
50                         key = "flow";
51                 }
52                 if (iNemoItem instanceof Operation) {
53                         key = "operation";
54                 }
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);
60                 else
61                         inputValueJson.put("objects", objectsJs);
62                 dataJs.put("input", inputValueJson);
63                 return dataJs.toString();
64         }
65 }