Revision 5998
Added by Chris Jones almost 14 years ago
src/edu/ucsb/nceas/metacat/MetacatHandler.java | ||
---|---|---|
1165 | 1165 |
return fileInputStream; |
1166 | 1166 |
} |
1167 | 1167 |
|
1168 |
/* |
|
1169 |
* Delete a document in metacat based on the docid. |
|
1170 |
* |
|
1171 |
* @param out - the print writer used to send output |
|
1172 |
* @param response - the HTTP servlet response to be returned |
|
1173 |
* @param docid - the internal docid as a String |
|
1174 |
* @param user - the username of the principal doing the delete |
|
1175 |
* @param groups - the groups list of the principal doing the delete |
|
1176 |
* |
|
1177 |
* @throws AccessionNumberException |
|
1178 |
* @throws McdbDocNotFoundException |
|
1179 |
* @throws InsufficientKarmaException |
|
1180 |
* @throws SQLException |
|
1181 |
* @throws Exception |
|
1182 |
*/ |
|
1183 |
private void deleteFromMetacat(PrintWriter out, HttpServletRequest request, |
|
1184 |
HttpServletResponse response, String docid, String user, String[] groups) |
|
1185 |
throws McdbDocNotFoundException { |
|
1186 |
|
|
1187 |
// Delete a document from the database based on the docid |
|
1188 |
try { |
|
1189 |
|
|
1190 |
DocumentImpl.delete(docid, user, groups, null); // null: don't notify server |
|
1191 |
EventLog.getInstance().log(request.getRemoteAddr(), |
|
1192 |
user, docid, "delete"); |
|
1193 |
response.setContentType("text/xml"); |
|
1194 |
out.println(this.PROLOG); |
|
1195 |
out.println(this.SUCCESS); |
|
1196 |
out.println("Document deleted."); |
|
1197 |
out.println(this.SUCCESSCLOSE); |
|
1198 |
logMetacat.info("MetaCatServlet.handleDeleteAction - " + |
|
1199 |
"Document deleted."); |
|
1200 |
|
|
1201 |
try { |
|
1202 |
// Delete from spatial cache if runningSpatialOption |
|
1203 |
if ( PropertyService.getProperty("spatial.runSpatialOption").equals("true") ) { |
|
1204 |
SpatialHarvester sh = new SpatialHarvester(); |
|
1205 |
sh.addToDeleteQue( DocumentUtil.getSmartDocId( docid ) ); |
|
1206 |
sh.destroy(); |
|
1207 |
} |
|
1208 |
|
|
1209 |
} catch ( PropertyNotFoundException pnfe ) { |
|
1210 |
logMetacat.error("MetacatHandler.deleteFromMetacat() - " + |
|
1211 |
"Couldn't find spatial.runSpatialOption property during " + |
|
1212 |
"document deletion."); |
|
1213 |
|
|
1214 |
} |
|
1215 |
|
|
1216 |
} catch (AccessionNumberException ane) { |
|
1217 |
response.setContentType("text/xml"); |
|
1218 |
out.println(this.PROLOG); |
|
1219 |
out.println(this.ERROR); |
|
1220 |
//out.println("Error deleting document!!!"); |
|
1221 |
out.println(ane.getMessage()); |
|
1222 |
out.println(this.ERRORCLOSE); |
|
1223 |
logMetacat.error("MetacatHandler.deleteFromMetacat() - " + |
|
1224 |
"Document could not be deleted: " |
|
1225 |
+ ane.getMessage()); |
|
1226 |
ane.printStackTrace(System.out); |
|
1227 |
|
|
1228 |
} catch ( SQLException sqle ) { |
|
1229 |
response.setContentType("text/xml"); |
|
1230 |
out.println(this.PROLOG); |
|
1231 |
out.println(this.ERROR); |
|
1232 |
//out.println("Error deleting document!!!"); |
|
1233 |
out.println(sqle.getMessage()); |
|
1234 |
out.println(this.ERRORCLOSE); |
|
1235 |
logMetacat.error("MetacatHandler.deleteFromMetacat() - " + |
|
1236 |
"Document could not be deleted: " |
|
1237 |
+ sqle.getMessage()); |
|
1238 |
sqle.printStackTrace(System.out); |
|
1239 |
|
|
1240 |
} catch ( McdbDocNotFoundException dnfe ) { |
|
1241 |
throw dnfe; |
|
1242 |
|
|
1243 |
} catch ( InsufficientKarmaException ike ) { |
|
1244 |
response.setContentType("text/xml"); |
|
1245 |
out.println(this.PROLOG); |
|
1246 |
out.println(this.ERROR); |
|
1247 |
//out.println("Error deleting document!!!"); |
|
1248 |
out.println(ike.getMessage()); |
|
1249 |
out.println(this.ERRORCLOSE); |
|
1250 |
logMetacat.error("MetacatHandler.deleteFromMetacat() - " + |
|
1251 |
"Document could not be deleted: " |
|
1252 |
+ ike.getMessage()); |
|
1253 |
ike.printStackTrace(System.out); |
|
1254 |
|
|
1255 |
} catch ( Exception e ) { |
|
1256 |
response.setContentType("text/xml"); |
|
1257 |
out.println(this.PROLOG); |
|
1258 |
out.println(this.ERROR); |
|
1259 |
//out.println("Error deleting document!!!"); |
|
1260 |
out.println(e.getMessage()); |
|
1261 |
out.println(this.ERRORCLOSE); |
|
1262 |
logMetacat.error("MetacatHandler.deleteFromMetacat() - " + |
|
1263 |
"Document could not be deleted: " |
|
1264 |
+ e.getMessage()); |
|
1265 |
e.printStackTrace(System.out); |
|
1266 |
|
|
1267 |
} |
|
1268 |
} |
|
1269 |
|
|
1168 | 1270 |
/** read metadata or data from Metacat |
1169 | 1271 |
* @throws PropertyNotFoundException |
1170 | 1272 |
* @throws ParseLSIDException |
... | ... | |
1906 | 2008 |
* database connection |
1907 | 2009 |
*/ |
1908 | 2010 |
public void handleDeleteAction(PrintWriter out, Hashtable<String, String[]> params, |
1909 |
HttpServletRequest request, HttpServletResponse response, |
|
1910 |
String user, String[] groups) { |
|
1911 |
Logger logMetacat = Logger.getLogger(MetaCatServlet.class); |
|
1912 |
String[] docid = params.get("docid"); |
|
2011 |
HttpServletRequest request, HttpServletResponse response, |
|
2012 |
String user, String[] groups) { |
|
2013 |
|
|
2014 |
Logger logMetacat = Logger.getLogger(MetaCatServlet.class); |
|
2015 |
String[] docid = params.get("docid"); |
|
2016 |
|
|
2017 |
if(docid == null){ |
|
2018 |
response.setContentType("text/xml"); |
|
2019 |
out.println(this.PROLOG); |
|
2020 |
out.println(this.ERROR); |
|
2021 |
out.println("Docid not specified."); |
|
2022 |
out.println(this.ERRORCLOSE); |
|
2023 |
logMetacat.error("MetaCatServlet.handleDeleteAction - " + |
|
2024 |
"Docid not specified for the document to be deleted."); |
|
2025 |
|
|
2026 |
} else { |
|
1913 | 2027 |
|
1914 |
if(docid == null){ |
|
2028 |
// delete the document from the database |
|
2029 |
try { |
|
2030 |
|
|
2031 |
// is the docid a GUID? |
|
2032 |
IdentifierManager im = IdentifierManager.getInstance(); |
|
2033 |
String localId = im.getLocalId(docid[0]); |
|
2034 |
this.deleteFromMetacat(out, request, response, localId, |
|
2035 |
user, groups); |
|
2036 |
|
|
2037 |
} catch (McdbDocNotFoundException mdnfe) { |
|
2038 |
|
|
2039 |
try { |
|
2040 |
// not a GUID, use the docid instead |
|
2041 |
this.deleteFromMetacat(out, request, response, docid[0], |
|
2042 |
user, groups); |
|
2043 |
|
|
2044 |
} catch ( McdbDocNotFoundException dnfe ) { |
|
1915 | 2045 |
response.setContentType("text/xml"); |
1916 |
out.println("<?xml version=\"1.0\"?>"); |
|
1917 |
out.println("<error>"); |
|
1918 |
out.println("Docid not specified."); |
|
1919 |
out.println("</error>"); |
|
1920 |
logMetacat.error("MetaCatServlet.handleDeleteAction - Docid not specified for the document to be deleted."); |
|
1921 |
} else { |
|
2046 |
out.println(this.PROLOG); |
|
2047 |
out.println(this.ERROR); |
|
2048 |
//out.println("Error deleting document!!!"); |
|
2049 |
out.println(dnfe.getMessage()); |
|
2050 |
out.println(this.ERRORCLOSE); |
|
2051 |
logMetacat.error("MetaCatServlet.handleDeleteAction - " + |
|
2052 |
"Document could not be deleted: " |
|
2053 |
+ dnfe.getMessage()); |
|
2054 |
dnfe.printStackTrace(System.out); |
|
1922 | 2055 |
|
1923 |
// delete the document from the database |
|
1924 |
try { |
|
1925 |
|
|
1926 |
try { |
|
1927 |
// null means notify server is null |
|
1928 |
DocumentImpl.delete(docid[0], user, groups, null); |
|
1929 |
EventLog.getInstance().log(request.getRemoteAddr(), |
|
1930 |
user, docid[0], "delete"); |
|
1931 |
response.setContentType("text/xml"); |
|
1932 |
out.println("<?xml version=\"1.0\"?>"); |
|
1933 |
out.println("<success>"); |
|
1934 |
out.println("Document deleted."); |
|
1935 |
out.println("</success>"); |
|
1936 |
logMetacat.info("MetaCatServlet.handleDeleteAction - Document deleted."); |
|
1937 |
|
|
1938 |
// Delete from spatial cache if runningSpatialOption |
|
1939 |
if ( PropertyService.getProperty("spatial.runSpatialOption").equals("true") ) { |
|
1940 |
SpatialHarvester sh = new SpatialHarvester(); |
|
1941 |
sh.addToDeleteQue( DocumentUtil.getSmartDocId( docid[0] ) ); |
|
1942 |
sh.destroy(); |
|
1943 |
} |
|
1944 |
|
|
1945 |
} catch (AccessionNumberException ane) { |
|
1946 |
response.setContentType("text/xml"); |
|
1947 |
out.println("<?xml version=\"1.0\"?>"); |
|
1948 |
out.println("<error>"); |
|
1949 |
//out.println("Error deleting document!!!"); |
|
1950 |
out.println(ane.getMessage()); |
|
1951 |
out.println("</error>"); |
|
1952 |
logMetacat.error("MetaCatServlet.handleDeleteAction - Document could not be deleted: " |
|
1953 |
+ ane.getMessage()); |
|
1954 |
ane.printStackTrace(System.out); |
|
1955 |
} |
|
1956 |
} catch (Exception e) { |
|
1957 |
response.setContentType("text/xml"); |
|
1958 |
out.println("<?xml version=\"1.0\"?>"); |
|
1959 |
out.println("<error>"); |
|
1960 |
out.println(e.getMessage()); |
|
1961 |
out.println("</error>"); |
|
1962 |
logMetacat.error("MetaCatServlet.handleDeleteAction - Document could not be deleted: " |
|
1963 |
+ e.getMessage()); |
|
1964 |
e.printStackTrace(System.out); |
|
1965 |
} |
|
1966 |
} |
|
2056 |
} // end try() |
|
2057 |
|
|
2058 |
} // end try() |
|
2059 |
|
|
2060 |
} // end if() |
|
2061 |
|
|
1967 | 2062 |
} |
1968 | 2063 |
|
1969 | 2064 |
/** |
Also available in: Unified diff
To support GUIDs in MetacatHandler.handleDeleteAction(), I've added in a new method:
deleteFromMetacat() - deletes a document based on the docid
This factors the deletion code out of handleDeleteAction(). handleDeleteAction() now does a docid lookup based on GUID, and if it is not found, reverts to the deletion based on docid instead.