Changeset 24412
- Timestamp:
- 2011-08-16T17:52:13+12:00 (13 years ago)
- 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 113 113 // their build.cfg file at this point by collectserver::configure. The field 114 114 // is declared in comtypes.h) 115 text_t earliestDatestamp = ""; // do not set default to unix epoch time "1970-01-01" yet116 115 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 166 117 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"; 173 119 output << utf8convert << " <deletedRecord>no</deletedRecord>\n"; 174 120 output << utf8convert << " <granularity>YYYY-MM-DD</granularity>\n"; -
main/trunk/greenstone2/runtime-src/src/oaiservr/listrecsaction.cpp
r22739 r24412 156 156 this->errorType = "badArgument"; 157 157 return false; 158 } 158 } 159 159 } 160 160 … … 178 178 return false; 179 179 } 180 180 181 181 // Check the collection is one that is in the list in the oai.cfg file 182 182 text_tarray &collections = this->configuration->getCollectionsList(); … … 204 204 return false; 205 205 } 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 } 207 238 208 239 // If we've reached here everything must be fine -
main/trunk/greenstone2/runtime-src/src/oaiservr/oaiaction.cpp
r24109 r24412 41 41 #include <time.h> 42 42 43 44 43 oaiaction::oaiaction(const text_t &name) 45 44 { … … 47 46 this->configuration = NULL; 48 47 this->name = name; 48 this->mEarliestDatestamp = ""; 49 49 } 50 50 … … 491 491 return false; 492 492 } 493 494 text_t oaiaction::calcEarliestDatestamp(recptproto *protocol, oaiargs ¶ms) { 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 49 49 public: 50 50 oaiaction(const text_t &name); 51 51 52 52 virtual void setConfiguration(oaiconfig *config) { this->configuration = config; } 53 53 text_t getName(); 54 virtual text_t calcEarliestDatestamp(recptproto *protocol, oaiargs ¶ms); 54 55 text_t parseDatestamp(time_t &rawtime);// Convert date from raw time_t format to the string YYYY-MM-DD 55 56 void getResponseDate(text_t &date); // Get the response date in UTC (GMT) time, plus local offset … … 86 87 text_t errorType; 87 88 ostream * logout; 89 text_t mEarliestDatestamp; 88 90 }; 89 91 #endif
Note:
See TracChangeset
for help on using the changeset viewer.