Ignore:
Timestamp:
2008-05-09T16:29:17+12:00 (16 years ago)
Author:
mdewsnip
Message:

Quickly adding resumption token support to the ListSets action: this is part of the OAI specification but was never implemented in the code... no prizes for guessing who couldn't be bothered. By DL Consulting Ltd.

File:
1 edited

Legend:

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

    r15198 r15387  
    1818  while (param_iterator != params.end())
    1919  {
    20     if (param_iterator->first != "verb")
     20    if (param_iterator->first != "verb" && param_iterator->first != "resumptionToken")
    2121    {
    2222      params.erase(param_iterator->first);
     
    2626  }
    2727
    28   if(params_size != 1){
     28  if (params_size != params.getSize()) {
    2929    this->errorType = "badArgument";
    3030    return false;
     31  }
     32
     33  if (params["resumptionToken"] != "") {
     34    ResumptionToken token(params["resumptionToken"]);
     35    // TO DO: Resumption token validation checking (the token.isValid() function is useless for ListSets)
     36    // if (!token.isValid()) {
     37    //   this->errorType = "badResumptionToken";
     38    //   return false;
     39    // }
    3140  }
    3241
     
    5766  text_tset        metadata;
    5867  ofstream         logout("oai.log", ios::app);
    59   text_tarray *result = new text_tarray;
    6068 
    6169  // get a list of the collections available
     
    6573  }
    6674
     75  // check resumption token
     76  int startSet = 0;
     77  if (params["resumptionToken"] != "") {
     78    ResumptionToken token(params["resumptionToken"]);
     79    startSet = token.getPosition() - 1; // first document is said to be 1..
     80  }
     81  this->replyToken = NULL;
     82
     83  this->setNumber = 0;
     84  this->setsOutput = 0;
    6785  for(int current_col = 0; current_col < collections.size(); ++current_col) {
    6886    // output the collection as a set, first, then its children
    6987    text_t gsdlCollect = collections[current_col];
    7088
    71     output << "  <set>" << endl;
    72     output << "    <setSpec>" << gsdlCollect << "</setSpec>" << endl;;
    73     output << "    <setName>" << gsdlCollect << "</setName>" << endl;
    74     output << "  </set>" << endl;
     89    if (this->setsOutput == this->configuration->resumeAfter())
     90    {
     91      this->replyToken = new ResumptionToken("", "", "");
     92      this->replyToken->setPosition("", this->setNumber+1);
     93      break;
     94    }
     95
     96    if (this->setNumber >= startSet)
     97    {
     98      output << "  <set>" << endl;
     99      output << "    <setSpec>" << gsdlCollect << "</setSpec>" << endl;;
     100      output << "    <setName>" << gsdlCollect << "</setName>" << endl;
     101      output << "  </set>" << endl;
     102      this->setsOutput++;
     103    }
     104    setNumber++;
    75105
    76106    // get all the children of the (relevant) classifier data structures
     
    78108    // and send them to the "recurse_content" list
    79109    for (int c = 0; c < response.numDocs; ++c) {
    80       this->recurse_content(output, protocol, gsdlCollect, response.docInfo[c].OID, gsdlCollect);
    81     }
     110      this->recurse_content(output, protocol, gsdlCollect, response.docInfo[c].OID, gsdlCollect, startSet);
     111    }
     112  }
     113
     114  // do a resumption token if required; errors cancel a token...
     115  if (this->replyToken != NULL && this->errorType == "") {
     116    output << "  <resumptionToken>" << endl;
     117    output << "    " << this->replyToken->getToken() << endl;
     118    output << "  </resumptionToken>" << endl;
    82119  }
    83120
     
    86123
    87124void listsetsaction::recurse_content(ostream &output, recptproto *protocol, text_t &collection,
    88                      const text_t &classifier, text_t setHierarchy)
     125                     const text_t &classifier, text_t setHierarchy, int startSet)
    89126{
    90127  // metadata for this call
     
    92129  text_tset        metadata;
    93130  ofstream         logout("oai.log", ios::app);
     131
     132  if (this->setsOutput == this->configuration->resumeAfter())
     133  {
     134    this->replyToken = new ResumptionToken("", "", "");
     135    this->replyToken->setPosition("", this->setNumber+1);
     136    return;
     137  }
    94138
    95139  metadata.insert("contains");
     
    135179  // output the xml for this set; use the classifier id for the name
    136180  // if the title is blank
    137   output << "  <set>" << endl;
    138   text_t oai_classifier = classifier;
    139   oaiclassifier::toOAI(collection, oai_classifier);
    140   output << "    <setSpec>" << oai_classifier << "</setSpec>" << endl;
    141   output << "    <setName>";
    142181  // curSet holds the colon-separated sequence of parent sets of the current set
    143182  text_t curSet;
    144   if (!title.empty()) {
    145     curSet = setHierarchy + ":" + title;
    146   }
    147   else {
    148     curSet = classifier; // Pretty much never gets here (shouldn't, at least)
    149   }
    150   output << curSet;
    151   output << "</setName>" << endl;
    152   output << "  </set>" << endl;
     183  if (this->setNumber >= startSet)
     184  {
     185    output << "  <set>" << endl;
     186    text_t oai_classifier = classifier;
     187    oaiclassifier::toOAI(collection, oai_classifier);
     188    output << "    <setSpec>" << oai_classifier << "</setSpec>" << endl;
     189    output << "    <setName>";
     190    if (!title.empty()) {
     191      curSet = setHierarchy + ":" + title;
     192    }
     193    else {
     194      curSet = classifier; // Pretty much never gets here (shouldn't, at least)
     195    }
     196    output << curSet;
     197    output << "</setName>" << endl;
     198    output << "  </set>" << endl;
     199    this->setsOutput++;
     200  }
     201  this->setNumber++;
    153202
    154203  // get the children of this classifier and iterate them
     
    173222    // parent sets. curSet is pass-by-value, so that as we step out of recursion we remember
    174223    // old set hierarchies.
    175     this->recurse_content(output, protocol, collection, child, curSet);
     224    this->recurse_content(output, protocol, collection, child, curSet, startSet);
    176225  }
    177226 
Note: See TracChangeset for help on using the changeset viewer.