source: gsdl/trunk/runtime-src/src/oaiservr/listrecsaction.cpp@ 16713

Last change on this file since 16713 was 16713, checked in by mdewsnip, 16 years ago

The ListRecords action requires the metadataPrefix argument for both versions of OAI.

  • Property svn:keywords set to Author Date Id Revision
File size: 5.8 KB
Line 
1#include "listrecsaction.h"
2
3#include "oaitools.h"
4#include "recordaction.h"
5
6bool listrecsaction::validateAction(recptproto *protocol, oaiargs &params)
7{
8 // ----------------------------------------------------------------------------
9 // 1. Check for invalid arguments
10 // ----------------------------------------------------------------------------
11 bool invalid_argument_supplied = false;
12 text_tmap::const_iterator param_iterator = params.begin();
13 while (param_iterator != params.end())
14 {
15 // Check for arguments that aren't valid for this action
16 if (param_iterator->first != "verb" &&
17 param_iterator->first != "from" &&
18 param_iterator->first != "until" &&
19 param_iterator->first != "set" &&
20 param_iterator->first != "resumptionToken" &&
21 param_iterator->first != "metadataPrefix")
22 {
23 // We've found an invalid argument
24 invalid_argument_supplied = true;
25
26 // Delete the invalid argument from the list so it doesn't end up in the <request> tag that is returned
27 params.erase(param_iterator->first);
28 }
29
30 param_iterator++;
31 }
32
33 // If we found an invalid argument it's an error, so don't go any further
34 if (invalid_argument_supplied)
35 {
36 this->errorType = "badArgument";
37 return false;
38 }
39
40 // ----------------------------------------------------------------------------
41 // 2. Handle any exclusive arguments
42 // ----------------------------------------------------------------------------
43
44 // The resumptionToken argument is exclusive
45 if (params["resumptionToken"] != "")
46 {
47 // This argument is exclusive, so no other arguments are allowed (except "verb" of course)
48 if (params.getSize() != 2)
49 {
50 this->errorType = "badArgument";
51 return false;
52 }
53
54 // Check the resumption token is valid
55 ResumptionToken token(params["resumptionToken"]);
56 if (token.isValid())
57 {
58 // Everything is fine, and we don't continue further because this is an exclusive argument
59 this->errorType = "";
60 return true;
61 }
62 else
63 {
64 // There was an error with the resumption token
65 this->errorType = "badResumptionToken";
66 return false;
67 }
68 }
69
70 // ----------------------------------------------------------------------------
71 // 3. Handle any required arguments
72 // ----------------------------------------------------------------------------
73
74 // The metadataPrefix is required
75 text_t metadataPrefix = params["metadataPrefix"];
76
77 // Check that the metadataPrefix argument exists
78 if (metadataPrefix == "")
79 {
80 this->errorType = "badArgument";
81 return false;
82 }
83 // Check that the metadataPrefix is a format we support
84 if (this->formatNotSupported(metadataPrefix))
85 {
86 this->errorType = "cannotDisseminateFormat";
87 return false;
88 }
89
90 // ----------------------------------------------------------------------------
91 // 4. Check any remaining arguments
92 // ----------------------------------------------------------------------------
93
94 // Check "from" and "until" arguments
95 if (params["from"] != "" || params["until"] != "")
96 {
97 text_t from = params["from"];
98 text_t until = params["until"];
99
100 // Check the from date is in the correct format: YYYY-MM-DD
101 if (from != "")
102 {
103 // Must be in the form YYYY-MM-DD
104 if (from.size() != 10 || from[4] != '-' || from[7] != '-')
105 {
106 this->errorType = "badArgument";
107 params.erase("from");
108 }
109 }
110 // Check the until date is in the correct format: YYYY-MM-DD
111 if (until != "")
112 {
113 // Must be in the form YYYY-MM-DD
114 if (until.size() != 10 || until[4] != '-' || until[7] != '-')
115 {
116 this->errorType = "badArgument";
117 params.erase("until");
118 }
119 }
120
121 if (this->errorType == "badArgument")
122 {
123 return false;
124 }
125
126 // If both arguments are supplied the from date must be less than or equal to the until date
127 if (from != "" && until != "" && !(from <= until))
128 {
129 this->errorType = "badArgument";
130 return false;
131 }
132 }
133
134 // Check "set" argument
135 if (params["set"] != "")
136 {
137 // Example set specification: "demo:CL2"
138 text_t set = params["set"];
139
140 // given 'demo:CL2', toGSDL returns 'demo' in collection and 'CL2' in set. If there is no further
141 // set specified after the name of the collection however, then set is empty.
142 text_t collection = "";
143 oaiclassifier::toGSDL(collection, set);
144
145 // Check that the collection is accessible
146 ColInfoResponse_t cinfo;
147 comerror_t err;
148 protocol->get_collectinfo(collection, cinfo, err, cerr);
149 if (err != noError)
150 {
151 this->errorType = "badArgument";
152 return false;
153 }
154
155 // Check the collection is one that is in the list in the oai.cfg file
156 text_tarray &collections = this->configuration->getCollectionsList();
157 bool collection_found = false;
158 for (int c = 0; c < collections.size(); c++)
159 {
160 if (collections[c] == collection)
161 {
162 collection_found = true;
163 break;
164 }
165 }
166
167 // The collection was not found
168 if (!collection_found)
169 {
170 this->errorType = "badArgument";
171 return false;
172 }
173
174 // Check the child set if it was given
175 if (set != "" && !this->check_classifier(protocol, collection, set))
176 {
177 this->errorType = "badArgument";
178 return false;
179 }
180 }
181
182 // If we've reached here everything must be fine
183 this->errorType = "";
184 return true;
185}
186
187//-----------------------------------------------------------------------------------------------
188
189bool listrecsaction::output_document(ostream &output, recptproto *protocol, const text_t &collection,
190 const text_t &OID, const text_t &metadataPrefix)
191{
192 this->record_action->output_record(output, protocol, collection, OID, metadataPrefix);
193 return true;
194}
195
196//-----------------------------------------------------------------------------------------------
197
198
199
Note: See TracBrowser for help on using the repository browser.