use of org.opennms.netmgt.model.OnmsCategory in project opennms by OpenNMS.
the class NodeCategoryBoxController method handleRequestInternal.
/** {@inheritDoc} */
@Override
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
String nodeIdString = request.getParameter("node");
if (nodeIdString == null) {
throw new MissingParameterException("node");
}
int nodeId = WebSecurityUtils.safeParseInt(nodeIdString);
List<OnmsCategory> categories = m_adminCategoryService.findByNode(nodeId);
ModelAndView modelAndView = new ModelAndView("/includes/nodeCategory-box", "categories", categories);
if (request.isUserInRole(Authentication.ROLE_ADMIN)) {
modelAndView.addObject("isAdmin", "true");
}
return modelAndView;
}
use of org.opennms.netmgt.model.OnmsCategory in project opennms by OpenNMS.
the class CategoryController method handleRequestInternal.
/** {@inheritDoc} */
@Override
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
String removeCategoryIdString = request.getParameter("removeCategoryId");
String newCategoryName = request.getParameter("newCategoryName");
String categoryIdString = request.getParameter("categoryid");
String editString = request.getParameter("edit");
String nodeIdString = request.getParameter("node");
RedirectView redirect = new RedirectView("/admin/categories.htm", true);
// delete a category
if (removeCategoryIdString != null) {
m_adminCategoryService.removeCategory(removeCategoryIdString);
return new ModelAndView(redirect);
}
// add a category
if (newCategoryName != null) {
OnmsCategory cat = m_adminCategoryService.getCategoryWithName(newCategoryName);
if (cat == null) {
m_adminCategoryService.addNewCategory(newCategoryName);
}
/*
* We could be smart and take the user straight to the edit page
* for this new category, which would be great, however it's
* not so great if the site has a huge number of available
* category and they need to edit category member nodes
* from the node pages. So, we don't do it.
*/
return new ModelAndView(redirect);
}
// high-level category edit (add or remove nodes from a category)
if (categoryIdString != null && editString != null) {
String editAction = request.getParameter("action");
if (editAction != null) {
String[] toAdd = request.getParameterValues("toAdd");
String[] toDelete = request.getParameterValues("toDelete");
m_adminCategoryService.performEdit(categoryIdString, editAction, toAdd, toDelete);
ModelAndView modelAndView = new ModelAndView(redirect);
modelAndView.addObject("categoryid", categoryIdString);
modelAndView.addObject("edit", "edit");
return modelAndView;
}
EditModel model = m_adminCategoryService.findCategoryAndAllNodes(categoryIdString);
return new ModelAndView("/admin/editCategory", "model", model);
}
// if we don't have an edit string, we just show the category
if (categoryIdString != null) {
return new ModelAndView("/admin/showCategory", "model", m_adminCategoryService.getCategory(categoryIdString));
}
// if we have a nodeId and we're in edit mode, edit the categories for a specific node
if (nodeIdString != null && editString != null) {
String editAction = request.getParameter("action");
// if we've specified an action, perform that action
if (editAction != null) {
String[] toAdd = request.getParameterValues("toAdd");
String[] toDelete = request.getParameterValues("toDelete");
m_adminCategoryService.performNodeEdit(nodeIdString, editAction, toAdd, toDelete);
ModelAndView modelAndView = new ModelAndView(redirect);
modelAndView.addObject("node", nodeIdString);
modelAndView.addObject("edit", "edit");
return modelAndView;
}
// otherwise, display the edit page for adding and removing categories from a node
NodeEditModel model = m_adminCategoryService.findNodeCategories(nodeIdString);
return new ModelAndView("/admin/editNodeCategories", "model", model);
}
// otherwise, just show the category editor
List<OnmsCategory> sortedCategories = m_adminCategoryService.findAllCategories();
List<String> surveillanceCategories = getAllSurveillanceViewCategories();
ModelAndView modelAndView = new ModelAndView("/admin/categories");
modelAndView.addObject("categories", sortedCategories);
modelAndView.addObject("surveillanceCategories", surveillanceCategories);
//new ModelAndView("/admin/categories", "categories", sortedCategories);
return modelAndView;
}
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);
}
use of org.opennms.netmgt.model.OnmsCategory in project opennms by OpenNMS.
the class GroupRestServiceIT method testCategories.
@Test
public void testCategories() throws Exception {
createGroup("testGroup");
String xml = sendRequest(GET, "/groups/testGroup/categories", 200);
assertNotNull(xml);
OnmsCategoryCollection categories = JAXB.unmarshal(new StringReader(xml), OnmsCategoryCollection.class);
assertNotNull(categories);
assertTrue(categories.getCategories().isEmpty());
// add category to group
// fails, because Category is not there
sendRequest(PUT, "/groups/testGroup/categories/testCategory", 400);
// create category
createCategory("testCategory");
// should not fail, because Category is now there
sendRequest(PUT, "/groups/testGroup/categories/testCategory", 204);
// get data
xml = sendRequest(GET, "/groups/testGroup/categories/testCategory", 200);
assertNotNull(xml);
OnmsCategory category = JAXB.unmarshal(new StringReader(xml), OnmsCategory.class);
assertNotNull(category);
assertEquals("testCategory", category.getName());
// add again (fails)
// should fail, because Category is already there
sendRequest(PUT, "/groups/testGroup/categories/testCategory", 400);
// remove category from group
// should not fail
sendRequest(DELETE, "/groups/testGroup/categories/testCategory", 204);
// should fail, because category is already removed
sendRequest(DELETE, "/groups/testGroup/categories/testCategory", 400);
// test that all categories for group "testGroup" have been removed
xml = sendRequest(GET, "/groups/testGroup/categories", 200);
assertNotNull(xml);
categories = JaxbUtils.unmarshal(OnmsCategoryCollection.class, xml);
assertNotNull(categories);
assertTrue(categories.getCategories().isEmpty());
}
Aggregations