use of org.opennms.netmgt.model.OnmsCategory in project opennms by OpenNMS.
the class GroupRestService method getCategoryForGroup.
@GET
@Path("{groupName}/categories/{categoryName}")
public OnmsCategory getCategoryForGroup(@PathParam("groupName") final String groupName, @PathParam("categoryName") final String categoryName) {
// check if group exists.
getOnmsGroup(groupName);
List<OnmsCategory> categories = m_groupService.getAuthorizedCategories(groupName);
for (OnmsCategory eachCategory : categories) {
if (eachCategory.getName().equals(categoryName))
return eachCategory;
}
throw getException(Status.NOT_FOUND, "Category with name '{}' does not exist for group '{}'.", categoryName, groupName);
}
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 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