Search in sources :

Example 16 with AbstractObject

use of org.netxms.client.objects.AbstractObject in project netxms by netxms.

the class ObjectTest method testObjectCreateAndDelete.

public void testObjectCreateAndDelete() throws Exception {
    final NXCSession session = connect();
    session.syncObjects();
    AbstractObject object = session.findObjectById(2);
    assertNotNull(object);
    NXCObjectCreationData cd = new NXCObjectCreationData(AbstractObject.OBJECT_NODE, "TestNode", 2);
    cd.setCreationFlags(NXCObjectCreationData.CF_CREATE_UNMANAGED);
    cd.setIpAddress(new InetAddressEx(InetAddress.getByName("192.168.10.1"), 0));
    long id = session.createObject(cd);
    assertFalse(id == 0);
    // Object update should be received from server
    Thread.sleep(1000);
    object = session.findObjectById(id);
    assertNotNull(object);
    assertEquals("TestNode", object.getObjectName());
    session.deleteObject(id);
    // Object update should be received from server
    Thread.sleep(1000);
    object = session.findObjectById(id);
    assertNull(object);
    session.disconnect();
}
Also used : InetAddressEx(org.netxms.base.InetAddressEx) AbstractObject(org.netxms.client.objects.AbstractObject)

Example 17 with AbstractObject

use of org.netxms.client.objects.AbstractObject in project netxms by netxms.

the class ObjectTest method testObjectSync.

public void testObjectSync() throws Exception {
    final NXCSession session = connect(true);
    session.syncObjects();
    final AbstractObject obj = session.findObjectById(1);
    assertEquals(true, obj != null);
    assertEquals(1, obj.getObjectId());
    assertEquals("Entire Network", obj.getObjectName());
    session.disconnect();
}
Also used : AbstractObject(org.netxms.client.objects.AbstractObject)

Example 18 with AbstractObject

use of org.netxms.client.objects.AbstractObject in project netxms by netxms.

the class SendEventTest method testSendEvent.

public void testSendEvent() throws Exception {
    final NXCSession session = connect();
    session.sendEvent(1, new String[0]);
    session.sendEvent("SYS_NODE_ADDED", new String[0]);
    session.syncObjects();
    for (AbstractObject o : session.getAllObjects()) {
        if (o instanceof Node) {
            session.sendEvent(0, "SYS_SCRIPT_ERROR", o.getObjectId(), new String[] { "test1", "test2", "0" }, "TAG");
            break;
        }
    }
    session.disconnect();
}
Also used : AbstractObject(org.netxms.client.objects.AbstractObject) Node(org.netxms.client.objects.Node)

Example 19 with AbstractObject

use of org.netxms.client.objects.AbstractObject in project netxms by netxms.

the class ServiceTreeModel method addToModel.

/**
 * Add given object and it's appropriate child objects to model
 *
 * @param object NetXMS object
 */
private void addToModel(ServiceTreeElement parent, AbstractObject object, int level) {
    final ServiceTreeElement element = new ServiceTreeElement(parent, object);
    elements.add(element);
    for (AbstractObject o : object.getChildsAsArray()) {
        if ((o instanceof Container) || (o instanceof Node) || (o instanceof Cluster) || (o instanceof Condition)) {
            addToModel(element, o, level + 1);
        }
    }
}
Also used : Condition(org.netxms.client.objects.Condition) Container(org.netxms.client.objects.Container) AbstractObject(org.netxms.client.objects.AbstractObject) Node(org.netxms.client.objects.Node) Cluster(org.netxms.client.objects.Cluster)

Example 20 with AbstractObject

use of org.netxms.client.objects.AbstractObject in project netxms by netxms.

the class ExportDashboard method run.

/* (non-Javadoc)
	 * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
	 */
@Override
public void run(IAction action) {
    if (dashboard == null)
        return;
    final Set<Long> objects = new HashSet<Long>();
    final Map<Long, Long> items = new HashMap<Long, Long>();
    // $NON-NLS-1$
    final StringBuilder xml = new StringBuilder("<dashboard>\n\t<name>");
    xml.append(dashboard.getObjectName());
    // $NON-NLS-1$
    xml.append("</name>\n\t<columns>");
    xml.append(dashboard.getNumColumns());
    // $NON-NLS-1$
    xml.append("</columns>\n\t<options>");
    xml.append(dashboard.getOptions());
    // $NON-NLS-1$
    xml.append("</options>\n\t<elements>\n");
    for (DashboardElement e : dashboard.getElements()) {
        // $NON-NLS-1$
        xml.append("\t\t<dashboardElement>\n\t\t\t<type>");
        xml.append(e.getType());
        // $NON-NLS-1$
        xml.append("</type>\n");
        xml.append(e.getLayout());
        xml.append('\n');
        xml.append(e.getData());
        // $NON-NLS-1$
        xml.append("\n\t\t</dashboardElement>\n");
        DashboardElementConfig config = (DashboardElementConfig) Platform.getAdapterManager().getAdapter(e, DashboardElementConfig.class);
        if (config != null) {
            objects.addAll(config.getObjects());
            items.putAll(config.getDataCollectionItems());
        }
    }
    // $NON-NLS-1$
    xml.append("\t</elements>\n");
    final NXCSession session = (NXCSession) ConsoleSharedData.getSession();
    new ConsoleJob(Messages.get().ExportDashboard_JobTitle, wbPart, Activator.PLUGIN_ID, null) {

        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            // Add object ID mapping
            // $NON-NLS-1$
            xml.append("\t<objectMap>\n");
            for (Long id : objects) {
                AbstractObject o = session.findObjectById(id);
                if (o != null) {
                    // $NON-NLS-1$
                    xml.append("\t\t<object id=\"");
                    xml.append(id);
                    // $NON-NLS-1$
                    xml.append("\" class=\"");
                    xml.append(o.getObjectClass());
                    // $NON-NLS-1$
                    xml.append("\">");
                    xml.append(o.getObjectName());
                    // $NON-NLS-1$
                    xml.append("</object>\n");
                }
            }
            // $NON-NLS-1$
            xml.append("\t</objectMap>\n\t<dciMap>\n");
            // Add DCI ID mapping
            long[] nodeList = new long[items.size()];
            long[] dciList = new long[items.size()];
            int pos = 0;
            for (Entry<Long, Long> dci : items.entrySet()) {
                dciList[pos] = dci.getKey();
                nodeList[pos] = dci.getValue();
                pos++;
            }
            String[] names = session.dciIdsToNames(nodeList, dciList);
            for (int i = 0; i < names.length; i++) {
                // $NON-NLS-1$
                xml.append("\t\t<dci id=\"");
                xml.append(dciList[i]);
                // $NON-NLS-1$
                xml.append("\" node=\"");
                xml.append(nodeList[i]);
                // $NON-NLS-1$
                xml.append("\">");
                xml.append(names[i]);
                // $NON-NLS-1$
                xml.append("</dci>\n");
            }
            // $NON-NLS-1$
            xml.append("\t</dciMap>\n</dashboard>\n");
            // $NON-NLS-1$
            OutputStreamWriter out = new OutputStreamWriter(new FileOutputStream(dashboard.getObjectName() + ".xml"), "UTF-8");
            try {
                out.write(xml.toString());
            } finally {
                out.close();
                final File dashboardFile = new File(dashboard.getObjectName() + ".xml");
                if (dashboardFile.length() > 0) {
                    DownloadServiceHandler.addDownload(dashboardFile.getName(), dashboardFile.getName(), dashboardFile, "application/octet-stream");
                    runInUIThread(new Runnable() {

                        @Override
                        public void run() {
                            DownloadServiceHandler.startDownload(dashboardFile.getName());
                        }
                    });
                }
            }
        }

        @Override
        protected String getErrorMessage() {
            return Messages.get().ExportDashboard_ErrorText;
        }
    }.start();
}
Also used : NXCSession(org.netxms.client.NXCSession) HashMap(java.util.HashMap) DashboardElement(org.netxms.client.dashboards.DashboardElement) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Entry(java.util.Map.Entry) DashboardElementConfig(org.netxms.ui.eclipse.dashboard.widgets.internal.DashboardElementConfig) AbstractObject(org.netxms.client.objects.AbstractObject) FileOutputStream(java.io.FileOutputStream) OutputStreamWriter(java.io.OutputStreamWriter) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) File(java.io.File) HashSet(java.util.HashSet)

Aggregations

AbstractObject (org.netxms.client.objects.AbstractObject)216 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)55 NXCSession (org.netxms.client.NXCSession)51 AbstractNode (org.netxms.client.objects.AbstractNode)31 PartInitException (org.eclipse.ui.PartInitException)27 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)26 ConsoleJob (org.netxms.ui.eclipse.jobs.ConsoleJob)25 Cluster (org.netxms.client.objects.Cluster)22 ObjectSelectionDialog (org.netxms.ui.eclipse.objectbrowser.dialogs.ObjectSelectionDialog)22 ArrayList (java.util.ArrayList)20 Node (org.netxms.client.objects.Node)20 GridData (org.eclipse.swt.layout.GridData)18 Composite (org.eclipse.swt.widgets.Composite)18 NetworkMapObject (org.netxms.client.maps.elements.NetworkMapObject)18 GridLayout (org.eclipse.swt.layout.GridLayout)15 Container (org.netxms.client.objects.Container)15 Interface (org.netxms.client.objects.Interface)12 Template (org.netxms.client.objects.Template)12 SelectionEvent (org.eclipse.swt.events.SelectionEvent)11 Point (org.eclipse.swt.graphics.Point)11