Changeset 31387 for main/trunk/greenstone2
- Timestamp:
- 2017-02-08T18:31:18+13:00 (7 years ago)
- Location:
- main/trunk/greenstone2/runtime-src/src
- Files:
-
- 19 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone2/runtime-src/src/colservr/browsefilter.cpp
r16310 r31387 26 26 #include "browsefilter.h" 27 27 #include "fileutil.h" 28 #include <assert.h> 28 29 29 30 30 31 browsefilterclass::browsefilterclass () { 31 32 db_ptr = NULL; 33 oaidb_ptr = NULL; 32 34 33 35 // -- onePerQuery StartResults integer … … 60 62 } 61 63 62 browsefilterclass::~browsefilterclass () { 63 } 64 browsefilterclass::~browsefilterclass () {} 64 65 65 66 void browsefilterclass::configure (const text_t &key, const text_tarray &cfgline) { … … 75 76 if (!filterclass::init(logout)) return false; 76 77 77 if (db_ptr == NULL ) {78 if (db_ptr == NULL || oaidb_ptr == NULL) { 78 79 // most likely a configuration problem 79 80 logout << text_t2ascii … … 93 94 } 94 95 96 oaidb_filename = resolve_oaidb_filename(oaidb_ptr->getfileextension()); 97 95 98 return true; 96 99 } … … 104 107 response.clear (); 105 108 err = noError; 106 if (db_ptr == NULL) {107 // most likely a configuration problem108 logout << text_t2ascii109 << "configuration error: browsefilter contains a null dbclass\n\n";110 err = configurationError;111 return;112 }113 114 // open the database115 db_ptr->setlogout(&logout);116 if (!db_ptr->opendatabase (db_filename, DB_READER, 100, false)) {117 // most likely a system problem (we have already checked that the database exists)118 logout << text_t2ascii119 << "system problem: open on database \""120 << db_filename << "\" failed\n\n";121 err = systemProblem;122 return;123 }124 109 125 110 // get the browse parameters … … 146 131 } 147 132 133 // if we're only working on oai, open oai_db, no need to work with index_db in browsefilter.cpp 134 // (but source.cpp uses both oai-inf.db and index.db to get metadata for OAI request) 135 // If we can't open the oai-inf db, this can be because it didn't exist in older versions of GS 136 // in that case, proceed as usual, using the index db. 137 if((request.filterResultOptions & FROAI)) { // OAI request 138 bool success = false; 139 140 if(parentnode == "oai") { // doing an OAI listidentifiers request 141 142 // open up the oai-inf db, if it exists, and return all IDs 143 // if it doesn't exist, proceed as usual 144 success = get_oaiinf_db_entries(response, err, logout); //adds any stuff in oai-inf db for the current OID to resultdoc.metadata 145 146 response.numDocs = response.docInfo.size(); 147 response.isApprox = Exact; 148 } 149 if (success) return; // oai request successfully completed with oai-inf.db, no need to open index_db 150 } 151 152 // Since we're here, it means we're not doing anything oai (or oai-inf.db did not exist/open) 153 // So we don't need to work with oai_db. Instead, work with index_db: 154 155 if (db_ptr == NULL) { 156 // most likely a configuration problem 157 logout << text_t2ascii 158 << "configuration error: browsefilter contains a null index dbclass\n\n"; 159 err = configurationError; 160 return; 161 } 162 163 // open the database 164 db_ptr->setlogout(&logout); 165 if (!db_ptr->opendatabase (db_filename, DB_READER, 100, false)) { 166 // most likely a system problem (we have already checked that the database exists) 167 logout << text_t2ascii 168 << "system problem: open on database \"" 169 << db_filename << "\" failed\n\n"; 170 err = systemProblem; 171 return; 172 } 173 148 174 infodbclass info; 149 175 … … 158 184 (request.filterResultOptions & FRmetadata)) { 159 185 if (!db_ptr->getinfo(parentnode, info)) { 160 // didn't find the node 186 // didn't find the node in index db 161 187 logout << text_t2ascii 162 188 << "warning: lookup for node \"" << parentnode … … 308 334 response.isApprox = Exact; 309 335 } 336 337 bool browsefilterclass::get_oaiinf_db_entries(FilterResponse_t &response, 338 comerror_t &err, ostream &logout) 339 { 340 outconvertclass text_t2ascii; 341 342 //logout << text_t2ascii << "browsefilterclass::get_oaiinf_db_entries\n"; 343 344 // ONLY if we're doing any OAI stuff (FROAI will be set then) will we be here 345 // So next try to open the oai-inf db if it exists for this collection 346 347 348 if (!file_exists(oaidb_filename)) { // if the oaidb file doesn't even exist, let's not bother with oaidb 349 350 logout << text_t2ascii 351 << "warning: collection's oai-inf database \"" << oaidb_filename << "\" does not exist\n\n"; 352 return false; 353 354 } else { // let's try opening the oaidb file 355 oaidb_ptr->setlogout(&logout); 356 if (!oaidb_ptr->opendatabase (oaidb_filename, DB_READER, 100, false)) { 357 // most likely a system problem (we have already checked that the database exists just above) 358 logout << text_t2ascii 359 << "system problem: open on database \"" 360 << oaidb_filename << "\" failed\n\n"; 361 err = systemProblem; 362 return false; 363 } // now we've opened the oai-inf db file successfully 364 } 365 366 infodbclass oai_info; 367 ResultDocInfo_t resultdoc; 368 369 text_tarray keys = oaidb_ptr->getkeys(); 370 371 text_tarray::iterator key_here = keys.begin(); 372 text_tarray::iterator key_end = keys.end(); 373 while (key_here != key_end) { 374 375 resultdoc.OID = (*key_here); 376 377 if(!oaidb_ptr->getinfo(resultdoc.OID, oai_info)) { 378 logout << text_t2ascii 379 << "warning: lookup for node \"" << resultdoc.OID 380 << "\" in etc/oai-inf db failed for browsefilter.\n\n"; 381 } else { 382 //logout << text_t2ascii << "@@@@ found node \"" << resultdoc.OID << "\" in etc/oai-inf db.\n\n"; 383 384 resultdoc.metadata["oaiinf.status"].isRef = false; 385 resultdoc.metadata["oaiinf.status"].values.push_back(oai_info["status"]); 386 resultdoc.metadata["oaiinf.timestamp"].isRef = false; 387 resultdoc.metadata["oaiinf.timestamp"].values.push_back(oai_info["timestamp"]); 388 resultdoc.metadata["oaiinf.datestamp"].isRef = false; 389 resultdoc.metadata["oaiinf.datestamp"].values.push_back(oai_info["datestamp"]); 390 } 391 392 response.docInfo.push_back(resultdoc); 393 ++key_here; 394 395 } 396 397 // we're done with oai-inf db 398 399 oaidb_ptr->closedatabase(); // don't leave files open 400 401 return true; 402 } -
main/trunk/greenstone2/runtime-src/src/colservr/browsefilter.h
r15558 r31387 41 41 text_t indexstem; 42 42 dbclass *db_ptr; 43 text_t oaidb_filename; 44 dbclass *oaidb_ptr; 43 45 44 46 public: … … 50 52 virtual void configure (const text_t &key, const text_tarray &cfgline); 51 53 52 // the db ptr remains the responsability of the calling code and53 // should be destroyed after this browsefilter is destroyed54 // the db ptr and oaidb ptr remain the responsibility of the calling code and should 55 // be destroyed after this browsefilter is destroyed (source.h class destroys these) 54 56 void set_db_ptr (dbclass *db_ptr_arg) { db_ptr = db_ptr_arg; } 57 void set_oaidb_ptr (dbclass *oaidb_ptr_arg) { oaidb_ptr = oaidb_ptr_arg; } 55 58 56 59 bool init (ostream &logout); … … 59 62 FilterResponse_t &response, 60 63 comerror_t &err, ostream &logout); 64 65 protected: 66 bool get_oaiinf_db_entries(FilterResponse_t &response, 67 comerror_t &err, ostream &logout); 61 68 }; 62 69 -
main/trunk/greenstone2/runtime-src/src/colservr/collectserver.cpp
r29100 r31387 515 515 thisfilter->filter (request, response, err, logout); 516 516 if (err != noError) return; 517 517 518 // fill in the metadata for each of the OIDs (if it is requested) 518 519 if (request.filterResultOptions & FRmetadata) { 520 519 521 bool processed = false; 520 522 ResultDocInfo_tarray::iterator resultdoc_here = response.docInfo.begin(); 521 523 ResultDocInfo_tarray::iterator resultdoc_end = response.docInfo.end(); 522 524 while (resultdoc_here != resultdoc_end) { 525 526 text_t deleted_status = ""; 527 bool append_metadata = (request.filterResultOptions & FROAI) ? true : false; 528 523 529 // try each of the sources in turn 524 530 sourcelistclass::iterator source_here = sources.begin(); … … 526 532 while (source_here != source_end) { 527 533 assert ((*source_here).s != NULL); 534 535 // first check for oai metadata from the oai_db, if asked for it (if FROAI is set) 536 if(((*source_here).s != NULL) && 537 request.filterResultOptions & FROAI && 538 ((*source_here).s->get_oai_metadata(request.requestParams, request.refParams, 539 request.getParents, request.fields, 540 (*resultdoc_here).OID, deleted_status, (*resultdoc_here).metadata, 541 err, logout))) { 542 543 if (err != noError) return; 544 545 processed = true; 546 } 547 548 // We may or may not have got oai_meta (depends on if FROAI was set). 549 // If we didn't get oai_meta, then deleted_status would still be "". 550 // If we did get oai_meta, and if the deleted_status for the OID was D for deleted entry, 551 // don't bother getting any other metadata, as there will be no entry for that OID in index db. 552 553 // Note that if we did get oai_meta and OID marked as existing, we're in append_mode: 554 // don't let get_metadata() clear the metadata list, as there's already stuff in there 555 //if(deleted_status == "E") append_metadata = true; 556 528 557 if (((*source_here).s != NULL) && 558 deleted_status != "D" && 529 559 ((*source_here).s->get_metadata(request.requestParams, request.refParams, 530 560 request.getParents, request.fields, 531 561 (*resultdoc_here).OID, (*resultdoc_here).metadata, 532 err, logout))) { 533 if (err != noError) return; 534 processed = true; 535 break; 562 err, logout, append_metadata))) { 563 if (err != noError) return; // check for errors again 564 565 processed = processed || true; // processed would not have been set yet if not doing FROAI. Set now. 566 // OR-ing isn't necessary, but indicates some consideration of both get oai meta & get meta success 536 567 } 568 569 if(processed) break; 570 537 571 ++source_here; 538 572 } … … 548 582 } 549 583 } 550 584 551 585 err = noError; 552 586 } -
main/trunk/greenstone2/runtime-src/src/colservr/collectset.cpp
r25235 r31387 335 335 336 336 // Create a dbclass of the correct type 337 dbclass *db_ptr = NULL; 337 dbclass *db_ptr = NULL; // index database in index/text 338 dbclass *oaidb_ptr = NULL; // etc/oai-inf database 338 339 339 340 if (infodbtype == "sqlite") … … 342 343 sqlitedbclass *sql_db_ptr = new sqlitedbclass(gsdlhome); 343 344 db_ptr = sql_db_ptr; 345 346 sqlitedbclass *sql_oaidb_ptr = new sqlitedbclass(gsdlhome); 347 oaidb_ptr = sql_oaidb_ptr; 344 348 345 349 // add a sql browse filter … … 364 368 mssqldbclass *mssql_db_ptr = new mssqldbclass(gsdlhome); 365 369 db_ptr = mssql_db_ptr; 370 371 mssqldbclass *mssql_oaidb_ptr = new mssqldbclass(gsdlhome); 372 oaidb_ptr = mssql_oaidb_ptr; 366 373 367 374 // add a sql browse filter … … 380 387 jdbmnaiveclass *jdbm_db_ptr = new jdbmnaiveclass(gsdlhome); 381 388 db_ptr = jdbm_db_ptr; 389 390 jdbmnaiveclass *jdbm_oaidb_ptr = new jdbmnaiveclass(gsdlhome); 391 oaidb_ptr = jdbm_oaidb_ptr; 382 392 #else 383 393 cerr << "Warning: infodbtype of 'jdbm' was not compiled in to " << endl; … … 392 402 #ifdef USE_GDBM 393 403 db_ptr = new gdbmclass(gsdlhome); 404 oaidb_ptr = new gdbmclass(gsdlhome); 394 405 #else 395 406 cerr << "Warning: infodbtype of 'gdbm' was not compiled in to " << endl; … … 405 416 browsefilterclass *browsefilter = new browsefilterclass(); 406 417 browsefilter->set_db_ptr(db_ptr); 418 // set the oaidb ptr for the browse filter. As with the db_ptr, the oaidb_ptr 419 // is not managed and deleted by the browsefilter class, but by the sourceclass 420 browsefilter->set_oaidb_ptr(oaidb_ptr); 407 421 cserver->add_filter (browsefilter); 408 422 … … 420 434 mgsourceclass *mgsource = new mgsourceclass (); 421 435 mgsource->set_db_ptr(db_ptr); 436 mgsource->set_oaidb_ptr(oaidb_ptr); 422 437 mgsource->set_textsearchptr (mgsearch); 423 438 cserver->add_source (mgsource); … … 439 454 mgppsourceclass *mgppsource = new mgppsourceclass (); 440 455 mgppsource->set_db_ptr(db_ptr); 456 mgppsource->set_oaidb_ptr(oaidb_ptr); 441 457 mgppsource->set_textsearchptr (mgppsearch); 442 458 cserver->add_source (mgppsource); … … 459 475 lucenesourceclass *lucenesource = new lucenesourceclass (); 460 476 lucenesource->set_db_ptr(db_ptr); 477 lucenesource->set_oaidb_ptr(oaidb_ptr); 461 478 lucenesource->set_textsearchptr (lucenesearch); 462 479 cserver->add_source (lucenesource); -
main/trunk/greenstone2/runtime-src/src/colservr/comtypes.h
r24114 r31387 243 243 // used to indicate a full text browse query for mgpp 244 244 #define FRfullTextBrowse 128 245 #define FROAI 256 245 246 246 247 struct FilterRequest_t { -
main/trunk/greenstone2/runtime-src/src/colservr/filter.cpp
r16310 r31387 61 61 } 62 62 63 text_t filterclass::getcollectionpath() 64 { 65 text_t resolved_filename; 66 67 if (gsdlhome==dbhome) { 68 // dbhome has defaulted to gsdlhome which we take to means the 69 // database has been specifically moved out of gsdlhome area. 70 // => it should be whereever collecthome is set to 71 resolved_filename = filename_cat(collecthome, collection); 72 } 73 else { 74 // dbhome is explicitly set to something other than gsdlhome 75 // => use dbhome 76 resolved_filename = filename_cat(dbhome, "collect", collection); 77 } 78 79 return resolved_filename; 80 } 81 63 82 text_t filterclass::resolve_db_filename(const text_t& idx, 64 83 const text_t& file_ext) 65 84 { 85 /* 66 86 text_t resolved_filename; 67 87 … … 77 97 resolved_filename = filename_cat(dbhome, "collect", collection, "index", "text", idx); 78 98 } 99 */ 100 101 text_t resolved_filename = filename_cat(getcollectionpath(), "index", "text", idx); 102 resolved_filename += file_ext; 103 104 return resolved_filename; 105 } 106 107 text_t filterclass::resolve_oaidb_filename(const text_t& file_ext) 108 { 109 text_t resolved_filename = filename_cat(getcollectionpath(), "etc", "oai-inf"); 79 110 80 111 resolved_filename += file_ext; -
main/trunk/greenstone2/runtime-src/src/colservr/filter.h
r16310 r31387 69 69 protected: 70 70 text_t resolve_db_filename(const text_t& idx,const text_t& file_ext); 71 71 text_t resolve_oaidb_filename(const text_t& file_ext); 72 text_t getcollectionpath(); 72 73 73 74 }; -
main/trunk/greenstone2/runtime-src/src/colservr/source.cpp
r21772 r31387 33 33 { 34 34 db_ptr = NULL; 35 oaidb_ptr = NULL; 35 36 textsearchptr = NULL; 36 37 classname = "source"; … … 41 42 if (db_ptr != NULL) delete db_ptr; 42 43 if (textsearchptr != NULL) delete textsearchptr; 44 45 // http://stackoverflow.com/questions/677620/do-i-need-to-explicitly-call-the-base-virtual-destructor 46 // Answer: "No, destructors are called automatically [by the derived destructor] in the reverse 47 // order of construction. (Base classes last). Do not call base class destructors." 48 // The link also explains why the destructors should be declared as virtual in the header files. 49 50 // now delete the oaidb object pointed to by the oaidb_ptr too 51 if (oaidb_ptr != NULL) delete oaidb_ptr; 52 oaidb_ptr = NULL; 43 53 } 44 54 … … 78 88 } 79 89 90 text_t sourceclass::getcollectionpath() 91 { 92 text_t resolved_filename; 93 94 if (gsdlhome==dbhome) { 95 // dbhome has defaulted to gsdlhome which we take to means the 96 // database has been specifically moved out of gsdlhome area. 97 // => it should be whereever collecthome is set to 98 resolved_filename = filename_cat(collecthome, collection); 99 } 100 else { 101 // dbhome is explicitly set to something other than gsdlhome 102 // => use dbhome 103 resolved_filename = filename_cat(dbhome, "collect", collection); 104 } 105 106 return resolved_filename; 107 } 108 80 109 text_t sourceclass::resolve_db_filename(const text_t& idx, 81 110 const text_t& file_ext) … … 91 120 // are also drawn from one object 92 121 122 /* 93 123 text_t resolved_filename; 94 124 … … 105 135 resolved_filename = filename_cat(dbhome, "collect", collection, "index", "text", idx); 106 136 } 107 137 */ 138 139 text_t resolved_filename = filename_cat(getcollectionpath(), "index", "text", idx); 108 140 resolved_filename += file_ext; 109 141 … … 111 143 } 112 144 113 145 text_t sourceclass::resolve_oaidb_filename(const text_t& file_ext) 146 { 147 text_t resolved_filename = filename_cat(getcollectionpath(), "etc", "oai-inf"); 148 149 resolved_filename += file_ext; 150 151 return resolved_filename; 152 } 114 153 115 154 // init should be called after all the configuration is done but … … 172 211 } 173 212 213 oaidb_filename = resolve_oaidb_filename(oaidb_ptr->getfileextension()); 214 174 215 return true; 175 216 } … … 207 248 } 208 249 250 // get_oai_metadata fills out the oai metadata from oaidb if possible 251 // if it is not responsible for the given OID then it will return false. 252 bool sourceclass::get_oai_metadata (const text_t &requestParams, const text_t &refParams, 253 bool getParents, const text_tset &fields, 254 const text_t &OID, text_t &deleted_status, MetadataInfo_tmap &metadata, 255 comerror_t &err, ostream &logout) 256 { 257 outconvertclass text_t2ascii; 258 metadata.erase(metadata.begin(), metadata.end()); 259 err = noError; 260 261 //logout << text_t2ascii << "sourceclass::get_oai_meta for OID: " << OID << "\n"; 262 263 // ONLY if we're doing any OAI stuff (FROAI will be set then) will we even be in here 264 // So next try to open the oai-inf db if it exists for this collection 265 if (!file_exists(oaidb_filename)) { // if the oaidb file doesn't even exist, let's not bother with oaidb 266 267 logout << text_t2ascii 268 << "warning: collection's oai-inf database \"" << oaidb_filename << "\" does not exist\n\n"; 269 return false; 270 271 } else { // let's try opening the oaidb file 272 oaidb_ptr->setlogout(&logout); 273 if (!oaidb_ptr->opendatabase (oaidb_filename, DB_READER, 100, false)) { 274 // most likely a system problem (we have already checked that the database exists just above) 275 logout << text_t2ascii 276 << "system problem: open on database \"" 277 << oaidb_filename << "\" failed\n\n"; 278 err = systemProblem; 279 return false; 280 } // now we've opened the oai-inf db file successfully 281 } 282 283 // get the metadata (deleted status, timestamp, datestamp) for OID, and pushback onto the metadata array 284 infodbclass oai_info; 285 if (!oaidb_ptr->getinfo(OID, oai_info)) { // OID not found in oai_inf db 286 logout << text_t2ascii 287 << "warning: lookup for OID \"" << OID 288 << "\" in etc/oai-inf db failed when getting metadata (in sourceclass source.cpp).\n\n"; 289 290 return false; 291 } else { 292 //logout << text_t2ascii << "@@@@ getting metadata for OID \"" << OID << "\" from etc/oai-inf db.\n\n"; 293 //logout << text_t2ascii << "@@@@ timestamp: " << oai_info["timestamp"] << "\n\n"; 294 295 metadata["oaiinf.status"].isRef = false; 296 metadata["oaiinf.status"].values.push_back(oai_info["status"]); 297 metadata["oaiinf.timestamp"].isRef = false; 298 metadata["oaiinf.timestamp"].values.push_back(oai_info["timestamp"]); 299 metadata["oaiinf.datestamp"].isRef = false; 300 metadata["oaiinf.datestamp"].values.push_back(oai_info["datestamp"]); 301 } 302 303 // we're done with oai-inf db 304 305 oaidb_ptr->closedatabase(); // don't leave files open 306 307 return true; 308 } 309 209 310 210 311 // get_metadata fills out the metadata if possible, if it is not responsible … … 213 314 bool getParents, const text_tset &fields, 214 315 const text_t &OID, MetadataInfo_tmap &metadata, 215 comerror_t &err, ostream &logout )316 comerror_t &err, ostream &logout, bool append) 216 317 { 217 318 outconvertclass text_t2ascii; 218 319 219 metadata.erase(metadata.begin(), metadata.end()); 320 if(!append) { 321 metadata.erase(metadata.begin(), metadata.end()); 322 } 220 323 221 324 err = noError; -
main/trunk/greenstone2/runtime-src/src/colservr/source.h
r16310 r31387 62 62 text_t db_filename; 63 63 dbclass *db_ptr; 64 text_t oaidb_filename; 65 dbclass *oaidb_ptr; 64 66 65 67 searchclass *textsearchptr; … … 69 71 virtual ~sourceclass (); 70 72 71 // the DB ptr remains the responsibility of the calling code 73 // the DB ptrs remain the responsibility of the calling code 74 // but as the db_ptr is deleted by this source object, the oaidb_ptr will be deleted by this object too 72 75 void set_db_ptr (dbclass *db_ptr_arg) { db_ptr = db_ptr_arg; } 76 void set_oaidb_ptr (dbclass *oaidb_ptr_arg) { oaidb_ptr = oaidb_ptr_arg; } 73 77 74 78 // the textsearchptr remains the responsibility of the calling code … … 86 90 comerror_t &err, ostream &logout); 87 91 88 // get_metadata fills out the metadata if possible , if it is not responsable89 // for the given OID then it will return false.92 // get_metadata fills out the metadata if possible. 93 // If it is not responsible for the given OID then it will return false. 90 94 virtual bool get_metadata (const text_t &requestParams, const text_t &refParams, 91 95 bool getParents, const text_tset &fields, 92 96 const text_t &OID, MetadataInfo_tmap &metadata, 93 comerror_t &err, ostream &logout); 97 comerror_t &err, ostream &logout, bool append); 98 99 // get_oai_metadata fills out the metadata from the oai_db if possible 100 // if it is not responsible for the given OID then it will return false. 101 virtual bool get_oai_metadata (const text_t &requestParams, const text_t &refParams, 102 bool getParents, const text_tset &fields, 103 const text_t &OID, text_t &deleted_status, 104 MetadataInfo_tmap &metadata, comerror_t &err, ostream &logout); 94 105 95 106 virtual bool get_document (const text_t &OID, text_t &doc, … … 101 112 text_t resolve_db_filename(const text_t& idx, 102 113 const text_t& file_ext); 114 text_t resolve_oaidb_filename(const text_t& file_ext); 115 text_t getcollectionpath(); 103 116 104 117 }; -
main/trunk/greenstone2/runtime-src/src/oaiservr/abstractlistaction.cpp
r27534 r31387 170 170 text_tset metadata; // Must be empty for efficiency 171 171 FilterResponse_t identifiers_response; 172 get_children(gsdl_classifier_OID, collection_name, "", metadata, false, protocol, identifiers_response, *this->logout );172 get_children(gsdl_classifier_OID, collection_name, "", metadata, false, protocol, identifiers_response, *this->logout, FROAI); 173 173 174 174 // Find the starting position, if necessary … … 251 251 metadata.insert("gs.OAIDateStamp"); 252 252 FilterResponse_t response; 253 if (!get_ info(document_OID, collection, "", metadata, false, protocol, response, *this->logout))253 if (!get_oai_info(document_OID, collection, "", metadata, false, protocol, response, *this->logout)) 254 254 { 255 255 return false; -
main/trunk/greenstone2/runtime-src/src/oaiservr/identifyaction.cpp
r24412 r31387 117 117 118 118 output << utf8convert << " <earliestDatestamp>"<< this->mEarliestDatestamp <<"</earliestDatestamp>\n"; 119 output << utf8convert << " <deletedRecord> no</deletedRecord>\n";119 output << utf8convert << " <deletedRecord>persistent</deletedRecord>\n"; 120 120 output << utf8convert << " <granularity>YYYY-MM-DD</granularity>\n"; 121 121 } -
main/trunk/greenstone2/runtime-src/src/oaiservr/listidsaction.cpp
r27534 r31387 237 237 text_tset metadata; 238 238 ofstream logout("oai.log", ios::app); 239 text_t lastModified; 239 text_t lastModified = ""; 240 text_t deleted_status = ""; 240 241 int oaiVersion = this->configuration->getOAIVersion(); 241 242 text_t repos_id = this->configuration->getRepositoryId(); 242 get_ info(OID, collection, "", metadata, false, protocol, response, logout);243 get_oai_info(OID, collection, "", metadata, false, protocol, response, logout); 243 244 doc_info = response.docInfo[0]; 244 245 this->getLastModifiedDate(doc_info, lastModified); 246 this->getMeta(doc_info, "oaiinf.status", deleted_status); 245 247 246 248 // output the record for this document … … 251 253 output << " <identifier>" << oaiLabel << "</identifier>\n"; 252 254 else 253 this->output_record_header(output, oaiLabel, lastModified, 255 this->output_record_header(output, oaiLabel, lastModified, deleted_status, 254 256 doc_info.metadata["memberof"].values, oaiVersion); 255 257 -
main/trunk/greenstone2/runtime-src/src/oaiservr/metaformatsaction.cpp
r24108 r31387 97 97 text_tset metadata; 98 98 99 if (!get_ info(identifier, collection, "", metadata, false, protocol, this->gsdlResponse, *logout))99 if (!get_oai_info(identifier, collection, "", metadata, false, protocol, this->gsdlResponse, *logout)) 100 100 { 101 101 this->errorType = "idDoesNotExist"; -
main/trunk/greenstone2/runtime-src/src/oaiservr/oaiaction.cpp
r27534 r31387 403 403 404 404 void oaiaction::output_record_header(ostream &output, const text_t &oaiLabel, const text_t &lastModified, 405 const text_tarray &memberOf, int oaiVersion) 406 { 405 const text_t &deleted_status, const text_tarray &memberOf, int oaiVersion) 406 { 407 if(deleted_status == "D") { // record marked as deleted 408 output << " <header status=\"deleted\">" << endl; 409 } else { // deleted_status is "" or E for exists 407 410 output << " <header>" << endl; 411 } 408 412 output << " <identifier>" << oaiLabel << "</identifier>" << endl; 409 413 output << " <datestamp>" << lastModified << "</datestamp>" << endl; … … 443 447 } 444 448 449 // Method that looks for the requested metaname in the doc_info, and if found, sets the value 450 // in the argument 'metavalue'. 451 void oaiaction::getMeta(ResultDocInfo_t &doc_info, const text_t &metaname, text_t &metavalue) 452 { 453 text_t current_metaname; 454 455 //ofstream logout("oai.log", ios::app); 456 457 MetadataInfo_tmap::iterator current = doc_info.metadata.begin(); 458 MetadataInfo_tmap::iterator end = doc_info.metadata.end(); 459 460 while(current != end){ 461 current_metaname = current->first; 462 lc(current_metaname); // lowercased for string comparison below 463 464 if (current_metaname == metaname && current->second.values.size() >= 1) { // found match with a value 465 metavalue = current->second.values[0]; 466 467 //logout << "Looking for metaname = " << current_metaname << endl; 468 //logout << "\t\t\t Found value = " << metavalue << endl; 469 return; // done 470 } 471 472 ++current; 473 } 474 475 //logout.close(); 476 } 477 445 478 void oaiaction::getLastModifiedDate(ResultDocInfo_t &doc_info, text_t &lastModified) 446 479 { … … 460 493 } 461 494 else{ 462 if (temp == "oailastmodified" && lastModified == "" && current->second.values.size() >= 1) { 463 lastModified = current->second.values[0]; 464 time_t raw_time = (time_t)lastModified.getint(); 465 lastModified = this->parseDatestamp(raw_time); 495 if(lastModified == "" && current->second.values.size() >= 1) { 496 497 if (temp == "oaiinf.timestamp") { // new way is to store oai timestamp in oai db and get it from there 498 // check if there was a timestamp for the doc in the etc/oai-inf database 499 lastModified = current->second.values[0]; 500 501 } else if (temp == "oailastmodified") { // old way, being phased out 502 // check if there was an oailastmodified timestamp for the doc in the collection index db 503 lastModified = current->second.values[0]; 504 } 505 506 if(lastModified != "") { // if we've now set the lastModified value, convert it for display and return 507 time_t raw_time = (time_t)lastModified.getint(); 508 lastModified = this->parseDatestamp(raw_time); 509 510 return; 511 } 466 512 } 467 } 513 } // else keep looking for oai timestamp 468 514 ++current; 469 515 } 516 470 517 } 471 518 … … 475 522 FilterResponse_t response; 476 523 text_tset metadata; 477 bool status_ok = get_info(OID, collection, "", metadata, false, protocol, response, logout); 524 bool status_ok = get_oai_info(OID, collection, "", metadata, false, protocol, response, logout); 525 // get timestamp from etc/oai-inf.<db> now, no longer from index.db 478 526 bool not_too_early = false, not_too_recent = false; 479 527 -
main/trunk/greenstone2/runtime-src/src/oaiservr/oaiaction.h
r24412 r31387 59 59 void output_action_tag(ostream &output, bool openTag); 60 60 void output_record_header(ostream &output, const text_t &oaiLabel, const text_t &lastModified, 61 const text_t array &memberOf, int oaiVersion);61 const text_t &deleted_status, const text_tarray &memberOf, int oaiVersion); 62 62 void output_error(ostream &output, text_t &errorType); // Output any error conditions 63 63 bool formatNotSupported(text_t &metaFormat); // Return true if the supplied metadataPrefix … … 66 66 text_t getErrorType(){return this->errorType;}; 67 67 void getLastModifiedDate(ResultDocInfo_t &doc_info, text_t &lastModified); 68 void getMeta(ResultDocInfo_t &doc_info, const text_t &metaname, text_t &metavalue); 68 69 bool inDateRange(const text_t &from, const text_t &until, const text_t &collection, 69 70 const text_t &OID, recptproto *protocol, ostream &logout); -
main/trunk/greenstone2/runtime-src/src/oaiservr/oaitools.cpp
r24096 r31387 52 52 53 53 bool status_ok = get_children(oai_id, collection, "", metadata, false, protocol, response, logout); 54 // OLD: gets the ID in the 'contains' field of the index_db for OID key of type [oai.x] where x is numeric 55 // Now we check the etc/oai-inf.<db> instead. 54 56 text_t gsdl_id = ""; 55 57 if (status_ok) { -
main/trunk/greenstone2/runtime-src/src/oaiservr/recordaction.cpp
r24286 r31387 148 148 // Check a document with the specified identifier exists 149 149 text_tset metadata; 150 if (!get_ info(identifier, collection, "", metadata, false, protocol, this->gsdlResponse, *logout))150 if (!get_oai_info(identifier, collection, "", metadata, false, protocol, this->gsdlResponse, *logout)) 151 151 { 152 152 this->errorType = "idDoesNotExist"; … … 200 200 201 201 // get the document information 202 if (!get_ info(OID, collection, "", metadata, false, protocol, this->gsdlResponse, logout)) {202 if (!get_oai_info(OID, collection, "", metadata, false, protocol, this->gsdlResponse, logout)) { 203 203 204 204 this->errorType = "idDoesNotExist"; … … 208 208 return false; 209 209 } 210 } 211 else { 212 this->errorType = ""; 210 213 } 211 214 … … 232 235 ResultDocInfo_t doc_info = this->gsdlResponse.docInfo[0]; 233 236 text_t lastModified = ""; 237 text_t deleted_status = ""; 234 238 235 239 // Fills lastModified with the date from the document in doc_info, in the format YYYY-MM-DD 236 240 this->getLastModifiedDate(doc_info, lastModified); 241 this->getMeta(doc_info, "oaiinf.status", deleted_status); 237 242 238 243 // If the ID exists, output record for oai response (OAI v1.1) … … 246 251 247 252 // output header part of oai response 248 this->output_record_header(output, oaiLabel, lastModified, 253 this->output_record_header(output, oaiLabel, lastModified, deleted_status, 249 254 doc_info.metadata["memberof"].values, oaiVersion); 250 255 251 if (this->errorType != "cannotDisseminateFormat"){ 256 // only output <metadata /> section if record is not marked as deleted 257 if (this->errorType != "cannotDisseminateFormat" && deleted_status != "D") { 252 258 if (this->formatMap[metadataPrefix].get_class()->output_metadata(output, collection, doc_info)) { 253 259 // output 'about' part of oai response - we probably won't ever use this -
main/trunk/greenstone2/runtime-src/src/protocol/recptprototools.cpp
r22142 r31387 32 32 // metadata fields are to be requested. 33 33 34 // THIS FILE IS A CANDIDATE FOR REFACTORING: merge get_info methods 35 34 36 bool get_info (const text_t &OID, const text_t &collection, const text_t &lang, 35 37 const text_tset &metadata, bool getParents, 36 38 recptproto *collectproto, FilterResponse_t &response, 37 ostream &logout )39 ostream &logout, int filterResultOptions) 38 40 { 39 41 response.clear(); … … 45 47 request.filterName = "NullFilter"; 46 48 request.filterLang = lang; 47 request.filterResultOptions = FRmetadata;49 request.filterResultOptions = filterResultOptions | FRmetadata; 48 50 request.getParents = getParents; 49 51 request.fields = metadata; … … 65 67 } 66 68 69 bool get_oai_info (const text_t &OID, const text_t &collection, const text_t &lang, 70 const text_tset &metadata, bool getParents, 71 recptproto *collectproto, FilterResponse_t &response, 72 ostream &logout) 73 { 74 // set filteroption to FROAI 75 return get_info(OID, collection, lang, metadata, getParents, collectproto, response, logout, FROAI); 76 } 67 77 68 78 // overloaded, to allow "custom" filter options. … … 162 172 const text_tset &metadata, bool getParents, 163 173 recptproto *collectproto, FilterResponse_t &response, 164 ostream &logout )174 ostream &logout, int filterResultOptions) 165 175 { 166 176 response.clear(); … … 175 185 request.filterName = "BrowseFilter"; 176 186 request.filterLang = lang; 177 request.filterResultOptions = FROID;187 request.filterResultOptions = filterResultOptions | FROID; 178 188 179 189 // Efficiency improvement: only get the filter to retrieve metadata if some has been requested -
main/trunk/greenstone2/runtime-src/src/protocol/recptprototools.h
r16180 r31387 38 38 const text_tset &metadata, bool getParents, 39 39 recptproto *collectproto, FilterResponse_t &response, 40 ostream &logout, int filterResultOptions=0); 41 bool get_oai_info (const text_t &OID, const text_t &collection, const text_t &lang, 42 const text_tset &metadata, bool getParents, 43 recptproto *collectproto, FilterResponse_t &response, 40 44 ostream &logout); 41 45 bool get_info (const text_t &OID, const text_t &collection, const text_t &lang, … … 59 63 const text_tset &metadata, bool getParents, 60 64 recptproto *collectproto, FilterResponse_t &response, 61 ostream &logout );65 ostream &logout, int filterResultOptions=0); 62 66 63 67 // get_contents returns OIDs and metadata of all contents
Note:
See TracChangeset
for help on using the changeset viewer.