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

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

Minor comment change.

  • 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 // 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 // Extract the collection name from the set specification
141 text_t collection = "";
142 oaiclassifier::toGSDL(collection, set);
143
144 // Check that the collection is accessible
145 ColInfoResponse_t cinfo;
146 comerror_t err;
147 protocol->get_collectinfo(collection, cinfo, err, cerr);
148 if (err != noError)
149 {
150 this->errorType = "badArgument";
151 return false;
152 }
153
154 // Check the collection is one that is in the list in the oai.cfg file
155 text_tarray &collections = this->configuration->getCollectionsList();
156 bool collection_found = false;
157 for (int c = 0; c < collections.size(); c++)
158 {
159 if (collections[c] == collection)
160 {
161 collection_found = true;
162 break;
163 }
164 }
165
166 // The collection was not found
167 if (!collection_found)
168 {
169 this->errorType = "badArgument";
170 return false;
171 }
172
173 // Check the child set if it was given
174 if (set != "" && !this->check_classifier(protocol, collection, set))
175 {
176 this->errorType = "badArgument";
177 return false;
178 }
179 }
180
181 // If we've reached here everything must be fine
182 this->errorType = "";
183 return true;
184}
185
186//-----------------------------------------------------------------------------------------------
187
188bool listrecsaction::output_document(ostream &output, recptproto *protocol, const text_t &collection,
189 const text_t &OID, const text_t &metadataPrefix)
190{
191 this->record_action->output_record(output, protocol, collection, OID, metadataPrefix);
192 return true;
193}
194
195//-----------------------------------------------------------------------------------------------
196
197
198
Note: See TracBrowser for help on using the repository browser.