Changeset 23938


Ignore:
Timestamp:
2011-04-20T21:02:12+12:00 (13 years ago)
Author:
ak19
Message:

GS3's OAIserver passes final official oaiserver validation tests: to do with earliestDatestamp. Both the datestamp of the records (documents) returned by listRecords, listIdentifiers and getRecord, as well as the earliestDatestamp returned by an Identify request are now in sync with each other. Related code changes made to perllib to write the earliestDatestamp into GS3's buildconfig.xml (and build.cfg for GS2), and to write new fields oailastmodified and oailastmodifieddate into the collection's database for each document.

Location:
main/trunk/greenstone3/src/java/org/greenstone/gsdl3
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/collection/Collection.java

    r23901 r23938  
    6868    /** time when this collection was built */
    6969    protected long lastmodified = 0;
    70    
     70    /** earliestDatestamp of this collection. Necessary for OAI */
     71    protected long earliestDatestamp = 0;
     72
     73
    7174    /** An element containing the serviceRackList element of buildConfig.xml, used to determine whether it contains
    7275     *  the OAIPMH serviceRack
     
    133136    return is_public;
    134137    }
    135     //used by the OAIReceptionist to find out the earliest datestamp amongst all oai collections in the repository
     138    // Not used anymore by the OAIReceptionist to find out the earliest datestamp
     139    // amongst all oai collections in the repository. May be useful generally.
    136140    public long getLastmodified() {
    137141      return lastmodified;
    138142    }
     143    //used by the OAIReceptionist to find out the earliest datestamp amongst all oai collections in the repository
     144    public long getEarliestDatestamp() {
     145    return earliestDatestamp;
     146    }
     147
    139148    /** whether the service_map in ServiceCluster.java contains the service 'OAIPMH'
    140149     *  11/06/2007 xiao
     
    179188        build_config_elem = build_config_doc.getDocumentElement();
    180189    }
    181  
     190
    182191    lastmodified = build_config_file.lastModified();
    183192 
     
    264273      } else {
    265274    has_oai = true;
     275   
     276    // extract earliestDatestamp from the buildconfig.xml for OAI
     277    Element metadata_list = (Element)GSXML.getChildByTagName(build_config_xml, GSXML.METADATA_ELEM+GSXML.LIST_MODIFIER);
     278
     279    if(metadata_list != null) {
     280        NodeList children = metadata_list.getElementsByTagName(GSXML.METADATA_ELEM);
     281               // can't do getChildNodes(), because whitespace, such as newlines, creates Text nodes
     282        for (int i = 0; i < children.getLength(); i++) {
     283        Element metadata = (Element)children.item(i);
     284        if(metadata.getAttribute(GSXML.NAME_ATT).equals(OAIXML.EARLIEST_DATESTAMP)) {
     285            String earliestDatestampStr = GSXML.getValue(metadata);
     286            if(!earliestDatestampStr.equals("")) {
     287            earliestDatestamp = Long.parseLong(earliestDatestampStr);
     288            }
     289            break; // found a metadata element with name=earliestDatestamp in buildconfig
     290        }
     291        }
     292    }
     293   
     294    // If at the end of this, there is no value for earliestDatestamp, print out a warning
     295    logger.warn("No earliestDatestamp in buildConfig.xml for collection: " + this.cluster_name + ". Defaulting to 0.");
     296
    266297      }
    267298    } else { // no list of services (no ServiceRackList), so no oai_service_rack either
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/core/MessageRouter.java

    r23793 r23938  
    621621          //The collection name is returned as site_name:coll_name, which is in fact the set specification
    622622          ane.setAttribute(GSXML.NAME_ATT, site_name + ":" + col_name);
    623           ane.setAttribute(OAIXML.LASTMODIFIED, "" + c.getLastmodified());
    624          
     623          ane.setAttribute(OAIXML.LASTMODIFIED, "" + c.getLastmodified());
     624           // lastmodified not of use anymore for OAI, perhaps useful as general information
     625      ane.setAttribute(OAIXML.EARLIEST_DATESTAMP, "" + c.getEarliestDatestamp()); // for OAI
     626
    625627          this.oai_collection_list.appendChild(ane);
    626628          //logger.info(GSXML.xmlNodeToString(oai_collection_list));
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/core/OAIReceptionist.java

    r23913 r23938  
    296296       *  Use the time value plus the current system time to get the expiration date string.
    297297       */
    298       String expiration_date = OAIXML.getTime(System.currentTimeMillis() + OAIXML.getTokenExpiration());
     298    String expiration_date = OAIXML.getTime(System.currentTimeMillis() + OAIXML.getTokenExpiration()); // in milliseconds
    299299      token.setAttribute(OAIXML.EXPIRATION_DATE, expiration_date);
    300300    }
     
    10341034    // See OAIConfig.xml
    10351035    // dynamically works out what the earliestDateStamp is, since it varies by collection
     1036    // returns this time in *milliseconds*.
    10361037    protected long getEarliestDateStamp(NodeList oai_coll) {
    10371038    //do the earliestDatestamp
    1038     long lastmodified = System.currentTimeMillis();
     1039    long earliestDatestamp = System.currentTimeMillis();   
    10391040    int oai_coll_size = oai_coll.getLength();
    10401041    if (oai_coll_size == 0) {
    10411042        logger.info("returned oai collection list is empty. Setting repository earliestDatestamp to be 1970-01-01.");
    1042         lastmodified = 0;
     1043        earliestDatestamp = 0;
    10431044    }
    1044     //the collection build time is determined by the last modified time of the buildConfig.xml file
     1045    // the earliestDatestamp is now stored as a metadata element in the collection's buildConfig.xml file
     1046    // we get the earliestDatestamp among the collections
    10451047    for(int i=0; i<oai_coll_size; i++) {
    1046         long coll_build_time = Long.parseLong(((Element)oai_coll.item(i)).getAttribute(OAIXML.LASTMODIFIED));
    1047         lastmodified = (lastmodified > coll_build_time)? coll_build_time : lastmodified;
     1048        long coll_earliestDatestamp = Long.parseLong(((Element)oai_coll.item(i)).getAttribute(OAIXML.EARLIEST_DATESTAMP));
     1049        earliestDatestamp = (earliestDatestamp > coll_earliestDatestamp)? coll_earliestDatestamp : earliestDatestamp;
    10481050    }
    1049     return lastmodified;
     1051
     1052    return earliestDatestamp*1000; // converting from seconds to milliseconds
    10501053    }
    10511054}
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/service/OAIPMH.java

    r23922 r23938  
    253253
    254254    ArrayList keys = new ArrayList(info.getKeys());
    255     String lastmodified = "";
    256     if(keys.contains(OAIXML.LASTMODIFIED)) {
    257       lastmodified = info.getInfo(OAIXML.LASTMODIFIED);
    258       lastmodified = OAIXML.getTime(Long.parseLong(lastmodified)*1000); // java wants dates in milliseconds
     255    String oailastmodified = "";
     256    if(keys.contains(OAIXML.OAI_LASTMODIFIED)) {
     257      oailastmodified = info.getInfo(OAIXML.OAI_LASTMODIFIED);
     258      oailastmodified = OAIXML.getTime(Long.parseLong(oailastmodified)*1000); // java wants dates in milliseconds
    259259    }
    260260
     
    262262    Element record = OAIXML.createElement(OAIXML.RECORD);
    263263    //compose the header element
    264     record.appendChild(createHeaderElement(oid, lastmodified));     
     264    record.appendChild(createHeaderElement(oid, oailastmodified));     
    265265    //compose the metadata element
    266266    record.appendChild(createMetadataElement(prefix, info, metadata_format));
     
    332332      }
    333333      ArrayList keys = new ArrayList(info.getKeys());
    334       String lastmodified = "";
    335       if(keys.contains(OAIXML.LASTMODIFIED)) {
    336         lastmodified = info.getInfo(OAIXML.LASTMODIFIED);
    337     lastmodified = OAIXML.getTime(Long.parseLong(lastmodified)*1000); // java wants dates in milliseconds
     334      String oailastmodified = "";
     335      if(keys.contains(OAIXML.OAI_LASTMODIFIED)) {
     336        oailastmodified = info.getInfo(OAIXML.OAI_LASTMODIFIED);
     337    oailastmodified = OAIXML.getTime(Long.parseLong(oailastmodified)*1000); // java wants dates in milliseconds
    338338      }
    339339     
    340       Date this_date = OAIXML.getDate(lastmodified);       
     340      Date this_date = OAIXML.getDate(oailastmodified);       
    341341      if (from_date != null) {
    342342        if(this_date.before(from_date)) {
     
    350350      }     
    351351      //compose the header element and append it
    352       list_identifiers.appendChild(createHeaderElement(oid, lastmodified));     
     352      list_identifiers.appendChild(createHeaderElement(oid, oailastmodified));     
    353353    }//end of for(int i=0; i<oid_list.size(); i++) of doing thru each record
    354354   
     
    418418      }
    419419      ArrayList keys = new ArrayList(info.getKeys());
    420       String lastmodified = "";
    421       if(keys.contains(OAIXML.LASTMODIFIED)) {
    422         lastmodified = info.getInfo(OAIXML.LASTMODIFIED);
    423     lastmodified = OAIXML.getTime(Long.parseLong(lastmodified)*1000); // java wants dates in milliseconds
     420      String oailastmodified = "";
     421      if(keys.contains(OAIXML.OAI_LASTMODIFIED)) {
     422        oailastmodified = info.getInfo(OAIXML.OAI_LASTMODIFIED);
     423    oailastmodified = OAIXML.getTime(Long.parseLong(oailastmodified)*1000); // java wants dates in milliseconds
    424424      }
    425425     
    426       Date this_date = OAIXML.getDate(lastmodified);       
     426      Date this_date = OAIXML.getDate(oailastmodified);       
    427427      if (from_date != null) {
    428428        if(this_date.before(from_date)) {
     
    439439      list_records.appendChild(record);
    440440      //compose the header element
    441       record.appendChild(createHeaderElement(oid, lastmodified));     
     441      record.appendChild(createHeaderElement(oid, oailastmodified));     
    442442      //compose the metadata element
    443443      record.appendChild(createMetadataElement(prefix, info, metadata_format));
     
    501501  /** create a header element used when processing requests like ListRecords/GetRecord/ListIdentifiers
    502502   */
    503   private Element createHeaderElement(String oid, String lastmodified) {   
     503  private Element createHeaderElement(String oid, String oailastmodified) {   
    504504        Element header = OAIXML.createElement(OAIXML.HEADER);
    505505        Element identifier = OAIXML.createElement(OAIXML.IDENTIFIER);
     
    510510        header.appendChild(set_spec);
    511511        Element datestamp = OAIXML.createElement(OAIXML.DATESTAMP);
    512         GSXML.setNodeText(datestamp, lastmodified);
     512        GSXML.setNodeText(datestamp, oailastmodified);
    513513        header.appendChild(datestamp);
    514514        return header;
     
    656656<contains>".1;".2;".3;".4;".5;".6;".7;".8;".9
    657657<docnum>349
     658<oailastmodified>1303283795
     659<lastmodifieddate>20110412
     660<oailastmodifieddate>20110420
    658661----------------------------------------------------------------------
    659662     */
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/util/OAIXML.java

    r23922 r23938  
    112112    public static final String OAI = "OAI";
    113113    public static final String OAI_DASH_PMH = "OAI-PMH";
     114    public static final String OAI_LASTMODIFIED = "oailastmodified";
    114115    public static final String OAIPMH = "OAIPMH";
    115116    public static final String OAI_RESUMPTION_TOKENS = "OAIResumptionTokens";
Note: See TracChangeset for help on using the changeset viewer.