Index: /main/trunk/greenstone3/src/java/org/greenstone/gsdl3/core/OAIReceptionist.java
===================================================================
--- /main/trunk/greenstone3/src/java/org/greenstone/gsdl3/core/OAIReceptionist.java	(revision 32867)
+++ /main/trunk/greenstone3/src/java/org/greenstone/gsdl3/core/OAIReceptionist.java	(revision 32868)
@@ -64,4 +64,16 @@
   /** a vector of the names, for convenience */
   protected Vector<String> collection_name_list = null;
+  /** a vector to be maintained in parallel to Vector collection_name_list in terms of adds/removes.
+   * This is a list of Integers that denote whether the associated collection in collection_name_list is currently ACTIVE or DEACTIVATED.
+   * The state for any collection can be changed when the building folder is moved to index during rebuilding, before and after which
+   * activateOrDeactivateCollection() here is called to deactivate a collection and then activate it again, respectively.
+   * Can't make collection_name_list a HashMap, since a map's keys are unique (i.e. a Set) whereas collection_name_list is a Vector.   
+   * I've confirmed that collection_name_list is specifically a list of OAI collection names, not non-OAI collections.
+  */
+  protected Vector<Integer> collection_state_list = null;
+  /** Possible states for a collection */
+  protected static final Integer DEACTIVATED = new Integer(0);
+  protected static final Integer ACTIVE = new Integer(1);
+  
   /** If this is true, then there are no OAI enabled collections, so can always return noRecordsMatch (after validating the request params) */
   protected boolean noRecordsMatch = false;
@@ -82,5 +94,5 @@
   /** the list metadata formats response */
   protected Element listmetadataformats_response = null;
-
+  
   public OAIReceptionist() {
 
@@ -208,4 +220,5 @@
     
     this.collection_name_list = new Vector<String>();
+	this.collection_state_list = new Vector<Integer>();
     StringBuffer to = new StringBuffer();
     boolean first = true;
@@ -214,4 +227,5 @@
 	String coll_id =((Element) child).getAttribute(GSXML.NAME_ATT);
 	this.collection_name_list.add(coll_id);
+	this.collection_state_list.add(ACTIVE); // collections start out active (they get activated during configuring) until deactivation takes place
 	if (!first) {
 	  to.append(',');
@@ -280,4 +294,7 @@
       } // for each set in the collection
     } // for each OAI enabled collection
+	
+	
+	debugListActivatedCollections("List of collections after configuring Set Info");
     return true;
   }
@@ -329,8 +346,35 @@
 		return false;
 	} else {
+		// the collection's state has successfully been set to the requested activationState (be it ACTIVE or DEACTIVATED)
+		Integer changedState = (activationState == OAIXML.ACTIVATION) ? ACTIVE : DEACTIVATED;
+		int index = this.collection_name_list.indexOf(collName); // TODO: Check that whatever collname passed in by servercontrol.pm is fully qualified, to account for super/sub collections.
+		if(index != -1) { // shouldn't be? since startup never calls this method. This method is only called when building an existing collection?
+			this.collection_state_list.set(index, changedState);
+		} else {
+			logger.error("@@@@ index == -1, could not find collection " + collName +  " in collection_name_list");
+		}
+		debugListActivatedCollections("After activation/deactivation: " + changedState);		
+	
 		return true;
 	}
   }
   
+    private void debugListActivatedCollections(String heading) {
+	  	
+		logger.info("#### " + heading + ", colls are: ");
+		for(int i = 0; i < collection_name_list.size(); i++) {
+			logger.info("###### collname: " + collection_name_list.get(i));
+			logger.info("###### state: " + collection_state_list.get(i));
+		}	  
+	}
+  
+  private void debugPrintCurrentCollList(Vector<String> current_coll_list, String heading) {
+	  logger.info("@@@@ " + heading + ", colls are: ");
+	  for(int i = 0; i < current_coll_list.size(); i++) {
+		  String coll = current_coll_list.get(i);
+		  logger.info("@@@@@@ collname: " + coll);
+	  }
+  }  
+	  
   /** process using strings - just calls process using Elements */
   public String process(String xml_in) {
@@ -639,7 +683,46 @@
     // if a subset, send to the collection
     Vector<String> current_coll_list = getCollectionListForSet(set_spec_str);
+	if(set_spec_str != null) {
+		logger.info(">>>> Set spec: " + set_spec_str);
+		debugPrintCurrentCollList(current_coll_list, "Before removing any deactivated colls. Set spec: " + set_spec_str);
+	}	
+	
     boolean single_collection = false;
     if (current_coll_list.size() == 1) {
       single_collection = true;
+	  
+	  // now handle any deactivated OAI collections. OAI collections can be deactivated briefly during build, when the building folder gets moved to index
+	  String collName = current_coll_list.get(0); //set_spec_str;
+	  
+	  int index = collection_name_list.indexOf(collName);
+	  if(collection_state_list.get(index).equals(DEACTIVATED)) {
+		 // forced to send this as an OAI error message, since the XML output is of OAI schema
+		 // and has to match http://www.openarchives.org/OAI/2.0/OAI-PMH.xsd, which has no info message
+		//return OAIXML.createCollectionDeactivatedMessage(collName); 
+		String errorCode = (record_type.equals(OAIXML.RECORD)) ? OAIXML.NO_RECORDS_MATCH : OAIXML.ID_DOES_NOT_EXIST; // GetRecords vs GetIdentifiers request
+		return OAIXML.createErrorMessage(errorCode, "OAI collection " + collName + " is temporarily inactive. Likely it's in the final stages of being rebuilt. Check back shortly.");
+	  }		
+	} else {
+		
+		debugListActivatedCollections("doListRecordsOrIdentifiers");
+		
+		for(int i = 0; i < collection_name_list.size(); i++) {			
+			if(collection_state_list.get(i).equals(DEACTIVATED)) {
+				String collName = collection_name_list.get(i);
+				// remove from the list of collections for which we're going to get identifiers/records
+				// so we won't get identifiers/records for any deactivated collections
+				current_coll_list.remove(collName);
+				logger.info("@@@@ collection " + collName + " is still deactivated!");
+			}			
+		}
+		
+		// Have we 0 active OAI collections?
+		if (current_coll_list.size() == 0) {
+			// 0 collections are active, but (the remaining one) would have been deactivated, not other reason
+			String errorCode = (record_type.equals(OAIXML.RECORD)) ? OAIXML.NO_RECORDS_MATCH : OAIXML.ID_DOES_NOT_EXIST; // GetRecords vs GetIdentifiers request
+			return OAIXML.createErrorMessage(errorCode, "OAI collections temporarily active. Likely because of collection rebuilding. Check back shortly.");
+		}
+		
+		debugPrintCurrentCollList(current_coll_list, "After removing any deactivated colls");
     }
     if (set_spec_str != null && set_spec_str.indexOf(":") != -1) {
@@ -671,6 +754,6 @@
 
       Element result = (Element)mr.process(mr_msg);
-      logger.info("*** " + verb+ " result for coll "+current_coll);
-      logger.info("*** " + XMLConverter.getPrettyString(result));
+      //logger.info("*** " + verb+ " result for coll "+current_coll);
+      //logger.info("*** " + XMLConverter.getPrettyString(result));
       if (result == null) {
 	logger.info("message router returns null");
@@ -780,5 +863,9 @@
     if (set == null) {
       // no set requested, need the complete collection list
-      return this.collection_name_list;
+	  
+	  // Important to return a clone of the member variable, since collection names can be locally removed from the Vector by
+	  // the caller for any collection that is deactivated. This is so the caller can determine which collections are active and
+	  // thus have records/identifiers to display. We don't want to remove elements from the member variable collection_name_list.
+      return (Vector<String>)this.collection_name_list.clone();
     }
     if (has_super_colls && super_coll_map.containsKey(set)) {
