[8182] | 1 | #include "recordaction.h"
|
---|
[15428] | 2 | #include "recptprototools.h"
|
---|
[8182] | 3 | #include "dublincore.h"
|
---|
[18861] | 4 | #include "qualified_dublincore.h"
|
---|
[8182] | 5 | #include "rfc1807.h"
|
---|
| 6 | #include "oaitools.h"
|
---|
| 7 |
|
---|
| 8 |
|
---|
[18889] | 9 | recordaction::recordaction(text_tset &metadataset) : oaiaction("GetRecord") {
|
---|
[8182] | 10 | metaformatptr fptr;
|
---|
| 11 |
|
---|
[18889] | 12 | if (metadataset.count("oai_dc") > 0) {
|
---|
| 13 | fptr.set_class(new dublin_core());
|
---|
| 14 | this->formatMap[fptr.get_class()->formatName()] = fptr;
|
---|
| 15 | }
|
---|
[8182] | 16 |
|
---|
[18889] | 17 | if (metadataset.count("gsdl_qdc") > 0) {
|
---|
| 18 | fptr.set_class(new qualified_dublin_core());
|
---|
| 19 | this->formatMap[fptr.get_class()->formatName()] = fptr;
|
---|
| 20 | }
|
---|
| 21 |
|
---|
| 22 | if (metadataset.count("rfc1807") > 0) {
|
---|
[18861] | 23 |
|
---|
[18889] | 24 | fptr.set_class(new rfc1807());
|
---|
| 25 | this->formatMap[fptr.get_class()->formatName()] = fptr;
|
---|
| 26 | }
|
---|
[8182] | 27 | }
|
---|
| 28 |
|
---|
| 29 | recordaction::~recordaction() {
|
---|
| 30 | metaformat_map::iterator here = this->formatMap.begin();
|
---|
| 31 | metaformat_map::iterator end = this->formatMap.end();
|
---|
| 32 |
|
---|
| 33 | while (here != end) {
|
---|
| 34 | here->second.clear();
|
---|
[9608] | 35 | ++here;
|
---|
[8182] | 36 | }
|
---|
| 37 | }
|
---|
| 38 |
|
---|
| 39 |
|
---|
| 40 | bool recordaction::validateAction(recptproto *protocol, oaiargs ¶ms)
|
---|
[15198] | 41 | {
|
---|
[16715] | 42 | // ----------------------------------------------------------------------------
|
---|
| 43 | // 1. Check for invalid arguments
|
---|
| 44 | // ----------------------------------------------------------------------------
|
---|
| 45 | bool invalid_argument_supplied = false;
|
---|
[15198] | 46 | text_tmap::const_iterator param_iterator = params.begin();
|
---|
| 47 | while (param_iterator != params.end())
|
---|
| 48 | {
|
---|
[16715] | 49 | // Check for arguments that aren't valid for this action
|
---|
[15198] | 50 | if (param_iterator->first != "verb" &&
|
---|
| 51 | param_iterator->first != "identifier" &&
|
---|
| 52 | param_iterator->first != "metadataPrefix")
|
---|
| 53 | {
|
---|
[16715] | 54 | // We've found an invalid argument
|
---|
| 55 | invalid_argument_supplied = true;
|
---|
| 56 |
|
---|
| 57 | // Delete the invalid argument from the list so it doesn't end up in the <request> tag that is returned
|
---|
[15198] | 58 | params.erase(param_iterator->first);
|
---|
| 59 | }
|
---|
| 60 |
|
---|
| 61 | param_iterator++;
|
---|
| 62 | }
|
---|
| 63 |
|
---|
[16715] | 64 | // If we found an invalid argument it's an error, so don't go any further
|
---|
| 65 | if (invalid_argument_supplied)
|
---|
| 66 | {
|
---|
| 67 | this->errorType = "badArgument";
|
---|
| 68 | return false;
|
---|
| 69 | }
|
---|
[8182] | 70 |
|
---|
[16715] | 71 | // ----------------------------------------------------------------------------
|
---|
| 72 | // 2. Handle any exclusive arguments
|
---|
| 73 | // ----------------------------------------------------------------------------
|
---|
| 74 |
|
---|
| 75 | // None!
|
---|
| 76 |
|
---|
| 77 | // ----------------------------------------------------------------------------
|
---|
| 78 | // 3. Handle any required arguments
|
---|
| 79 | // ----------------------------------------------------------------------------
|
---|
| 80 |
|
---|
| 81 | // The "metadataPrefix" argument is required
|
---|
| 82 | text_t metadataPrefix = params["metadataPrefix"];
|
---|
| 83 |
|
---|
| 84 | // Check that the metadataPrefix argument exists
|
---|
| 85 | if (metadataPrefix == "")
|
---|
| 86 | {
|
---|
[8182] | 87 | this->errorType = "badArgument";
|
---|
| 88 | return false;
|
---|
| 89 | }
|
---|
[16718] | 90 |
|
---|
[16715] | 91 | // Check that the metadataPrefix is a format we support
|
---|
| 92 | if (this->formatNotSupported(metadataPrefix))
|
---|
| 93 | {
|
---|
[8182] | 94 | this->errorType = "cannotDisseminateFormat";
|
---|
[16715] | 95 | return false;
|
---|
[8182] | 96 | }
|
---|
| 97 |
|
---|
[16715] | 98 | // The "identifier" argument is required
|
---|
| 99 | text_t identifier = params["identifier"];
|
---|
| 100 |
|
---|
[16718] | 101 | // Check that the identifier argument exists
|
---|
| 102 | if (identifier == "")
|
---|
| 103 | {
|
---|
| 104 | this->errorType = "badArgument";
|
---|
| 105 | return false;
|
---|
| 106 | }
|
---|
| 107 |
|
---|
[16715] | 108 | // Extract the collection name from the identifier specification
|
---|
| 109 | text_t collection = "";
|
---|
| 110 | oaiclassifier::toGSDL(collection, identifier);
|
---|
[8182] | 111 |
|
---|
[16715] | 112 | // Check a document with the specified identifier exists
|
---|
| 113 | text_tset metadata;
|
---|
| 114 | if (!get_info(identifier, collection, "", metadata, false, protocol, this->gsdlResponse, *logout))
|
---|
| 115 | {
|
---|
[8182] | 116 | this->errorType = "idDoesNotExist";
|
---|
[16715] | 117 | return false;
|
---|
[8182] | 118 | }
|
---|
| 119 |
|
---|
[16715] | 120 | // ----------------------------------------------------------------------------
|
---|
| 121 | // 4. Check any remaining arguments
|
---|
| 122 | // ----------------------------------------------------------------------------
|
---|
| 123 |
|
---|
| 124 | // None!
|
---|
| 125 |
|
---|
| 126 | // If we've reached here everything must be fine
|
---|
| 127 | this->errorType = "";
|
---|
[8182] | 128 | return true;
|
---|
| 129 | }
|
---|
| 130 |
|
---|
| 131 | //
|
---|
| 132 | // Output the content of a GetRecord request; in this case, the static member
|
---|
| 133 | // output_record below is used to fulfill most of the request
|
---|
| 134 | //
|
---|
| 135 | bool recordaction::output_content(ostream &output, recptproto *protocol, oaiargs ¶ms)
|
---|
| 136 | {
|
---|
| 137 | // validateAction will already have set up the correct response content
|
---|
| 138 | text_t gsdlId = params["identifier"];
|
---|
| 139 | text_t gsdlCollect;
|
---|
| 140 |
|
---|
| 141 | // convert record identifier into GSDL format from OAI
|
---|
| 142 | oaiclassifier::toGSDL(gsdlCollect, gsdlId);
|
---|
| 143 |
|
---|
| 144 | // go direct to output_record
|
---|
| 145 | return output_record(output, gsdlCollect, gsdlId, params["metadataPrefix"]);
|
---|
| 146 | }
|
---|
| 147 |
|
---|
| 148 | //
|
---|
| 149 | // A static member that does everything the output_content method above needs,
|
---|
| 150 | // but can be called when individual records are being output for another
|
---|
| 151 | // action.
|
---|
| 152 | //
|
---|
| 153 | bool recordaction::output_record(ostream &output, recptproto *protocol, const text_t &collection, const text_t &OID, const text_t &metadataPrefix)
|
---|
| 154 | {
|
---|
| 155 | text_tset metadata;
|
---|
[8303] | 156 | ofstream logout("oai.log", ios::app);
|
---|
[8182] | 157 |
|
---|
| 158 | // get the document information
|
---|
| 159 | if (!get_info(OID, collection, "", metadata, false, protocol, this->gsdlResponse, logout)) {
|
---|
[11311] | 160 |
|
---|
[8182] | 161 | this->errorType = "idDoesNotExist";
|
---|
| 162 |
|
---|
| 163 | if(this->configuration->getOAIVersion() >= 200) {
|
---|
| 164 | this->output_error(output, errorType);
|
---|
| 165 | return false;
|
---|
| 166 | }
|
---|
| 167 | }
|
---|
| 168 |
|
---|
[8306] | 169 | return this->output_record(output, collection, OID, metadataPrefix);
|
---|
[8182] | 170 | }
|
---|
| 171 |
|
---|
| 172 | bool recordaction::output_record(ostream &output, const text_t &collection, const text_t &OID,
|
---|
| 173 | const text_t &metadataPrefix)
|
---|
| 174 | { int oaiVersion = this->configuration->getOAIVersion();
|
---|
| 175 |
|
---|
| 176 | // check to see if it's a classifier
|
---|
| 177 | text_t childHead;
|
---|
| 178 | text_t::const_iterator start = OID.begin();
|
---|
| 179 | text_t::const_iterator here = OID.begin();
|
---|
[11311] | 180 | here += 2;
|
---|
[8182] | 181 | childHead = substr(start, here);
|
---|
| 182 |
|
---|
| 183 | // if it isn't a document, kill it now
|
---|
[11311] | 184 | if (childHead == "CL") {
|
---|
[8182] | 185 | cerr << "Not a document" << endl;
|
---|
| 186 | return false;
|
---|
| 187 | }
|
---|
| 188 |
|
---|
| 189 | ResultDocInfo_t doc_info = this->gsdlResponse.docInfo[0];
|
---|
| 190 | text_t lastModified = "";
|
---|
| 191 |
|
---|
| 192 | // Fills lastModified with the date from the document in doc_info, in the format YYYY-MM-DD
|
---|
| 193 | this->getLastModifiedDate(doc_info, lastModified);
|
---|
| 194 |
|
---|
| 195 | // If the ID exists, output record for oai response (OAI v1.1)
|
---|
| 196 | // OAI v2.0 will already have bailed if ID doesn't exist (yes?)
|
---|
| 197 | if (this->errorType != "idDoesNotExist") {
|
---|
| 198 | text_t oaiLabel = OID;
|
---|
| 199 | oaiclassifier::toOAI(collection, oaiLabel); // Concatenates HASH id to collection, which OAI needs
|
---|
| 200 |
|
---|
| 201 | // output a record
|
---|
| 202 | output << " <record>\n";
|
---|
| 203 |
|
---|
| 204 | // output header part of oai response
|
---|
| 205 | this->output_record_header(output, oaiLabel, lastModified,
|
---|
| 206 | doc_info.metadata["memberof"].values, oaiVersion);
|
---|
| 207 |
|
---|
| 208 | if (this->errorType != "cannotDisseminateFormat"){
|
---|
| 209 | if (this->formatMap[metadataPrefix].get_class()->output_metadata(output, collection, doc_info)) {
|
---|
| 210 | // output 'about' part of oai response - we probably won't ever use this
|
---|
| 211 | //output << " <about>\n";
|
---|
| 212 | //output << " </about>\n";
|
---|
| 213 | }
|
---|
| 214 | }
|
---|
| 215 | // close record
|
---|
| 216 | output << " </record>\n\n";
|
---|
| 217 | }
|
---|
| 218 | return true;
|
---|
| 219 | }
|
---|