Ignore:
Timestamp:
2011-08-16T17:52:13+12:00 (10 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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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}
Note: See TracChangeset for help on using the changeset viewer.