Index: /main/trunk/greenstone3/src/java/org/greenstone/gsdl3/service/OAIPMH.java
===================================================================
--- /main/trunk/greenstone3/src/java/org/greenstone/gsdl3/service/OAIPMH.java	(revision 31910)
+++ /main/trunk/greenstone3/src/java/org/greenstone/gsdl3/service/OAIPMH.java	(revision 31911)
@@ -368,12 +368,15 @@
 	    logger.warn("OID: " + oid + " is not present in the collection's oai-inf database.");
 	} else  {
+
+	    // indexdb doesn't have info on deleted docs, only oaiinf db does.
+	    // So only oaiinfdb has timestamps for deleted docs
+	    // For non-deleted doc ids: also obtain timestamp from oaiinf db, 
+	    // but if the oaiinf db doesn't exist, resort to oailastmodified fields of indexdb.
+	    String timestamp = oai_info.getInfo(OAIXML.OAI_INF_TIMESTAMP); // stored in seconds, like oailastmodified in the collection index db
+	    millis = Long.parseLong(timestamp)*1000; // in milliseconds	    
+	    
 	    String oaiinf_status = oai_info.getInfo(OAIXML.OAI_INF_STATUS);
 	    if(oaiinf_status != null && oaiinf_status.equals(OAIXML.OAI_INF_DELETED)) {
 		OID_is_deleted = true;
-
-		// get the right timestamp for deletion: from oaiinf db
-		String timestamp = oai_info.getInfo(OAIXML.OAI_INF_TIMESTAMP); // in seconds presumably, like oailastmodified in the collection index db		
-		
-		millis = Long.parseLong(timestamp)*1000; // in milliseconds
 	    }
 	}
@@ -384,9 +387,10 @@
     DBInfo info = this.coll_db.getInfo(oid);
     if (info == null) {
-      logger.error("OID: " + oid + " is not present in the collection database.");
-      //return OAIXML.createErrorResponse(OAIXML.ID_DOES_NOT_EXIST, ""); // not an error: may exist as deleted (marked 'D') in oai-inf db
-    }
-    else if (millis == -1) { // so !OID_is_deleted, get oailastmodified from collection's index db
-	ArrayList<String> keys = new ArrayList<String>(info.getKeys());	
+	if(!OID_is_deleted) { // we don't expect to find entries for deleted docs in index db.
+	    logger.error("OID: " + oid + " is not present in the collection index database.");
+	    return OAIXML.createErrorResponse(OAIXML.ID_DOES_NOT_EXIST, "");
+	} // if doc deleted, id missing in indexdb is not an error: doc id would exist only in oai-inf db, marked as deleted 'D'
+    }
+    else if (millis == -1) { // so couldn't get doc lastmod from oaiinf db, get oailastmodified from collection's index db
 	millis = getDateStampMillis(info);	
     }
@@ -494,4 +498,9 @@
     for(int i=0; i<oid_list.size(); i++) {
       String oid = oid_list.get(i);
+
+      if(oid.equals(OAIXML.OAI_EARLIEST_TIMESTAMP_OID)) { // internal id not doc id, so skip
+	  continue;
+      }
+      
       boolean OID_is_deleted = false;
       long millis = -1;
@@ -503,12 +512,15 @@
 	      logger.warn("OID: " + oid + " is not present in the collection's oai-inf database.");
 	  } else  {
+	      
+	      // indexdb doesn't have info on deleted docs, only oaiinf db does.
+	      // So only oaiinfdb has timestamps for deleted docs
+	      // For non-deleted doc ids: also obtain timestamp from oaiinf db, 
+	      // but if the oaiinf db doesn't exist, resort to oailastmodified fields of indexdb.
+	      String timestamp = oai_info.getInfo(OAIXML.OAI_INF_TIMESTAMP); // stored in seconds like oailastmodified in the collection index db	      
+	      millis = Long.parseLong(timestamp)*1000; // in milliseconds
+		  
 	      String oaiinf_status = oai_info.getInfo(OAIXML.OAI_INF_STATUS);
 	      if(oaiinf_status != null && oaiinf_status.equals(OAIXML.OAI_INF_DELETED)) {
 		  OID_is_deleted = true;
-		  
-		  // get the right timestamp for deletion: from oaiinf db
-		  String timestamp = oai_info.getInfo(OAIXML.OAI_INF_TIMESTAMP); // in seconds presumably, like oailastmodified in the collection index db		
-		  
-		  millis = Long.parseLong(timestamp)*1000; // in milliseconds
 	      }
 	  }
@@ -516,7 +528,9 @@
       DBInfo info = this.coll_db.getInfo(oid);
       if (info == null) { // can happen if oid was deleted, in which case only oai_info keeps a record of the oid
-        logger.error("Collection database does not contain information about oid: " +oid);
-      }
-      else if (millis == -1) { // so !OID_is_deleted, get oailastmodified from collection's index db
+	  if(!OID_is_deleted) { // we don't expect to find entries for deleted docs in index db.
+	      logger.error("Collection database does not contain information about oid: " +oid);
+	  }
+      }
+      else if (millis == -1) { // so couldn't get doc lastmod from oaiinf db, get oailastmodified from collection's index db
 	  
 	  millis = getDateStampMillis(info);
@@ -524,4 +538,6 @@
 
       Date this_date = null;
+      String oailastmodified = (millis == -1) ? "" : OAIXML.getTime(millis);
+      
       if (millis == -1) {
 	  if (from_date != null || until_date !=null) {
@@ -544,5 +560,5 @@
       
       //compose the header element, which we'll be appending no matter what
-      Element header = createHeaderElement(doc, oid, OAIXML.getTime(millis), OID_is_deleted);
+      Element header = createHeaderElement(doc, oid, oailastmodified, OID_is_deleted);
 
       if (include_metadata) { // doing ListRecords
Index: /main/trunk/greenstone3/src/java/org/greenstone/gsdl3/util/OAIXML.java
===================================================================
--- /main/trunk/greenstone3/src/java/org/greenstone/gsdl3/util/OAIXML.java	(revision 31910)
+++ /main/trunk/greenstone3/src/java/org/greenstone/gsdl3/util/OAIXML.java	(revision 31911)
@@ -78,5 +78,9 @@
   public static final String RESPONSE_DATE = "responseDate";
   public static final String REQUEST = "request";
-  
+
+  // internal "OID" identifiers in the oai-inf db
+  /** represents the timestamp of the OAI collection (when its oai-inf db was first created) */
+  public static final String OAI_EARLIEST_TIMESTAMP_OID = "_earliesttimestamp";  
+    
   // Identify data
   public static final String ADMIN_EMAIL = "adminEmail";
