Search in sources :

Example 21 with NXCSession

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);
}
Also used : NXCSession(org.netxms.client.NXCSession) Table(org.netxms.client.Table) JSONArray(org.json.JSONArray) ArrayList(java.util.ArrayList) Date(java.util.Date) AggregationFunction(org.netxms.client.constants.AggregationFunction) JSONObject(org.json.JSONObject) AbstractObject(org.netxms.client.objects.AbstractObject) TableRow(org.netxms.client.TableRow) DciSummaryTableColumn(org.netxms.client.datacollection.DciSummaryTableColumn) ResponseContainer(org.netxms.websvc.json.ResponseContainer)

Example 22 with NXCSession

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();
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) NXCSession(org.netxms.client.NXCSession) SummaryTable(org.netxms.ui.eclipse.datacollection.views.SummaryTable) Table(org.netxms.client.Table) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) PartInitException(org.eclipse.ui.PartInitException) PartInitException(org.eclipse.ui.PartInitException) SummaryTable(org.netxms.ui.eclipse.datacollection.views.SummaryTable)

Example 23 with NXCSession

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();
    }
}
Also used : NXCSession(org.netxms.client.NXCSession) AbstractNode(org.netxms.client.objects.AbstractNode) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) NXCException(org.netxms.client.NXCException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CreateInterfaceDciDialog(org.netxms.ui.eclipse.datacollection.dialogs.CreateInterfaceDciDialog) IViewReference(org.eclipse.ui.IViewReference) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) Interface(org.netxms.client.objects.Interface) HashSet(java.util.HashSet)

Example 24 with NXCSession

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();
        }
    }
}
Also used : DciRemoveConfirmationDialog(org.netxms.ui.eclipse.datacollection.dialogs.DciRemoveConfirmationDialog) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) NXCSession(org.netxms.client.NXCSession) ChildObjectListDialog(org.netxms.ui.eclipse.objectbrowser.dialogs.ChildObjectListDialog) List(java.util.List) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob)

Example 25 with NXCSession

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();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) NXCSession(org.netxms.client.NXCSession) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob)

Aggregations

NXCSession (org.netxms.client.NXCSession)248 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)167 ConsoleJob (org.netxms.ui.eclipse.jobs.ConsoleJob)163 AbstractObject (org.netxms.client.objects.AbstractObject)54 NXCObjectModificationData (org.netxms.client.NXCObjectModificationData)45 PartInitException (org.eclipse.ui.PartInitException)31 NXCObjectCreationData (org.netxms.client.NXCObjectCreationData)28 List (java.util.List)26 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)22 NXCException (org.netxms.client.NXCException)22 ArrayList (java.util.ArrayList)19 GridData (org.eclipse.swt.layout.GridData)18 GridLayout (org.eclipse.swt.layout.GridLayout)17 Composite (org.eclipse.swt.widgets.Composite)17 CreateObjectDialog (org.netxms.ui.eclipse.objectbrowser.dialogs.CreateObjectDialog)15 AbstractNode (org.netxms.client.objects.AbstractNode)14 ArrayContentProvider (org.eclipse.jface.viewers.ArrayContentProvider)13 IOException (java.io.IOException)11 ObjectSelectionDialog (org.netxms.ui.eclipse.objectbrowser.dialogs.ObjectSelectionDialog)11 SelectionEvent (org.eclipse.swt.events.SelectionEvent)10