Project

General

Profile

« Previous | Next » 

Revision 6001

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.

View differences:

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 {

Also available in: Unified diff