/
View.java
172 lines (146 loc) · 4.65 KB
/
View.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
package org.pentaho.cdf.views;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.commons.codec.binary.Base64;
import org.json.JSONException;
import org.json.JSONObject;
import org.json.JSONArray;
import pt.webdetails.cpf.persistence.Persistable;
/**
*
* @author pdpi
*/
public class View implements Persistable {
private Map<String, Object> parameters;
private List<String> unboundParams;
private String name, id, user, description, key;
private String solution, path, file;
private Date timestamp;
public String getSolution() {
return solution;
}
public void setSolution(String solution) {
this.solution = solution;
}
public String getPath() {
return path;
}
public void setPath(String path) {
this.path = path;
}
public String getFile() {
return file;
}
public void setFile(String file) {
this.file = file;
}
public void setParameter(String name, Object value) {
parameters.put(name, value);
}
public Object getParameter(String name) {
return parameters.get(name);
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getUser() {
return user;
}
public void setUser(String user) {
this.user = user;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public Date getTimestamp() {
return timestamp;
}
public void setTimestamp(Date timestamp) {
this.timestamp = timestamp;
}
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
public JSONObject toJSON() {
try {
String p = new String(Base64.encodeBase64(new JSONObject(parameters).toString(2).getBytes()));
JSONObject json = new JSONObject();
json.put("description", description);
json.put("name", name);
json.put("id", id);
json.put("key", key);
json.put("timestamp", timestamp == null ? 0 : timestamp.getTime());
json.put("user", user);
json.put("unbound", new JSONArray(unboundParams));
json.put("params", p);
json.put("solution", solution);
json.put("path", path);
json.put("file", file);
return json;
} catch (JSONException e) {
return null;
}
}
public void fromJSON(JSONObject json) {
try {
String _description, _name, _id, _key, _user, _solution, _path, _file;
Date _timestamp;
_description = json.optString("description");
_name = json.getString("name");
_id = json.getString("id");
_timestamp = new Date(json.optLong("timestamp",0));
_user = json.getString("user");
_key = json.isNull("key") ? null : json.optString("key");
_solution = json.getString("solution");
_path = json.getString("path");
_file = json.getString("file");
String p =json.getString("params");
JSONObject jsonParams = new JSONObject(new String(Base64.decodeBase64(p.getBytes())));
JSONArray jsonUnbound = json.getJSONArray("unbound");
Map<String, Object> _params = new HashMap<String, Object>();
String[] keys = JSONObject.getNames(jsonParams);
if (keys != null) {
for (String k : keys) {
_params.put(k, jsonParams.get(k));
}
}
List<String> _unbound = new ArrayList<String>();
for (int i = 0; i < jsonUnbound.length(); i++) {
_unbound.add(jsonUnbound.getString(i));
}
name = _name;
user = _user;
description = _description;
id = _id;
key = _key;
timestamp = _timestamp;
parameters = _params;
unboundParams = _unbound;
solution = _solution;
path = _path;
file = _file;
} catch (JSONException e) {
}
}
}