Search in sources :

Example 1 with EditModel

use of org.opennms.web.svclayer.support.DefaultAdminCategoryService.EditModel 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)

Aggregations

OnmsCategory (org.opennms.netmgt.model.OnmsCategory)1 EditModel (org.opennms.web.svclayer.support.DefaultAdminCategoryService.EditModel)1 NodeEditModel (org.opennms.web.svclayer.support.DefaultAdminCategoryService.NodeEditModel)1 ModelAndView (org.springframework.web.servlet.ModelAndView)1 RedirectView (org.springframework.web.servlet.view.RedirectView)1