Revision 6001
Added by Chris Jones almost 14 years ago
src/edu/ucsb/nceas/metacat/DocumentImpl.java | ||
---|---|---|
56 | 56 |
|
57 | 57 |
import edu.ucsb.nceas.metacat.accesscontrol.AccessControlInterface; |
58 | 58 |
import edu.ucsb.nceas.metacat.accesscontrol.AccessControlList; |
59 |
import edu.ucsb.nceas.metacat.client.InsufficientKarmaException; |
|
59 | 60 |
import edu.ucsb.nceas.metacat.database.DBConnection; |
60 | 61 |
import edu.ucsb.nceas.metacat.database.DBConnectionPool; |
61 | 62 |
import edu.ucsb.nceas.metacat.database.DatabaseService; |
... | ... | |
3169 | 3170 |
* @param docid |
3170 | 3171 |
* the ID of the document to be deleted from the database |
3171 | 3172 |
*/ |
3172 |
public static void delete(String accnum, String user, String[] groups, String notifyServer) |
|
3173 |
throws Exception |
|
3173 |
public static void delete(String accnum, String user, |
|
3174 |
String[] groups, String notifyServer) |
|
3175 |
throws SQLException, InsufficientKarmaException, McdbDocNotFoundException, |
|
3176 |
Exception |
|
3174 | 3177 |
{ |
3175 | 3178 |
|
3176 | 3179 |
DBConnection conn = null; |
... | ... | |
3199 | 3202 |
rs.close(); |
3200 | 3203 |
pstmt.close(); |
3201 | 3204 |
conn.increaseUsageCount(1); |
3202 |
throw new Exception("Docid " + accnum + " does not exist. "
|
|
3203 |
+ "Please check that you have also specified the"
|
|
3204 |
+ " revision number of the document.");
|
|
3205 |
throw new McdbDocNotFoundException("Docid " + accnum +
|
|
3206 |
" does not exist. Please check that you have also " +
|
|
3207 |
"specified the revision number of the document.");
|
|
3205 | 3208 |
} |
3206 | 3209 |
rs.close(); |
3207 | 3210 |
pstmt.close(); |
... | ... | |
3214 | 3217 |
isXML = false; |
3215 | 3218 |
} |
3216 | 3219 |
|
3217 |
logMetacat.info("DocumentImpl.delete - Start deleting doc " + docid + "..."); |
|
3220 |
logMetacat.info("DocumentImpl.delete - Start deleting doc " + |
|
3221 |
docid + "..."); |
|
3218 | 3222 |
double start = System.currentTimeMillis()/1000; |
3219 | 3223 |
// check for 'write' permission for 'user' to delete this document |
3220 | 3224 |
if (!hasAllPermission(user, groups, accnum)) { |
3221 | 3225 |
if(!AuthUtil.isAdministrator(user, groups)){ |
3222 |
throw new Exception( |
|
3223 |
"User " + user |
|
3224 |
+ " does not have permission to delete XML Document #"
|
|
3225 |
+ accnum);
|
|
3226 |
throw new InsufficientKarmaException(
|
|
3227 |
"User " + user +
|
|
3228 |
" does not have permission to delete XML Document #" +
|
|
3229 |
accnum); |
|
3226 | 3230 |
} |
3227 | 3231 |
} |
3228 | 3232 |
|
... | ... | |
3370 | 3374 |
double end = System.currentTimeMillis()/1000; |
3371 | 3375 |
logMetacat.info("DocumentImpl.delete - total delete time is: " + (end - start)); |
3372 | 3376 |
|
3373 |
} catch (Exception e) { |
|
3377 |
} catch ( SQLException sqle ) { |
|
3378 |
logMetacat.error("DocumentImpl.delete - SQL error: " + sqle.getMessage()); |
|
3379 |
throw sqle; |
|
3380 |
|
|
3381 |
} catch ( Exception e ) { |
|
3374 | 3382 |
logMetacat.error("DocumentImpl.delete - General error: " + e.getMessage()); |
3375 | 3383 |
throw e; |
3376 | 3384 |
} finally { |
src/edu/ucsb/nceas/metacat/dataone/CrudService.java | ||
---|---|---|
968 | 968 |
{ |
969 | 969 |
DocumentImpl.delete(docid, sessionData.getUserName(), sessionData.getGroupNames(), null); |
970 | 970 |
} |
971 |
catch(Exception e) |
|
971 |
catch(SQLException e)
|
|
972 | 972 |
{ |
973 | 973 |
throw new ServiceFailure("1350", "Could not delete document: " + e.getMessage()); |
974 | 974 |
} |
975 |
|
|
975 |
catch(McdbDocNotFoundException e) |
|
976 |
{ |
|
977 |
throw new ServiceFailure("1350", "Could not delete document: " + e.getMessage()); |
|
978 |
} |
|
979 |
catch(InsufficientKarmaException e) |
|
980 |
{ |
|
981 |
throw new ServiceFailure("1350", "Could not delete document: " + e.getMessage()); |
|
982 |
} |
|
983 |
catch(Exception e) |
|
984 |
{ |
|
985 |
throw new ServiceFailure("1350", "Could not delete document: " + e.getMessage()); |
|
986 |
} |
|
976 | 987 |
return guid; |
977 | 988 |
} |
978 | 989 |
|
src/edu/ucsb/nceas/metacat/replication/ReplicationHandler.java | ||
---|---|---|
32 | 32 |
import edu.ucsb.nceas.metacat.DocumentImpl; |
33 | 33 |
import edu.ucsb.nceas.metacat.DocumentImplWrapper; |
34 | 34 |
import edu.ucsb.nceas.metacat.EventLog; |
35 |
import edu.ucsb.nceas.metacat.McdbDocNotFoundException; |
|
35 | 36 |
import edu.ucsb.nceas.metacat.accesscontrol.AccessControlForSingleFile; |
36 | 37 |
import edu.ucsb.nceas.metacat.accesscontrol.XMLAccessDAO; |
38 |
import edu.ucsb.nceas.metacat.client.InsufficientKarmaException; |
|
37 | 39 |
import edu.ucsb.nceas.metacat.database.DBConnection; |
38 | 40 |
import edu.ucsb.nceas.metacat.database.DBConnectionPool; |
39 | 41 |
import edu.ucsb.nceas.metacat.database.DatabaseService; |
... | ... | |
695 | 697 |
} |
696 | 698 |
|
697 | 699 |
}//try |
700 |
catch(McdbDocNotFoundException e) |
|
701 |
{ |
|
702 |
logMetacat.error("ReplicationHandler.handleDeleteSingleDocument - " + ReplicationService.METACAT_REPL_ERROR_MSG); |
|
703 |
logReplication.error("ReplicationHandler.handleDeleteSingleDocument - Failed to delete doc " + docId + |
|
704 |
" in db because because " + e.getMessage()); |
|
705 |
throw new HandlerException("ReplicationHandler.handleDeleteSingleDocument - generic exception " |
|
706 |
+ "when handling document: " + e.getMessage()); |
|
707 |
} |
|
708 |
catch(InsufficientKarmaException e) |
|
709 |
{ |
|
710 |
logMetacat.error("ReplicationHandler.handleDeleteSingleDocument - " + ReplicationService.METACAT_REPL_ERROR_MSG); |
|
711 |
logReplication.error("ReplicationHandler.handleDeleteSingleDocument - Failed to delete doc " + docId + |
|
712 |
" in db because because " + e.getMessage()); |
|
713 |
throw new HandlerException("ReplicationHandler.handleDeleteSingleDocument - generic exception " |
|
714 |
+ "when handling document: " + e.getMessage()); |
|
715 |
} |
|
716 |
catch(SQLException e) |
|
717 |
{ |
|
718 |
logMetacat.error("ReplicationHandler.handleDeleteSingleDocument - " + ReplicationService.METACAT_REPL_ERROR_MSG); |
|
719 |
logReplication.error("ReplicationHandler.handleDeleteSingleDocument - Failed to delete doc " + docId + |
|
720 |
" in db because because " + e.getMessage()); |
|
721 |
throw new HandlerException("ReplicationHandler.handleDeleteSingleDocument - generic exception " |
|
722 |
+ "when handling document: " + e.getMessage()); |
|
723 |
} |
|
698 | 724 |
catch(Exception e) |
699 | 725 |
{ |
700 | 726 |
logMetacat.error("ReplicationHandler.handleDeleteSingleDocument - " + ReplicationService.METACAT_REPL_ERROR_MSG); |
src/edu/ucsb/nceas/metacat/replication/ReplicationService.java | ||
---|---|---|
69 | 69 |
import edu.ucsb.nceas.metacat.accesscontrol.AccessControlForSingleFile; |
70 | 70 |
import edu.ucsb.nceas.metacat.accesscontrol.PermOrderException; |
71 | 71 |
import edu.ucsb.nceas.metacat.accesscontrol.XMLAccessDAO; |
72 |
import edu.ucsb.nceas.metacat.client.InsufficientKarmaException; |
|
72 | 73 |
import edu.ucsb.nceas.metacat.database.DBConnection; |
73 | 74 |
import edu.ucsb.nceas.metacat.database.DBConnectionPool; |
74 | 75 |
import edu.ucsb.nceas.metacat.database.DatabaseService; |
... | ... | |
752 | 753 |
EventLog.getInstance().log(request.getRemoteAddr(), REPLICATIONUSER, docid, |
753 | 754 |
"delete"); |
754 | 755 |
logReplication.info("ReplicationService.handleForceReplicateDeleteRequest - document " + docid + " was successfully deleted "); |
756 |
} catch (McdbDocNotFoundException e) { |
|
757 |
logMetacat.error("ReplicationService.handleForceReplicateDeleteRequest - " + ReplicationService.METACAT_REPL_ERROR_MSG); |
|
758 |
logReplication.error("document " + docid |
|
759 |
+ " failed to delete because " + e.getMessage()); |
|
760 |
logReplication.error("ReplicationService.handleForceReplicateDeleteRequest - error: " + e.getMessage()); |
|
761 |
} catch (InsufficientKarmaException e) { |
|
762 |
logMetacat.error("ReplicationService.handleForceReplicateDeleteRequest - " + ReplicationService.METACAT_REPL_ERROR_MSG); |
|
763 |
logReplication.error("document " + docid |
|
764 |
+ " failed to delete because " + e.getMessage()); |
|
765 |
logReplication.error("ReplicationService.handleForceReplicateDeleteRequest - error: " + e.getMessage()); |
|
766 |
} catch (SQLException e) { |
|
767 |
logMetacat.error("ReplicationService.handleForceReplicateDeleteRequest - " + ReplicationService.METACAT_REPL_ERROR_MSG); |
|
768 |
logReplication.error("document " + docid |
|
769 |
+ " failed to delete because " + e.getMessage()); |
|
770 |
logReplication.error("ReplicationService.handleForceReplicateDeleteRequest - error: " + e.getMessage()); |
|
755 | 771 |
} catch (Exception e) { |
756 | 772 |
logMetacat.error("ReplicationService.handleForceReplicateDeleteRequest - " + ReplicationService.METACAT_REPL_ERROR_MSG); |
757 | 773 |
logReplication.error("document " + docid |
Also available in: Unified diff
DocumentImpl.delete() now throws finer grained exceptions (not a general exception). Consequently, the classes that call it have been updated to handle the thrown exceptions, including CrudService, ReplicationHandler, and ReplicationService.