Commit 2580f5ea authored by shake's avatar shake
Browse files

Changed Filter servlet, added ssl settings for IMS connection

git-svn-id: https://subversion.umiacs.umd.edu/ace/trunk@197 f1b3a171-7291-4a19-a512-95ad0ad9394a
parent e35a065c
......@@ -48,7 +48,7 @@ import javax.persistence.Table;
*
* @author toaster
*/
@Entity()
@Entity
@Table(name = "filter_entry")
@NamedQueries({
@NamedQuery(name = "FilterEntry.dropByCollection", query =
......
......@@ -33,13 +33,12 @@ package edu.umiacs.ace.driver.filter;
import edu.umiacs.ace.util.EntityManagerServlet;
import edu.umiacs.ace.monitor.core.Collection;
import edu.umiacs.ace.util.PersistUtil;
import edu.umiacs.util.Strings;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;
import javax.persistence.EntityManager;
import javax.persistence.EntityTransaction;
import javax.persistence.Query;
......@@ -57,15 +56,11 @@ import org.apache.log4j.Logger;
*/
public class FilterServlet extends EntityManagerServlet {
public static final String PARAM_TEST = "teststring";
public static final String PARAM_MODIFY = "modify";
public static final String PARAM_REGEX_PREFIX = "regex";
public static final String PARAM_TYPE_PREFIX = "type";
public static final String PARAM_REGEX_PREFIX = "regex-";
public static final String PARAM_AFFECTED_PREFIX = "affected-";
public static final String PAGE_REGEX_LIST = "regexlist";
public static final String PAGE_COLLECTION = "collection";
public static final String PAGE_NEXT = "next";
public static final String PAGE_ERROR = "errors";
public static final String PAGE_TEST = "teststring";
private static final Logger LOG = Logger.getLogger(FilterServlet.class);
@Override
......@@ -73,67 +68,43 @@ public class FilterServlet extends EntityManagerServlet {
HttpServletResponse response, EntityManager em ) throws ServletException, IOException {
RequestDispatcher dispatcher;
Collection c;
String testString;
ErrorList<MyFilterEntry> regexResults;
ErrorList<FilterEntry> regexResults = null;
if ( (c = getCollection(request, em)) == null ) {
throw new ServletException("No valid collection specified");
}
testString = request.getParameter(PARAM_TEST);
regexResults = getRegexList(request, testString);
regexResults = getRegexList(request);
if ( regexResults != null ) {
if ( !regexResults.isError() ) {
EntityTransaction et = em.getTransaction();
et.begin();
try {
// drop existing regex'
Query q = em.createNamedQuery("FilterEntry.dropByCollection");
q.setParameter("coll", c);
q.executeUpdate();
// add new regex
for ( FilterEntry fe : regexResults ) {
fe.setCollection(c);
em.persist(fe);
}
et.commit();
} catch ( Exception e ) {
et.rollback();
LOG.error("Error saving regex list ", e);
}
em = PersistUtil.getEntityManager();
EntityTransaction trans = em.getTransaction();
trans.begin();
Query q = em.createNamedQuery("FilterEntry.dropByCollection");
q.setParameter("coll", c);
q.executeUpdate();
for (FilterEntry fe : regexResults ) {
System.out.println(fe.getRegex() + " :: " + fe.getAffectedItem() + " :: " + fe.getCollection());
fe.setCollection(c);
em.persist(fe);
}
} else // just loading page
{
trans.commit();
} else { // just loading page
Query q = em.createNamedQuery("FilterEntry.listByCollection");
q.setParameter("coll", c);
regexResults = new ErrorList();
for ( Object o : q.getResultList() ) {
regexResults.add(new MyFilterEntry((FilterEntry) o));
regexResults.add((FilterEntry) o);
}
}
if ( !Strings.isEmpty(testString) ) {
request.setAttribute(PAGE_TEST, testString);
}
request.setAttribute(PAGE_NEXT,
(regexResults != null ? regexResults.size() : 1));
request.setAttribute(PAGE_REGEX_LIST, regexResults);
request.setAttribute(PAGE_ERROR, regexResults.isError());
request.setAttribute(PAGE_COLLECTION, c);
dispatcher = request.getRequestDispatcher("managefilters.jsp");
dispatcher.forward(request, response);
}
private ErrorList<MyFilterEntry> getRegexList( HttpServletRequest request,
String testString ) {
ErrorList<MyFilterEntry> retList = new ErrorList<MyFilterEntry>();
private ErrorList<FilterEntry> getRegexList( HttpServletRequest request) {
ErrorList<FilterEntry> retList = new ErrorList<FilterEntry>();
Map paramMap = request.getParameterMap();
if ( !Strings.isEmpty(paramMap.get(PARAM_MODIFY)) ) {
......@@ -144,13 +115,10 @@ public class FilterServlet extends EntityManagerServlet {
String[] regex = (String[]) entry.getValue();
String count = name.substring(PARAM_REGEX_PREFIX.length());
int type = Integer.parseInt(((String[]) paramMap.get(
PARAM_TYPE_PREFIX + count))[0]);
MyFilterEntry fe = new MyFilterEntry();
PARAM_AFFECTED_PREFIX + count))[0]);
FilterEntry fe = new FilterEntry();
fe.setRegex(regex[0]);
fe.setAffectedItem(type);
if ( !testEntry(fe, testString) ) {
retList.error = true;
}
if ( !Strings.isEmpty(fe.getRegex()) ) {
retList.add(fe);
......@@ -165,20 +133,6 @@ public class FilterServlet extends EntityManagerServlet {
}
}
private boolean testEntry( MyFilterEntry fe, String testString ) {
try {
Pattern p = Pattern.compile(fe.getRegex());
if ( !Strings.isEmpty(testString) ) {
fe.setMatchesTest(p.matcher(testString).matches());
}
return true;
} catch ( PatternSyntaxException e ) {
fe.setErrorMessage(e.getMessage() + " " + e.getDescription());
LOG.debug("Bad user supplied pattern: ", e);
return false;
}
}
public static class ErrorList<T> extends ArrayList<T> {
private boolean error = false;
......@@ -195,38 +149,4 @@ public class FilterServlet extends EntityManagerServlet {
}
}
public static class MyFilterEntry extends FilterEntry {
private String error = null;
private boolean matchesTest = false;
private MyFilterEntry() {
}
public MyFilterEntry( FilterEntry fe ) {
super.setId(fe.getId());
super.setAffectedItem(fe.getAffectedItem());
super.setRegex(fe.getRegex());
}
public boolean isError() {
return error != null;
}
public String getErrorMessage() {
return error;
}
public void setErrorMessage( String error ) {
this.error = error;
}
public boolean isMatchesTest() {
return matchesTest;
}
public void setMatchesTest( boolean matchesTest ) {
this.matchesTest = matchesTest;
}
}
}
......@@ -83,10 +83,10 @@ public class SimpleFilter implements PathFilter {
}
}
if ( fileRegex.size() == 0 ) {
if ( fileRegex.isEmpty() ) {
fileRegex = null;
}
if ( dirRegex.size() == 0 ) {
if ( dirRegex.isEmpty() ) {
dirRegex = null;
}
} finally {
......
......@@ -66,6 +66,8 @@ import javax.xml.bind.annotation.XmlRootElement;
@Entity
@Table(name = "collection")
@NamedQueries({
@NamedQuery(name = "Collection.listIds", query =
"SELECT c.id FROM Collection c"),
@NamedQuery(name = "Collection.listAllCollections", query =
"SELECT c FROM Collection c ORDER BY c.group"),
@NamedQuery(name = "Collection.getCollectionByName", query =
......
......@@ -66,6 +66,8 @@ import javax.persistence.TemporalType;
@Entity
@Table(name = "monitored_item")
@NamedQueries({
@NamedQuery(name = "MonitoredItem.listIds", query =
"SELECT m.id FROM MonitoredItem m WHERE m.parentCollection = :coll AND m.directory = false"),
@NamedQuery(name = "MonitoredItem.getItemByPath", query =
"SELECT m FROM MonitoredItem m WHERE m.path = :path AND m.parentCollection = :coll"),
//@NamedQuery(name = "MonitoredItem.setItemState", query = "UPDATE MonitoredItem m set m.state = :state, m.lastSeen = :date WHERE m.path = :path AND m.parentCollection = :coll"),
......@@ -265,4 +267,8 @@ public class MonitoredItem implements Serializable, Comparable {
public String getFileDigest() {
return fileDigest;
}
public boolean isError() {
return (this.state == 'I' || this.state == 'C');
}
}
......@@ -10,6 +10,7 @@ public class SettingsConstants {
public static final String PARAM_IMS = "ims";
public static final String PARAM_IMS_PORT = "ims.port";
public static final String PARAM_IMS_TOKEN_CLASS = "ims.tokenclass";
public static final String PARAM_IMS_SSL = "ims.ssl";
public static final String PARAM_DISABLE_AUDIT = "auto.audit.disable";
public static final String PARAM_THROTTLE_MAXAUDIT = "throttle.maxaudit";
public static final String PARAM_TIME = "throttle.wait";
......@@ -40,6 +41,7 @@ public class SettingsConstants {
public static final String ims = "ims.umiacs.umd.edu";
public static final String imsPort = "8080";
public static final String imsTokenClass = "SHA-256";
public static final String imsSSL = "false";
public static final String authManagement = "true";
public static final String maxIngestThreads = "4";
public static final String throttleWait = "0";
......
package edu.umiacs.ace.monitor.settings;
import edu.umiacs.ace.monitor.audit.AuditThreadFactory;
import edu.umiacs.ace.monitor.core.Collection;
import edu.umiacs.ace.util.PersistUtil;
import java.util.ArrayList;
......@@ -75,6 +76,8 @@ public class SettingsUtil {
trans.commit();
em.clear();
reloadSettings();
}
public static void deleteSettings(List<String> settings) {
......@@ -198,4 +201,29 @@ public class SettingsUtil {
}
// Update the settings our context listeners would normally do
private static void reloadSettings() {
EntityManager em = PersistUtil.getEntityManager();
Query q = em.createNamedQuery("SettingsParameter.getAttr");
SettingsParameter s = null;
// Host
q.setParameter("attr", SettingsConstants.PARAM_IMS);
s = (SettingsParameter) q.getSingleResult();
AuditThreadFactory.setIMS(s.getValue());
// Port
q.setParameter("attr", SettingsConstants.PARAM_IMS_PORT);
s = (SettingsParameter) q.getSingleResult();
AuditThreadFactory.setImsPort(Integer.parseInt(s.getValue()));
// SSL
q.setParameter("attr", SettingsConstants.PARAM_IMS_SSL);
s = (SettingsParameter) q.getSingleResult();
AuditThreadFactory.setSSL(Boolean.valueOf(s.getValue()));
// Token Class
q.setParameter("attr", SettingsConstants.PARAM_IMS_TOKEN_CLASS);
s = (SettingsParameter) q.getSingleResult();
AuditThreadFactory.setTokenClass(s.getValue());
}
}
\ No newline at end of file
<%--
Document : managefilters2
Created on : Jan 29, 2013, 3:13:13 PM
Author : shake
--%>
<%@page pageEncoding="UTF-8"%>
<%--
......@@ -5,7 +10,7 @@ The taglib directive below imports the JSTL library. If you uncomment it,
you must also add the JSTL library to the project. The Add Library... action
on Libraries node in Projects view can be used to add the JSTL 1.1 library.
--%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
......@@ -14,129 +19,86 @@ PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Modify Collection Filters</title>
<link rel="stylesheet" type="text/css" href="style.css" />
<script type="text/javascript" src="jquery-1.7.1.min.js"></script>
<script type="text/javascript">
var next = ${next};
function addNewRow(tableRef){
var myTable = document.getElementById(tableRef);
var tBody = myTable.getElementsByTagName('tbody')[0];
var newTR = document.createElement('tr');
newTR.id = 'tr'+next;
var td1 = document.createElement('td');
td1.innerHTML = '<input type="text" name="regex' + next +'>';
var td2 = document.createElement('td');
td2.innerHTML = '<input type=radio name="type'+next+'" value="1" checked> Files<br> <input type=radio name="type'+next+'" value="2"> Directories<br><input type=radio name="type'+next+'" value="3"> Both';
var td3 = document.createElement('td');
td3.innerHTML = '<a href="#" onclick="removeElement(\'tr' + next + '\')">Remove</a>';
newTR.appendChild (td1);
newTR.appendChild (td2);
newTR.appendChild (td3);
tBody.appendChild(newTR);
next++;
}
function removeElement(trNum) {
var child = document.getElementById(trNum);
child.parentNode.removeChild(child);
var counter = 0;
var $regval = $(
'<div name="item-0">' +
'<input class="regexVal" name="regex" value=""/>' +
'<input type="radio" name="affected" value="1" /> Files' +
'<input type="radio" name="affected" value="2" /> Directories' +
'<input type="radio" name="affected" value="3" /> Both' +
'<img src="images/file-bad.png" style="margin-left: 1%; cursor: hand; cursor: pointer;"/>' +
'<br/>' +
'</div>'
);
function addRegexItem(re, affected) {
var re = re || '';
var affected = affected || 1;
var $item = $regval.clone();
$item.attr('class', 'item-'+ ++counter);
$item.children("input[name=regex]").attr({'name': 'regex-'+counter, 'value':re});
$item.children("input[name=affected]").attr('name', 'affected-'+counter);
$item.children("input[value="+affected+"]").attr('checked', 'checked');
$("div.list").append($item)
}
$(document).ready(function() {
$("input[name=add]").click(function() {
addRegexItem();
});
$("img").live('click' ,function () {
$(this).parent().remove();
});
});
</script>
<style type="text/css">
#exp {
width: 200px;
}
#apply {
width: 100px;
}
#removecol {
width: 75px;
}
.regex {
font-size: large
}
</style>
</head>
<body>
<jsp:include page="header.jsp" />
<div class="standardBody">
<h3>Filters for files in '${collection.name}'</h3>
<br>
<c:if test="${error}">
There are errors in the listed filters therefore changes were not saved.<br>
</c:if>
<form action="ManageFilters" method="post">
Sample file to ignore: <input type="text" name="teststring" value="${teststring}">
<br><br>
<input type=hidden name="collectionid" value="${collection.id}">
<table id="regexTable">
<thead>
<tr>
<td id="exp">File pattern</td>
<td id="apply">Apply to</td>
<td id="removecol"></td>
<c:if test="${teststring != null}">
<td id="match">Will file be ignored?</td>
</c:if>
</tr>
</thead>
<tbody >
<c:set var="count" value="0"/>
<c:forEach var="item" items="${regexlist}">
<c:set var="filecheck" value=""/>
<c:set var="dircheck" value=""/>
<c:set var="bothcheck" value=""/>
<c:choose>
<c:when test="${item.affectedItem == 1}">
<c:set var="filecheck" value="checked"/>
</c:when>
<c:when test="${item.affectedItem == 2}">
<c:set var="dircheck" value="checked"/>
</c:when>
<c:when test="${item.affectedItem == 3}">
<c:set var="bothcheck" value="checked"/>
</c:when>
</c:choose>
<tr id="tr${count}">
<td><input type="text" name="regex${count}" value="${item.regex}"><br>${item.errorMessage}</td>
<td>
<input type=radio name="type${count}" value="1" ${filecheck}>Files<br>
<input type=radio name="type${count}" value="2" ${dircheck}>Directories<br>
<input type=radio name="type${count}" value="3" ${bothcheck}>Both
</td>
<td><a href="#" onclick="removeElement('tr${count}')">Remove</a></td>
<c:if test="${teststring != null}"><td>${item.matchesTest}</td></c:if>
</tr>
<c:set var="count" value="${count + 1}"/>
</c:forEach>
</tbody>
<tfoot><tr><td><a href="#" onclick="addNewRow('regexTable')">Add New Filter</a>&nbsp;&nbsp;<input type="submit" name="modify" value="Save"></td></tr></tfoot>
</table>
<h4>
<span style="width: 25%">Regular Expression</span>
<span style="margin-left: 11%">Affected Types </span>
</h4>
<form method=post action="ManageFilters">
<input type=hidden name="collectionid" value="${collection.id}"/>
<div class="list">
</div>
<script type="text/javascript">
<c:forEach var="re" items="${regexlist}" >
addRegexItem('${re.regex}', '${re.affectedItem}');
</c:forEach>
</script>
<input type="button" name="add" value="Add New Filter" class="submitLink" style="font-size: small; padding: 5px; margin-left: -1%; text-decoration: none"/>
<br/><br/>
<input type="submit" name="modify" value="Save" class="submitLink" style="margin-left: -1%"/>
</form>
<br>File patterns follow the java regular expression syntax described on <a href="http://java.sun.com/docs/books/tutorial/essential/regex/">Sun's website</a>
<br>
<br/>File patterns follow the java regular expression syntax described on <a href="http://java.sun.com/docs/books/tutorial/essential/regex/">Sun's website</a>
<br/>
Some basic file patterns
<dl>
<dt>Ignore all files containing 'test'
<dd><span class="regex">.*test.*</span><br>Will match ddtest, test, testdd, and ddtestdd
<dt>Ignore files named '.DS_Store' (useful on a OS-X)
<dd><span class="regex">\.DS_Store</span> <br> will match .DS_Store, but not DS_Store or .ds_store
<dt>Only include files that contain .jpg or .JPG
<dd>
<dt/>Ignore all files containing 'test'
<dd/><span class="regex">.*test.*</span><br/>Will match ddtest, test, testdd, and ddtestdd
<dt/>Ignore files named '.DS_Store' (useful on a OS-X)
<dd/><span class="regex">\.DS_Store</span> <br/> will match .DS_Store, but not DS_Store or .ds_store
<dt/>Only include files that contain .jpg or .JPG
<dd/>
</dl>
</div>
</div>
<jsp:include page="footer.jsp" />
</body>
</html>
......@@ -67,6 +67,11 @@
<div class="settingsVal"><input type=text name="ims.port" value="${currSettings['ims.port']}"/></div>
<div class="settingsHelp"><img src="images/help.png" title="Port the IMS Host runs on."></div>
</div>
<div class="settingsRow">
<div class="settingsName">IMS SSL:</div>
<div class="settingsVal"><input type=text name="ims.ssl" value="${currSettings['ims.ssl']}"/></div>
<div class="settingsHelp"><img src="images/help.png" title="Use SSL when connecting to the IMS."></div>
</div>
<div class="settingsRow">
<div class="settingsName">IMS Token Class:</div>
<div class="settingsVal"><input type=text name="ims.tokenclass" value="${currSettings['ims.tokenclass']}"/></div>
......
Supports Markdown
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