Commit 76e8799e authored by shake's avatar shake
Browse files

Add servlet to delete settings

git-svn-id: https://subversion.umiacs.umd.edu/ace/trunk@173 f1b3a171-7291-4a19-a512-95ad0ad9394a
parent d1f7168f
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package edu.umiacs.ace.monitor.settings;
import edu.umiacs.ace.util.EntityManagerServlet;
import edu.umiacs.util.Strings;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import javax.persistence.EntityManager;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
*
* @author shake
*/
public class DeleteSettingsServlet extends EntityManagerServlet{
public static final String PARAM_SETTING = "setting";
@Override
protected void processRequest(HttpServletRequest request, HttpServletResponse
response, EntityManager em) throws ServletException, IOException {
List<String> settingsToDelete = new ArrayList<String>();
RequestDispatcher dispatcher = null;
if ( !Strings.isEmpty(request.getParameter(PARAM_SETTING)) ) {
String[] selectedRoles = request.getParameterValues(PARAM_SETTING);
settingsToDelete.addAll(Arrays.asList(selectedRoles));
SettingsUtil.deleteSettings(settingsToDelete);
}
List<SettingsParameter> customSettings = SettingsUtil.getCustomSettings();
request.setAttribute("customSettings", customSettings);
dispatcher = request.getRequestDispatcher("deletesettings.jsp");
dispatcher.forward(request, response);
}
}
......@@ -78,6 +78,26 @@ public class SettingsUtil {
em.clear();
}
public static void deleteSettings(List<String> settings) {
EntityManager em = PersistUtil.getEntityManager();
EntityTransaction trans = em.getTransaction();
trans.begin();
for ( String name : settings ) {
// TODO: Find a better way to do this
SettingsParameter setting = getItemByAttr(name);
SettingsParameter managedSetting =
em.find(SettingsParameter.class, setting.getId());
if ( setting != null ) {
em.remove(managedSetting);
}
}
trans.commit();
em.close();
}
// Get the names of all curent settings
public static Set<String> getParamNames() {
List<SettingsParameter> settings = getCurrentSettings();
......
......@@ -191,6 +191,10 @@
<servlet-name>AddSettingServlet</servlet-name>
<servlet-class>edu.umiacs.ace.monitor.settings.AddSettingServlet</servlet-class>
</servlet>
<servlet>
<servlet-name>DeleteSettingsServlet</servlet-name>
<servlet-class>edu.umiacs.ace.monitor.settings.DeleteSettingsServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ServletAdaptor</servlet-name>
<url-pattern>/rest/*</url-pattern>
......@@ -308,6 +312,10 @@
<servlet-name>AddSettingServlet</servlet-name>
<url-pattern>/AddSettings</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>DeleteSettingsServlet</servlet-name>
<url-pattern>/DeleteSettings</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
......
<%--
Document : addsetting
Created on : Aug 6, 2012, 2:41:40 PM
Author : shake
--%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>System Settings</title>
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
<jsp:include page="header.jsp"/>
<fieldset id="settingsTable">
<legend>
<h2>Delete Custom Settings</h2>
</legend>
<FORM METHOD="POST" ACTION="DeleteSettings">
<c:forEach var="item" items="${customSettings}">
<div class="settingsRow">
<input type="checkbox" name="setting" value="${item.name}"/>
<div class="settingsName">${item.name}</div>
</div>
</c:forEach>
<input type=submit value="Delete" name="update" class="submitLink">
<a href="UpdateSettings" style="font-size: medium; text-decoration: underline;">Cancel</a>
</FORM>
</fieldset>
<jsp:include page="footer.jsp"/>
</body>
</html>
......@@ -149,6 +149,7 @@
</c:forEach>
<div class="settingsRow">
<div class="settingsName"><a href="addsetting.jsp">Add setting</a></div>
<div class="settingsName"><a href="DeleteSettings">Delete settings</a></div>
</div>
</fieldset>
<br>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment