Search in sources :

Example 1 with MapNode

use of org.opennms.features.vaadin.nodemaps.internal.gwt.client.MapNode in project opennms by OpenNMS.

the class NodeMapComponentTest method testShowNodes.

@Test
public void testShowNodes() {
    final NodeMapState state = new NodeMapState();
    final NodeMapComponent component = new NodeMapComponent() {

        private static final long serialVersionUID = 1L;

        public NodeMapState getState() {
            return state;
        }
    };
    final Map<Integer, MapNode> entries = new HashMap<>();
    component.showNodes(entries);
    assertEquals(0, state.nodes.size());
    entries.put(1, createMapNode(1, "Foo", 3f, 4f));
    component.showNodes(entries);
    assertEquals(1, state.nodes.size());
    assertEquals("Foo", state.nodes.get(0).getNodeLabel());
    assertEquals(3d, state.nodes.get(0).getLongitude(), 0.1d);
    assertEquals(4d, state.nodes.get(0).getLatitude(), 0.1d);
    entries.put(1, createMapNode(1, "Bar", 6f, 8f));
    component.showNodes(entries);
    assertEquals(1, state.nodes.size());
    assertEquals("Bar", state.nodes.get(0).getNodeLabel());
    assertEquals(6d, state.nodes.get(0).getLongitude(), 0.1d);
    assertEquals(8d, state.nodes.get(0).getLatitude(), 0.1d);
    entries.remove(1);
    component.showNodes(entries);
    assertEquals(0, state.nodes.size());
}
Also used : NodeMapState(org.opennms.features.vaadin.nodemaps.internal.gwt.client.NodeMapState) HashMap(java.util.HashMap) MapNode(org.opennms.features.vaadin.nodemaps.internal.gwt.client.MapNode) Test(org.junit.Test)

Example 2 with MapNode

use of org.opennms.features.vaadin.nodemaps.internal.gwt.client.MapNode in project opennms by OpenNMS.

the class NodeMapComponent method createMapNode.

private static MapNode createMapNode(GeolocationInfo geolocationInfo) {
    final MapNode node = new MapNode();
    // Coordinates
    if (geolocationInfo.getCoordinates() != null) {
        node.setLatitude(geolocationInfo.getCoordinates().getLatitude());
        node.setLongitude(geolocationInfo.getCoordinates().getLongitude());
    }
    // Node Info
    final NodeInfo nodeInfo = geolocationInfo.getNodeInfo();
    node.setNodeId(String.valueOf(nodeInfo.getNodeId()));
    node.setNodeLabel(nodeInfo.getNodeLabel());
    node.setForeignSource(nodeInfo.getForeignSource());
    node.setForeignId(nodeInfo.getForeignId());
    node.setIpAddress(nodeInfo.getIpAddress());
    node.setDescription(nodeInfo.getDescription());
    node.setMaintcontract(nodeInfo.getMaintcontract());
    node.setCategories(new ArrayList<>(nodeInfo.getCategories()));
    // Severity
    node.setSeverityLabel(geolocationInfo.getSeverityInfo().getLabel());
    node.setSeverity(String.valueOf(geolocationInfo.getSeverityInfo().getId()));
    // Count
    node.setUnackedCount(geolocationInfo.getAlarmUnackedCount());
    return node;
}
Also used : NodeInfo(org.opennms.features.geolocation.api.NodeInfo) MapNode(org.opennms.features.vaadin.nodemaps.internal.gwt.client.MapNode)

Example 3 with MapNode

use of org.opennms.features.vaadin.nodemaps.internal.gwt.client.MapNode in project opennms by OpenNMS.

the class NodeMapComponentTest method testStateNotUpdatedWhenNodesAreUnchanged.

@Test
public void testStateNotUpdatedWhenNodesAreUnchanged() {
    final NodeMapState state = new NodeMapState();
    final NodeMapComponent component = new NodeMapComponent() {

        private static final long serialVersionUID = 1L;

        public NodeMapState getState() {
            return state;
        }
    };
    Map<Integer, MapNode> entries = new HashMap<>();
    entries.put(1, createMapNode(1, "Foo", 3f, 4f));
    entries.put(2, createMapNode(2, "Bar", 6f, 7f));
    component.showNodes(entries);
    List<MapNode> stateNodes = state.nodes;
    assertEquals(2, state.nodes.size());
    // Now recreate the entries using new objects and update the component
    entries = new HashMap<>();
    entries.put(1, createMapNode(1, "Foo", 3f, 4f));
    entries.put(2, createMapNode(2, "Bar", 6f, 7f));
    component.showNodes(entries);
    assertSame("An update with the same entries should not update the underlying array.", stateNodes, state.nodes);
}
Also used : NodeMapState(org.opennms.features.vaadin.nodemaps.internal.gwt.client.NodeMapState) HashMap(java.util.HashMap) MapNode(org.opennms.features.vaadin.nodemaps.internal.gwt.client.MapNode) Test(org.junit.Test)

Example 4 with MapNode

use of org.opennms.features.vaadin.nodemaps.internal.gwt.client.MapNode in project opennms by OpenNMS.

the class NodeMapComponentTest method createMapNode.

private MapNode createMapNode(int nodeId, String nodeLabel, float longitude, float latitude) {
    MapNode mapNode = new MapNode();
    mapNode.setNodeId(String.valueOf(nodeId));
    mapNode.setNodeLabel(nodeLabel);
    mapNode.setLongitude(longitude);
    mapNode.setLatitude(latitude);
    return mapNode;
}
Also used : MapNode(org.opennms.features.vaadin.nodemaps.internal.gwt.client.MapNode)

Example 5 with MapNode

use of org.opennms.features.vaadin.nodemaps.internal.gwt.client.MapNode in project opennms by OpenNMS.

the class NodeMapConnector method updateNodes.

private void updateNodes() {
    final List<MapNode> nodes = getState().nodes;
    LOG.info("NodeMapConnector.onStateChanged(): nodes list is now: " + nodes);
    final List<JSNodeMarker> featureCollection = new ArrayList<>();
    if (nodes.isEmpty()) {
        getWidget().setMarkers(featureCollection);
        return;
    }
    for (final MapNode node : nodes) {
        final JSNodeMarker marker = new JSNodeMarker(new LatLng(node.getLatitude(), node.getLongitude()));
        marker.putProperty(JSNodeMarker.Property.NODE_ID, node.getNodeId());
        marker.putProperty(JSNodeMarker.Property.NODE_LABEL, node.getNodeLabel());
        marker.putProperty(JSNodeMarker.Property.FOREIGN_SOURCE, node.getForeignSource());
        marker.putProperty(JSNodeMarker.Property.FOREIGN_ID, node.getForeignId());
        marker.putProperty(JSNodeMarker.Property.DESCRIPTION, node.getDescription());
        marker.putProperty(JSNodeMarker.Property.MAINTCONTRACT, node.getMaintcontract());
        marker.putProperty(JSNodeMarker.Property.IP_ADDRESS, node.getIpAddress());
        marker.putProperty(JSNodeMarker.Property.SEVERITY, node.getSeverity());
        marker.putProperty(JSNodeMarker.Property.SEVERITY_LABEL, node.getSeverityLabel());
        final List<String> categories = node.getCategories();
        if (categories != null) {
            marker.setCategories(categories.toArray(new String[] {}));
        }
        // TODO: Icon handling should be moved to the Widget
        if (m_icons.containsKey(marker.getSeverityLabel())) {
            marker.setIcon(m_icons.get(marker.getSeverityLabel()));
        } else {
            marker.setIcon(m_icons.get("Normal"));
        }
        // TODO: This should be moved to the Widget
        marker.bindPopup(NodeMarkerClusterCallback.getPopupTextForMarker(marker));
        featureCollection.add(marker);
    }
    getWidget().setMarkers(featureCollection);
    getConnection().getLoadingIndicator().hide();
}
Also used : ArrayList(java.util.ArrayList) MapNode(org.opennms.features.vaadin.nodemaps.internal.gwt.client.MapNode) LatLng(org.discotools.gwt.leaflet.client.types.LatLng) JSNodeMarker(org.opennms.features.vaadin.nodemaps.internal.gwt.client.JSNodeMarker)

Aggregations

MapNode (org.opennms.features.vaadin.nodemaps.internal.gwt.client.MapNode)5 HashMap (java.util.HashMap)2 Test (org.junit.Test)2 NodeMapState (org.opennms.features.vaadin.nodemaps.internal.gwt.client.NodeMapState)2 ArrayList (java.util.ArrayList)1 LatLng (org.discotools.gwt.leaflet.client.types.LatLng)1 NodeInfo (org.opennms.features.geolocation.api.NodeInfo)1 JSNodeMarker (org.opennms.features.vaadin.nodemaps.internal.gwt.client.JSNodeMarker)1