use of org.netxms.client.NXCSession 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.NXCSession in project netxms by netxms.
the class SummaryTablesDynamicMenu method queryTable.
/**
* Query table using selected base object
*
* @param baseObjectId
* @param tableId
*/
private void queryTable(final long baseObjectId, final int tableId) {
final NXCSession session = (NXCSession) ConsoleSharedData.getSession();
new ConsoleJob(Messages.get().SummaryTablesDynamicMenu_QueryTableJob, null, Activator.PLUGIN_ID, null) {
@Override
protected void runInternal(IProgressMonitor monitor) throws Exception {
final Table results = session.queryDciSummaryTable(tableId, baseObjectId);
runInUIThread(new Runnable() {
@Override
public void run() {
// $NON-NLS-1$
String secondaryId = Integer.toString(tableId) + "&" + Long.toString(baseObjectId);
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
try {
SummaryTable view = (SummaryTable) window.getActivePage().showView(SummaryTable.ID, secondaryId, IWorkbenchPage.VIEW_ACTIVATE);
view.setTable(results);
} catch (PartInitException e) {
MessageDialogHelper.openError(window.getShell(), Messages.get().SummaryTablesDynamicMenu_Error, String.format(Messages.get().SummaryTablesDynamicMenu_CannotOpenView, e.getLocalizedMessage()));
}
}
});
}
@Override
protected String getErrorMessage() {
return Messages.get().SummaryTablesDynamicMenu_CannotReadData;
}
}.start();
}
use of org.netxms.client.NXCSession in project netxms by netxms.
the class CreateInterfraceDci method run.
/**
* @see IActionDelegate#run(IAction)
*/
public void run(IAction action) {
final CreateInterfaceDciDialog dlg = new CreateInterfaceDciDialog(shell, (objects.size() == 1) ? objects.get(0) : null);
if (dlg.open() == Window.OK) {
final List<Interface> ifaces = new ArrayList<Interface>(objects);
// Get set of nodes
final Set<AbstractNode> nodes = new HashSet<AbstractNode>();
for (Interface iface : ifaces) {
AbstractNode node = iface.getParentNode();
if (node != null) {
nodes.add(node);
}
}
// Check what nodes requires DCI list lock
final Map<Long, Boolean> lockRequired = new HashMap<Long, Boolean>(nodes.size());
final IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
for (AbstractNode n : nodes) {
IViewReference ref = page.findViewReference(DataCollectionEditor.ID, Long.toString(n.getObjectId()));
lockRequired.put(n.getObjectId(), !((ref != null) && (ref.getView(false) != null)));
}
final NXCSession session = (NXCSession) ConsoleSharedData.getSession();
new ConsoleJob(Messages.get().CreateInterfraceDci_JobTitle, viewPart, Activator.PLUGIN_ID, null) {
@Override
protected String getErrorMessage() {
return Messages.get().CreateInterfraceDci_JobError;
}
@Override
protected void runInternal(IProgressMonitor monitor) throws Exception {
InterfaceDciInfo[] dciInfo = dlg.getDciInfo();
monitor.beginTask(Messages.get(getDisplay()).CreateInterfraceDci_TaskName, ifaces.size() * dciInfo.length);
for (int i = 0; i < ifaces.size(); i++) {
for (int j = 0; j < dciInfo.length; j++) {
if (dciInfo[j].enabled) {
createInterfaceDci(session, ifaces.get(i), j, dciInfo[j], dlg.getPollingInterval(), dlg.getRetentionTime(), ifaces.size() > 1, lockRequired);
}
monitor.worked(1);
}
}
monitor.done();
}
}.start();
}
}
use of org.netxms.client.NXCSession in project netxms by netxms.
the class RemoveTemplate method run.
/* (non-Javadoc)
* @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
*/
public void run(IAction action) {
final ChildObjectListDialog dlg = new ChildObjectListDialog(shell, parentId, null);
if (dlg.open() == Window.OK) {
final DciRemoveConfirmationDialog dlg2 = new DciRemoveConfirmationDialog(shell);
if (dlg2.open() == Window.OK) {
final NXCSession session = (NXCSession) ConsoleSharedData.getSession();
new ConsoleJob(Messages.get().RemoveTemplate_JobTitle, viewPart, Activator.PLUGIN_ID, null) {
@Override
protected String getErrorMessage() {
return Messages.get().RemoveTemplate_JobError;
}
@Override
protected void runInternal(IProgressMonitor monitor) throws Exception {
List<AbstractObject> objects = dlg.getSelectedObjects();
for (int i = 0; i < objects.size(); i++) session.removeTemplate(parentId, objects.get(i).getObjectId(), dlg2.getRemoveFlag());
}
}.start();
}
}
}
use of org.netxms.client.NXCSession in project netxms by netxms.
the class StartDataRecalculation method run.
/* (non-Javadoc)
* @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
*/
@Override
public void run(IAction action) {
if (objects == null)
return;
if (!MessageDialogHelper.openQuestion(part.getSite().getShell(), "Start Data Recalculation", "Collected values will be re-calculated using stored raw values and current transformation settings. Continue?"))
return;
final NXCSession session = (NXCSession) ConsoleSharedData.getSession();
final Set<DCI> dciToProcess = objects;
new ConsoleJob("Start DCI data recalculation", part, Activator.PLUGIN_ID, null) {
@Override
protected void runInternal(IProgressMonitor monitor) throws Exception {
monitor.beginTask("Start DCI data recalculation", dciToProcess.size());
for (DCI d : dciToProcess) {
session.recalculateDCIValues(d.nodeId, d.dciId);
monitor.worked(1);
}
monitor.done();
}
@Override
protected String getErrorMessage() {
return "Cannot initiate data recalculation";
}
}.start();
}
Aggregations