Ignore:
Timestamp:
2017-02-08T18:31:18+13:00 (7 years ago)
Author:
ak19
Message:

Round 1 of commits for getting OAI deletion policy to work with GS2 (server end). The perl code writing out the OAI db and the GS3 server code implementing the deletion policy had already been completed earlier (end 2016).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone2/runtime-src/src/colservr/source.cpp

    r21772 r31387  
    3333{
    3434  db_ptr = NULL;
     35  oaidb_ptr = NULL;
    3536  textsearchptr = NULL;
    3637  classname = "source";
     
    4142  if (db_ptr != NULL) delete db_ptr;
    4243  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;
    4353}
    4454
     
    7888}
    7989
     90text_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
    80109text_t sourceclass::resolve_db_filename(const text_t& idx,
    81110                    const text_t& file_ext)
     
    91120  // are also drawn from one object
    92121
     122  /*
    93123  text_t resolved_filename;
    94124
     
    105135    resolved_filename = filename_cat(dbhome, "collect", collection, "index", "text", idx);
    106136  }
    107 
     137  */
     138
     139  text_t resolved_filename = filename_cat(getcollectionpath(), "index", "text", idx);
    108140  resolved_filename += file_ext;
    109141
     
    111143}
    112144
    113 
     145text_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}
    114153
    115154// init should be called after all the configuration is done but
     
    172211  }
    173212 
     213  oaidb_filename = resolve_oaidb_filename(oaidb_ptr->getfileextension());
     214
    174215  return true;
    175216}
     
    207248}
    208249
     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.
     252bool 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
    209310
    210311// get_metadata fills out the metadata if possible, if it is not responsible
     
    213314                bool getParents, const text_tset &fields,
    214315                const text_t &OID, MetadataInfo_tmap &metadata,
    215                 comerror_t &err, ostream &logout)
     316                comerror_t &err, ostream &logout, bool append)
    216317{
    217318  outconvertclass text_t2ascii;
    218319
    219   metadata.erase(metadata.begin(), metadata.end());
     320  if(!append) {
     321    metadata.erase(metadata.begin(), metadata.end());
     322  }
    220323
    221324  err = noError;
Note: See TracChangeset for help on using the changeset viewer.