Revision 2113
Added by Matt Jones about 20 years ago
MetaCatServlet.java | ||
---|---|---|
38 | 38 |
import java.sql.PreparedStatement; |
39 | 39 |
import java.sql.ResultSet; |
40 | 40 |
import java.sql.SQLException; |
41 |
import java.sql.Timestamp; |
|
42 |
import java.text.ParseException; |
|
43 |
import java.text.SimpleDateFormat; |
|
41 | 44 |
import java.util.Enumeration; |
42 | 45 |
import java.util.Hashtable; |
43 | 46 |
import java.util.PropertyResourceBundle; |
... | ... | |
95 | 98 |
* action=getdataguide -- retrieve a Data Guide <br> |
96 | 99 |
* action=getprincipals -- retrieve a list of principals in XML <br> |
97 | 100 |
* datadoc -- data document name (id) <br> |
101 |
* action=getlog -- get a report of events that have occurred in the system<br> |
|
102 |
* ipAddress -- filter on one or more IP addresses<br> |
|
103 |
* principal -- filter on one or more principals (LDAP DN syntax)<br> |
|
104 |
* docid -- filter on one or more document identifiers (with revision)<br> |
|
105 |
* event -- filter on event type (e.g., read, insert, update, delete)<br> |
|
106 |
* start -- filter out events before the start date-time<br> |
|
107 |
* end -- filter out events before the end date-time<br> |
|
98 | 108 |
* <p> |
99 | 109 |
* The particular combination of parameters that are valid for each particular |
100 | 110 |
* action value is quite specific. This documentation will be reorganized to |
... | ... | |
205 | 215 |
{ |
206 | 216 |
// Close all db connection |
207 | 217 |
System.out.println("Destroying MetacatServlet"); |
208 |
connPool.release();
|
|
218 |
DBConnectionPool.release();
|
|
209 | 219 |
} |
210 | 220 |
|
211 | 221 |
/** Handle "GET" method requests from HTTP clients */ |
... | ... | |
467 | 477 |
PrintWriter out = response.getWriter(); |
468 | 478 |
out.println(Version.getVersionAsXml()); |
469 | 479 |
out.close(); |
480 |
} else if (action.equals("getlog")) { |
|
481 |
handleGetLogAction(params, request, response); |
|
470 | 482 |
} else if (action.equals("login") || action.equals("logout")) { |
471 | 483 |
} else if (action.equals("protocoltest")) { |
472 | 484 |
String testURL = "metacat://dev.nceas.ucsb.edu/NCEAS.897766.9"; |
... | ... | |
1139 | 1151 |
DocumentImpl doc = new DocumentImpl(docid); |
1140 | 1152 |
|
1141 | 1153 |
//check the permission for read |
1142 |
if (!doc.hasReadPermission(user, groups, docid)) {
|
|
1154 |
if (!DocumentImpl.hasReadPermission(user, groups, docid)) {
|
|
1143 | 1155 |
Exception e = new Exception("User " + user |
1144 | 1156 |
+ " does not have permission" |
1145 | 1157 |
+ " to read the document with the docid " + docid); |
... | ... | |
1312 | 1324 |
DocumentImpl doc = new DocumentImpl(docid); |
1313 | 1325 |
|
1314 | 1326 |
//check the permission for read |
1315 |
if (!doc.hasReadPermission(user, groups, docid)) {
|
|
1327 |
if (!DocumentImpl.hasReadPermission(user, groups, docid)) {
|
|
1316 | 1328 |
Exception e = new Exception("User " + user |
1317 | 1329 |
+ " does not have " |
1318 | 1330 |
+ "permission to read the document with the docid " |
... | ... | |
1980 | 1992 |
out.println(e.getMessage()); |
1981 | 1993 |
out.println("</error>"); |
1982 | 1994 |
} |
1983 |
|
|
1984 | 1995 |
} |
1985 | 1996 |
|
1986 | 1997 |
/** |
1998 |
* Print a report from the event log based on filter parameters passed in |
|
1999 |
* from the web. |
|
2000 |
* |
|
2001 |
* TODO: make sure urlencoding of timestamp params is working |
|
2002 |
* |
|
2003 |
* @param params the parameters from the web request |
|
2004 |
* @param request the http request object for getting request details |
|
2005 |
* @param response the http response object for writing output |
|
2006 |
*/ |
|
2007 |
private void handleGetLogAction(Hashtable params, HttpServletRequest request, |
|
2008 |
HttpServletResponse response) |
|
2009 |
{ |
|
2010 |
// Get all of the parameters in the correct formats |
|
2011 |
String[] ipAddress = (String[])params.get("ipaddress"); |
|
2012 |
String[] principal = (String[])params.get("principal"); |
|
2013 |
String[] docid = (String[])params.get("docid"); |
|
2014 |
String[] event = (String[])params.get("event"); |
|
2015 |
String[] startArray = (String[]) params.get("start"); |
|
2016 |
String[] endArray = (String[]) params.get("end"); |
|
2017 |
String start = null; |
|
2018 |
String end = null; |
|
2019 |
if (startArray != null) { |
|
2020 |
start = startArray[0]; |
|
2021 |
} |
|
2022 |
if (endArray != null) { |
|
2023 |
end = endArray[0]; |
|
2024 |
} |
|
2025 |
Timestamp startDate = null; |
|
2026 |
Timestamp endDate = null; |
|
2027 |
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
|
2028 |
try { |
|
2029 |
if (start != null) { |
|
2030 |
startDate = new Timestamp((format.parse(start)).getTime()); |
|
2031 |
} |
|
2032 |
if (end != null) { |
|
2033 |
endDate = new Timestamp((format.parse(end)).getTime()); |
|
2034 |
} |
|
2035 |
} catch (ParseException e) { |
|
2036 |
System.out.println("Failed to created Timestamp from input."); |
|
2037 |
} |
|
2038 |
|
|
2039 |
// Request the report by passing the filter parameters |
|
2040 |
try { |
|
2041 |
response.setContentType("text/xml"); |
|
2042 |
PrintWriter out = response.getWriter(); |
|
2043 |
out.println(EventLog.getInstance().getReport(ipAddress, principal, |
|
2044 |
docid, event, startDate, endDate)); |
|
2045 |
out.close(); |
|
2046 |
} catch (IOException e) { |
|
2047 |
MetaCatUtil.debugMessage( |
|
2048 |
"Could not open http response for writing: " |
|
2049 |
+ e.getMessage(), 5); |
|
2050 |
} |
|
2051 |
} |
|
2052 |
|
|
2053 |
/** |
|
1987 | 2054 |
* Handle documents passed to metacat that are encoded using the |
1988 | 2055 |
* "multipart/form-data" mime type. This is typically used for uploading |
1989 | 2056 |
* data files which may be binary and large. |
Also available in: Unified diff
Added the EventLog functionality to the servlet as action=getlog. Valid parameters are ipAddress, principal, docid, event, start, end. All parameters can be repeated except start and end.