#include "listidsaction.h" #include "recptprototools.h" #include "oaitools.h" //-------------------------------------------------------------------------------------------------- bool listidsaction::validateAction(recptproto *protocol, oaiargs ¶ms) { // ---------------------------------------------------------------------------- // 1. Check for invalid arguments // ---------------------------------------------------------------------------- bool invalid_argument_supplied = false; text_tmap::const_iterator param_iterator = params.begin(); while (param_iterator != params.end()) { // Check for arguments that aren't valid for this action if (param_iterator->first != "verb" && param_iterator->first != "from" && param_iterator->first != "until" && param_iterator->first != "set" && param_iterator->first != "resumptionToken" && param_iterator->first != "metadataPrefix") { // We've found an invalid argument invalid_argument_supplied = true; // Delete the invalid argument from the list so it doesn't end up in the tag that is returned params.erase(param_iterator->first); } // The metadataPrefix argument is not allowed in OAI v1.1 else if (param_iterator->first == "metadataPrefix" && this->configuration->getOAIVersion() <= 110) { // We've found an invalid argument invalid_argument_supplied = true; // Delete the invalid argument from the list so it doesn't end up in the tag that is returned params.erase(param_iterator->first); } param_iterator++; } // If we found an invalid argument it's an error, so don't go any further if (invalid_argument_supplied) { this->errorType = "badArgument"; return false; } // ---------------------------------------------------------------------------- // 2. Handle any exclusive arguments // ---------------------------------------------------------------------------- // The resumptionToken argument is exclusive if (params["resumptionToken"] != "") { // This argument is exclusive, so no other arguments are allowed (except "verb" of course) if (params.getSize() != 2) { this->errorType = "badArgument"; return false; } // Check the resumption token is valid ResumptionToken token(params["resumptionToken"]); if (token.isValid()) { // Everything is fine, and we don't continue further because this is an exclusive argument this->errorType = ""; return true; } else { // There was an error with the resumption token this->errorType = "badResumptionToken"; return false; } } // ---------------------------------------------------------------------------- // 3. Handle any required arguments // ---------------------------------------------------------------------------- // OAI v2.0 requires metadataPrefix if (this->configuration->getOAIVersion() > 110) { text_t metadataPrefix = params["metadataPrefix"]; // Check that the metadataPrefix argument exists if (metadataPrefix == "") { this->errorType = "badArgument"; return false; } // Check that the metadataPrefix is a format we support if (this->formatNotSupported(metadataPrefix)) { this->errorType = "cannotDisseminateFormat"; return false; } } // ---------------------------------------------------------------------------- // 4. Check any remaining arguments // ---------------------------------------------------------------------------- // Check "from" and "until" arguments if (params["from"] != "" || params["until"] != "") { text_t from = params["from"]; text_t until = params["until"]; // Check the from date is in the correct format: YYYY-MM-DD if (from != "") { // Must be in the form YYYY-MM-DD if (from.size() != 10 || from[4] != '-' || from[7] != '-') { this->errorType = "badArgument"; params.erase("from"); } } // Check the until date is in the correct format: YYYY-MM-DD if (until != "") { // Must be in the form YYYY-MM-DD if (until.size() != 10 || until[4] != '-' || until[7] != '-') { this->errorType = "badArgument"; params.erase("until"); } } if (this->errorType == "badArgument") { return false; } // If both arguments are supplied the from date must be less than or equal to the until date if (from != "" && until != "" && !(from <= until)) { this->errorType = "badArgument"; return false; } } // Check "set" argument if (params["set"] != "") { // Example set specification: "demo:CL2" text_t set = params["set"]; // Extract the collection name from the set specification text_t collection = ""; oaiclassifier::toGSDL(collection, set); // Check that the collection is accessible ColInfoResponse_t cinfo; comerror_t err; protocol->get_collectinfo(collection, cinfo, err, cerr); if (err != noError) { this->errorType = "badArgument"; return false; } // Check the collection is one that is in the list in the oai.cfg file text_tarray &collections = this->configuration->getCollectionsList(); bool collection_found = false; for (int c = 0; c < collections.size(); c++) { if (collections[c] == collection) { collection_found = true; break; } } // The collection was not found if (!collection_found) { this->errorType = "badArgument"; return false; } // Check the child set if it was given if (set != "" && !this->check_classifier(protocol, collection, set)) { this->errorType = "badArgument"; return false; } } // If we've reached here everything must be fine this->errorType = ""; return true; } //-------------------------------------------------------------------------------------------------- bool listidsaction::output_document(ostream& output, recptproto *protocol, const text_t &collection, const text_t &OID, const text_t &metadataPrefix /* ignored */) { FilterResponse_t response; ResultDocInfo_t doc_info; text_tset metadata; ofstream logout("oai.log", ios::app); text_t lastModified; int oaiVersion = this->configuration->getOAIVersion(); get_info(OID, collection, "", metadata, false, protocol, response, logout); doc_info = response.docInfo[0]; this->getLastModifiedDate(doc_info, lastModified); // output the record for this document text_t oaiLabel = OID; oaiclassifier::toOAI(collection, oaiLabel); if(oaiVersion <= 110) output << " " << oaiLabel << "\n"; else this->output_record_header(output, oaiLabel, lastModified, doc_info.metadata["memberof"].values, oaiVersion); return true; }