Changeset 28881

Show
Ignore:
Timestamp:
06.03.2014 14:07:18 (6 years ago)
Author:
kjdon
Message:

added getCollectionListForSet method to avoid duplicating code. added collectionsChangedSinceTime method to check whether any collecitons have changed since a resumption token was issued - if so, then we need to expire the token.

Files:
1 modified

Legend:

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

    r28879 r28881  
    408408    int current_cursor = 0; 
    409409    String current_set = null; 
     410    long initial_time = 0; 
    410411     
    411412    int total_size = -1; // we are only going to set this in resumption  
     
    437438    cursor = cursor + resume_after; // increment cursor 
    438439    current_cursor = Integer.parseInt(token_data.get(OAIResumptionToken.CURRENT_CURSOR)); 
     440    initial_time = Long.parseLong(token_data.get(OAIResumptionToken.INITIAL_TIME)); 
    439441      } catch (NumberFormatException e) { 
    440442    logger.error("tried to parse int from cursor data and failed"); 
    441443      } 
    442444       
     445      // check that the collections/sets haven't changed since the token was issued 
     446      if (collectionsChangedSinceTime(set_spec_str, initial_time)) { 
     447    logger.error("one of the collections in set "+set_spec_str+" has changed since token issued. Expiring the token"); 
     448    OAIResumptionToken.expireToken(token); 
     449    return OAIXML.createErrorMessage(OAIXML.BAD_RESUMPTION_TOKEN, "Repository data has changed since this token was issued. Resend original request"); 
     450      } 
    443451    } 
    444452    else { 
     
    520528    // if a single collection, send to it 
    521529    // if a subset, send to the collection 
    522     Vector<String> current_coll_list = null; 
     530    Vector<String> current_coll_list = getCollectionListForSet(set_spec_str); 
    523531    boolean single_collection = false; 
    524     if (set_requested == false) { 
    525       // just do all colls 
    526       current_coll_list = collection_name_list; 
    527     } 
    528     else if (has_super_colls && super_coll_map.containsKey(set_spec_str)) { 
    529       current_coll_list = super_coll_map.get(set_spec_str); 
    530     } 
    531     else { 
    532       current_coll_list = new Vector<String>(); 
    533       if (set_spec_str.indexOf(":") != -1) { 
    534     // we have a subset 
    535     //add the set param back into the request, but send the request to the collection 
    536     String col_name = set_spec_str.substring(0, set_spec_str.indexOf(":")); 
    537     current_coll_list.add(col_name); 
    538     mr_req.appendChild(GSXML.createParameter(doc, OAIXML.SET, set_spec_str)); 
    539     single_collection = true; 
    540       } 
    541       else { 
    542     // it must be a single collection name 
    543     current_coll_list.add(set_spec_str); 
    544     single_collection = true; 
    545       } 
     532    if (current_coll_list.size() == 1) { 
     533      single_collection = true; 
     534    } 
     535    if (set_spec_str != null && set_spec_str.indexOf(":") != -1) { 
     536      // we have a subset - add the set param back in 
     537      mr_req.appendChild(GSXML.createParameter(doc, OAIXML.SET, set_spec_str)); 
    546538    } 
    547539 
     
    675667  } 
    676668 
     669  private Vector<String> getCollectionListForSet(String set) { 
     670    if (set == null) { 
     671      // no set requested, need the complete collection list 
     672      return this.collection_name_list; 
     673    } 
     674    if (has_super_colls && super_coll_map.containsKey(set)) { 
     675      return super_coll_map.get(set); 
     676    } 
     677    //********************8 
     678    Vector<String> coll_list = new Vector<String>(); 
     679    if (set.indexOf(":") != -1) { 
     680      String col_name = set.substring(0, set.indexOf(":")); 
     681      coll_list.add(col_name); 
     682    } 
     683    else { 
     684      coll_list.add(set); 
     685    } 
     686    return coll_list; 
     687  } 
    677688  private void addRecordsToList(Document doc, Element result_element, NodeList 
    678689                record_list, int start_point, int num_records) { 
     
    10331044    return earliestDatestamp;  
    10341045  } 
     1046 
     1047  private boolean collectionsChangedSinceTime(String set_spec_str, long initial_time) { 
     1048 
     1049    // we need to look though all collections in the set to see if any have last modified dates > initial_time 
     1050    Vector<String> set_coll_list = getCollectionListForSet(set_spec_str); 
     1051 
     1052    Node child = this.collection_list.getFirstChild(); 
     1053    while (child != null) { 
     1054      if (child.getNodeName().equals(GSXML.COLLECTION_ELEM)) { 
     1055    String coll_id =((Element) child).getAttribute(GSXML.NAME_ATT); 
     1056    if (set_coll_list.contains(coll_id)) { 
     1057      long last_modified = Long.parseLong(((Element)child).getAttribute(OAIXML.LAST_MODIFIED)); 
     1058      if (initial_time < last_modified) { 
     1059        return true; 
     1060      } 
     1061    } 
     1062      } 
     1063      child = child.getNextSibling(); 
     1064    } 
     1065    return false; 
     1066  
     1067  } 
     1068 
    10351069} 
    10361070