use of org.opennms.netmgt.model.OnmsGeolocation 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.netmgt.model.OnmsGeolocation in project opennms by OpenNMS.
the class OpenlayersWidgetCompontentTest method testGeolocation.
@Test
@Ignore
public void testGeolocation() throws Exception {
final OnmsNode node = new OnmsNode();
final OnmsAssetRecord asset = new OnmsAssetRecord();
final OnmsGeolocation geo = new OnmsGeolocation();
node.setId(1);
node.setAssetRecord(asset);
asset.setGeolocation(geo);
geo.setAddress1("220 Chatham Business Dr.");
geo.setCity("Pittsboro");
geo.setState("NC");
geo.setZip("27312");
assertEquals("220 Chatham Business Dr., Pittsboro, NC 27312", geo.asAddressString());
EasyMock.expect(m_geocoder.getCoordinates(geo.asAddressString())).andReturn(new Coordinates(-1.0f, 1.0f)).times(1);
final PaintTarget target = EasyMock.createMock(PaintTarget.class);
m_assetDao.saveOrUpdate(EasyMock.isA(OnmsAssetRecord.class));
target.startTag(EasyMock.eq("1"));
target.addAttribute(EasyMock.eq("longitude"), EasyMock.eq("-1.0"));
target.addAttribute(EasyMock.eq("latitude"), EasyMock.eq("1.0"));
target.endTag(EasyMock.eq("1"));
EasyMock.replay(m_nodeDao, m_assetDao, m_geocoder, target);
// m_component.paintNode(target, node);
EasyMock.verify(m_nodeDao, m_assetDao, m_geocoder, target);
}
use of org.opennms.netmgt.model.OnmsGeolocation in project opennms by OpenNMS.
the class ProvisionerIT method testImportWithGeoData.
@Test(timeout = 300000)
@JUnitTemporaryDatabase
public void testImportWithGeoData() throws Exception {
importFromResource("classpath:/tec_dump.xml", Boolean.TRUE.toString());
final NodeDao nodeDao = getNodeDao();
OnmsNode node = nodeDao.findByForeignId("empty", "4243");
nodeDao.initialize(node.getAssetRecord());
nodeDao.initialize(node.getAssetRecord().getGeolocation());
OnmsGeolocation geolocation = new OnmsGeolocation();
geolocation.setAddress1("220 Chatham Business Dr.");
geolocation.setCity("Pittsboro");
geolocation.setState("NC");
geolocation.setZip("27312");
geolocation.setLatitude(35.715723f);
geolocation.setLongitude(-79.162261f);
node.getAssetRecord().setGeolocation(geolocation);
nodeDao.saveOrUpdate(node);
nodeDao.flush();
node = nodeDao.findByForeignId("empty", "4243");
geolocation = node.getAssetRecord().getGeolocation();
assertNotNull(geolocation.getLatitude());
assertNotNull(geolocation.getLongitude());
assertEquals(Float.valueOf(35.715723f).doubleValue(), geolocation.getLatitude().doubleValue(), 0.1d);
assertEquals(Float.valueOf(-79.162261f).doubleValue(), geolocation.getLongitude().doubleValue(), 0.1d);
System.err.println("=================================================================BLEARGH");
importFromResource("classpath:/tec_dump.xml", Boolean.TRUE.toString());
node = nodeDao.findByForeignId("empty", "4243");
geolocation = node.getAssetRecord().getGeolocation();
// Ensure it is reset
assertNull(geolocation.asAddressString());
assertNull(geolocation.getLatitude());
assertNull(geolocation.getLongitude());
}
use of org.opennms.netmgt.model.OnmsGeolocation in project opennms by OpenNMS.
the class AssetRecordDaoIT method testGeolocation.
@Test
@Transactional
public void testGeolocation() {
OnmsNode onmsNode = new OnmsNode(m_locationDao.getDefaultLocation(), "myNode");
m_nodeDao.save(onmsNode);
OnmsAssetRecord assetRecord = onmsNode.getAssetRecord();
OnmsGeolocation geo = assetRecord.getGeolocation();
if (geo == null) {
geo = new OnmsGeolocation();
assetRecord.setGeolocation(geo);
}
geo.setAddress1("220 Chatham Business Drive");
geo.setCity("Pittsboro");
geo.setState("NC");
geo.setZip("27312");
geo.setCountry("US");
m_assetRecordDao.update(assetRecord);
m_assetRecordDao.flush();
//Test findAll method
int id = assetRecord.getId();
OnmsAssetRecord assetRecordFromDb = m_assetRecordDao.get(id);
assertNotNull(assetRecordFromDb.getGeolocation());
assertEquals(geo.getAddress1(), assetRecordFromDb.getGeolocation().getAddress1());
assertEquals(geo.getCity(), assetRecordFromDb.getGeolocation().getCity());
assertEquals(geo.getState(), assetRecordFromDb.getGeolocation().getState());
assertEquals(geo.getZip(), assetRecordFromDb.getGeolocation().getZip());
assertEquals(geo.getCountry(), assetRecordFromDb.getGeolocation().getCountry());
}
use of org.opennms.netmgt.model.OnmsGeolocation in project opennms by OpenNMS.
the class GeolocationProvisioningAdapterIT method canHandleNullGeolocation.
// See NMS-9187
@Test
public void canHandleNullGeolocation() throws Exception {
// Ensure that the geolocation is null
final OnmsNode node = nodeDao.get(databasePopulator.getNode1().getId());
Assert.assertNull(node.getAssetRecord().getGeolocation());
// Mock the geolocation resolution
final Coordinates coordinates = new Coordinates(-3.179090f, 51.481583f);
final GeolocationResolver geolocationResolverMock = Mockito.mock(GeolocationResolver.class);
Mockito.when(geolocationResolverMock.resolve(Mockito.anyString())).thenReturn(coordinates);
// Manually invoke provisioning adapter
final GeolocationProvisioningAdapter geolocationProvisioningAdapter = new GeolocationProvisioningAdapter();
geolocationProvisioningAdapter.setNodeDao(nodeDao);
geolocationProvisioningAdapter.afterPropertiesSet();
geolocationProvisioningAdapter.updateGeolocation(geolocationResolverMock, node);
// Node should not have been updated
Assert.assertNull(node.getAssetRecord().getGeolocation());
// Set a geolocation and resolve coordinates
node.getAssetRecord().setGeolocation(new OnmsGeolocation());
node.getAssetRecord().getGeolocation().setCity("Cardiff");
nodeDao.saveOrUpdate(node);
geolocationProvisioningAdapter.updateGeolocation(geolocationResolverMock, node);
// Node should have been updated
Assert.assertEquals(coordinates.getLongitude(), node.getAssetRecord().getGeolocation().getLongitude(), 0.001);
Assert.assertEquals(coordinates.getLatitude(), node.getAssetRecord().getGeolocation().getLatitude(), 0.001);
}
Aggregations