Changeset 32868 for main


Ignore:
Timestamp:
03/05/19 20:30:43 (23 months ago)
Author:
ak19
Message:

After 3 attempts, finally succeeded in implementing Kathy's suggestion: between deactivating and activating an OAICollection (during the period when building gets moved to index), the OAI collection should indeed still be listed among the Sets (collections) served by the OAICollection, so that DL users know that the collection exists and will continue to exist. But the failure of getting the Identifiers and Records for a deactivated OAI collection must instead produce a message telling users they're only temporarily unavailable and to check back later.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/core/OAIReceptionist.java

    r32830 r32868  
    6464  /** a vector of the names, for convenience */
    6565  protected Vector<String> collection_name_list = null;
     66  /** a vector to be maintained in parallel to Vector collection_name_list in terms of adds/removes.
     67   * This is a list of Integers that denote whether the associated collection in collection_name_list is currently ACTIVE or DEACTIVATED.
     68   * The state for any collection can be changed when the building folder is moved to index during rebuilding, before and after which
     69   * activateOrDeactivateCollection() here is called to deactivate a collection and then activate it again, respectively.
     70   * 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.   
     71   * I've confirmed that collection_name_list is specifically a list of OAI collection names, not non-OAI collections.
     72  */
     73  protected Vector<Integer> collection_state_list = null;
     74  /** Possible states for a collection */
     75  protected static final Integer DEACTIVATED = new Integer(0);
     76  protected static final Integer ACTIVE = new Integer(1);
     77 
    6678  /** If this is true, then there are no OAI enabled collections, so can always return noRecordsMatch (after validating the request params) */
    6779  protected boolean noRecordsMatch = false;
     
    8294  /** the list metadata formats response */
    8395  protected Element listmetadataformats_response = null;
    84 
     96 
    8597  public OAIReceptionist() {
    8698
     
    208220   
    209221    this.collection_name_list = new Vector<String>();
     222    this.collection_state_list = new Vector<Integer>();
    210223    StringBuffer to = new StringBuffer();
    211224    boolean first = true;
     
    214227    String coll_id =((Element) child).getAttribute(GSXML.NAME_ATT);
    215228    this.collection_name_list.add(coll_id);
     229    this.collection_state_list.add(ACTIVE); // collections start out active (they get activated during configuring) until deactivation takes place
    216230    if (!first) {
    217231      to.append(',');
     
    280294      } // for each set in the collection
    281295    } // for each OAI enabled collection
     296   
     297   
     298    debugListActivatedCollections("List of collections after configuring Set Info");
    282299    return true;
    283300  }
     
    329346        return false;
    330347    } else {
     348        // the collection's state has successfully been set to the requested activationState (be it ACTIVE or DEACTIVATED)
     349        Integer changedState = (activationState == OAIXML.ACTIVATION) ? ACTIVE : DEACTIVATED;
     350        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.
     351        if(index != -1) { // shouldn't be? since startup never calls this method. This method is only called when building an existing collection?
     352            this.collection_state_list.set(index, changedState);
     353        } else {
     354            logger.error("@@@@ index == -1, could not find collection " + collName +  " in collection_name_list");
     355        }
     356        debugListActivatedCollections("After activation/deactivation: " + changedState);       
     357   
    331358        return true;
    332359    }
    333360  }
    334361 
     362    private void debugListActivatedCollections(String heading) {
     363       
     364        logger.info("#### " + heading + ", colls are: ");
     365        for(int i = 0; i < collection_name_list.size(); i++) {
     366            logger.info("###### collname: " + collection_name_list.get(i));
     367            logger.info("###### state: " + collection_state_list.get(i));
     368        }     
     369    }
     370 
     371  private void debugPrintCurrentCollList(Vector<String> current_coll_list, String heading) {
     372      logger.info("@@@@ " + heading + ", colls are: ");
     373      for(int i = 0; i < current_coll_list.size(); i++) {
     374          String coll = current_coll_list.get(i);
     375          logger.info("@@@@@@ collname: " + coll);
     376      }
     377  } 
     378     
    335379  /** process using strings - just calls process using Elements */
    336380  public String process(String xml_in) {
     
    639683    // if a subset, send to the collection
    640684    Vector<String> current_coll_list = getCollectionListForSet(set_spec_str);
     685    if(set_spec_str != null) {
     686        logger.info(">>>> Set spec: " + set_spec_str);
     687        debugPrintCurrentCollList(current_coll_list, "Before removing any deactivated colls. Set spec: " + set_spec_str);
     688    }   
     689   
    641690    boolean single_collection = false;
    642691    if (current_coll_list.size() == 1) {
    643692      single_collection = true;
     693     
     694      // now handle any deactivated OAI collections. OAI collections can be deactivated briefly during build, when the building folder gets moved to index
     695      String collName = current_coll_list.get(0); //set_spec_str;
     696     
     697      int index = collection_name_list.indexOf(collName);
     698      if(collection_state_list.get(index).equals(DEACTIVATED)) {
     699         // forced to send this as an OAI error message, since the XML output is of OAI schema
     700         // and has to match http://www.openarchives.org/OAI/2.0/OAI-PMH.xsd, which has no info message
     701        //return OAIXML.createCollectionDeactivatedMessage(collName);
     702        String errorCode = (record_type.equals(OAIXML.RECORD)) ? OAIXML.NO_RECORDS_MATCH : OAIXML.ID_DOES_NOT_EXIST; // GetRecords vs GetIdentifiers request
     703        return OAIXML.createErrorMessage(errorCode, "OAI collection " + collName + " is temporarily inactive. Likely it's in the final stages of being rebuilt. Check back shortly.");
     704      }     
     705    } else {
     706       
     707        debugListActivatedCollections("doListRecordsOrIdentifiers");
     708       
     709        for(int i = 0; i < collection_name_list.size(); i++) {         
     710            if(collection_state_list.get(i).equals(DEACTIVATED)) {
     711                String collName = collection_name_list.get(i);
     712                // remove from the list of collections for which we're going to get identifiers/records
     713                // so we won't get identifiers/records for any deactivated collections
     714                current_coll_list.remove(collName);
     715                logger.info("@@@@ collection " + collName + " is still deactivated!");
     716            }           
     717        }
     718       
     719        // Have we 0 active OAI collections?
     720        if (current_coll_list.size() == 0) {
     721            // 0 collections are active, but (the remaining one) would have been deactivated, not other reason
     722            String errorCode = (record_type.equals(OAIXML.RECORD)) ? OAIXML.NO_RECORDS_MATCH : OAIXML.ID_DOES_NOT_EXIST; // GetRecords vs GetIdentifiers request
     723            return OAIXML.createErrorMessage(errorCode, "OAI collections temporarily active. Likely because of collection rebuilding. Check back shortly.");
     724        }
     725       
     726        debugPrintCurrentCollList(current_coll_list, "After removing any deactivated colls");
    644727    }
    645728    if (set_spec_str != null && set_spec_str.indexOf(":") != -1) {
     
    671754
    672755      Element result = (Element)mr.process(mr_msg);
    673       logger.info("*** " + verb+ " result for coll "+current_coll);
    674       logger.info("*** " + XMLConverter.getPrettyString(result));
     756      //logger.info("*** " + verb+ " result for coll "+current_coll);
     757      //logger.info("*** " + XMLConverter.getPrettyString(result));
    675758      if (result == null) {
    676759    logger.info("message router returns null");
     
    780863    if (set == null) {
    781864      // no set requested, need the complete collection list
    782       return this.collection_name_list;
     865     
     866      // Important to return a clone of the member variable, since collection names can be locally removed from the Vector by
     867      // the caller for any collection that is deactivated. This is so the caller can determine which collections are active and
     868      // thus have records/identifiers to display. We don't want to remove elements from the member variable collection_name_list.
     869      return (Vector<String>)this.collection_name_list.clone();
    783870    }
    784871    if (has_super_colls && super_coll_map.containsKey(set)) {
Note: See TracChangeset for help on using the changeset viewer.