Search in sources :

Example 31 with OnmsApplication

use of org.opennms.netmgt.model.OnmsApplication in project opennms by OpenNMS.

the class DefaultAdminApplicationService method performServiceEdit.

/**
 * <p>performServiceEdit</p>
 *
 * @param ifServiceIdString a {@link java.lang.String} object.
 * @param editAction a {@link java.lang.String} object.
 * @param toAdd an array of {@link java.lang.String} objects.
 * @param toDelete an array of {@link java.lang.String} objects.
 */
@Override
public void performServiceEdit(String ifServiceIdString, String editAction, String[] toAdd, String[] toDelete) {
    if (ifServiceIdString == null) {
        throw new IllegalArgumentException("ifServiceIdString cannot be null");
    }
    if (editAction == null) {
        throw new IllegalArgumentException("editAction cannot be null");
    }
    OnmsMonitoredService service = findService(ifServiceIdString);
    if (editAction.contains("Add")) {
        // @i18n
        if (toAdd == null) {
            return;
        // throw new IllegalArgumentException("toAdd cannot be null if editAction is 'Add'");
        }
        for (String idString : toAdd) {
            Integer id;
            try {
                id = WebSecurityUtils.safeParseInt(idString);
            } catch (NumberFormatException e) {
                throw new IllegalArgumentException("toAdd element '" + idString + "' is not an integer");
            }
            OnmsApplication application = m_applicationDao.get(id);
            if (application == null) {
                throw new IllegalArgumentException("application with " + "id of " + id + " could not be found");
            }
            if (service.getApplications().contains(application)) {
                throw new IllegalArgumentException("application with " + "id of " + id + " is already a member of " + "service " + service.getServiceName());
            }
            service.getApplications().add(application);
        }
        m_monitoredServiceDao.save(service);
    } else if (editAction.contains("Remove")) {
        // @i18n
        if (toDelete == null) {
            return;
        // throw new IllegalArgumentException("toDelete cannot be null if editAction is 'Remove'");
        }
        for (String idString : toDelete) {
            Integer id;
            try {
                id = WebSecurityUtils.safeParseInt(idString);
            } catch (NumberFormatException e) {
                throw new IllegalArgumentException("toDelete element '" + idString + "' is not an integer");
            }
            OnmsApplication application = m_applicationDao.get(id);
            if (application == null) {
                throw new IllegalArgumentException("application with " + "id of " + id + " could not be found");
            }
            if (!service.getApplications().contains(application)) {
                throw new IllegalArgumentException("application with " + "id of " + id + " is not a member of " + "service " + service.getServiceName());
            }
            service.getApplications().add(application);
        }
        m_monitoredServiceDao.save(service);
    } else {
        throw new IllegalArgumentException("editAction of '" + editAction + "' is not allowed");
    }
}
Also used : OnmsApplication(org.opennms.netmgt.model.OnmsApplication) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService)

Example 32 with OnmsApplication

use of org.opennms.netmgt.model.OnmsApplication in project opennms by OpenNMS.

the class DefaultAdminApplicationService method findApplication.

/**
 * <p>findApplication</p>
 *
 * @param name a {@link java.lang.String} object.
 * @return a {@link org.opennms.netmgt.model.OnmsApplication} object.
 */
public OnmsApplication findApplication(String name) {
    int applicationId = -1;
    try {
        applicationId = WebSecurityUtils.safeParseInt(name);
    } catch (NumberFormatException e) {
        throw new IllegalArgumentException("parameter 'applicationid' " + "with value '" + name + "' could not be parsed " + "as an integer");
    }
    OnmsApplication application = m_applicationDao.get(applicationId);
    if (application == null) {
        throw new IllegalArgumentException("Could not find application " + "with application ID " + applicationId);
    }
    return application;
}
Also used : OnmsApplication(org.opennms.netmgt.model.OnmsApplication)

Example 33 with OnmsApplication

use of org.opennms.netmgt.model.OnmsApplication in project opennms by OpenNMS.

the class DefaultAdminApplicationService method performEdit.

/**
 * <p>performEdit</p>
 *
 * @param applicationIdString a {@link java.lang.String} object.
 * @param editAction a {@link java.lang.String} object.
 * @param toAdd an array of {@link java.lang.String} objects.
 * @param toDelete an array of {@link java.lang.String} objects.
 */
@Override
public void performEdit(String applicationIdString, String editAction, String[] toAdd, String[] toDelete) {
    if (applicationIdString == null) {
        throw new IllegalArgumentException("applicationIdString cannot be null");
    }
    if (editAction == null) {
        throw new IllegalArgumentException("editAction cannot be null");
    }
    OnmsApplication application = findApplication(applicationIdString);
    if (editAction.contains("Add")) {
        // @i18n
        if (toAdd == null) {
            return;
        // throw new IllegalArgumentException("toAdd cannot be null if editAction is 'Add'");
        }
        for (String idString : toAdd) {
            Integer id;
            try {
                id = WebSecurityUtils.safeParseInt(idString);
            } catch (NumberFormatException e) {
                throw new IllegalArgumentException("toAdd element '" + idString + "' is not an integer");
            }
            OnmsMonitoredService service = m_monitoredServiceDao.get(id);
            if (service == null) {
                throw new IllegalArgumentException("monitored service with " + "id of " + id + "could not be found");
            }
            if (service.getApplications().contains(application)) {
                throw new IllegalArgumentException("monitored service with " + "id of " + id + "is already a member of " + "application " + application.getName());
            }
            service.addApplication(application);
            m_monitoredServiceDao.save(service);
        }
    } else if (editAction.contains("Remove")) {
        // @i18n
        if (toDelete == null) {
            return;
        // throw new IllegalArgumentException("toDelete cannot be null if editAction is 'Remove'");
        }
        for (String idString : toDelete) {
            Integer id;
            try {
                id = WebSecurityUtils.safeParseInt(idString);
            } catch (NumberFormatException e) {
                throw new IllegalArgumentException("toDelete element '" + idString + "' is not an integer");
            }
            OnmsMonitoredService service = m_monitoredServiceDao.get(id);
            if (service == null) {
                throw new IllegalArgumentException("monitored service with " + "id of " + id + "could not be found");
            }
            if (!service.getApplications().contains(application)) {
                throw new IllegalArgumentException("monitored service with " + "id of " + id + "is not a member of " + "application " + application.getName());
            }
            service.removeApplication(application);
            m_monitoredServiceDao.save(service);
        }
        m_applicationDao.save(application);
    } else {
        throw new IllegalArgumentException("editAction of '" + editAction + "' is not allowed");
    }
}
Also used : OnmsApplication(org.opennms.netmgt.model.OnmsApplication) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService)

Example 34 with OnmsApplication

use of org.opennms.netmgt.model.OnmsApplication in project opennms by OpenNMS.

the class DefaultAdminApplicationService method getApplication.

/**
 * {@inheritDoc}
 */
@Override
public ApplicationAndMemberServices getApplication(String applicationIdString) {
    if (applicationIdString == null) {
        throw new IllegalArgumentException("applicationIdString must not be null");
    }
    OnmsApplication application = findApplication(applicationIdString);
    Collection<OnmsMonitoredService> memberServices = m_monitoredServiceDao.findByApplication(application);
    for (OnmsMonitoredService service : memberServices) {
        m_applicationDao.initialize(service.getIpInterface());
        m_applicationDao.initialize(service.getIpInterface().getNode());
    }
    return new ApplicationAndMemberServices(application, memberServices);
}
Also used : OnmsApplication(org.opennms.netmgt.model.OnmsApplication) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService)

Example 35 with OnmsApplication

use of org.opennms.netmgt.model.OnmsApplication in project opennms by OpenNMS.

the class ApplicationController method handleRequestInternal.

/**
 * {@inheritDoc}
 */
@Override
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
    String removeApplicationIdString = getNonEmptyParameter(request, "removeApplicationId");
    String newApplicationName = getNonEmptyParameter(request, "newApplicationName");
    String applicationIdString = getNonEmptyParameter(request, "applicationid");
    String editString = getNonEmptyParameter(request, "edit");
    String ifServiceIdString = getNonEmptyParameter(request, "ifserviceid");
    if (removeApplicationIdString != null) {
        m_adminApplicationService.removeApplication(removeApplicationIdString);
        return new ModelAndView(new RedirectView("/admin/applications.htm", true));
    }
    if (newApplicationName != null) {
        m_adminApplicationService.addNewApplication(newApplicationName);
        /*
             * We could be smart and take the user straight to the edit page
             * for this new application, which would be great, however it's
             * not so great if the site has a huge number of available
             * applications and they need to edit application member services
             * from the service pages.  So, we don't do it.
             */
        return new ModelAndView(new RedirectView("/admin/applications.htm", true));
    }
    if (applicationIdString != null && editString != null) {
        String editAction = getNonEmptyParameter(request, "action");
        if (editAction != null) {
            String[] toAdd = request.getParameterValues("toAdd");
            String[] toDelete = request.getParameterValues("toDelete");
            m_adminApplicationService.performEdit(applicationIdString, editAction, toAdd, toDelete);
            ModelAndView modelAndView = new ModelAndView(new RedirectView("/admin/applications.htm", true));
            modelAndView.addObject("applicationid", applicationIdString);
            modelAndView.addObject("edit", "edit");
            return modelAndView;
        }
        EditModel model = m_adminApplicationService.findApplicationAndAllMonitoredServices(applicationIdString);
        return new ModelAndView("/admin/editApplication", "model", model);
    }
    if (applicationIdString != null) {
        return new ModelAndView("/admin/showApplication", "model", m_adminApplicationService.getApplication(applicationIdString));
    }
    if (ifServiceIdString != null && editString != null) {
        String editAction = getNonEmptyParameter(request, "action");
        if (editAction != null) {
            String[] toAdd = request.getParameterValues("toAdd");
            String[] toDelete = request.getParameterValues("toDelete");
            m_adminApplicationService.performServiceEdit(ifServiceIdString, editAction, toAdd, toDelete);
            ModelAndView modelAndView = new ModelAndView(new RedirectView("/admin/applications.htm", true));
            modelAndView.addObject("ifserviceid", ifServiceIdString);
            modelAndView.addObject("edit", "edit");
            return modelAndView;
        }
        ServiceEditModel model = m_adminApplicationService.findServiceApplications(ifServiceIdString);
        return new ModelAndView("/admin/editServiceApplications", "model", model);
    }
    List<OnmsApplication> sortedApplications = m_adminApplicationService.findAllApplications();
    return new ModelAndView("/admin/applications", "applications", sortedApplications);
}
Also used : EditModel(org.opennms.web.svclayer.support.DefaultAdminApplicationService.EditModel) ServiceEditModel(org.opennms.web.svclayer.support.DefaultAdminApplicationService.ServiceEditModel) ModelAndView(org.springframework.web.servlet.ModelAndView) RedirectView(org.springframework.web.servlet.view.RedirectView) OnmsApplication(org.opennms.netmgt.model.OnmsApplication) ServiceEditModel(org.opennms.web.svclayer.support.DefaultAdminApplicationService.ServiceEditModel)

Aggregations

OnmsApplication (org.opennms.netmgt.model.OnmsApplication)42 OnmsMonitoredService (org.opennms.netmgt.model.OnmsMonitoredService)20 OnmsLocationMonitor (org.opennms.netmgt.model.OnmsLocationMonitor)14 ArrayList (java.util.ArrayList)13 OnmsMonitoringLocation (org.opennms.netmgt.model.monitoringLocations.OnmsMonitoringLocation)12 Date (java.util.Date)11 OnmsLocationSpecificStatus (org.opennms.netmgt.model.OnmsLocationSpecificStatus)11 LinkedList (java.util.LinkedList)8 Transactional (org.springframework.transaction.annotation.Transactional)6 HashSet (java.util.HashSet)5 ApplicationInfo (org.opennms.features.poller.remote.gwt.client.ApplicationInfo)4 StatusDetails (org.opennms.features.poller.remote.gwt.client.StatusDetails)4 SimpleWebTable (org.opennms.web.svclayer.model.SimpleWebTable)4 LinkedHashMap (java.util.LinkedHashMap)3 List (java.util.List)3 Test (org.junit.Test)3 OnmsNode (org.opennms.netmgt.model.OnmsNode)3 OnmsServiceType (org.opennms.netmgt.model.OnmsServiceType)3 DistributedStatusHistoryModel (org.opennms.web.svclayer.model.DistributedStatusHistoryModel)3 HashMap (java.util.HashMap)2