use of org.opennms.netmgt.model.OnmsGeolocation in project opennms by OpenNMS.
the class NodeCacheImpl method populateBodyWithNodeInfo.
/**
* utility method to populate a Map with the most import node attributes
*
* @param body the map
* @param node the node object
*/
private static void populateBodyWithNodeInfo(Map<String, String> body, OnmsNode node) {
body.put("nodelabel", node.getLabel());
body.put("nodesysname", node.getSysName());
body.put("nodesyslocation", node.getSysLocation());
body.put("foreignsource", node.getForeignSource());
body.put("foreignid", node.getForeignId());
body.put("operatingsystem", node.getOperatingSystem());
final StringBuilder categories = new StringBuilder();
for (Iterator<OnmsCategory> i = node.getCategories().iterator(); i.hasNext(); ) {
categories.append(((OnmsCategory) i.next()).getName());
if (i.hasNext()) {
categories.append(",");
}
}
body.put("categories", categories.toString());
if (archiveAssetData) {
// parent information
OnmsNode parent = node.getParent();
if (parent != null) {
if (parent.getLabel() != null)
body.put("parent-nodelabel", parent.getLabel());
if (parent.getNodeId() != null)
body.put("parent-nodeid", parent.getNodeId());
if (parent.getForeignSource() != null)
body.put("parent-foreignsource", parent.getForeignSource());
if (parent.getForeignId() != null)
body.put("parent-foreignid", parent.getForeignId());
}
// assetRecord.
OnmsAssetRecord assetRecord = node.getAssetRecord();
if (assetRecord != null) {
// geolocation
OnmsGeolocation gl = assetRecord.getGeolocation();
if (gl != null) {
if (gl.getLatitude() != null)
body.put("asset-latitude", gl.getLatitude().toString());
if (gl.getLongitude() != null)
body.put("asset-longitude", gl.getLongitude().toString());
}
// assetRecord
if (assetRecord.getRegion() != null && !"".equals(assetRecord.getRegion()))
body.put("asset-region", assetRecord.getRegion());
if (assetRecord.getBuilding() != null && !"".equals(assetRecord.getBuilding()))
body.put("asset-building", assetRecord.getBuilding());
if (assetRecord.getFloor() != null && !"".equals(assetRecord.getFloor()))
body.put("asset-floor", assetRecord.getFloor());
if (assetRecord.getRoom() != null && !"".equals(assetRecord.getRoom()))
body.put("asset-room", assetRecord.getRoom());
if (assetRecord.getRack() != null && !"".equals(assetRecord.getRack()))
body.put("asset-rack", assetRecord.getRack());
if (assetRecord.getSlot() != null && !"".equals(assetRecord.getSlot()))
body.put("asset-slot", assetRecord.getSlot());
if (assetRecord.getPort() != null && !"".equals(assetRecord.getPort()))
body.put("asset-port", assetRecord.getPort());
if (assetRecord.getCategory() != null && !"".equals(assetRecord.getCategory()))
body.put("asset-category", assetRecord.getCategory());
if (assetRecord.getDisplayCategory() != null && !"".equals(assetRecord.getDisplayCategory()))
body.put("asset-displaycategory", assetRecord.getDisplayCategory());
if (assetRecord.getNotifyCategory() != null && !"".equals(assetRecord.getNotifyCategory()))
body.put("asset-notifycategory", assetRecord.getNotifyCategory());
if (assetRecord.getPollerCategory() != null && !"".equals(assetRecord.getPollerCategory()))
body.put("asset-pollercategory", assetRecord.getPollerCategory());
if (assetRecord.getThresholdCategory() != null && !"".equals(assetRecord.getThresholdCategory()))
body.put("asset-thresholdcategory", assetRecord.getThresholdCategory());
if (assetRecord.getManagedObjectType() != null && !"".equals(assetRecord.getManagedObjectType()))
body.put("asset-managedobjecttype", assetRecord.getManagedObjectType());
if (assetRecord.getManagedObjectInstance() != null && !"".equals(assetRecord.getManagedObjectInstance()))
body.put("asset-managedobjectinstance", assetRecord.getManagedObjectInstance());
if (assetRecord.getManufacturer() != null && !"".equals(assetRecord.getManufacturer()))
body.put("asset-manufacturer", assetRecord.getManufacturer());
if (assetRecord.getVendor() != null && !"".equals(assetRecord.getVendor()))
body.put("asset-vendor", assetRecord.getVendor());
if (assetRecord.getModelNumber() != null && !"".equals(assetRecord.getModelNumber()))
body.put("asset-modelnumber", assetRecord.getModelNumber());
}
}
}
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.715723);
geolocation.setLongitude(-79.162261);
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 NodeRestService method updateNode.
/**
* <p>updateNode</p>
*
* @param nodeCriteria a {@link java.lang.String} object.
* @param params a {@link org.opennms.web.rest.support.MultivaluedMapImpl} object.
* @return a {@link javax.ws.rs.core.Response} object.
*/
@PUT
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Path("{nodeCriteria}")
public Response updateNode(@PathParam("nodeCriteria") final String nodeCriteria, final MultivaluedMapImpl params) {
writeLock();
try {
final OnmsNode node = m_nodeDao.get(nodeCriteria);
if (node == null)
throw getException(Status.BAD_REQUEST, "Node {} was not found.", nodeCriteria);
if (node.getAssetRecord().getGeolocation() == null) {
node.getAssetRecord().setGeolocation(new OnmsGeolocation());
}
LOG.debug("updateNode: updating node {}", node);
boolean modified = false;
final BeanWrapper wrapper = PropertyAccessorFactory.forBeanPropertyAccess(node);
for (final String key : params.keySet()) {
if (wrapper.isWritableProperty(key)) {
final String stringValue = params.getFirst(key);
final Object value = wrapper.convertIfNecessary(stringValue, (Class<?>) wrapper.getPropertyType(key));
wrapper.setPropertyValue(key, value);
modified = true;
}
}
if (modified) {
LOG.debug("updateNode: node {} updated", node);
m_nodeDao.saveOrUpdate(node);
return Response.noContent().build();
}
return Response.notModified().build();
} finally {
writeUnlock();
}
}
use of org.opennms.netmgt.model.OnmsGeolocation in project opennms by OpenNMS.
the class GeolocationProvisioningAdapter method updateGeolocation.
protected void updateGeolocation(GeolocationResolver geolocationResolver, OnmsNode node) {
Objects.requireNonNull(geolocationResolver);
Objects.requireNonNull(node);
// Only resolve long/lat if not already set and an address is set
final OnmsGeolocation geolocation = node.getAssetRecord().getGeolocation();
if (geolocation != null && geolocation.getLatitude() == null && geolocation.getLatitude() == null && !Strings.isNullOrEmpty(geolocation.asAddressString())) {
final Coordinates coordinates = geolocationResolver.resolve(geolocation.asAddressString());
if (coordinates != null) {
geolocation.setLongitude(coordinates.getLongitude());
geolocation.setLatitude(coordinates.getLatitude());
nodeDao.saveOrUpdate(node);
} else {
LOG.warn("Could not resolve address string '{}' for node with id {}", geolocation.asAddressString(), node.getId());
}
}
}
use of org.opennms.netmgt.model.OnmsGeolocation in project opennms by OpenNMS.
the class AssetRecordResource method updateAssetRecord.
/**
* <p>updateAssetRecord</p>
*
* @param nodeCriteria a {@link java.lang.String} object.
* @param params a {@link org.opennms.web.rest.support.MultivaluedMapImpl} object.
* @return a {@link javax.ws.rs.core.Response} object.
*/
@PUT
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
public Response updateAssetRecord(@PathParam("nodeCriteria") final String nodeCriteria, final MultivaluedMapImpl params) {
OnmsNode node = m_nodeDao.get(nodeCriteria);
if (node == null) {
throw getException(Status.BAD_REQUEST, "updateAssetRecord: Can't find node " + nodeCriteria);
}
OnmsAssetRecord assetRecord = getAssetRecord(node);
if (assetRecord == null) {
throw getException(Status.BAD_REQUEST, "updateAssetRecord: Node " + node + " could not update ");
}
if (assetRecord.getGeolocation() == null) {
assetRecord.setGeolocation(new OnmsGeolocation());
}
LOG.debug("updateAssetRecord: updating asset {}", assetRecord);
boolean modified = false;
BeanWrapper wrapper = PropertyAccessorFactory.forBeanPropertyAccess(assetRecord);
wrapper.registerCustomEditor(Date.class, new ISO8601DateEditor());
for (String key : params.keySet()) {
if (wrapper.isWritableProperty(key)) {
String stringValue = params.getFirst(key);
Object value = wrapper.convertIfNecessary(stringValue, (Class<?>) wrapper.getPropertyType(key));
wrapper.setPropertyValue(key, value);
modified = true;
}
}
if (modified) {
LOG.debug("updateAssetRecord: assetRecord {} updated", assetRecord);
node.setAssetRecord(assetRecord);
m_nodeDao.saveOrUpdate(node);
try {
sendEvent(EventConstants.ASSET_INFO_CHANGED_EVENT_UEI, node.getId());
} catch (EventProxyException e) {
throw getException(Status.INTERNAL_SERVER_ERROR, e.getMessage());
}
return Response.noContent().build();
}
return Response.notModified().build();
}
Aggregations