#include "recordaction.h" #include "recptprototools.h" #include "dublincore.h" #include "rfc1807.h" #include "oaitools.h" #include recordaction::recordaction() : oaiaction("GetRecord") { metaformatptr fptr; fptr.set_class(new dublin_core()); this->formatMap[fptr.get_class()->formatName()] = fptr; fptr.set_class(new rfc1807()); this->formatMap[fptr.get_class()->formatName()] = fptr; } recordaction::~recordaction() { metaformat_map::iterator here = this->formatMap.begin(); metaformat_map::iterator end = this->formatMap.end(); while (here != end) { here->second.clear(); ++here; } } bool recordaction::validateAction(recptproto *protocol, oaiargs ¶ms) { int params_size = params.getSize(); // Remove any parameters that aren't valid for this action text_tmap::const_iterator param_iterator = params.begin(); while (param_iterator != params.end()) { if (param_iterator->first != "verb" && param_iterator->first != "identifier" && param_iterator->first != "metadataPrefix") { params.erase(param_iterator->first); } param_iterator++; } text_t meta = params["metadataPrefix"]; text_t gsdlId = params["identifier"]; text_t gsdlCollect; text_t language = ""; int oaiVersion = this->configuration->getOAIVersion(); // The identifier and metadataPrefix args MUST be supplied, and are the only // args allowed (excluding verb arg). If we don't have them, throw an error. if(gsdlId == "" || meta == "" || params_size != 3){ this->errorType = "badArgument"; return false; } // Check to see if the metadataPrefix supplied is supported if(this->formatNotSupported(meta)) { this->errorType = "cannotDisseminateFormat"; if(oaiVersion == 200) return false; } // convert record identifier into GSDL format from OAI oaiclassifier::toGSDL(gsdlCollect, gsdlId); // get the document information text_tset metadata; if (!get_info(gsdlId, gsdlCollect, language, metadata, false, protocol, this->gsdlResponse, *logout)) { this->errorType = "idDoesNotExist"; if(oaiVersion == 200) return false; } return true; } // // Output the content of a GetRecord request; in this case, the static member // output_record below is used to fulfill most of the request // bool recordaction::output_content(ostream &output, recptproto *protocol, oaiargs ¶ms) { // validateAction will already have set up the correct response content text_t gsdlId = params["identifier"]; text_t gsdlCollect; // convert record identifier into GSDL format from OAI oaiclassifier::toGSDL(gsdlCollect, gsdlId); // go direct to output_record return output_record(output, gsdlCollect, gsdlId, params["metadataPrefix"]); } // // A static member that does everything the output_content method above needs, // but can be called when individual records are being output for another // action. // bool recordaction::output_record(ostream &output, recptproto *protocol, const text_t &collection, const text_t &OID, const text_t &metadataPrefix) { text_tset metadata; ofstream logout("oai.log", ios::app); // get the document information if (!get_info(OID, collection, "", metadata, false, protocol, this->gsdlResponse, logout)) { this->errorType = "idDoesNotExist"; if(this->configuration->getOAIVersion() >= 200) { this->output_error(output, errorType); return false; } } return this->output_record(output, collection, OID, metadataPrefix); } bool recordaction::output_record(ostream &output, const text_t &collection, const text_t &OID, const text_t &metadataPrefix) { int oaiVersion = this->configuration->getOAIVersion(); // check to see if it's a classifier text_t childHead; text_t::const_iterator start = OID.begin(); text_t::const_iterator here = OID.begin(); here += 2; childHead = substr(start, here); // if it isn't a document, kill it now if (childHead == "CL") { cerr << "Not a document" << endl; return false; } ResultDocInfo_t doc_info = this->gsdlResponse.docInfo[0]; text_t lastModified = ""; // Fills lastModified with the date from the document in doc_info, in the format YYYY-MM-DD this->getLastModifiedDate(doc_info, lastModified); // If the ID exists, output record for oai response (OAI v1.1) // OAI v2.0 will already have bailed if ID doesn't exist (yes?) if (this->errorType != "idDoesNotExist") { text_t oaiLabel = OID; oaiclassifier::toOAI(collection, oaiLabel); // Concatenates HASH id to collection, which OAI needs // output a record output << " \n"; // output header part of oai response this->output_record_header(output, oaiLabel, lastModified, doc_info.metadata["memberof"].values, oaiVersion); if (this->errorType != "cannotDisseminateFormat"){ if (this->formatMap[metadataPrefix].get_class()->output_metadata(output, collection, doc_info)) { // output 'about' part of oai response - we probably won't ever use this //output << " \n"; //output << " \n"; } } // close record output << " \n\n"; } return true; }