Skip to content
Permalink
Browse files

Use the identifier table to help to decide if a missing-systemmetadat…

…a object was deleted.
  • Loading branch information
taojing2002 committed Feb 15, 2019
1 parent b2ece3c commit 4c083cccac2ac2647dbf4492ded5d63ce484cce0
@@ -2523,7 +2523,7 @@ public boolean existsInIdentifierTable(Identifier pid) throws SQLException {
// Check if the document exists in xml_revisions table.
//this only archives a document from xml_documents to xml_revisions (also archive the xml_nodes table as well)
logMetacat.debug("IdentifierManager.existsInIdentifierTable - check if the document "+ pid.getValue() +" exists in the identifier table");
pstmt = conn.prepareStatement("SELECT guid FROM xml_revisions WHERE guid = ?");
pstmt = conn.prepareStatement("SELECT guid FROM identifier WHERE guid = ?");
pstmt.setString(1, pid.getValue());
logMetacat.debug("IdentifierManager.existsInXmlLRevisionTable - executing SQL: " + pstmt.toString());
pstmt.execute();
@@ -1048,17 +1048,13 @@ public Checksum getChecksum(Session session, Identifier pid)

if (systemMetadata == null ) {
String error ="";
String localId = null;
boolean existsInIdentifierTable = false;
try {
localId = IdentifierManager.getInstance().getLocalId(pid.getValue());

existsInIdentifierTable = IdentifierManager.getInstance().existsInIdentifierTable(pid);
} catch (Exception e) {
logMetacat.warn("Couldn't find the local id for the pid "+pid.getValue());
logMetacat.warn("Couldn't determine if the "+pid.getValue()+" is in the identifier table since "+e.getMessage()+". So we assume it is not there.");
}

if(localId != null && EventLog.getInstance().isDeleted(localId)) {
error = DELETEDMESSAGE;
} else if (localId == null && EventLog.getInstance().isDeleted(pid.getValue())) {
if(existsInIdentifierTable) {
error = DELETEDMESSAGE;
}
throw new NotFound("1420", "Couldn't find an object identified by " + pid.getValue()+". "+error);
@@ -1725,17 +1721,14 @@ public boolean isNodeAuthorized(Session originatingNodeSession,
logMetacat.debug("System metadata for identifier " + pid.getValue() +
" is null.");
String error ="";
String localId = null;
boolean existsInIdentifierTable = false;
try {
localId = IdentifierManager.getInstance().getLocalId(pid.getValue());
existsInIdentifierTable = IdentifierManager.getInstance().existsInIdentifierTable(pid);

} catch (Exception e) {
logMetacat.warn("Couldn't find the local id for the pid "+pid.getValue());
logMetacat.warn("Couldn't determine if the "+pid.getValue()+" is in the identifier table since "+e.getMessage()+". So we assume it is not there.");
}

if(localId != null && EventLog.getInstance().isDeleted(localId)) {
error = DELETEDMESSAGE;
} else if (localId == null && EventLog.getInstance().isDeleted(pid.getValue())) {
if(existsInIdentifierTable) {
error = DELETEDMESSAGE;
}
throw new NotFound("4874", "Couldn't find an object identified by " + pid.getValue()+". "+error);
@@ -746,9 +746,14 @@ public InputStream get(Session session, Identifier pid)
inputStream = MetacatHandler.read(localId);
} catch (McdbDocNotFoundException de) {
String error ="";
if(EventLog.getInstance().isDeleted(localId)) {
error=DELETEDMESSAGE;
try {
if(IdentifierManager.getInstance().existsInIdentifierTable(pid)) {
error=DELETEDMESSAGE;
}
} catch(Exception e) {
logMetacat.warn("Can't determine if the pid "+pid.getValue()+" is deleted or not.");
}

throw new NotFound("1020", "The object specified by " +
pid.getValue() +
" does not exist at this node. "+error);
@@ -763,8 +768,12 @@ public InputStream get(Session session, Identifier pid)
// if we fail to set the input stream
if ( inputStream == null ) {
String error ="";
if(EventLog.getInstance().isDeleted(localId)) {
error=DELETEDMESSAGE;
try {
if(IdentifierManager.getInstance().existsInIdentifierTable(pid)) {
error=DELETEDMESSAGE;
}
} catch (Exception e) {
logMetacat.warn("Can't determine if the pid "+pid.getValue()+" is deleted or not.");
}
throw new NotFound("1020", "The object specified by " +
pid.getValue() +
@@ -1936,8 +1945,8 @@ public void checkV1SystemMetaPidExist(Identifier identifier, String serviceFailu
//the v1 method only handles a pid. so it should throw a not-found exception.
// check if the pid was deleted.
try {
String localId = IdentifierManager.getInstance().getLocalId(identifier.getValue());
if(EventLog.getInstance().isDeleted(localId)) {
boolean existsIndentifierTable = IdentifierManager.getInstance().existsInIdentifierTable(identifier);
if(existsIndentifierTable) {
notFoundMessage=notFoundMessage+" "+DELETEDMESSAGE;
}
} catch (Exception e) {
@@ -2006,15 +2015,13 @@ protected SystemMetadata getSystemMetadataForPID(Identifier pid, String serviceF
if(sysmeta == null) {
String error = "No system metadata could be found for given PID: " + pid.getValue();
if (needDeleteInfo) {
String localId = null;
boolean existsInIdentifierTable =false;
try {
localId = IdentifierManager.getInstance().getLocalId(pid.getValue());
existsInIdentifierTable = IdentifierManager.getInstance().existsInIdentifierTable(pid);
} catch (Exception e) {
logMetacat.warn("Couldn't find the local id for the pid "+pid.getValue());
logMetacat.warn("Couldn't determine if the pid "+pid.getValue()+" exists in the identifier table. We assume it doesn't");
}
if(localId != null && EventLog.getInstance().isDeleted(localId)) {
error = error + ". "+DELETEDMESSAGE;
} else if (localId == null && EventLog.getInstance().isDeleted(pid.getValue())) {
if(existsInIdentifierTable) {
error = error + ". "+DELETEDMESSAGE;
}
}
@@ -96,6 +96,7 @@ public static Test suite() {
suite.addTest(new IdentifierManagerTest("testSystemMetadataSIDExists"));
suite.addTest(new IdentifierManagerTest("testObjectFileExist"));
suite.addTest(new IdentifierManagerTest("testExistsInXmlRevisionTable"));
suite.addTest(new IdentifierManagerTest("testExistsInIdentifierTable"));

return suite;
}

0 comments on commit 4c083cc

Please sign in to comment.
You can’t perform that action at this time.