Changeset 24412


Ignore:
Timestamp:
2011-08-16T17:52:13+12:00 (13 years ago)
Author:
ak19
Message:

Fixed a new failure of the OAI validation test of GS2's OAI server: where list records is given an Until date that is earlier than the earliestDatestamp. Needs to return a noRecordsMatch. It does now. The calculation of the earliestDatestamp is now shifted to the oaiaction.cpp superclass and called by both identifyaction and listrecordsaction for the identify and listrecords OAI queries, since these tasks need to work with earliestDatestamp.

Location:
main/trunk/greenstone2/runtime-src/src/oaiservr
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone2/runtime-src/src/oaiservr/identifyaction.cpp

    r24114 r24412  
    113113    // their build.cfg file at this point by collectserver::configure. The field
    114114    // is declared in comtypes.h)   
    115     text_t earliestDatestamp = ""; // do not set default to unix epoch time "1970-01-01" yet
    116115   
    117     // Get a list of the OAI-enabled collections available
    118     text_tarray& collections = this->configuration->getCollectionsList();
    119     if (collections.size() > 0)
    120     {       
    121         // get the identifier from the params
    122         text_t identifier = params["identifier"];
    123         text_t oai_OID_prefix = "oai:"+this->configuration->getRepositoryId()+":";
    124         identifier.replace(oai_OID_prefix, "");
    125 
    126         // Get the current collection from the identifier
    127         text_t collection_name = "";
    128         oaiclassifier::toGSDL(collection_name, identifier);
    129 
    130         // Find the starting collection
    131         text_tarray::iterator collection_iterator = collections.begin();
    132         while (collection_iterator != collections.end())
    133         {
    134             if (collection_name == "" || collection_name == *collection_iterator)
    135             {
    136               break;
    137             }
    138 
    139             collection_iterator++;
    140         }
    141        
    142         // Now loop through the remaining collections
    143         // to work out the earliest datestamp
    144         while (collection_iterator != collections.end())
    145         {
    146             collection_name = (*collection_iterator);
    147            
    148             ColInfoResponse_t cinfo;
    149             comerror_t err;
    150             protocol->get_collectinfo(collection_name, cinfo, err, cerr);
    151             if (err == noError) {               
    152                 text_t eDatestamp = cinfo.earliestDatestamp;
    153                 time_t raw_time = (time_t)eDatestamp.getint();
    154                 eDatestamp = this->parseDatestamp(raw_time);
    155                
    156                 if(earliestDatestamp == "") { // first earliestdatestamp we've seen for an oai collection
    157                     earliestDatestamp = eDatestamp;
    158                 } else if(eDatestamp < earliestDatestamp) {
    159                     earliestDatestamp = eDatestamp;
    160                 }               
    161             }
    162             collection_iterator++;
    163            
    164         }       
    165     }
     116    this->calcEarliestDatestamp(protocol, params);  // force the calculation. Sets mEarliestDatestamp member variable
    166117   
    167     // if repository's earliestDatestamp is still unset, default to unix epoch time
    168     if(earliestDatestamp == "") {
    169         earliestDatestamp = "1970-01-01";
    170     }   
    171    
    172     output << utf8convert << "  <earliestDatestamp>"<< earliestDatestamp <<"</earliestDatestamp>\n";
     118    output << utf8convert << "  <earliestDatestamp>"<< this->mEarliestDatestamp <<"</earliestDatestamp>\n";
    173119    output << utf8convert << "  <deletedRecord>no</deletedRecord>\n";
    174120    output << utf8convert << "  <granularity>YYYY-MM-DD</granularity>\n";
  • main/trunk/greenstone2/runtime-src/src/oaiservr/listrecsaction.cpp

    r22739 r24412  
    156156      this->errorType = "badArgument";
    157157      return false;
    158     }
     158    }   
    159159  }
    160160
     
    178178      return false;
    179179    }
    180 
     180   
    181181    // Check the collection is one that is in the list in the oai.cfg file
    182182    text_tarray &collections = this->configuration->getCollectionsList();
     
    204204      return false;
    205205    }
    206   }
     206   
     207    // check we're not requested to retrieve records of *this* set/coll
     208    // from an earlier date than *this* set's earliestdatestamp
     209    if (params["until"] != "") {
     210        text_t eDatestamp = cinfo.earliestDatestamp;
     211        time_t raw_time = (time_t)eDatestamp.getint();
     212        eDatestamp = this->parseDatestamp(raw_time);
     213       
     214        // error if request is for records of an earlier date than this coll/set's earliestDatestamp       
     215        if(params["until"] < eDatestamp) {
     216            this->errorType = "noRecordsMatch"; // for *this* set/coll of the repository
     217            return false;
     218        }
     219    }
     220   
     221  } else { // no set (collection) specified
     222     if (params ["until"] != "") {  // check we're not requested to retrieve records of an earlier
     223                                    // date than the earliestdatestamp across all collections/sets
     224        // John Thompson advises not to do lazy evaluation of earliestDatestamp here, because
     225        // reading x number of build.cfg files for x number of collections to work out the
     226        // earliestDatestamp among them is not too expensive an operation, but we do want the OAI
     227        // Server to give accurate results when queried, as that's specified by the OAI protocol.
     228        //if(this->mEarliestDatestamp == "") {
     229        text_t eDatestamp = this->calcEarliestDatestamp(protocol, params);
     230        //}
     231       
     232        if(params["until"] < eDatestamp) { // request is for records of an earlier date than earliestDatestamp     
     233            this->errorType = "noRecordsMatch";
     234            return false;
     235        }       
     236     }
     237  }
    207238
    208239  // If we've reached here everything must be fine
  • main/trunk/greenstone2/runtime-src/src/oaiservr/oaiaction.cpp

    r24109 r24412  
    4141#include <time.h>
    4242
    43 
    4443oaiaction::oaiaction(const text_t &name)
    4544{
     
    4746  this->configuration = NULL;
    4847  this->name = name;
     48  this->mEarliestDatestamp = "";
    4949}
    5050
     
    491491    return false;
    492492}
     493
     494text_t oaiaction::calcEarliestDatestamp(recptproto *protocol, oaiargs &params) {
     495   
     496    text_t earliestDatestamp = ""; // do not set default to unix epoch time "1970-01-01" yet
     497   
     498    //text_t version = (this->configuration->getOAIVersion() <= 110) ? (text_t)"1.1":(text_t)"2.0";
     499    //if(version == "2.0"){
     500   
     501    // earliestDatestamp *should* be the YYYY-MM-DD format of the oldest lastmodified record in the
     502    // repository, but we're just setting it to be the default oldest possible date - ugly, but judged
     503    // not to be worth the effort of trolling through all the lastmodified dates (by others with more
     504    // say than me)
     505   
     506    // The above was before. However, now we mirror GS3 way of dealing with
     507    // earliestDatestamp by going through the earliestDatestamp field of each OAI
     508    // collection's build.cfg in order to work out earliestdatestamp of this Repository:
     509    // by going through all the collections and getting the earliest among the
     510    // "earliestDatestamp" values stored for each collection in its build.cfg
     511    // (the earliestDatestamp for a collection has already been extracted from
     512    // their build.cfg file at this point by collectserver::configure. The field
     513    // is declared in comtypes.h)   
     514   
     515   
     516    // Get a list of the OAI-enabled collections available
     517    text_tarray& collections = this->configuration->getCollectionsList();
     518    if (collections.size() > 0)
     519    {   
     520        // get the identifier from the params
     521        text_t identifier = params["identifier"];
     522        text_t oai_OID_prefix = "oai:"+this->configuration->getRepositoryId()+":";
     523        identifier.replace(oai_OID_prefix, "");
     524
     525        // Get the current collection from the identifier
     526        text_t collection_name = "";
     527        oaiclassifier::toGSDL(collection_name, identifier);
     528
     529        // Find the starting collection
     530        text_tarray::iterator collection_iterator = collections.begin();
     531        while (collection_iterator != collections.end())
     532        {
     533            if (collection_name == "" || collection_name == *collection_iterator)
     534            {
     535              break;
     536            }
     537
     538            collection_iterator++;
     539        }
     540       
     541        // Now loop through the remaining collections
     542        // to work out the earliest datestamp
     543        while (collection_iterator != collections.end())
     544        {
     545            collection_name = (*collection_iterator);
     546           
     547            ColInfoResponse_t cinfo;
     548            comerror_t err;
     549            protocol->get_collectinfo(collection_name, cinfo, err, cerr);
     550            if (err == noError) {               
     551                text_t eDatestamp = cinfo.earliestDatestamp;
     552                time_t raw_time = (time_t)eDatestamp.getint();
     553                eDatestamp = this->parseDatestamp(raw_time);
     554               
     555                if(earliestDatestamp == "") { // first earliestdatestamp we've seen for an oai collection
     556                    earliestDatestamp = eDatestamp;
     557                } else if(eDatestamp < earliestDatestamp) {
     558                    earliestDatestamp = eDatestamp;
     559                }
     560            }
     561            collection_iterator++;
     562           
     563        }       
     564    }
     565       
     566    //}
     567   
     568    // if repository's earliestDatestamp is still unset, default to unix epoch time
     569    if(earliestDatestamp == "") {       
     570        earliestDatestamp = "1970-01-01";
     571    }
     572   
     573    this->mEarliestDatestamp = earliestDatestamp;
     574    return mEarliestDatestamp;
     575}
  • main/trunk/greenstone2/runtime-src/src/oaiservr/oaiaction.h

    r22739 r24412  
    4949 public:
    5050  oaiaction(const text_t &name);
    51 
     51 
    5252  virtual void setConfiguration(oaiconfig *config) { this->configuration = config; }
    5353  text_t getName();
     54  virtual text_t calcEarliestDatestamp(recptproto *protocol, oaiargs &params);
    5455  text_t parseDatestamp(time_t &rawtime);// Convert date from raw time_t format to the string YYYY-MM-DD
    5556  void   getResponseDate(text_t &date);  // Get the response date in UTC (GMT) time, plus local offset
     
    8687  text_t     errorType;
    8788  ostream  * logout;
     89  text_t    mEarliestDatestamp;
    8890};
    8991#endif
Note: See TracChangeset for help on using the changeset viewer.