source: trunk/gsdl/src/oaiservr/recordaction.cpp@ 11311

Last change on this file since 11311 was 11311, checked in by kjdon, 18 years ago

anywhere where we determine document/classifier by checking for starting with HASH, I changed to check if starts with CL

  • Property svn:keywords set to Author Date Id Revision
File size: 4.7 KB
Line 
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
9recordaction::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
19recordaction::~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();
25 ++here;
26 }
27}
28
29
30bool recordaction::validateAction(recptproto *protocol, oaiargs &params)
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//
69bool recordaction::output_content(ostream &output, recptproto *protocol, oaiargs &params)
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//
87bool recordaction::output_record(ostream &output, recptproto *protocol, const text_t &collection, const text_t &OID, const text_t &metadataPrefix)
88{
89 text_tset metadata;
90 ofstream logout("oai.log", ios::app);
91
92 // get the document information
93 if (!get_info(OID, collection, "", metadata, false, protocol, this->gsdlResponse, logout)) {
94
95 this->errorType = "idDoesNotExist";
96
97 if(this->configuration->getOAIVersion() >= 200) {
98 this->output_error(output, errorType);
99 return false;
100 }
101 }
102
103 return this->output_record(output, collection, OID, metadataPrefix);
104}
105
106bool 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();
114 here += 2;
115 childHead = substr(start, here);
116
117 // if it isn't a document, kill it now
118 if (childHead == "CL") {
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}
Note: See TracBrowser for help on using the repository browser.