Changeset 28879

Show
Ignore:
Timestamp:
06.03.2014 12:10:12 (6 years ago)
Author:
kjdon
Message:

changed collection_list from NodeList? to Element as NodeList? operations are not thread safe. Tried to get a more accurate earliestdatestamp. don't use datestamps of 0 as they are not real datestamps. use value from oaiconfig.xml if haven't found a valid collection one

Files:
1 modified

Legend:

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

    r28873 r28879  
    6464   
    6565  /** A list of all the collections available to this OAI server */ 
    66   protected NodeList collection_list = null; 
     66  protected Element collection_list = null; 
    6767  /** a vector of the names, for convenience */ 
    6868  protected Vector<String> collection_name_list = null; 
     
    189189    } 
    190190 
    191     NodeList list = coll_list.getElementsByTagName(GSXML.COLLECTION_ELEM); 
    192     int length = list.getLength(); 
    193     if (length == 0) { 
    194       logger.error("length is 0"); 
     191    this.collection_list = (Element)doc.importNode(coll_list, true); 
     192 
     193    // go through and store a list of collection names for convenience 
     194    // also create a 'to' attribute 
     195    Node child = this.collection_list.getFirstChild(); 
     196    if (child == null) { 
     197      logger.error("collection list has no children"); 
    195198      noRecordsMatch = true; 
    196199      return false; 
    197200    } 
    198  
    199     this.collection_list = list; 
     201     
    200202    this.collection_name_list = new Vector<String>(); 
    201      
     203    StringBuffer to = new StringBuffer(); 
     204    boolean first = true; 
     205    while (child != null) { 
     206      if (child.getNodeName().equals(GSXML.COLLECTION_ELEM)) { 
     207    String coll_id =((Element) child).getAttribute(GSXML.NAME_ATT); 
     208    this.collection_name_list.add(coll_id); 
     209    if (!first) { 
     210      to.append(','); 
     211    } 
     212    first = false; 
     213    to.append(coll_id+"/"+OAIXML.LIST_SETS); 
     214      } 
     215      child = child.getNextSibling(); 
     216    } 
     217    if (first) { 
     218      // we haven't found any collections 
     219      logger.error("found no collection elements in collectionList"); 
     220      noRecordsMatch = true; 
     221      return false; 
     222    } 
    202223    Document listsets_doc = this.converter.newDOM(); 
    203224    Element listsets_element = listsets_doc.createElement(OAIXML.LIST_SETS); 
     
    208229    // We'll reuse the first message, changing its type and to atts 
    209230    request.setAttribute(GSXML.TYPE_ATT, ""); 
    210     StringBuffer to = new StringBuffer(); 
    211     for (int i=0; i<collection_list.getLength(); i++) { 
    212       if (i!=0) { 
    213     to.append(','); 
    214       } 
    215       String coll_id =((Element) collection_list.item(i)).getAttribute(GSXML.NAME_ATT); 
    216       logger.error("coll_id = "+coll_id); 
    217       to.append(coll_id+"/"+OAIXML.LIST_SETS); 
    218       this.collection_name_list.add(coll_id); 
    219     } 
    220     logger.error ("to att = "+to.toString()); 
    221231    request.setAttribute(GSXML.TO_ATT, to.toString()); 
    222232    // send to MR 
     
    985995  // dynamically works out what the earliestDateStamp is, since it varies by collection 
    986996  // returns this time in *milliseconds*. 
    987   protected long getEarliestDateStamp(NodeList oai_coll) { 
     997  protected long getEarliestDateStamp(Element oai_coll_list) { 
     998    // config earliest datstamp 
     999    long config_datestamp = 0; 
     1000    Element config_datestamp_elem = (Element)GSXML.getChildByTagName(this.oai_config, OAIXML.EARLIEST_DATESTAMP); 
     1001    if (config_datestamp_elem != null) { 
     1002      String datest = GSXML.getNodeText(config_datestamp_elem); 
     1003      config_datestamp = OAIXML.getTime(datest); 
     1004      if (config_datestamp == -1) { 
     1005    config_datestamp = 0; 
     1006      } 
     1007    } 
    9881008    //do the earliestDatestamp 
    989     long earliestDatestamp = System.currentTimeMillis();     
     1009    long current_time = System.currentTimeMillis(); 
     1010    long earliestDatestamp = current_time; 
     1011    NodeList oai_coll = oai_coll_list.getElementsByTagName(GSXML.COLLECTION_ELEM); 
    9901012    int oai_coll_size = oai_coll.getLength(); 
    9911013    if (oai_coll_size == 0) { 
    992       logger.info("returned oai collection list is empty. Setting repository earliestDatestamp to be 1970-01-01."); 
    993       earliestDatestamp = 0; 
     1014      logger.info("returned oai collection list is empty. Setting repository earliestDatestamp to be the earliest datestamp from OAIConfig.xml, or 1970-01-01 if not specified."); 
     1015      return config_datestamp; 
    9941016    } 
    9951017    // the earliestDatestamp is now stored as a metadata element in the collection's buildConfig.xml file 
     
    9971019    for(int i=0; i<oai_coll_size; i++) { 
    9981020      long coll_earliestDatestamp = Long.parseLong(((Element)oai_coll.item(i)).getAttribute(OAIXML.EARLIEST_DATESTAMP)); 
    999       earliestDatestamp = (earliestDatestamp > coll_earliestDatestamp)? coll_earliestDatestamp : earliestDatestamp; 
    1000     } 
    1001  
    1002     return earliestDatestamp*1000; // converting from seconds to milliseconds 
     1021      if (coll_earliestDatestamp == 0) { 
     1022    // try last modified 
     1023    coll_earliestDatestamp = Long.parseLong(((Element)oai_coll.item(i)).getAttribute(OAIXML.LAST_MODIFIED)); 
     1024      } 
     1025      if (coll_earliestDatestamp > 0) { 
     1026    earliestDatestamp = (earliestDatestamp > coll_earliestDatestamp)? coll_earliestDatestamp : earliestDatestamp; 
     1027      } 
     1028    } 
     1029    if (earliestDatestamp == current_time) { 
     1030      logger.info("no collection had a real datestamp, using value from OAIConfig"); 
     1031      return config_datestamp; 
     1032    } 
     1033    return earliestDatestamp;  
    10031034  } 
    10041035}