64 |
64 |
import edu.ucsb.nceas.metacat.accesscontrol.AccessControlList;
|
65 |
65 |
import edu.ucsb.nceas.metacat.client.InsufficientKarmaException;
|
66 |
66 |
import edu.ucsb.nceas.metacat.common.query.EnabledQueryEngines;
|
|
67 |
import edu.ucsb.nceas.metacat.common.resourcemap.ResourceMapNamespaces;
|
67 |
68 |
import edu.ucsb.nceas.metacat.database.DBConnection;
|
68 |
69 |
import edu.ucsb.nceas.metacat.database.DBConnectionPool;
|
69 |
70 |
import edu.ucsb.nceas.metacat.database.DatabaseService;
|
... | ... | |
85 |
86 |
import edu.ucsb.nceas.utilities.PropertyNotFoundException;
|
86 |
87 |
import edu.ucsb.nceas.utilities.UtilException;
|
87 |
88 |
|
|
89 |
import org.apache.commons.io.FileUtils;
|
88 |
90 |
import org.apache.commons.io.IOUtils;
|
89 |
91 |
import org.apache.commons.io.input.XmlStreamReader;
|
90 |
92 |
import org.apache.log4j.Logger;
|
... | ... | |
1557 |
1559 |
throw new McdbException("Could not delete file. Accession Number number is null" );
|
1558 |
1560 |
}
|
1559 |
1561 |
|
1560 |
|
// remove the document from disk
|
1561 |
|
String documentDir = null;
|
1562 |
|
String documentPath = null;
|
1563 |
|
|
1564 |
|
try {
|
|
1562 |
// remove the document from disk
|
|
1563 |
String documentPath = null;
|
|
1564 |
|
|
1565 |
// get the correct location on disk
|
|
1566 |
documentPath = getFilePath(accNumber, isXml);
|
|
1567 |
// delete it if it exists
|
|
1568 |
if (accNumber != null && FileUtil.getFileStatus(documentPath) != FileUtil.DOES_NOT_EXIST) {
|
|
1569 |
try {
|
|
1570 |
FileUtil.deleteFile(documentPath);
|
|
1571 |
} catch (IOException ioe) {
|
|
1572 |
throw new McdbException("Could not delete file: " + documentPath + " : " + ioe.getMessage());
|
|
1573 |
}
|
|
1574 |
}
|
|
1575 |
|
|
1576 |
}
|
|
1577 |
|
|
1578 |
private static String getFilePath(String accNumber, boolean isXml) throws McdbException{
|
|
1579 |
if (accNumber == null) {
|
|
1580 |
throw new McdbException("Could not get the file path since the Accession Number number is null" );
|
|
1581 |
}
|
|
1582 |
String documentPath = null;
|
|
1583 |
try {
|
|
1584 |
String documentDir = null;
|
|
1585 |
|
1565 |
1586 |
// get the correct location on disk
|
1566 |
1587 |
if (isXml) {
|
1567 |
1588 |
documentDir = PropertyService.getProperty("application.documentfilepath");
|
... | ... | |
1569 |
1590 |
documentDir = PropertyService.getProperty("application.datafilepath");
|
1570 |
1591 |
}
|
1571 |
1592 |
documentPath = documentDir + FileUtil.getFS() + accNumber;
|
1572 |
|
|
1573 |
|
// delete it if it exists
|
1574 |
|
if (accNumber != null && FileUtil.getFileStatus(documentPath) != FileUtil.DOES_NOT_EXIST) {
|
1575 |
|
try {
|
1576 |
|
FileUtil.deleteFile(documentPath);
|
1577 |
|
} catch (IOException ioe) {
|
1578 |
|
throw new McdbException("Could not delete file: " + documentPath + " : " + ioe.getMessage());
|
1579 |
|
}
|
1580 |
|
}
|
|
1593 |
return documentPath;
|
|
1594 |
|
1581 |
1595 |
} catch (PropertyNotFoundException pnfe) {
|
1582 |
1596 |
throw new McdbException(pnfe.getClass().getName() + ": Could not delete file because: "
|
1583 |
1597 |
+ documentPath + " : " + pnfe.getMessage());
|
1584 |
1598 |
}
|
1585 |
|
}
|
|
1599 |
}
|
1586 |
1600 |
|
1587 |
1601 |
/**
|
1588 |
1602 |
* Strip out an inline data section from a 2.0.X version document. This assumes
|
... | ... | |
3566 |
3580 |
sysMeta.setDateSysMetadataModified(Calendar.getInstance().getTime());
|
3567 |
3581 |
if(!removeAll) {
|
3568 |
3582 |
HazelcastService.getInstance().getSystemMetadataMap().put(guid, sysMeta);
|
|
3583 |
MetacatSolrIndex.getInstance().submit(guid, sysMeta, null, false);
|
3569 |
3584 |
} else {
|
3570 |
3585 |
try {
|
3571 |
3586 |
logMetacat.debug("the system metadata contains the key - guid "+guid.getValue()+" before removing is "+HazelcastService.getInstance().getSystemMetadataMap().containsKey(guid));
|
3572 |
3587 |
HazelcastService.getInstance().getSystemMetadataMap().remove(guid);
|
3573 |
3588 |
logMetacat.debug("the system metadata contains the guid "+guid.getValue()+" after removing is "+HazelcastService.getInstance().getSystemMetadataMap().containsKey(guid));
|
|
3589 |
if(ResourceMapNamespaces.isResourceMap(sysMeta.getFormatId())) {
|
|
3590 |
byte[] resourceMapData = FileUtils.readFileToByteArray(new File(getFilePath(accnum, isXML)));
|
|
3591 |
MetacatSolrIndex.getInstance().submit(guid, sysMeta, null, false, resourceMapData);
|
|
3592 |
} else {
|
|
3593 |
MetacatSolrIndex.getInstance().submit(guid, sysMeta, null, false);
|
|
3594 |
}
|
3574 |
3595 |
} catch (RuntimeException ee) {
|
3575 |
3596 |
logMetacat.warn("we catch the run time exception in deleting system metadata "+ee.getMessage());
|
3576 |
3597 |
throw new Exception("DocumentImpl.delete -"+ee.getMessage());
|
3577 |
3598 |
}
|
3578 |
3599 |
}
|
3579 |
|
MetacatSolrIndex.getInstance().submit(guid, sysMeta, null, false);
|
|
3600 |
|
3580 |
3601 |
}
|
3581 |
3602 |
|
3582 |
3603 |
// only commit if all of this was successful
|
Add the code to handle the delete of the resource map.