a01053be52eaf79a8d8e6600ec0d98975b5a912d
[public/netxms.git] / src / java / client / netxms-client / src / main / java / org / netxms / client / datacollection / DciSummaryTable.java
1 /**
2 * NetXMS - open source network management system
3 * Copyright (C) 2003-2013 Victor Kirhenshtein
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19 package org.netxms.client.datacollection;
20
21 import java.util.ArrayList;
22 import java.util.List;
23 import java.util.UUID;
24 import org.netxms.base.NXCPCodes;
25 import org.netxms.base.NXCPMessage;
26
27 /**
28 * DCI summary table
29 */
30 public class DciSummaryTable
31 {
32 public static final int SUMMARY_TABLE_TABLE_VALUE = 0x0002;
33
34 private int id;
35 private UUID guid;
36 private String menuPath;
37 private String title;
38 private int flags;
39 private String nodeFilter;
40 private List<DciSummaryTableColumn> columns;
41 private String tableDciName;
42
43 /**
44 * Create new empty summary table object
45 *
46 * @param menuPath The menu path
47 * @param title The title
48 * @param isSingleValue if table is single value DCI
49 */
50 public DciSummaryTable(String menuPath, String title, boolean isSingleValue)
51 {
52 id = 0;
53 guid = UUID.randomUUID();
54 this.menuPath = menuPath;
55 this.title = title;
56 flags = isSingleValue ? 0 : SUMMARY_TABLE_TABLE_VALUE;
57 nodeFilter = "";
58 columns = new ArrayList<DciSummaryTableColumn>();
59 tableDciName = "";
60 }
61
62 /**
63 * Create full object from NXCP message.
64 *
65 * @param msg message with object from the server
66 */
67 public DciSummaryTable(NXCPMessage msg)
68 {
69 id = msg.getFieldAsInt32(NXCPCodes.VID_SUMMARY_TABLE_ID);
70 guid = msg.getFieldAsUUID(NXCPCodes.VID_GUID);
71 menuPath = msg.getFieldAsString(NXCPCodes.VID_MENU_PATH);
72 title = msg.getFieldAsString(NXCPCodes.VID_TITLE);
73 flags = msg.getFieldAsInt32(NXCPCodes.VID_FLAGS);
74 nodeFilter = msg.getFieldAsString(NXCPCodes.VID_FILTER);
75 tableDciName = msg.getFieldAsString(NXCPCodes.VID_DCI_NAME);
76
77 String s = msg.getFieldAsString(NXCPCodes.VID_COLUMNS);
78 if ((s != null) && (s.length() > 0))
79 {
80 String[] parts = s.split("\\^\\~\\^");
81 columns = new ArrayList<DciSummaryTableColumn>(parts.length);
82 for(int i = 0; i < parts.length; i++)
83 {
84 String[] data = parts[i].split("\\^\\#\\^");
85 if (data.length == 2)
86 {
87 columns.add(new DciSummaryTableColumn(data[0], data[1], 0, ";"));
88 }
89 else if (data.length >= 3)
90 {
91 int flags;
92 try
93 {
94 flags = Integer.parseInt(data[2]);
95 }
96 catch(NumberFormatException e)
97 {
98 flags = 0;
99 }
100 columns.add(new DciSummaryTableColumn(data[0], data[1], flags, (data.length > 3) ? data[3] : ";"));
101 }
102 }
103 }
104 else
105 {
106 columns = new ArrayList<DciSummaryTableColumn>(0);
107 }
108 }
109
110 /**
111 * Fill NXCP message with object data
112 *
113 * @param msg NXCP message
114 */
115 public void fillMessage(NXCPMessage msg)
116 {
117 msg.setFieldInt32(NXCPCodes.VID_SUMMARY_TABLE_ID, id);
118 msg.setField(NXCPCodes.VID_GUID, guid);
119 msg.setField(NXCPCodes.VID_MENU_PATH, menuPath);
120 msg.setField(NXCPCodes.VID_TITLE, title);
121 msg.setFieldInt32(NXCPCodes.VID_FLAGS, flags);
122 msg.setField(NXCPCodes.VID_FILTER, nodeFilter);
123 msg.setField(NXCPCodes.VID_DCI_NAME, tableDciName);
124
125 StringBuilder sb = new StringBuilder();
126 for(DciSummaryTableColumn c : columns)
127 {
128 if (sb.length() > 0)
129 sb.append("^~^");
130 sb.append(c.getName());
131 sb.append("^#^");
132 sb.append(c.getDciName());
133 sb.append("^#^");
134 sb.append(c.getFlags());
135 sb.append("^#^");
136 sb.append(c.getSeparator());
137 }
138 msg.setField(NXCPCodes.VID_COLUMNS, sb.toString());
139 }
140
141 /**
142 * @return the id
143 */
144 public int getId()
145 {
146 return id;
147 }
148
149 /**
150 * @param id the id to set
151 */
152 public void setId(int id)
153 {
154 this.id = id;
155 }
156
157 /**
158 * @return the guid
159 */
160 public UUID getGuid()
161 {
162 return guid;
163 }
164
165 /**
166 * @return the menuPath
167 */
168 public String getMenuPath()
169 {
170 return menuPath;
171 }
172
173 /**
174 * @param menuPath the menuPath to set
175 */
176 public void setMenuPath(String menuPath)
177 {
178 this.menuPath = menuPath;
179 }
180
181 /**
182 * @return the title
183 */
184 public String getTitle()
185 {
186 return title;
187 }
188
189 /**
190 * @param title the title to set
191 */
192 public void setTitle(String title)
193 {
194 this.title = title;
195 }
196
197 /**
198 * @return the flags
199 */
200 public int getFlags()
201 {
202 return flags;
203 }
204
205 /**
206 * @param flags the flags to set
207 */
208 public void setFlags(int flags)
209 {
210 this.flags = flags;
211 }
212
213 /**
214 * @return the nodeFilter
215 */
216 public String getNodeFilter()
217 {
218 return nodeFilter;
219 }
220
221 /**
222 * @param nodeFilter the nodeFilter to set
223 */
224 public void setNodeFilter(String nodeFilter)
225 {
226 this.nodeFilter = nodeFilter;
227 }
228
229 /**
230 * @return the columns
231 */
232 public List<DciSummaryTableColumn> getColumns()
233 {
234 return columns;
235 }
236
237 /**
238 * Check if table is single value or table value
239 *
240 * @return true if single value
241 */
242 public boolean isSingleValue()
243 {
244 return (flags & SUMMARY_TABLE_TABLE_VALUE) > 0 ? false : true;
245 }
246
247 /**
248 * Return table dci name
249 * @return table dci name if set
250 */
251 public String getTableDciName()
252 {
253 return tableDciName;
254 }
255
256 /**
257 * Set table dci name
258 * @param name of table DCI
259 */
260 public void setTableDciName(String name)
261 {
262 tableDciName = name;
263 }
264 }