Commit a4896c41 authored by shake's avatar shake
Browse files

Updated settings interface

git-svn-id: https://subversion.umiacs.umd.edu/ace/trunk@155 f1b3a171-7291-4a19-a512-95ad0ad9394a
parent a09d59ca
......@@ -19,7 +19,9 @@ import javax.persistence.Table;
@NamedQuery(name = "SettingsParameter.getAttr", query =
"SELECT p FROM SettingsParameter p WHERE p.attr = :attr"),
@NamedQuery(name = "SettingsParameter.getAttrList", query =
"SELECT p FROM SettingsParameter p WHERE p.attr LIKE :attr")
"SELECT p FROM SettingsParameter p WHERE p.attr LIKE :attr"),
@NamedQuery(name = "SettingsParameter.getCurrentSettings", query =
"SELECT p FROM SettingsParameter p")
})
public class SettingsParameter implements Serializable {
@Id
......
package edu.umiacs.ace.monitor.settings;
import edu.umiacs.ace.util.EntityManagerServlet;
import edu.umiacs.util.Strings;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.List;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.persistence.EntityManager;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
......@@ -21,37 +24,67 @@ import org.apache.commons.fileupload.util.Streams;
*
* @author shake
*/
public class SettingsServlet extends EntityManagerServlet{
public class SettingsServlet extends EntityManagerServlet {
private final String LOG_CLASS = "org.apache.log4j.FileAppender";
@Override
protected void processRequest(HttpServletRequest request, HttpServletResponse response,
EntityManager em) throws ServletException, IOException {
Set<String> paramSet = SettingsUtil.getParamSet();
HashMap<String, String> settings = new HashMap<String, String>();
boolean update = false;
// See if we have a multipart/form and take care of it
if (!Strings.isEmpty(request.getHeader("content-type"))) {
ServletFileUpload su = new ServletFileUpload();
try {
FileItemIterator iter = su.getItemIterator(request);
while ( iter.hasNext() ) {
FileItemStream item = iter.next();
InputStream stream = item.openStream();
ServletFileUpload su = new ServletFileUpload();
try {
FileItemIterator iter = su.getItemIterator(request);
while ( iter.hasNext() ) {
FileItemStream item = iter.next();
InputStream stream = item.openStream();
if ( item.isFormField() ) {
String name = item.getFieldName();
String value = Streams.asString(stream);
if ( paramSet.contains(name) && !value.isEmpty()) {
settings.put(name, value);
}else {
System.out.println("Ignoring " + name + " :: " + value);
if ( item.isFormField() ) {
String name = item.getFieldName();
String value = Streams.asString(stream);
if ( paramSet.contains(name) && !value.isEmpty() ) {
settings.put(name, value);
}
if ( name.equals("update") ) {
update = true;
}
}
}
} catch (FileUploadException ex) {
Logger.getLogger(SettingsServlet.class.getName()).log(Level.SEVERE, null, ex);
}
if ( update ) {
SettingsUtil.updateSettings(settings);
} else {
SettingsUtil.updateSettings(SettingsUtil.getDefaultMap());
}
} catch (FileUploadException ex) {
Logger.getLogger(SettingsServlet.class.getName()).log(Level.SEVERE, null, ex);
}
SettingsUtil.updateSettings(settings);
response.sendRedirect("Status");
}
List<SettingsParameter> currentSettings = SettingsUtil.getCurrentSettings();
HashMap<String, String> settingsMap = new HashMap<String, String>();
for ( SettingsParameter s : currentSettings ) {
settingsMap.put(s.getName(), s.getValue());
}
request.setAttribute("currSettings", settingsMap);
if ( settingsMap.get(SettingsConstants.PARAM_4J_APPENDER).equals(LOG_CLASS)) {
request.setAttribute("fileAppender", true);
}else {
request.setAttribute("fileAppender", false);
}
RequestDispatcher dispatcher = request.getRequestDispatcher("settings.jsp");
dispatcher.forward(request, response);
}
}
......@@ -31,18 +31,24 @@ public class SettingsUtil {
return null;
}
public static List<SettingsParameter> getCurrentSettings() {
EntityManager em = PersistUtil.getEntityManager();
Query q = em.createNamedQuery("SettingsParameter.getCurrentSettings");
return q.getResultList();
}
public static void updateSettings(Map<String, String> settings) {
EntityManager em = PersistUtil.getEntityManager();
EntityTransaction trans = em.getTransaction();
trans.begin();
for ( String attr : settings.keySet() ) {
SettingsParameter item = getItemByAttr(attr);
for ( String name : settings.keySet() ) {
SettingsParameter item = getItemByAttr(name);
if ( item == null ) {
System.out.println("Item es nool");
em.persist(new SettingsParameter(attr, settings.get(attr)));
em.persist(new SettingsParameter(name, settings.get(name)));
} else {
item.setValue(settings.get(attr));
item.setValue(settings.get(name));
em.merge(item);
}
}
......
......@@ -49,7 +49,7 @@ on Libraries node in Projects view can be used to add the JSTL 1.1 library.
<td align="center">
<div class="menucell">
<a href="settings.jsp">System Settings</a>
<a href="UpdateSettings">System Settings</a>
</div>
</td>
......
......@@ -5,6 +5,7 @@
--%>
<%@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">
......@@ -18,26 +19,121 @@
<jsp:include page="header.jsp"/>
<h1>System Settings</h1>
<FORM name="settingsform" METHOD="POST" ENCTYPE="multipart/form-data" ACTION="UpdateSettings">
<h3>Mail Server: <input type=text name="mail.server"> </h3>
<h3>Mail From: <input type=text name="mail.from"> </h3>
<h3>Max Audit: <input type=text name="throttle.maxaudit"></h3>
<h3>Audit Wait Time: <input type=text name="throttle.wait"></h3>
<h3>Audit BPS: <input type=text name="throttle.bps"></h3>
<h3>Auto Audit: <input type=text name="auto.audit.disable"></h3>
<h3>IMS Host: <input type=text name="ims"></h3>
<h3>User Management: <input type=text name="auth.management"></h3>
<h3>Log Location: <input type=text name="log4j.appender.A1.file"></h3>
<h3>Log Type: <input type=text name="log4j.appender.A1"></h3>
<h3>Log File Size: <input type=text name="log4j.appender.A1.maxFileSize"></h3>
<h3>Log Backup Index: <input type=text name="log4j.appender.A1.maxBackupIndex"></h3>
<h3>Root Logger: <input type=text name="log4j.rootLogger"></h3>
<h3>Pattern Layout: <input type=text name="log4j.appender.A1.layout"></h3>
<h3>Conversion Pattern: <input type=text name="log4j.appender.A1.layout.ConversionPattern"></h3>
<h3>IRods: <input type=text name="log4j.logger.edu.umiacs.irods"></h3>
<h3>umiacs: <input type=text name="log4j.logger.edu.umiacs"></h3>
<h3>IRods Connection: <input type=text name="irods.connection"></h3>
<div id="settingstable">
<table border="0">
<tr>
<td>Mail Server:</td>
<td><input type=text name="mail.server" value="${currSettings['mail.server']}"></td>
<td><img src="images/help.png" title="Mail server to use when mailing reports. You will need to set this if you want reports to be mailed properly."></td>
</tr>
<tr>
<td>Mail From:</td>
<td><input type=text name="mail.from" value="${currSettings['mail.from']}"></td>
<td><img src="images/help.png" title="Set this e-mail address to an address e-mail should originate from"></td>
</tr>
<tr>
<td>Max Audit:</td>
<td><input type=text name="throttle.maxaudit" value="${currSettings['throttle.maxaudit']}"></td>
<td><img src="images/help.png" title="Max number of running audits"></td>
</tr>
<tr>
<td>Audit Wait Time:</td>
<td><input type=text name="throttle.wait" value="${currSettings['throttle.wait']}"></td>
<td><img src="images/help.png" title="Minimum time between srb file reads in milliseconds"></td>
</tr>
<tr>
<td>Audit BPS:</td>
<td><input type=text name="throttle.bps" value="${currSettings['throttle.bps']}"></td>
<td><img src="images/help.png" title="Maximum bytes per second per running audit, default = 0 = unlimited"></td>
</tr>
<tr>
<td>Auto Audit:</td>
<td><input type=text name="auto.audit.disable" value="${currSettings['auto.audit.disable']}"></td>
<td><img src="images/help.png" title="Start automated auditing"></td>
</tr>
<tr>
<td>IMS Host:</td>
<td><input type=text name="ims" value="${currSettings['ims']}"></td>
<td><img src="images/help.png" title="IMS hostname to use. Unless you deployed your own IMS, this should probably not be changed"></td>
</tr>
<tr>
<td>User Management:</td>
<td><input type=text name="auth.management" value="${currSettings['auth.management']}"></td>
<td><img src="images/help.png" title="Set this to true to disable internal user management. This should only be used in conjunction with changes to the Authentication realm listed above."></td>
</tr>
<tr>
<td>Log Location:</td>
<td><input type=text name="log4j.appender.A1.File" value="${currSettings['log4j.appender.A1.File']}"></td>
<td><img src="images/help.png" title="The location of your logfile"></td>
</tr>
<c:choose>
<c:when test="${fileAppender}">
<tr>
<td>Log Type:</td>
<td><input type=text name="log4j.appender.A1" value="${currSettings['log4j.appender.A1']}"></td>
<td><img src="images/help.png"></td>
</tr>
</c:when>
<c:otherwise>
<tr>
<td>Log Type:</td>
<td><input type=text name="log4j.appender.A1" value="${currSettings['log4j.appender.A1']}"></td>
<td><img src="images/help.png"></td>
</tr>
<tr>
<td>Log File Size:</td>
<td><input type=text name="log4j.appender.A1.maxFileSize" value="${currSettings['log4j.appender.A1.maxFileSize']}"></td>
<td><img src="images/help.png" title="File size of your log"></td>
</tr>
<tr>
<td>Log Backup Index:</td>
<td><input type=text name="log4j.appender.A1.maxBackupIndex" value="${currSettings['log4j.appender.A1.maxBackupIndex']}"></td>
<td><img src="images/help.png"></td>
</tr>
</c:otherwise>
</c:choose>
<tr></tr>
<tr>
<td>Generic logging properties </td>
</tr>
<tr>
<td> change only if you know what you are doing</td>
</tr>
<h3><input type=submit value="Submit" class="submitLink"> <a href="Status">Cancel</a></h3>
<tr>
<td>Root Logger:</td>
<td><input type=text name="log4j.rootLogger" value="${currSettings['log4j.rootLogger']}"></td>
<td><img src="images/help.png"></td>
</tr>
<tr>
<td>Pattern Layout:</td>
<td><input type=text name="log4j.appender.A1.layout" value="${currSettings['log4j.appender.A1.layout']}"></td>
<td><img src="images/help.png"></td>
</tr>
<tr>
<td>Conversion Pattern:</td>
<td><input type=text name="log4j.appender.A1.layout.ConversionPattern" value="${currSettings['log4j.appender.A1.layout.ConversionPattern']}"></td>
<td><img src="images/help.png"></td>
</tr>
<tr>
<td>IRods:</td>
<td><input type=text name="log4j.logger.edu.umiacs.irods" value="${currSettings['log4j.logger.edu.umiacs.irods']}"></td>
<td><img src="images/help.png"></td>
</tr>
<tr>
<td>umiacs:</td>
<td><input type=text name="log4j.logger.edu.umiacs" value="${currSettings['log4j.logger.edu.umiacs']}"></td>
<td><img src="images/help.png"></td>
</tr>
<tr>
<td>IRods Connection:</td>
<td><input type=text name="irods.connection" value="${currSettings['irods.connection']}"></td>
<td><img src="images/help.png"></td>
</tr>
</table>
</div>
<input type=submit value="Submit" name="update" class="submitLink" style="margin-left: 50px;"> <input type=submit value="Default" name="default" class="submitLink"> <a href="Status">Cancel</a>
</FORM>
<jsp:include page="footer.jsp"/>
......
......@@ -144,9 +144,6 @@ vertical-align: top;
width: 650px;
}
#dettable tr td {
padding-top: 15px;
padding-left: 15px;
......@@ -164,3 +161,14 @@ vertical-align: top;
margin-top: 20px;
margin-bottom: 5px;
}
#settingstable {
font-size: small;
border: 1px solid #000000;
margin-left: 50px;
margin-right: 50px;
}
#settingsitem {
margin-left: 25%;
}
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