- Timestamp:
- 2019-03-05T20:30:43+13:00 (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone3/src/java/org/greenstone/gsdl3/core/OAIReceptionist.java
r32830 r32868 64 64 /** a vector of the names, for convenience */ 65 65 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 66 78 /** If this is true, then there are no OAI enabled collections, so can always return noRecordsMatch (after validating the request params) */ 67 79 protected boolean noRecordsMatch = false; … … 82 94 /** the list metadata formats response */ 83 95 protected Element listmetadataformats_response = null; 84 96 85 97 public OAIReceptionist() { 86 98 … … 208 220 209 221 this.collection_name_list = new Vector<String>(); 222 this.collection_state_list = new Vector<Integer>(); 210 223 StringBuffer to = new StringBuffer(); 211 224 boolean first = true; … … 214 227 String coll_id =((Element) child).getAttribute(GSXML.NAME_ATT); 215 228 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 216 230 if (!first) { 217 231 to.append(','); … … 280 294 } // for each set in the collection 281 295 } // for each OAI enabled collection 296 297 298 debugListActivatedCollections("List of collections after configuring Set Info"); 282 299 return true; 283 300 } … … 329 346 return false; 330 347 } 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 331 358 return true; 332 359 } 333 360 } 334 361 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 335 379 /** process using strings - just calls process using Elements */ 336 380 public String process(String xml_in) { … … 639 683 // if a subset, send to the collection 640 684 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 641 690 boolean single_collection = false; 642 691 if (current_coll_list.size() == 1) { 643 692 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"); 644 727 } 645 728 if (set_spec_str != null && set_spec_str.indexOf(":") != -1) { … … 671 754 672 755 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)); 675 758 if (result == null) { 676 759 logger.info("message router returns null"); … … 780 863 if (set == null) { 781 864 // 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(); 783 870 } 784 871 if (has_super_colls && super_coll_map.containsKey(set)) {
Note:
See TracChangeset
for help on using the changeset viewer.