Search in sources :

Example 1 with TableRow

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);
}
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 2 with TableRow

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();
}
Also used : Table(org.netxms.client.Table) NXCSession(org.netxms.client.NXCSession) ArrayList(java.util.ArrayList) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Point(org.eclipse.swt.graphics.Point) PartInitException(org.eclipse.ui.PartInitException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) TableRow(org.netxms.client.TableRow) AbstractObject(org.netxms.client.objects.AbstractObject) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob)

Example 3 with TableRow

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();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) TableRow(org.netxms.client.TableRow) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) IOException(java.io.IOException) NXCException(org.netxms.client.NXCException)

Example 4 with TableRow

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();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) TableRow(org.netxms.client.TableRow) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) IOException(java.io.IOException) NXCException(org.netxms.client.NXCException)

Example 5 with TableRow

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();
    }
}
Also used : TableCell(org.netxms.client.TableCell) TableRow(org.netxms.client.TableRow) GraphItem(org.netxms.client.datacollection.GraphItem) Point(org.eclipse.swt.graphics.Point)

Aggregations

TableRow (org.netxms.client.TableRow)10 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)5 ArrayList (java.util.ArrayList)4 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)4 TableCell (org.netxms.client.TableCell)4 ConsoleJob (org.netxms.ui.eclipse.jobs.ConsoleJob)4 IOException (java.io.IOException)3 Point (org.eclipse.swt.graphics.Point)3 NXCException (org.netxms.client.NXCException)3 AbstractObject (org.netxms.client.objects.AbstractObject)3 NXCSession (org.netxms.client.NXCSession)2 Table (org.netxms.client.Table)2 URL (java.net.URL)1 Date (java.util.Date)1 IDialogSettings (org.eclipse.jface.dialogs.IDialogSettings)1 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)1 DisposeEvent (org.eclipse.swt.events.DisposeEvent)1 DisposeListener (org.eclipse.swt.events.DisposeListener)1 PartInitException (org.eclipse.ui.PartInitException)1 IWebBrowser (org.eclipse.ui.browser.IWebBrowser)1