use of org.opennms.netmgt.model.OnmsCategory in project opennms by OpenNMS.
the class NodeRestService method removeCategoryFromNode.
@DELETE
@Path("/{nodeCriteria}/categories/{categoryName}")
public Response removeCategoryFromNode(@PathParam("nodeCriteria") String nodeCriteria, @PathParam("categoryName") String categoryName) {
writeLock();
try {
OnmsNode node = m_nodeDao.get(nodeCriteria);
if (node == null) {
throw getException(Status.BAD_REQUEST, "Node {} was not found.", nodeCriteria);
}
OnmsCategory category = getCategory(node, categoryName);
if (category == null) {
throw getException(Status.BAD_REQUEST, "Category {} not found on node {}", categoryName, nodeCriteria);
}
LOG.debug("deleteCaegory: deleting category {} from node {}", categoryName, nodeCriteria);
node.getCategories().remove(category);
m_nodeDao.saveOrUpdate(node);
return Response.noContent().build();
} finally {
writeUnlock();
}
}
use of org.opennms.netmgt.model.OnmsCategory in project opennms by OpenNMS.
the class NodeRestService method updateCategoryForNode.
@PUT
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Path("/{nodeCriteria}/categories/{categoryName}")
public Response updateCategoryForNode(@PathParam("nodeCriteria") final String nodeCriteria, @PathParam("categoryName") final String categoryName, MultivaluedMapImpl params) {
writeLock();
try {
OnmsNode node = m_nodeDao.get(nodeCriteria);
if (node == null) {
throw getException(Status.BAD_REQUEST, "Node {} was not found.", nodeCriteria);
}
OnmsCategory category = getCategory(node, categoryName);
if (category == null) {
throw getException(Status.BAD_REQUEST, "Category {} not found on node {}", categoryName, nodeCriteria);
}
LOG.debug("updateCategory: updating category {}", category);
BeanWrapper wrapper = PropertyAccessorFactory.forBeanPropertyAccess(category);
boolean updated = false;
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);
updated = true;
}
}
if (updated) {
LOG.debug("updateCategory: category {} updated", category);
m_categoryDao.saveOrUpdate(category);
} else {
LOG.debug("updateCategory: no fields updated in category {}", category);
}
return Response.noContent().build();
} finally {
writeUnlock();
}
}
use of org.opennms.netmgt.model.OnmsCategory 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());
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.OnmsCategory in project opennms by OpenNMS.
the class AvailabilityDatabasePopulator method getCategory.
private OnmsCategory getCategory(String categoryName) {
OnmsCategory cat = getCategoryDao().findByName(categoryName);
if (cat == null) {
cat = new OnmsCategory(categoryName);
cat.getAuthorizedGroups().add(categoryName + "Group");
getCategoryDao().save(cat);
getCategoryDao().flush();
}
return cat;
}
use of org.opennms.netmgt.model.OnmsCategory in project opennms by OpenNMS.
the class DatabasePopulator method doResetDatabase.
private void doResetDatabase() {
LOG.debug("==== DatabasePopulator Reset ====");
for (final OnmsOutage outage : m_outageDao.findAll()) {
m_outageDao.delete(outage);
}
for (final OnmsUserNotification not : m_userNotificationDao.findAll()) {
m_userNotificationDao.delete(not);
}
for (final OnmsNotification not : m_notificationDao.findAll()) {
m_notificationDao.delete(not);
}
for (final OnmsAlarm alarm : m_alarmDao.findAll()) {
m_alarmDao.delete(alarm);
}
for (final OnmsEvent event : m_eventDao.findAll()) {
m_eventDao.delete(event);
}
for (final OnmsSnmpInterface snmpIface : m_snmpInterfaceDao.findAll()) {
for (OnmsIpInterface eachIf : snmpIface.getIpInterfaces()) {
eachIf.setSnmpInterface(null);
snmpIface.getNode().getIpInterfaces().remove(eachIf);
}
snmpIface.getNode().getSnmpInterfaces().remove(snmpIface);
m_snmpInterfaceDao.delete(snmpIface);
}
for (final OnmsIpInterface iface : m_ipInterfaceDao.findAll()) {
iface.setSnmpInterface(null);
iface.getNode().getIpInterfaces().remove(iface);
m_ipInterfaceDao.delete(iface);
}
for (final OnmsNode node : m_nodeDao.findAll()) {
m_nodeDao.delete(node);
}
for (final OnmsServiceType service : m_serviceTypeDao.findAll()) {
m_serviceTypeDao.delete(service);
}
for (final OnmsMonitoringLocation location : m_monitoringLocationDao.findAll()) {
// Don't delete the default localhost monitoring location
if (!MonitoringLocationDao.DEFAULT_MONITORING_LOCATION_ID.equals(location.getLocationName())) {
m_monitoringLocationDao.delete(location);
}
}
for (final OnmsCategory category : m_categoryDao.findAll()) {
m_categoryDao.delete(category);
}
LOG.debug("= DatabasePopulatorExtension Reset Starting =");
for (Extension eachExtension : extensions) {
DaoSupport daoSupport = eachExtension.getDaoSupport();
OnmsDao<?, ?> dao = daoSupport != null && daoSupport.getDaoClass() != null ? lookupDao(daoSupport.getDaoClass()) : null;
eachExtension.onShutdown(this, dao);
if (dao != null) {
dao.flush();
}
}
LOG.debug("= DatabasePopulatorExtension Reset Finished =");
m_outageDao.flush();
m_userNotificationDao.flush();
m_notificationDao.flush();
m_alarmDao.flush();
m_eventDao.flush();
m_snmpInterfaceDao.flush();
m_ipInterfaceDao.flush();
m_nodeDao.flush();
m_serviceTypeDao.flush();
LOG.debug("==== DatabasePopulator Reset Finished ====");
}
Aggregations