Changeset 27528 for main/trunk


Ignore:
Timestamp:
2013-06-04T11:05:08+12:00 (11 years ago)
Author:
kjdon
Message:

implemented oaisupercollection. add to oai.cfg and the server will make a new set containing the specified collections

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

Legend:

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

    r24109 r27528  
    5555    position = resumption_token.getPosition();
    5656  }
    57 
    58   // Case for "set" argument present -- output just the records in the specified set
     57 
     58  // is it a super collection??
     59  bool is_super_collection = false;
     60 
    5961  if (set_name != "")
    6062  {
     63    text_tarray super_colls = this->configuration->getSuperCollectionsList();
     64    for (int s = 0; s<super_colls.size(); s++) {
     65      if (set_name == super_colls[s]) {
     66    is_super_collection = true;
     67    break;
     68      }
     69    }
     70  }
     71     
     72  // Case for "set" argument present that is not a super collection -- output just the records in the specified set
     73  if (set_name != "" && !is_super_collection) {
    6174    // Separate the collection name and Greenstone classifier OID from the set name
    6275    text_t collection_name = "";
     
    7285
    7386  // Case for no "set" argument present -- output all records in all collections
     87  // or we are a super collection
    7488  else
    7589  {
    7690    // Get a list of the collections available
    77     text_tarray& collections = this->configuration->getCollectionsList();
     91    text_tarray collections;
     92
     93    if (is_super_collection) {
     94      collections = this->configuration->getSuperCollectionCollections(set_name);
     95    } else {
     96      collections = this->configuration->getCollectionsList();
     97    }
    7898    if (collections.size() == 0)
    7999    {
     
    120140  return true;
    121141}
    122 
    123142
    124143bool abstractlistaction::output_content_for_set(ostream &output, recptproto *protocol, oaiargs &params, text_t collection_name, text_t gsdl_classifier_OID, text_t set_name)
  • main/trunk/greenstone2/runtime-src/src/oaiservr/listidsaction.cpp

    r22739 r27528  
    179179    text_t set = params["set"];
    180180
     181    // Is the set a super collection??
     182    text_tarray &super_collections = this->configuration->getSuperCollectionsList();
     183    bool super_collection_found = false;
     184    for (int c = 0; c < super_collections.size(); c++)
     185    {
     186      if (super_collections[c] == set)
     187      {
     188    super_collection_found = true;
     189    break;
     190      }
     191    }
     192    if (super_collection_found) {
     193      this->errorType = "";
     194      return true;
     195    }
     196   
    181197    // Extract the collection name from the set specification
    182198    text_t collection = "";
  • main/trunk/greenstone2/runtime-src/src/oaiservr/listsetsaction.cpp

    r22739 r27528  
    131131  }
    132132
     133  // if no resumption token, output the super colls. Otherwise, start from
     134  // the collection list correct position.
     135  // Assume for now that super coll list is always in the first list
     136  text_t set_name ="";
     137  if (position == "") {
     138    text_tarray& supercolls = this->configuration->getSuperCollectionsList();
     139    if (collections.size() != 0) {
     140      text_tarray::iterator supercoll_iterator = supercolls.begin();
     141      while (supercoll_iterator != supercolls.end()) {
     142    set_name = (*supercoll_iterator);
     143    output_content_for_supercol(output, set_name);
     144    supercoll_iterator++;
     145      }
     146    }
     147  }
    133148  // Get the current collection from the position value
    134149  text_t collection_name = "";
     
    173188  return true;
    174189}
     190
     191bool listsetsaction::output_content_for_supercol(ostream &output, text_t supercoll) {
     192    utf8outconvertclass utf8convert;
     193    output << utf8convert << "  <set>\n";
     194    output << utf8convert << "    <setSpec>" << supercoll << "</setSpec>\n";
     195    if (this->configuration->getSetName(supercoll) != "")
     196    {
     197      output << utf8convert << "    <setName>" << this->configuration->getSetName(supercoll) << "</setName>\n";
     198    }
     199    else
     200    {
     201      output << utf8convert << "    <setName>" << supercoll << "</setName>\n";
     202    }
     203    if (this->configuration->getSetDescription(supercoll) != "")
     204    {
     205      output << utf8convert << "    <setDescription>" << this->configuration->getSetDescription(supercoll) << "</setDescription>\n";
     206    }
     207    output << utf8convert << "  </set>\n";
     208    this->setsOutput++;
     209}
     210 
     211
    175212
    176213
  • main/trunk/greenstone2/runtime-src/src/oaiservr/listsetsaction.h

    r22739 r27528  
    4040  bool output_content(ostream &output, recptproto *protocol, oaiargs &params);
    4141
     42  bool output_content_for_supercol(ostream &output, text_t supercoll);
    4243  bool output_content_for_col(ostream &output, recptproto *protocol, oaiargs &params, text_t collection);
    4344};
  • main/trunk/greenstone2/runtime-src/src/oaiservr/oaiaction.cpp

    r24871 r27528  
    413413    oaiclassifier::getCollectionFromOAIID(oaiLabel, collection_id);
    414414    if(oaiVersion >= 200){
     415
     416      // A doc is always a member of its collection set
     417      output << "      <setSpec>" << collection_id << "</setSpec>" << endl;
     418      // are we part of a super collection?
     419      text_tarray super_colls = this->configuration->getSuperCollectionsForThisCollection(collection_id);
     420      if (super_colls.size()!=0) {
     421    text_tarray::const_iterator super_start = super_colls.begin();
     422    text_tarray::const_iterator super_end = super_colls.end();
     423    while(super_start != super_end) {
     424      output << "      <setSpec>" << *super_start << "</setSpec>" << endl;
     425      ++ super_start;
     426    }
     427      }
     428     
     429      // Do we have subsets?
    415430      text_tarray::const_iterator member = memberOf.begin();
    416431      text_tarray::const_iterator memEnd = memberOf.end();
    417 
    418       // As well as all the subsets that a doc appears in, it is also a member of the 'collection' set
    419       output << "      <setSpec>" << collection_id << "</setSpec>" << endl;
    420432      while (member != memEnd) {
    421433    text_t oaiSet = *member;
  • main/trunk/greenstone2/runtime-src/src/oaiservr/oaiconfig.cpp

    r24114 r27528  
    2929#include <stdlib.h>
    3030#include "fileutil.h"
    31 
    3231
    3332/**
     
    211210    }
    212211  }
     212  else if (key == "oaisupercollection" && cfgline.size() > 1) {
     213
     214    // Configure a hierarchical super set
     215    // The line should read
     216    //
     217    // oaisupercollection <setName> [collections part of this set]
     218    //
     219    // Records in specified collections will be advertised as being part
     220    // of the SetName set as well as their collectionName set
     221    //
     222    // This configuration should only appear in oai.cfg
     223    //
     224    if (this->collection != "") {
     225      cerr << "Attempt to configure an oai super collection outside of oai.cfg" << endl;
     226      cerr << "Configuration attempted in " << this->collection << " collection." << endl;
     227      exit(1);
     228    }
     229   
     230    text_t super_set = cfgline[0];
     231    this->superCollectList.push_back(super_set);
     232    this->superCollectMap[super_set] = new oaisupercollectconfig(super_set);
     233    for (int c = 1; c < cfgline.size(); ++c) {
     234      text_t sub_coll = cfgline[c];
     235      // Add the collection into the list for this supercoll
     236      this->superCollectMap[super_set]->collectionList.push_back(sub_coll);
     237      // Add the super coll into the list for the collection
     238      if (this->collectMap[sub_coll]== NULL) {
     239    this->collectMap[sub_coll] = new oaicollectconfig(sub_coll);
     240      }
     241      this->collectMap[sub_coll]->superCollectList.push_back(super_set);
     242    }
     243  }
    213244  else if (key == "oaimetadata" && cfgline.size() >= 1) {
    214245    // List of metadata prefixes to suuport
     
    274305    }
    275306    if (value != "") {
    276       if (this->collectMap[coll_name] == NULL) {
    277     this->collectMap[coll_name] = new oaicollectconfig(coll_name);
    278       }
    279       if (key == "oaisetname") {
    280     this->collectMap[coll_name]->setName = value;
    281       } else if (key == "oaisetdescription") {
    282     this->collectMap[coll_name]->setDescription = value;
     307      // check first for super collection
     308      if (this->superCollectMap[coll_name] != NULL) {
     309    if (key == "oaisetname") {
     310      this->superCollectMap[coll_name]->setName = value;
     311    } else if (key == "oaisetdescription") {
     312      this->superCollectMap[coll_name]->setDescription = value;
     313    }
     314      } else {
     315    if (this->collectMap[coll_name] == NULL) {
     316      this->collectMap[coll_name] = new oaicollectconfig(coll_name);
     317    }
     318    if (key == "oaisetname") {
     319      this->collectMap[coll_name]->setName = value;
     320    } else if (key == "oaisetdescription") {
     321      this->collectMap[coll_name]->setDescription = value;
     322    }
    283323      }
    284324    }
     
    418458text_t oaiconfig::getSetName(const text_t &setSpec)
    419459{
    420   if (this->collectMap[setSpec] == NULL) {
    421     return "" ;
    422   }
     460  if (this->collectMap[setSpec] != NULL) {
     461    this->collectMap[setSpec]->setName;
     462  }
     463  if (this->superCollectMap[setSpec] != NULL) {
     464    return this->superCollectMap[setSpec]->setName;
     465  }
     466  return "" ;
    423467 
    424   return this->collectMap[setSpec]->setName;
     468}
     469
     470text_t oaiconfig::getSetDescription(const text_t &setSpec)
     471{
     472  if (this->collectMap[setSpec] != NULL) {
     473  return this->collectMap[setSpec]->setDescription;
     474  }
     475  if (this->superCollectMap[setSpec] != NULL) {
     476    return this->superCollectMap[setSpec]->setDescription;
     477  }
    425478 
    426 }
    427 
    428 text_t oaiconfig::getSetDescription(const text_t &setSpec)
    429 {
    430   if (this->collectMap[setSpec] == NULL) {
    431     return "" ;
    432   }
     479  return "" ;
    433480 
    434   return this->collectMap[setSpec]->setDescription;
    435 }
    436 
     481}
     482
     483text_tarray oaiconfig::getSuperCollectionsForThisCollection(const text_t &collection) {
     484
     485  text_tarray super_colls;
     486  if (this->superCollectList.size() == 0) {
     487    return super_colls;
     488  }
     489
     490  for (int s = 0; s < this->superCollectList.size(); s++) {
     491    text_tarray colls = this->superCollectMap[this->superCollectList[s]]->collectionList;
     492    for (int c = 0; c < colls.size(); c++)
     493    {
     494      if (colls[c] == collection)
     495      {
     496    super_colls.push_back(this->superCollectList[s]);
     497    break;
     498      }
     499    }
     500  }
     501   
     502  return super_colls;
     503}
  • main/trunk/greenstone2/runtime-src/src/oaiservr/oaiconfig.h

    r23233 r27528  
    3939  text_t    setDescription; // A display description for the set (collection)
    4040  text_tmap fieldMap;    // maps from OAI name to GSDL name
     41  text_tarray superCollectList; // a list of all super collections this belongs to
    4142};
    4243
    4344typedef map<text_t, oaicollectconfig *, lttext_t> oaicollectmap;
     45
     46class oaisupercollectconfig {
     47 public:
     48  oaisupercollectconfig(const text_t &supercollectionname) { this->supercollection = supercollectionname; }
     49  text_t supercollection;
     50  text_t setName; // A display name for the set (supercollection)
     51  text_t setDescription; // A display description for the set (supercollection)
     52  text_tarray collectionList; // a list of collections contained in this super collection
     53};
     54
     55typedef map<text_t, oaisupercollectconfig *, lttext_t> oaisupercollectmap;
     56
    4457
    4558class oaiconfig : configurable {
     
    5063  virtual void  configure(const text_t &key, const text_tarray &cfgline);
    5164  text_tarray & getCollectionsList() { return this->collectList; }
     65  text_tarray & getSuperCollectionsList() { return this->superCollectList; }
     66  text_tarray & getSuperCollectionCollections(const text_t super_coll) {
     67    return this->superCollectMap[super_coll]->collectionList;
     68  }
     69  text_tarray getSuperCollectionsForThisCollection(const text_t &collection);
    5270  text_tset & getMetadataSet() { return this->metadataSet; }
    5371  text_t        getMapping(const text_t &collection, const text_t &collectfield);
     
    86104  oaicollectmap collectMap; // The configuration of collections
    87105  text_t collection;        // Used to track which collection is being configured
    88  
     106  text_tarray superCollectList; //a list of super collections. may be empty
     107  oaisupercollectmap superCollectMap; // The configuration of the super collections
    89108};
    90109#endif
Note: See TracChangeset for help on using the changeset viewer.