use of org.netxms.client.TableRow in project netxms by netxms.
the class SummaryTableAdHoc method create.
/* (non-Javadoc)
* @see org.netxms.websvc.handlers.AbstractHandler#create(org.json.JSONObject)
*/
@Override
protected Object create(JSONObject data) throws Exception {
NXCSession session = getSession();
if (!session.isObjectsSynchronized())
session.syncObjects();
String objectFilter = JsonTools.getStringFromJson(data, "baseObject", null);
log.debug("POST adhoc summaryTable: baseObject = " + objectFilter);
JSONArray columnFilter = JsonTools.getJsonArrayFromJson(data, "columns", null);
if (objectFilter == null || objectFilter.isEmpty() || columnFilter == null) {
log.warn("POST adhoc summaryTable: no DciSummaryTableColumn table or no value for BaseObject");
return createErrorResponse(RCC.INVALID_ARGUMENT);
}
long baseObjectId;
try {
baseObjectId = Long.parseLong(objectFilter);
} catch (NumberFormatException ex) {
AbstractObject obj = session.findObjectByName(objectFilter);
if (obj != null)
baseObjectId = obj.getObjectId();
else
baseObjectId = 0;
}
List<DciSummaryTableColumn> columns = new ArrayList<DciSummaryTableColumn>();
for (int i = 0; i < columnFilter.length(); i++) {
JSONObject obj = columnFilter.getJSONObject(i);
columns.add(new DciSummaryTableColumn(JsonTools.getStringFromJson(obj, "columnName", ""), JsonTools.getStringFromJson(obj, "dciName", ""), JsonTools.getBooleanFromJson(obj, "isRegexp", false) ? DciSummaryTableColumn.REGEXP_MATCH : 0));
}
AggregationFunction agrFunc = JsonTools.getEnumFromJson(data, AggregationFunction.class, "aggregationFunction", null);
Date startDate;
Date endDate;
long date = JsonTools.getLongFromJson(data, "startDate", -1);
startDate = date > 0 ? new Date(date * 1000) : null;
date = JsonTools.getLongFromJson(data, "endDate", -1);
endDate = date > 0 ? new Date(date * 1000) : null;
// end date
boolean multiInstance = JsonTools.getBooleanFromJson(data, "multiInstance", true);
Table table = session.queryAdHocDciSummaryTable(baseObjectId, columns, agrFunc, startDate, endDate, multiInstance);
// create json
JSONObject root = new JSONObject();
JSONArray columnList = new JSONArray();
JSONArray rowList = new JSONArray();
String[] names = table.getColumnDisplayNames();
for (int i = 0; i < names.length; i++) columnList.put(names[i]);
root.put("columns", columnList);
TableRow[] rows = table.getAllRows();
for (int i = 0; i < rows.length; i++) {
JSONArray row = new JSONArray();
for (int j = 0; j < rows[i].size(); j++) row.put(rows[i].get(j).getValue());
rowList.put(row);
}
root.put("rows", rowList);
return new ResponseContainer("table", root);
}
use of org.netxms.client.TableRow in project netxms by netxms.
the class SummaryTableWidget method forcePoll.
/**
* @param pollAll
*/
private void forcePoll(boolean pollAll) {
IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
if (selection.isEmpty())
return;
final List<PollRequest> requests = new ArrayList<PollRequest>();
for (Object o : selection.toList()) {
TableRow r = (TableRow) o;
long nodeId = r.getObjectId();
if (pollAll) {
int count = ((Table) viewer.getInput()).getColumnCount();
for (int i = 1; i < count; i++) {
long dciId = r.get(i).getObjectId();
if (dciId != 0) {
requests.add(new PollRequest(nodeId, dciId));
}
}
} else {
int index = ((Table) viewer.getInput()).getColumnIndex(currentColumn.getText());
long dciId = r.get(index).getObjectId();
if (dciId != 0) {
requests.add(new PollRequest(nodeId, dciId));
}
}
}
if (requests.isEmpty())
return;
final NXCSession session = ConsoleSharedData.getSession();
new ConsoleJob(Messages.get().SummaryTableWidget_ForceDciPoll, viewPart, Activator.PLUGIN_ID, null) {
@Override
protected void runInternal(IProgressMonitor monitor) throws Exception {
monitor.beginTask(Messages.get().SummaryTableWidget_DciPoll, requests.size());
for (PollRequest r : requests) {
session.forceDCIPoll(r.nodeId, r.dciId);
monitor.worked(1);
}
monitor.done();
runInUIThread(new Runnable() {
@Override
public void run() {
refresh();
}
});
}
@Override
protected String getErrorMessage() {
return Messages.get().SummaryTableWidget_13;
}
}.start();
}
use of org.netxms.client.TableRow in project netxms by netxms.
the class AlarmLogViewer method createIssue.
/**
* Create helpdesk ticket (issue) from selected alarms
*/
private void createIssue() {
IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
if (selection.size() != 1)
return;
final long id = Long.parseLong(((TableRow) selection.getFirstElement()).get(0).getValue());
new ConsoleJob("Create helpdesk ticket", this, Activator.PLUGIN_ID, JOB_FAMILY) {
@Override
protected void runInternal(IProgressMonitor monitor) throws Exception {
session.openHelpdeskIssue(id);
}
@Override
protected String getErrorMessage() {
return "Cannot create helpdesk ticket from alarm";
}
}.start();
}
use of org.netxms.client.TableRow in project netxms by netxms.
the class AlarmLogViewer method unlinkIssue.
/**
* Unlink helpdesk ticket (issue) from selected alarm
*/
private void unlinkIssue() {
IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
if (selection.size() != 1)
return;
final long id = Long.parseLong(((TableRow) selection.getFirstElement()).get(0).getValue());
new ConsoleJob("Unlink alarm from helpdesk ticket", this, Activator.PLUGIN_ID, JOB_FAMILY) {
@Override
protected void runInternal(IProgressMonitor monitor) throws Exception {
session.unlinkHelpdeskIssue(id);
}
@Override
protected String getErrorMessage() {
return "Cannot unlink alarm from helpdesk ticket";
}
}.start();
}
use of org.netxms.client.TableRow in project netxms by netxms.
the class TableComparisonChartElement method updateChart.
/**
* Update chart with new data
*
* @param data
*/
private void updateChart(final Table data) {
// FIXME //$NON-NLS-1$
String instanceColumn = (config.getInstanceColumn() != null) ? config.getInstanceColumn() : "";
if (instanceColumn == null)
return;
final int icIndex = data.getColumnIndex(instanceColumn);
final int dcIndex = data.getColumnIndex(config.getDataColumn());
if ((icIndex == -1) || (dcIndex == -1))
// at least one column is missing
return;
if (config.isSortOnDataColumn()) {
data.sort(new Comparator<TableRow>() {
@Override
public int compare(TableRow row1, TableRow row2) {
TableCell c1 = row1.get(dcIndex);
TableCell c2 = row2.get(dcIndex);
String s1 = (c1 != null) ? c1.getValue() : "";
String s2 = (c2 != null) ? c2.getValue() : "";
int result = 0;
try {
double value1 = Double.parseDouble(s1);
double value2 = Double.parseDouble(s2);
result = Double.compare(value1, value2);
} catch (NumberFormatException e) {
result = s1.compareToIgnoreCase(s2);
}
return config.isSortDescending() ? -result : result;
}
});
// Sorting may reorder instances, so clear everything
instanceMap.clear();
chart.removeAllParameters();
}
boolean rebuild = false;
for (int i = 0; i < data.getRowCount(); i++) {
String instance = data.getCellValue(i, icIndex);
if (instance == null)
continue;
double value;
try {
value = Double.parseDouble(data.getCellValue(i, dcIndex));
} catch (NumberFormatException e) {
value = 0.0;
}
Integer index = instanceMap.get(instance);
if (index == null) {
if ((instanceMap.size() >= DataChart.MAX_CHART_ITEMS) || ((value == 0) && config.isIgnoreZeroValues()))
continue;
// $NON-NLS-1$
index = chart.addParameter(new GraphItem(config.getNodeId(), config.getDciId(), 0, DataType.INT32, Long.toString(config.getDciId()), instance, "%s"), 0.0);
instanceMap.put(instance, index);
rebuild = true;
}
chart.updateParameter(index, value, false);
}
if (!chartInitialized) {
chart.initializationComplete();
chartInitialized = true;
} else {
if (rebuild)
chart.rebuild();
else
chart.refresh();
}
}
Aggregations