use of org.opennms.netmgt.model.OnmsCategory in project opennms by OpenNMS.
the class ProvisionerIT method testRequisitionedCategoriesWithUserCategoryThenUpdateRequisitionToRemoveRequisitionedCategory.
@Test(timeout = 300000)
public void testRequisitionedCategoriesWithUserCategoryThenUpdateRequisitionToRemoveRequisitionedCategory() throws Exception {
final int nextNodeId = m_nodeDao.getNextNodeId();
importFromResource("classpath:/provisioner-testCategories-oneCategory.xml", Boolean.TRUE.toString());
runPendingScans();
// make sure we have the 1 category we expect
OnmsNode n = getNodeDao().get(nextNodeId);
assertEquals(1, n.getCategories().size());
assertTrue(n.hasCategory("TotallyMadeUpCategoryName"));
OnmsCategory cat = new OnmsCategory("ThisIsAlsoMadeUp");
m_categoryDao.save(cat);
m_categoryDao.flush();
n.addCategory(m_categoryDao.findByName("ThisIsAlsoMadeUp"));
getNodeDao().save(n);
importFromResource("classpath:/provisioner-testCategories-noCategories.xml", Boolean.TRUE.toString());
runPendingScans();
// when the scan has completed, the requisitioned category should be removed, but the user-added one should remain
n = getNodeDao().get(nextNodeId);
assertEquals(1, n.getCategories().size());
assertTrue(n.hasCategory("ThisIsAlsoMadeUp"));
}
use of org.opennms.netmgt.model.OnmsCategory in project opennms by OpenNMS.
the class DefaultAdminCategoryService method findCategory.
private OnmsCategory findCategory(String name) {
int categoryId = -1;
try {
categoryId = WebSecurityUtils.safeParseInt(name);
} catch (NumberFormatException e) {
throw new IllegalArgumentException("parameter 'categoryid' " + "with value '" + name + "' could not be parsed " + "as an integer");
}
OnmsCategory category = m_categoryDao.get(categoryId);
if (category == null) {
throw new IllegalArgumentException("Could not find category " + "with category ID " + categoryId);
}
return category;
}
use of org.opennms.netmgt.model.OnmsCategory in project opennms by OpenNMS.
the class CategoryRestService method updateCategory.
@PUT
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Path("/{categoryName}")
public Response updateCategory(@PathParam("categoryName") final String categoryName, final MultivaluedMapImpl params) {
writeLock();
try {
OnmsCategory category = m_categoryDao.findByName(categoryName);
if (category == null) {
throw getException(Status.BAD_REQUEST, "Category with name '{}' was not found.", categoryName);
}
LOG.debug("updateCategory: updating category {}", category);
BeanWrapper wrapper = PropertyAccessorFactory.forBeanPropertyAccess(category);
boolean modified = 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);
modified = true;
}
}
LOG.debug("updateCategory: category {} updated", category);
if (modified) {
m_categoryDao.saveOrUpdate(category);
return Response.noContent().build();
}
return Response.notModified().build();
} finally {
writeUnlock();
}
}
use of org.opennms.netmgt.model.OnmsCategory in project opennms by OpenNMS.
the class HeatMapIT method setUp.
@BeforeTransaction
public void setUp() {
if (!m_populated) {
m_databasePopulator.populateDatabase();
m_populated = true;
}
numberOfNodesInCategory = new HashMap();
List<OnmsCategory> onmsCategories = m_categoryDao.findAll();
for (OnmsCategory onmsCategory : onmsCategories) {
int n = m_nodeDao.findByCategory(onmsCategory).size();
if (n > 0) {
numberOfNodesInCategory.put(onmsCategory.getName(), n);
}
}
}
use of org.opennms.netmgt.model.OnmsCategory in project opennms by OpenNMS.
the class CategoryRestServiceIT method createCategory.
protected void createCategory(final String categoryName) throws Exception {
OnmsCategory cat = new OnmsCategory();
cat.setName(categoryName);
createCategory(cat);
}
Aggregations