source: main/tags/2.53/gsdl/src/oaiservr/recordaction.cpp@ 33212

Last change on this file since 33212 was 8306, checked in by mdewsnip, 20 years ago

A few changes necessary to get the OAI server compiling with Microsoft Visual C++ 4.

  • 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 this->errorType = "idDoesNotExist";
95
96 if(this->configuration->getOAIVersion() >= 200) {
97 this->output_error(output, errorType);
98 return false;
99 }
100 }
101
102 return this->output_record(output, collection, OID, metadataPrefix);
103}
104
105bool recordaction::output_record(ostream &output, const text_t &collection, const text_t &OID,
106 const text_t &metadataPrefix)
107{ int oaiVersion = this->configuration->getOAIVersion();
108
109 // check to see if it's a classifier
110 text_t childHead;
111 text_t::const_iterator start = OID.begin();
112 text_t::const_iterator here = OID.begin();
113 here += 4;
114 childHead = substr(start, here);
115
116 // if it isn't a document, kill it now
117 if (childHead != "HASH") {
118 cerr << "Not a document" << endl;
119 return false;
120 }
121
122 ResultDocInfo_t doc_info = this->gsdlResponse.docInfo[0];
123 text_t lastModified = "";
124
125 // Fills lastModified with the date from the document in doc_info, in the format YYYY-MM-DD
126 this->getLastModifiedDate(doc_info, lastModified);
127
128 // If the ID exists, output record for oai response (OAI v1.1)
129 // OAI v2.0 will already have bailed if ID doesn't exist (yes?)
130 if (this->errorType != "idDoesNotExist") {
131 text_t oaiLabel = OID;
132 oaiclassifier::toOAI(collection, oaiLabel); // Concatenates HASH id to collection, which OAI needs
133
134 // output a record
135 output << " <record>\n";
136
137 // output header part of oai response
138 this->output_record_header(output, oaiLabel, lastModified,
139 doc_info.metadata["memberof"].values, oaiVersion);
140
141 if (this->errorType != "cannotDisseminateFormat"){
142 if (this->formatMap[metadataPrefix].get_class()->output_metadata(output, collection, doc_info)) {
143 // output 'about' part of oai response - we probably won't ever use this
144 //output << " <about>\n";
145 //output << " </about>\n";
146 }
147 }
148 // close record
149 output << " </record>\n\n";
150 }
151 return true;
152}
Note: See TracBrowser for help on using the repository browser.