Search in sources :

Example 6 with GeolocationInfo

use of org.opennms.features.geolocation.api.GeolocationInfo in project opennms by OpenNMS.

the class DefaultGeolocationServiceIT method verifyMerging.

@Test
@Transactional
public void verifyMerging() {
    // Set coordinates for all
    nodeDao.findAll().forEach(n -> {
        n.getAssetRecord().getGeolocation().setLongitude(coordinates.getLongitude());
        n.getAssetRecord().getGeolocation().setLatitude(coordinates.getLatitude());
        nodeDao.saveOrUpdate(n);
    });
    // Query
    GeolocationQuery query = new GeolocationQueryBuilder().withStatusCalculationStrategy(StatusCalculationStrategy.Alarms).build();
    // We do not have any alarms, therefore all nodes should be "NORMAL"
    List<GeolocationInfo> locations = geolocationService.getLocations(query);
    Assert.assertEquals(nodeDao.countAll(), locations.size());
    locations.forEach(l -> Assert.assertEquals("Normal", l.getSeverityInfo().getLabel()));
    // Add an alarm for one node and try again
    alarmDao.save(TestUtils.createAlarm(databasePopulator.getNode1(), OnmsSeverity.MAJOR, distPollerDao.whoami()));
    locations = geolocationService.getLocations(query);
    Assert.assertEquals(nodeDao.countAll(), locations.size());
    locations.forEach(l -> {
        if (l.getNodeInfo().getNodeId() == databasePopulator.getNode1().getId()) {
            Assert.assertEquals("Major", l.getSeverityInfo().getLabel());
        } else {
            Assert.assertEquals("Normal", l.getSeverityInfo().getLabel());
        }
    });
}
Also used : GeolocationQueryBuilder(org.opennms.features.geolocation.api.GeolocationQueryBuilder) GeolocationQuery(org.opennms.features.geolocation.api.GeolocationQuery) GeolocationInfo(org.opennms.features.geolocation.api.GeolocationInfo) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 7 with GeolocationInfo

use of org.opennms.features.geolocation.api.GeolocationInfo in project opennms by OpenNMS.

the class LocationInfoPanelItemProvider method getContributions.

@Override
public Collection<? extends InfoPanelItem> getContributions(GraphContainer container) {
    final List<Vertex> vertices = new ArrayList<>(container.getGraph().getDisplayVertices());
    final Set<Integer> nodeIds = vertices.stream().filter(v -> v.getNodeID() != null).map(v -> v.getNodeID()).collect(Collectors.toSet());
    if (nodeIds.isEmpty()) {
        return Collections.emptyList();
    }
    final List<GeolocationInfo> locations = geolocationService.getLocations(new GeolocationQueryBuilder().withNodeIds(nodeIds).withStatusCalculationStrategy(StatusCalculationStrategy.None).build());
    final List<Marker> markers = locations.stream().filter(locationInfo -> locationInfo.getCoordinates() != null).map(locationInfo -> {
        final Vertex vertex = vertices.stream().filter(v -> v.getNodeID() != null && locationInfo.getNodeInfo().getNodeId() == v.getNodeID()).findFirst().get();
        return new Marker(locationInfo.getCoordinates(), createTooltip(vertex, locationInfo.getAddressInfo()), container.getSelectionManager().isVertexRefSelected(vertex));
    }).collect(Collectors.toList());
    if (!markers.isEmpty()) {
        final LocationConfiguration config = new LocationConfiguration().withTileLayer(geolocationConfiguration.getTileServerUrl()).withMarker(markers).withInitialZoom(10).withLayerOptions(geolocationConfiguration.getOptions());
        final LocationComponent locationComponent = new LocationComponent(config, "mapId-" + getClass().getSimpleName().toLowerCase());
        locationComponent.setWidth(300, Sizeable.Unit.PIXELS);
        locationComponent.setHeight(300, Sizeable.Unit.PIXELS);
        return Collections.singleton(new DefaultInfoPanelItem().withTitle(String.format("Geolocation (%d/%d)", markers.size(), vertices.size())).withOrder(1).withComponent(locationComponent));
    }
    return Collections.emptyList();
}
Also used : AddressInfo(org.opennms.features.geolocation.api.AddressInfo) GraphContainer(org.opennms.features.topology.api.GraphContainer) GeolocationConfiguration(org.opennms.features.geolocation.api.GeolocationConfiguration) Collection(java.util.Collection) InfoPanelItem(org.opennms.features.topology.api.info.item.InfoPanelItem) Vertex(org.opennms.features.topology.api.topo.Vertex) Set(java.util.Set) LocationConfiguration(org.opennms.features.topology.app.internal.ui.geographical.LocationConfiguration) Marker(org.opennms.features.topology.app.internal.ui.geographical.Marker) LocationComponent(org.opennms.features.topology.app.internal.ui.geographical.LocationComponent) Collectors(java.util.stream.Collectors) Sizeable(com.vaadin.server.Sizeable) GeolocationQueryBuilder(org.opennms.features.geolocation.api.GeolocationQueryBuilder) ArrayList(java.util.ArrayList) Strings(com.google.common.base.Strings) List(java.util.List) GeolocationInfo(org.opennms.features.geolocation.api.GeolocationInfo) DefaultInfoPanelItem(org.opennms.features.topology.api.info.item.DefaultInfoPanelItem) StatusCalculationStrategy(org.opennms.features.geolocation.api.StatusCalculationStrategy) InfoPanelItemProvider(org.opennms.features.topology.api.info.InfoPanelItemProvider) Collections(java.util.Collections) GeolocationService(org.opennms.features.geolocation.api.GeolocationService) Vertex(org.opennms.features.topology.api.topo.Vertex) ArrayList(java.util.ArrayList) Marker(org.opennms.features.topology.app.internal.ui.geographical.Marker) LocationComponent(org.opennms.features.topology.app.internal.ui.geographical.LocationComponent) DefaultInfoPanelItem(org.opennms.features.topology.api.info.item.DefaultInfoPanelItem) LocationConfiguration(org.opennms.features.topology.app.internal.ui.geographical.LocationConfiguration) GeolocationQueryBuilder(org.opennms.features.geolocation.api.GeolocationQueryBuilder) GeolocationInfo(org.opennms.features.geolocation.api.GeolocationInfo)

Aggregations

GeolocationInfo (org.opennms.features.geolocation.api.GeolocationInfo)7 GeolocationQuery (org.opennms.features.geolocation.api.GeolocationQuery)4 GeolocationService (org.opennms.features.geolocation.api.GeolocationService)4 ArrayList (java.util.ArrayList)3 List (java.util.List)3 Set (java.util.Set)3 Collectors (java.util.stream.Collectors)3 AddressInfo (org.opennms.features.geolocation.api.AddressInfo)3 Coordinates (org.opennms.features.geolocation.api.Coordinates)3 GeolocationQueryBuilder (org.opennms.features.geolocation.api.GeolocationQueryBuilder)3 NodeInfo (org.opennms.features.geolocation.api.NodeInfo)3 StatusCalculationStrategy (org.opennms.features.geolocation.api.StatusCalculationStrategy)3 OnmsGeolocation (org.opennms.netmgt.model.OnmsGeolocation)3 Objects (java.util.Objects)2 CriteriaBuilder (org.opennms.core.criteria.CriteriaBuilder)2 Restrictions (org.opennms.core.criteria.restrictions.Restrictions)2 InetAddressUtils (org.opennms.core.utils.InetAddressUtils)2 GeolocationResolver (org.opennms.features.geolocation.api.GeolocationResolver)2 SeverityInfo (org.opennms.features.geolocation.api.SeverityInfo)2 AlarmStatusCalculator (org.opennms.features.geolocation.services.status.AlarmStatusCalculator)2