source: main/trunk/greenstone2/runtime-src/src/oaiservr/listrecsaction.cpp@ 22212

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

Minor fixes for validation.

  • Property svn:keywords set to Author Date Id Revision
File size: 5.6 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
84 // Check that the metadataPrefix is a format we support
85 if (this->formatNotSupported(metadataPrefix))
86 {
87 this->errorType = "cannotDisseminateFormat";
88 return false;
89 }
90
91 // ----------------------------------------------------------------------------
92 // 4. Check any remaining arguments
93 // ----------------------------------------------------------------------------
94
95 // Check "from" and "until" arguments
96 if (params["from"] != "" || params["until"] != "")
97 {
98 text_t from = params["from"];
99 text_t until = params["until"];
100
101 // Check the from date is in the correct format: YYYY-MM-DD
102 if (from != "")
103 {
104 // Must be in the form YYYY-MM-DD
105 if (from.size() != 10 || from[4] != '-' || from[7] != '-')
106 {
107 this->errorType = "badArgument";
108 params.erase("from");
109 }
110 }
111 // Check the until date is in the correct format: YYYY-MM-DD
112 if (until != "")
113 {
114 // Must be in the form YYYY-MM-DD
115 if (until.size() != 10 || until[4] != '-' || until[7] != '-')
116 {
117 this->errorType = "badArgument";
118 params.erase("until");
119 }
120 }
121
122 if (this->errorType == "badArgument")
123 {
124 return false;
125 }
126
127 // If both arguments are supplied the from date must be less than or equal to the until date
128 if (from != "" && until != "" && !(from <= until))
129 {
130 this->errorType = "badArgument";
131 return false;
132 }
133 }
134
135 // Check "set" argument
136 if (params["set"] != "")
137 {
138 // Example set specification: "demo:CL2"
139 text_t set = params["set"];
140
141 // Extract the collection name from the set specification
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.