Search in sources :

Example 11 with OnmsCategory

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;
}
Also used : OnmsCategory(org.opennms.netmgt.model.OnmsCategory) ModelAndView(org.springframework.web.servlet.ModelAndView) MissingParameterException(org.opennms.web.servlet.MissingParameterException)

Example 12 with OnmsCategory

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;
}
Also used : OnmsCategory(org.opennms.netmgt.model.OnmsCategory) NodeEditModel(org.opennms.web.svclayer.support.DefaultAdminCategoryService.NodeEditModel) NodeEditModel(org.opennms.web.svclayer.support.DefaultAdminCategoryService.NodeEditModel) EditModel(org.opennms.web.svclayer.support.DefaultAdminCategoryService.EditModel) RedirectView(org.springframework.web.servlet.view.RedirectView) ModelAndView(org.springframework.web.servlet.ModelAndView)

Example 13 with OnmsCategory

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);
        }
    }
}
Also used : OnmsCategory(org.opennms.netmgt.model.OnmsCategory) HashMap(java.util.HashMap) BeforeTransaction(org.springframework.test.context.transaction.BeforeTransaction)

Example 14 with OnmsCategory

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);
}
Also used : OnmsCategory(org.opennms.netmgt.model.OnmsCategory)

Example 15 with OnmsCategory

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());
}
Also used : OnmsCategory(org.opennms.netmgt.model.OnmsCategory) StringReader(java.io.StringReader) OnmsCategoryCollection(org.opennms.netmgt.model.OnmsCategoryCollection) Test(org.junit.Test)

Aggregations

OnmsCategory (org.opennms.netmgt.model.OnmsCategory)54 OnmsNode (org.opennms.netmgt.model.OnmsNode)25 ArrayList (java.util.ArrayList)12 Test (org.junit.Test)9 LinkedHashSet (java.util.LinkedHashSet)6 Path (javax.ws.rs.Path)6 HashSet (java.util.HashSet)4 AggregateStatusDefinition (org.opennms.netmgt.model.AggregateStatusDefinition)4 AggregateStatusView (org.opennms.netmgt.model.AggregateStatusView)4 Transactional (org.springframework.transaction.annotation.Transactional)4 StringReader (java.io.StringReader)3 JUnitTemporaryDatabase (org.opennms.core.test.db.annotations.JUnitTemporaryDatabase)3 RowDef (org.opennms.netmgt.config.siteStatusViews.RowDef)3 OnmsAssetRecord (org.opennms.netmgt.model.OnmsAssetRecord)3 OnmsEvent (org.opennms.netmgt.model.OnmsEvent)3 OnmsIpInterface (org.opennms.netmgt.model.OnmsIpInterface)3 OnmsMonitoredService (org.opennms.netmgt.model.OnmsMonitoredService)3 AggregateStatus (org.opennms.web.svclayer.model.AggregateStatus)3 Date (java.util.Date)2 Consumes (javax.ws.rs.Consumes)2