Project

General

Profile

« Previous | Next » 

Revision 7150

optionally remove the document/data file from the filesystem completely when 'deleting' it.
https://redmine.dataone.org/issues/2677

View differences:

src/edu/ucsb/nceas/metacat/DocumentImpl.java
1520 1520
	}	
1521 1521
    
1522 1522
    /**
1523
     * Deletes a doc or data file from the filesystem using the accession number.
1524
     * 
1525
     * @param accNumber
1526
     * @param isXml
1527
     * @throws McdbException
1528
     */
1529
    private static void deleteFromFileSystem(String accNumber, boolean isXml) throws McdbException {
1530

  
1531
    	// must have an id
1532
    	if (accNumber == null) {
1533
			throw new McdbException("Could not delete file.  Accession Number number is null" );
1534
		}
1535
    	
1536
		// remove the document from disk
1537
		String documentDir = null;
1538
		String documentPath = null;
1539

  
1540
		try {
1541
			// get the correct location on disk
1542
			if (isXml) {
1543
				documentDir = PropertyService.getProperty("application.documentfilepath");
1544
			} else {
1545
				documentDir = PropertyService.getProperty("application.datafilepath");
1546
			}
1547
			documentPath = documentDir + FileUtil.getFS() + accNumber;
1548

  
1549
			// delete it if it exists			
1550
			if (accNumber != null && FileUtil.getFileStatus(documentPath) != FileUtil.DOES_NOT_EXIST) {
1551
			    try {
1552
			    	FileUtil.deleteFile(documentPath);
1553
			    } catch (IOException ioe) {
1554
			        throw new McdbException("Could not delete file: " + documentPath + " : " + ioe.getMessage());
1555
			    }
1556
			}			
1557
		} catch (PropertyNotFoundException pnfe) {
1558
			throw new McdbException(pnfe.getClass().getName() + ": Could not delete file because: " 
1559
					+ documentPath + " : " + pnfe.getMessage());
1560
		}
1561
	}
1562
    
1563
    /**
1523 1564
	 * Strip out an inline data section from a 2.0.X version document. This assumes 
1524 1565
	 * that the inline element is within a distribution element and the id for the
1525 1566
	 * distribution is the same as the subtreeid in the xml_access table.
......
3195 3236
     *            the ID of the document to be deleted from the database
3196 3237
     */
3197 3238
    public static void delete(String accnum, String user, 
3198
      String[] groups, String notifyServer)
3239
      String[] groups, String notifyServer, boolean removeFile)
3199 3240
      throws SQLException, InsufficientKarmaException, McdbDocNotFoundException,
3200 3241
      Exception
3201 3242
    {
......
3375 3416
              //System.out.println("the string stored into cache is "+ resultsetBuffer.toString());
3376 3417
         	   DBQuery.clearQueryResultCache();
3377 3418
            }
3419
            
3420
            // remove the file if needed
3421
            if (removeFile) {
3422
            	deleteFromFileSystem(accnum, isXML);
3423
            }
3424
            
3378 3425
           double end = System.currentTimeMillis()/1000;
3379 3426
           logMetacat.info("DocumentImpl.delete - total delete time is:  " + (end - start));
3380 3427

  
......
4186 4233
                    xmldoc.toXml(System.out, null, null, true);
4187 4234
                }
4188 4235
            } else if (action.equals("DELETE")) {
4189
                DocumentImpl.delete(docid, null, null,null);
4236
                DocumentImpl.delete(docid, null, null, null, false);
4190 4237
                //System.out.println("Document deleted: " + docid);
4191 4238
            } else {
4192 4239
                /*
src/edu/ucsb/nceas/metacat/MetacatHandler.java
1137 1137
      // Delete a document from the database based on the docid
1138 1138
      try {
1139 1139
          
1140
        DocumentImpl.delete(docid, user, groups, null); // null: don't notify server
1140
        DocumentImpl.delete(docid, user, groups, null, false); // null: don't notify server
1141 1141
        EventLog.getInstance().log(request.getRemoteAddr(), request.getHeader("User-Agent"),
1142 1142
                user, docid, "delete");
1143 1143
        response.setContentType("text/xml");
src/edu/ucsb/nceas/metacat/dataone/D1NodeService.java
210 210
      if (allowed) {
211 211
          try {
212 212
              // delete the document
213
        	  //  TODO: the method - or one like it - actually needs to remove content not just archive it
214
              DocumentImpl.delete(localId, username, groupnames, null);
213
              DocumentImpl.delete(localId, username, groupnames, null, true);
215 214
              EventLog.getInstance().log(request.getRemoteAddr(), request.getHeader("User-Agent"), username, localId, Event.DELETE.xmlValue());
216 215

  
217 216
              // archive it
......
1439 1438
      if (allowed) {
1440 1439
          try {
1441 1440
              // archive the document
1442
        	  // this method just archives it in metacat
1443
              DocumentImpl.delete(localId, username, groupnames, null);
1441
              DocumentImpl.delete(localId, username, groupnames, null, false);
1444 1442
              EventLog.getInstance().log(request.getRemoteAddr(), request.getHeader("User-Agent"), username, localId, Event.DELETE.xmlValue());
1445 1443

  
1446 1444
              // archive it
src/edu/ucsb/nceas/metacat/replication/ReplicationHandler.java
714 714
         //because delete method docid should have rev number
715 715
         //so we just add one for it. This rev number is no sence.
716 716
         String accnum=docId+PropertyService.getProperty("document.accNumSeparator")+"1";
717
         DocumentImpl.delete(accnum, null, null, notifyServer);
717
         DocumentImpl.delete(accnum, null, null, notifyServer, false);
718 718
         logReplication.info("ReplicationHandler.handleDeleteSingleDocument - Successfully deleted doc " + docId);
719 719
         logReplication.info("ReplicationHandler.handleDeleteSingleDocument - Doc " + docId + " deleted");
720 720
         URL u = new URL("https://"+notifyServer);
src/edu/ucsb/nceas/metacat/replication/ReplicationService.java
660 660
			logReplication.info("ReplicationService.handleForceReplicateDeleteRequest - force replication delete docid " + docid);
661 661
			logReplication.info("ReplicationService.handleForceReplicateDeleteRequest - Force replication delete request from: " + server);
662 662
			logReplication.info("ReplicationService.handleForceReplicateDeleteRequest - Force replication delete docid: " + docid);
663
			DocumentImpl.delete(docid, null, null, server);
663
			DocumentImpl.delete(docid, null, null, server, false);
664 664
			logReplication.info("ReplicationService.handleForceReplicateDeleteRequest - document " + docid + " was successfully deleted ");
665 665
			EventLog.getInstance().log(request.getRemoteAddr(), request.getHeader("User-Agent"), REPLICATIONUSER, docid,
666 666
					"delete");

Also available in: Unified diff