Search in sources :

Example 1 with OnmsGeolocation

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;
}
Also used : NodeInfo(org.opennms.features.geolocation.api.NodeInfo) Coordinates(org.opennms.features.geolocation.api.Coordinates) GeolocationInfo(org.opennms.features.geolocation.api.GeolocationInfo) OnmsGeolocation(org.opennms.netmgt.model.OnmsGeolocation)

Example 2 with OnmsGeolocation

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);
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsAssetRecord(org.opennms.netmgt.model.OnmsAssetRecord) Coordinates(org.opennms.features.geocoder.Coordinates) PaintTarget(com.vaadin.server.PaintTarget) OnmsGeolocation(org.opennms.netmgt.model.OnmsGeolocation) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 3 with OnmsGeolocation

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());
}
Also used : MockNodeDao(org.opennms.netmgt.dao.mock.MockNodeDao) NodeDao(org.opennms.netmgt.dao.api.NodeDao) OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsGeolocation(org.opennms.netmgt.model.OnmsGeolocation) Test(org.junit.Test) JUnitTemporaryDatabase(org.opennms.core.test.db.annotations.JUnitTemporaryDatabase)

Example 4 with OnmsGeolocation

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());
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsAssetRecord(org.opennms.netmgt.model.OnmsAssetRecord) OnmsGeolocation(org.opennms.netmgt.model.OnmsGeolocation) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 5 with OnmsGeolocation

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);
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) Coordinates(org.opennms.features.geolocation.api.Coordinates) GeolocationResolver(org.opennms.features.geolocation.api.GeolocationResolver) OnmsGeolocation(org.opennms.netmgt.model.OnmsGeolocation) Test(org.junit.Test)

Aggregations

OnmsGeolocation (org.opennms.netmgt.model.OnmsGeolocation)10 OnmsNode (org.opennms.netmgt.model.OnmsNode)8 OnmsAssetRecord (org.opennms.netmgt.model.OnmsAssetRecord)5 Test (org.junit.Test)4 Coordinates (org.opennms.features.geolocation.api.Coordinates)3 Consumes (javax.ws.rs.Consumes)2 PUT (javax.ws.rs.PUT)2 OnmsCategory (org.opennms.netmgt.model.OnmsCategory)2 BeanWrapper (org.springframework.beans.BeanWrapper)2 PaintTarget (com.vaadin.server.PaintTarget)1 LinkedHashSet (java.util.LinkedHashSet)1 Path (javax.ws.rs.Path)1 Ignore (org.junit.Ignore)1 JUnitTemporaryDatabase (org.opennms.core.test.db.annotations.JUnitTemporaryDatabase)1 Coordinates (org.opennms.features.geocoder.Coordinates)1 GeolocationInfo (org.opennms.features.geolocation.api.GeolocationInfo)1 GeolocationResolver (org.opennms.features.geolocation.api.GeolocationResolver)1 NodeInfo (org.opennms.features.geolocation.api.NodeInfo)1 NodeDao (org.opennms.netmgt.dao.api.NodeDao)1 MockNodeDao (org.opennms.netmgt.dao.mock.MockNodeDao)1