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");
}
}
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;
}
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");
}
}
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);
}
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);
}
Aggregations