[8182] | 1 | #include "recordaction.h"
|
---|
| 2 | #include "OIDtools.h"
|
---|
| 3 | #include "dublincore.h"
|
---|
| 4 | #include "rfc1807.h"
|
---|
| 5 | #include "oaitools.h"
|
---|
| 6 | #include <time.h>
|
---|
| 7 |
|
---|
| 8 |
|
---|
| 9 | recordaction::recordaction() : oaiaction("GetRecord") {
|
---|
| 10 | metaformatptr fptr;
|
---|
| 11 |
|
---|
| 12 | fptr.set_class(new dublin_core());
|
---|
| 13 | this->formatMap[fptr.get_class()->formatName()] = fptr;
|
---|
| 14 |
|
---|
| 15 | fptr.set_class(new rfc1807());
|
---|
| 16 | this->formatMap[fptr.get_class()->formatName()] = fptr;
|
---|
| 17 | }
|
---|
| 18 |
|
---|
| 19 | recordaction::~recordaction() {
|
---|
| 20 | metaformat_map::iterator here = this->formatMap.begin();
|
---|
| 21 | metaformat_map::iterator end = this->formatMap.end();
|
---|
| 22 |
|
---|
| 23 | while (here != end) {
|
---|
| 24 | here->second.clear();
|
---|
[9608] | 25 | ++here;
|
---|
[8182] | 26 | }
|
---|
| 27 | }
|
---|
| 28 |
|
---|
| 29 |
|
---|
| 30 | bool recordaction::validateAction(recptproto *protocol, oaiargs ¶ms)
|
---|
| 31 | { text_t meta = params["metadataPrefix"];
|
---|
| 32 | text_t gsdlId = params["identifier"];
|
---|
| 33 | text_t gsdlCollect;
|
---|
| 34 | text_t language = "";
|
---|
| 35 | int oaiVersion = this->configuration->getOAIVersion();
|
---|
| 36 |
|
---|
| 37 | // The identifier and metadataPrefix args MUST be supplied, and are the only
|
---|
| 38 | // args allowed (excluding verb arg). If we don't have them, throw an error.
|
---|
| 39 | if(gsdlId == "" || meta == "" || params.getSize() != 3){
|
---|
| 40 | this->errorType = "badArgument";
|
---|
| 41 | return false;
|
---|
| 42 | }
|
---|
| 43 |
|
---|
| 44 | // Check to see if the metadataPrefix supplied is supported
|
---|
| 45 | if(this->formatNotSupported(meta)) {
|
---|
| 46 | this->errorType = "cannotDisseminateFormat";
|
---|
| 47 | if(oaiVersion == 200)
|
---|
| 48 | return false;
|
---|
| 49 | }
|
---|
| 50 |
|
---|
| 51 | // convert record identifier into GSDL format from OAI
|
---|
| 52 | oaiclassifier::toGSDL(gsdlCollect, gsdlId);
|
---|
| 53 |
|
---|
| 54 | // get the document information
|
---|
| 55 | text_tset metadata;
|
---|
| 56 | if (!get_info(gsdlId, gsdlCollect, language, metadata, false, protocol, this->gsdlResponse, *logout)) {
|
---|
| 57 | this->errorType = "idDoesNotExist";
|
---|
| 58 | if(oaiVersion == 200)
|
---|
| 59 | return false;
|
---|
| 60 | }
|
---|
| 61 |
|
---|
| 62 | return true;
|
---|
| 63 | }
|
---|
| 64 |
|
---|
| 65 | //
|
---|
| 66 | // Output the content of a GetRecord request; in this case, the static member
|
---|
| 67 | // output_record below is used to fulfill most of the request
|
---|
| 68 | //
|
---|
| 69 | bool recordaction::output_content(ostream &output, recptproto *protocol, oaiargs ¶ms)
|
---|
| 70 | {
|
---|
| 71 | // validateAction will already have set up the correct response content
|
---|
| 72 | text_t gsdlId = params["identifier"];
|
---|
| 73 | text_t gsdlCollect;
|
---|
| 74 |
|
---|
| 75 | // convert record identifier into GSDL format from OAI
|
---|
| 76 | oaiclassifier::toGSDL(gsdlCollect, gsdlId);
|
---|
| 77 |
|
---|
| 78 | // go direct to output_record
|
---|
| 79 | return output_record(output, gsdlCollect, gsdlId, params["metadataPrefix"]);
|
---|
| 80 | }
|
---|
| 81 |
|
---|
| 82 | //
|
---|
| 83 | // A static member that does everything the output_content method above needs,
|
---|
| 84 | // but can be called when individual records are being output for another
|
---|
| 85 | // action.
|
---|
| 86 | //
|
---|
| 87 | bool recordaction::output_record(ostream &output, recptproto *protocol, const text_t &collection, const text_t &OID, const text_t &metadataPrefix)
|
---|
| 88 | {
|
---|
| 89 | text_tset metadata;
|
---|
[8303] | 90 | ofstream logout("oai.log", ios::app);
|
---|
[8182] | 91 |
|
---|
| 92 | // get the document information
|
---|
| 93 | if (!get_info(OID, collection, "", metadata, false, protocol, this->gsdlResponse, logout)) {
|
---|
[11311] | 94 |
|
---|
[8182] | 95 | this->errorType = "idDoesNotExist";
|
---|
| 96 |
|
---|
| 97 | if(this->configuration->getOAIVersion() >= 200) {
|
---|
| 98 | this->output_error(output, errorType);
|
---|
| 99 | return false;
|
---|
| 100 | }
|
---|
| 101 | }
|
---|
| 102 |
|
---|
[8306] | 103 | return this->output_record(output, collection, OID, metadataPrefix);
|
---|
[8182] | 104 | }
|
---|
| 105 |
|
---|
| 106 | bool recordaction::output_record(ostream &output, const text_t &collection, const text_t &OID,
|
---|
| 107 | const text_t &metadataPrefix)
|
---|
| 108 | { int oaiVersion = this->configuration->getOAIVersion();
|
---|
| 109 |
|
---|
| 110 | // check to see if it's a classifier
|
---|
| 111 | text_t childHead;
|
---|
| 112 | text_t::const_iterator start = OID.begin();
|
---|
| 113 | text_t::const_iterator here = OID.begin();
|
---|
[11311] | 114 | here += 2;
|
---|
[8182] | 115 | childHead = substr(start, here);
|
---|
| 116 |
|
---|
| 117 | // if it isn't a document, kill it now
|
---|
[11311] | 118 | if (childHead == "CL") {
|
---|
[8182] | 119 | cerr << "Not a document" << endl;
|
---|
| 120 | return false;
|
---|
| 121 | }
|
---|
| 122 |
|
---|
| 123 | ResultDocInfo_t doc_info = this->gsdlResponse.docInfo[0];
|
---|
| 124 | text_t lastModified = "";
|
---|
| 125 |
|
---|
| 126 | // Fills lastModified with the date from the document in doc_info, in the format YYYY-MM-DD
|
---|
| 127 | this->getLastModifiedDate(doc_info, lastModified);
|
---|
| 128 |
|
---|
| 129 | // If the ID exists, output record for oai response (OAI v1.1)
|
---|
| 130 | // OAI v2.0 will already have bailed if ID doesn't exist (yes?)
|
---|
| 131 | if (this->errorType != "idDoesNotExist") {
|
---|
| 132 | text_t oaiLabel = OID;
|
---|
| 133 | oaiclassifier::toOAI(collection, oaiLabel); // Concatenates HASH id to collection, which OAI needs
|
---|
| 134 |
|
---|
| 135 | // output a record
|
---|
| 136 | output << " <record>\n";
|
---|
| 137 |
|
---|
| 138 | // output header part of oai response
|
---|
| 139 | this->output_record_header(output, oaiLabel, lastModified,
|
---|
| 140 | doc_info.metadata["memberof"].values, oaiVersion);
|
---|
| 141 |
|
---|
| 142 | if (this->errorType != "cannotDisseminateFormat"){
|
---|
| 143 | if (this->formatMap[metadataPrefix].get_class()->output_metadata(output, collection, doc_info)) {
|
---|
| 144 | // output 'about' part of oai response - we probably won't ever use this
|
---|
| 145 | //output << " <about>\n";
|
---|
| 146 | //output << " </about>\n";
|
---|
| 147 | }
|
---|
| 148 | }
|
---|
| 149 | // close record
|
---|
| 150 | output << " </record>\n\n";
|
---|
| 151 | }
|
---|
| 152 | return true;
|
---|
| 153 | }
|
---|