Changeset 11732


Ignore:
Timestamp:
2006-04-28T11:26:25+12:00 (18 years ago)
Author:
grbuchan
Message:

Improved functionality in resumptiontoken; additional support of resumption
behaviour in configuration; better honouring of OAI settings on collections
(i.e. collections not explicitly listed could be revealed through OAI by
accident).

Location:
trunk/gsdl/src/oaiservr
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/gsdl/src/oaiservr/abstractlistaction.cpp

    r11311 r11732  
    33
    44#include "oaitools.h"
    5 
    6 // The following makes sure that we don't actually use ResumptionTokens
    7 #define MAXRECORDS -1
    85
    96bool abstractlistaction::validateAction(recptproto *protocol, oaiargs &params, int &numArgs)
     
    108105  }
    109106
     107  this->replyToken = NULL;
     108
    110109  // if we've been asked for a set, then use it!
    111110  if (params["set"] != "") {
     
    128127    else {
    129128      if (this->check_classifier(protocol, gsdlCollect, gsdlSet)) {
    130     this->recurse_set(output, protocol, gsdlCollect, gsdlSet, params);
     129    this->recurse_set(output, protocol, gsdlCollect, gsdlSet, params, token);
    131130      }
    132131    }
     
    146145
    147146  // do a resumption token if required; errors cancel a token...
    148   if (this->replyToken != NULL && this->errorType != "") {
    149     output << "<resumptionToken>";
    150     output << this->replyToken->getToken();
    151     output << "</resumptionToken>";
     147  if (this->replyToken != NULL && this->errorType == "") {
     148    output << "  <resumptionToken>" << endl;
     149    output << "    " << this->replyToken->getToken() << endl;
     150    output << "  </resumptionToken>" << endl;
    152151  }
    153152
     
    196195    continue;
    197196      }
    198      
     197
     198
    199199      // Check that the item with the 0ID 'gsdl_id' has a lastmodified field that fits within
    200200      // the required date range (if specified).
     
    212212      }
    213213
    214       // if we've output MAXRECORDS documents; prepare a resumptionToken
    215       if (this->outputDocs == MAXRECORDS) {
     214      // if we've output the number of resumption documents; prepare a resumptionToken
     215      if (this->outputDocs == this->configuration->resumeAfter()) {
    216216    this->replyToken = new ResumptionToken(gsdlCollect, "", "");
    217217    this->replyToken->setPosition("", i+2);
     
    232232  text_tarray       collections;
    233233  text_t            gsdlCollect = "";
     234  ResumptionToken   *token = NULL;
    234235
    235236  // get a list of the collections available
    236   protocol->get_collection_list(collections, err, output);
    237  
     237  collections = this->configuration->getCollectionsList();
     238  //  protocol->get_collection_list(collections, err, output);
     239 
     240  if (params["resumptionToken"] != "") {
     241    token = new ResumptionToken(params["resumptionToken"]);
     242  }
     243
    238244  for(int current_col = 0; current_col < collections.size(); ++current_col){
    239245    gsdlCollect = collections[current_col];
     246
     247    // ignore all leading collections before the one that matches the resumptiontoken
     248    if (token != NULL &&
     249    token->getCollection() != gsdlCollect)
     250    { continue;
     251    }
     252
    240253    this->output_content_for_col(output, protocol, gsdlCollect, cinfo, err, params);
     254
     255    // once we've output at least one collection, continue
     256    // outputting all others until the resumption total hits
     257    token = NULL;
     258
     259    if (this->outputDocs == this->configuration->resumeAfter()) {
     260      break;
     261    }
    241262  }
    242263}
     
    295316
    296317void abstractlistaction::recurse_set(ostream &output, recptproto *protocol, const text_t &collection,
    297                      const text_t &classifier, oaiargs &params)
     318                     const text_t &classifier, oaiargs &params, ResumptionToken *resumptionToken)
    298319{
    299320  // metadata for this call
     
    304325  text_t           until = params["until"];
    305326  text_t           metadataPrefix = params["metadataPrefix"];
    306   ResumptionToken  resumptionToken(params["resumptionToken"]);
     327  //  ResumptionToken  resumptionToken(params["resumptionToken"]);
    307328  int              startPos = 0;
    308329
     
    322343  if (params["resumptionToken"] != "") {
    323344    // if we're at a resumptionToken
    324     if (classifier == resumptionToken.getNode()) {
    325       startPos = resumptionToken.getPosition();
     345    if (classifier == resumptionToken->getNode()) {
     346      startPos = resumptionToken->getPosition();
    326347    }
    327348    else {
    328       text_t fullNode = resumptionToken.getNode();
     349      text_t fullNode = resumptionToken->getNode();
    329350      text_t::iterator leafIter = fullNode.begin() + classifier.size();
    330351
     
    377398    // children which are classifiers are recursed
    378399    else {
    379       this->recurse_set(output, protocol, collection, child, params);
    380     }
    381 
    382     if (this->outputDocs == MAXRECORDS) {
    383       this->replyToken = new ResumptionToken(collection, params["set"], "");
    384       this->replyToken->setPosition(classifier, c+2);
    385     }
    386   }
    387 }
    388 
    389 
    390 
    391 
     400      if (resumptionToken != NULL) {
     401    int depth = countchar(classifier.begin(), classifier.end(), '.');
     402    resumptionToken->setOffset(depth, c+2);
     403      }
     404      this->recurse_set(output, protocol, collection, child, params, resumptionToken);
     405    }
     406
     407    if (this->outputDocs == this->configuration->resumeAfter()) {
     408      //      this->replyToken = new ResumptionToken(collection, params["set"], "");
     409      this->replyToken = resumptionToken;
     410      this->replyToken->setPosition(classifier, c+2);     
     411    }
     412  }
     413}
     414
     415
     416
     417
  • trunk/gsdl/src/oaiservr/abstractlistaction.h

    r8182 r11732  
    1717                      ColInfoResponse_t &cinfo, comerror_t &err, oaiargs &params);
    1818  virtual void recurse_set(ostream &output, recptproto *protocol, const text_t &collection,
    19                const text_t &classifier, oaiargs &params);
     19               const text_t &classifier, oaiargs &params, ResumptionToken *resumptionToken);
    2020 protected:
    2121  bool prevDocSeen;
  • trunk/gsdl/src/oaiservr/oaiconfig.cpp

    r9608 r11732  
    3434
    3535oaiconfig::oaiconfig() : configurable () {
     36  this->resumptionSize = -1; // Default = do not use resumption tokens
    3637}
    3738
     
    4142  text_t mainconfig = filename_cat(gsdlhome, "etc", "oai.cfg");
    4243  this->collection = "";
     44  this->resumptionSize = -1;
    4345  this->read_configfile(mainconfig);
    44  
     46
    4547  // then if we've not got a specified collection in the gsdlcollect
    4648  // parameter, read in all the collection's individual configurations
     
    6668    ++here;
    6769  }
     70}
     71
     72int oaiconfig::resumeAfter()
     73{ return this->resumptionSize;
    6874}
    6975
     
    186192    this->oaiVersion = cfgline[0];
    187193  }
     194  else if (key == "resumeafter" && cfgline.size() >= 1) {
     195    this->resumptionSize = cfgline[0].getint();
     196  }
    188197  // get and note a maintainer item to support the Identify Verb of OAI
    189198  else if (key == "maintainer" && cfgline.size() >= 1) {
  • trunk/gsdl/src/oaiservr/oaiconfig.h

    r8303 r11732  
    3232  text_tmap   * getInformation() { return &this->infoMap; }
    3333  int           getOAIVersion();
     34  int           resumeAfter();
    3435 private:
    3536  void configureCollection(const text_t &gsdlhome, const text_t &collection);
     
    4142  text_t collection;        // Used to track which collection is being configured
    4243  text_t oaiVersion;        // The version of OAI running
     44  int    resumptionSize;    // The number of items to produce before spitting out a
     45                            // resumptionToken
    4346};
    4447#endif
  • trunk/gsdl/src/oaiservr/resumptiontoken.cpp

    r8223 r11732  
    2525{ text_t::const_iterator first = URN.begin();
    2626  text_t::const_iterator last = URN.end();
     27  text_t::const_iterator second;
    2728
    2829  this->collection = "";
     
    4142
    4243  // increment past the first colon to get the location
     44  first = ++here; 
     45
     46  // get the collection, browseNode
     47  here = findchar(first, last, ',');
     48  if (here == last) {
     49    return;
     50  }
     51
     52  second = findchar(first, here,'.');
     53  this->collection = substr(first, second);
     54
     55  //  cerr << "Collection " << this->collection << endl;
     56
     57  if (second != here) {
     58    this->browseNode = substr(second, here);
     59  }
     60  else {
     61    first = here;
     62  }
     63  // get past the ','
    4364  first = ++here;
    4465
    45   // get the collection
    46   here = findchar(first, last, '.');
     66  // find the second ',' to delimit the position stack
     67  second = findchar(first, last, ',');
     68
     69  // if not found, then get build and start item
     70  if (second != first) {
     71    // extract list and step past it
     72    text_t offsetList = substr(first, second);
     73    first = ++second;
     74   
     75    do {
     76      second = findchar(offsetList.begin(), offsetList.end(), '.');
     77      if (second == offsetList.end())
     78    break;
     79     
     80      // extract and push the next position
     81      text_t thisPos = substr(offsetList.begin(), second);
     82      this->browsePosition.push_back(thisPos.getint());
     83
     84      // pop the position from the list
     85      offsetList = substr(++second, offsetList.end());
     86    } while (TRUE);   
     87    this->browsePosition.push_back(offsetList.getint());
     88  }
     89  else {
     90    first ++;
     91  }
     92
     93  // now find the build date marker
     94  here = findchar(first, last, '-');
    4795  if (here == first) {
    48     return;
     96    this->startItem = substr(first, last).getint();
    4997  }
    50   this->collection = substr(first, here);
    51 
    52   first = ++here;
    53 
    54   // get the browse node
    55   here = findchar(first, last, ',');
    56 
    57   // now, we *may* have truncated items where we start with the first
    58   // item in a node (i.e. suppress the ',0' for one reason or another,
    59   // let's be forgiving if we can...
    60   if (here == first) {
    61     this->startItem = 0;
    62 
    63     here = findchar(first, last, '-');   
    64 
    65     // no build date - keep trying...
    66     if (here == first) {
    67       this->browseNode = substr(first, last);
    68     }
    69     else {
    70       this->browseNode = substr(first, here);
    71       this->buildDate  = substr(++here, last);
    72     }
    73   }
    74   // got a proper item indicator...
    7598  else {
    76     // record the browse node
    77     this->browseNode = substr(first, here);
    78 
    79     // get past the ','
    80     first = ++here;
    81    
    82     // now find the build date marker
    83     here = findchar(first, last, '-');
    84     if (here == first) {
    85       this->startItem = substr(first, last).getint();
    86     }
    87     else {
    88       this->startItem = substr(first, here).getint();
    89       this->buildDate = substr(++here, last);
    90     }
     99    this->startItem = substr(first, here).getint();
     100    this->buildDate = substr(++here, last);
    91101  }
    92102}
     
    111121  if (this->browseNode != "") {
    112122    reply = reply + "." + this->browseNode;
     123  }
     124  reply = reply + ",";
     125  for (int i = 0; i < this->browsePosition.size(); i++) {
     126    if (i != 0) {
     127      reply.append(".");
     128    }
     129    reply.appendint(i);
    113130  }
    114131  reply = reply + ",";
  • trunk/gsdl/src/oaiservr/resumptiontoken.h

    r8182 r11732  
    22#define _RESUMPTIONTOKEN_H_
    33
     4#include <vector>
     5
    46#include "text_t.h"
     7
     8using namespace std;
    59
    610class ResumptionToken
     
    812  text_t  collection;
    913  text_t  browseNode;
     14  vector<int> browsePosition;
    1015  int     startItem;
    1116  text_t  buildDate;
     
    1621  ResumptionToken(const text_t &URN);
    1722  text_t  getToken();
     23
    1824  void setPosition(const text_t &node, int startItem);
     25
    1926  text_t  getCollection() { return collection; }
    2027  text_t  getNode() { return browseNode; }
    2128  int     getPosition() { return startItem; }
     29  int     getOffsetDepth() { return this->browsePosition.size(); }
     30  int     setOffset(int depth, int position) { this->browsePosition[depth] = position; }
     31  int getOffset(int offset) { return this->browsePosition[offset]; }
    2232  bool isValid();
    2333};
Note: See TracChangeset for help on using the changeset viewer.