use of org.opennms.features.geolocation.api.GeolocationInfo in project opennms by OpenNMS.
the class DefaultGeolocationService method applyStatus.
private void applyStatus(GeolocationQuery query, List<GeolocationInfo> locations) {
final Set<Integer> nodeIds = locations.stream().map(l -> l.getNodeInfo().getNodeId()).collect(Collectors.toSet());
if (!nodeIds.isEmpty()) {
final StatusCalculator calculator = getStatusCalculator(query.getStatusCalculationStrategy());
final Status status = calculator.calculateStatus(query, nodeIds);
// Appliing the calculated status to each location
for (GeolocationInfo info : locations) {
OnmsSeverity severity = status.getSeverity(info.getNodeInfo().getNodeId());
// Therefore for all locations with no status must be set to "NORMAL" in the result
if (severity == null) {
severity = OnmsSeverity.NORMAL;
}
info.setSeverityInfo(new SeverityInfo(severity.getId(), severity.getLabel()));
info.setAlarmUnackedCount(status.getUnacknowledgedAlarmCount(info.getNodeInfo().getNodeId()));
}
}
}
use of org.opennms.features.geolocation.api.GeolocationInfo in project opennms by OpenNMS.
the class DefaultGeolocationService method getLocations.
@Override
public List<GeolocationInfo> getLocations(GeolocationQuery query) {
if (query == null) {
return new ArrayList<>();
}
final List<OnmsNode> nodes = getNodes(query);
final List<GeolocationInfo> nodesWithCoordinates = nodes.stream().filter(n -> geoLocation(n) != null && geoLocation(n).getLongitude() != null && geoLocation(n).getLatitude() != null).filter(n -> geoLocation(n).getLatitude() != Float.NEGATIVE_INFINITY && geoLocation(n).getLongitude() != Float.NEGATIVE_INFINITY).map(node -> convert(node)).collect(Collectors.toList());
if (query.getStatusCalculationStrategy() != null) {
applyStatus(query, nodesWithCoordinates);
}
if (query.getSeverity() != null) {
OnmsSeverity severity = OnmsSeverity.get(query.getSeverity().getId());
return nodesWithCoordinates.stream().filter(n -> severity.getId() <= n.getSeverityInfo().getId()).collect(Collectors.toList());
}
return nodesWithCoordinates;
}
use of org.opennms.features.geolocation.api.GeolocationInfo in project opennms by OpenNMS.
the class DefaultGeolocationService method convert.
private GeolocationInfo convert(OnmsNode node) {
GeolocationInfo geolocationInfo = new GeolocationInfo();
// Coordinates
OnmsGeolocation onmsGeolocation = geoLocation(node);
if (onmsGeolocation != null) {
geolocationInfo.setAddressInfo(toAddressInfo(onmsGeolocation));
if (onmsGeolocation.getLongitude() != null && onmsGeolocation.getLatitude() != null) {
geolocationInfo.setCoordinates(new Coordinates(onmsGeolocation.getLongitude(), onmsGeolocation.getLatitude()));
}
}
// NodeInfo
NodeInfo nodeInfo = new NodeInfo();
nodeInfo.setNodeId(node.getId());
nodeInfo.setNodeLabel(node.getLabel());
nodeInfo.setNodeLabel(node.getLabel());
nodeInfo.setForeignSource(node.getForeignSource());
nodeInfo.setForeignId(node.getForeignId());
nodeInfo.setLocation(node.getLocation().getLocationName());
if (node.getAssetRecord() != null) {
nodeInfo.setDescription(node.getAssetRecord().getDescription());
nodeInfo.setMaintcontract(node.getAssetRecord().getMaintcontract());
}
if (node.getPrimaryInterface() != null) {
nodeInfo.setIpAddress(InetAddressUtils.str(node.getPrimaryInterface().getIpAddress()));
}
nodeInfo.setCategories(node.getCategories().stream().map(c -> c.getName()).collect(Collectors.toList()));
geolocationInfo.setNodeInfo(nodeInfo);
return geolocationInfo;
}
use of org.opennms.features.geolocation.api.GeolocationInfo in project opennms by OpenNMS.
the class NodeMapComponent method refresh.
public void refresh() {
List<GeolocationInfo> locations = geolocationService.getLocations(new GeolocationQueryBuilder().withIncludeAcknowledgedAlarms(false).withStatusCalculationStrategy(StatusCalculationStrategy.Alarms).withSeverity(GeolocationSeverity.Normal).build());
// apply acl filter if enabled
if (m_aclsEnabled) {
Map<Integer, String> nodes = m_nodeDao.getAllLabelsById();
locations = locations.stream().filter(l -> nodes.containsKey(l.getNodeInfo().getNodeId())).collect(Collectors.toList());
}
// Convert
m_activeNodes = locations.stream().map(l -> createMapNode(l)).collect(Collectors.toMap(l -> Integer.valueOf(l.getNodeId()), Function.identity()));
showNodes(m_activeNodes);
}
use of org.opennms.features.geolocation.api.GeolocationInfo in project opennms by OpenNMS.
the class GeolocationRestService method getLocations.
@POST
@Path("/")
public Response getLocations(GeolocationQueryDTO queryDTO) {
final GeolocationService service = getServiceRegistry().findProvider(GeolocationService.class);
if (service == null) {
return temporarilyNotAvailable();
}
try {
validate(queryDTO);
GeolocationQuery query = toQuery(queryDTO);
final List<GeolocationInfo> locations = service.getLocations(query);
if (locations.isEmpty()) {
return Response.noContent().build();
}
return Response.ok(locations).build();
} catch (InvalidQueryException ex) {
return Response.status(Response.Status.BAD_REQUEST).entity(ex.getMessage()).build();
}
}
Aggregations