1 | #include "listidsaction.h"
|
---|
2 | #include "recptprototools.h"
|
---|
3 | #include "oaitools.h"
|
---|
4 |
|
---|
5 | //--------------------------------------------------------------------------------------------------
|
---|
6 |
|
---|
7 | bool listidsaction::validateAction(recptproto *protocol, oaiargs ¶ms)
|
---|
8 | {
|
---|
9 | // ----------------------------------------------------------------------------
|
---|
10 | // 1. Check for invalid arguments
|
---|
11 | // ----------------------------------------------------------------------------
|
---|
12 | bool invalid_argument_supplied = false;
|
---|
13 | text_tmap::const_iterator param_iterator = params.begin();
|
---|
14 | while (param_iterator != params.end())
|
---|
15 | {
|
---|
16 | // Check for arguments that aren't valid for this action
|
---|
17 | if (param_iterator->first != "verb" &&
|
---|
18 | param_iterator->first != "from" &&
|
---|
19 | param_iterator->first != "until" &&
|
---|
20 | param_iterator->first != "set" &&
|
---|
21 | param_iterator->first != "resumptionToken" &&
|
---|
22 | param_iterator->first != "metadataPrefix")
|
---|
23 | {
|
---|
24 | // We've found an invalid argument
|
---|
25 | invalid_argument_supplied = true;
|
---|
26 |
|
---|
27 | // Delete the invalid argument from the list so it doesn't end up in the <request> tag that is returned
|
---|
28 | params.erase(param_iterator->first);
|
---|
29 | }
|
---|
30 |
|
---|
31 | // The metadataPrefix argument is not allowed in OAI v1.1
|
---|
32 | else if (param_iterator->first == "metadataPrefix" && this->configuration->getOAIVersion() <= 110)
|
---|
33 | {
|
---|
34 | // We've found an invalid argument
|
---|
35 | invalid_argument_supplied = true;
|
---|
36 |
|
---|
37 | // Delete the invalid argument from the list so it doesn't end up in the <request> tag that is returned
|
---|
38 | params.erase(param_iterator->first);
|
---|
39 | }
|
---|
40 |
|
---|
41 | param_iterator++;
|
---|
42 | }
|
---|
43 |
|
---|
44 | // If we found an invalid argument it's an error, so don't go any further
|
---|
45 | if (invalid_argument_supplied)
|
---|
46 | {
|
---|
47 | this->errorType = "badArgument";
|
---|
48 | return false;
|
---|
49 | }
|
---|
50 |
|
---|
51 | // ----------------------------------------------------------------------------
|
---|
52 | // 2. Handle any exclusive arguments
|
---|
53 | // ----------------------------------------------------------------------------
|
---|
54 |
|
---|
55 | // The resumptionToken argument is exclusive
|
---|
56 | if (params["resumptionToken"] != "")
|
---|
57 | {
|
---|
58 | // This argument is exclusive, so no other arguments are allowed (except "verb" of course)
|
---|
59 | if (params.getSize() != 2)
|
---|
60 | {
|
---|
61 | this->errorType = "badArgument";
|
---|
62 | return false;
|
---|
63 | }
|
---|
64 |
|
---|
65 | // Check the resumption token is valid
|
---|
66 | ResumptionToken token(params["resumptionToken"]);
|
---|
67 | if (token.isValid())
|
---|
68 | {
|
---|
69 | // Everything is fine, and we don't continue further because this is an exclusive argument
|
---|
70 | this->errorType = "";
|
---|
71 | return true;
|
---|
72 | }
|
---|
73 | else
|
---|
74 | {
|
---|
75 | // There was an error with the resumption token
|
---|
76 | this->errorType = "badResumptionToken";
|
---|
77 | return false;
|
---|
78 | }
|
---|
79 | }
|
---|
80 |
|
---|
81 | // ----------------------------------------------------------------------------
|
---|
82 | // 3. Handle any required arguments
|
---|
83 | // ----------------------------------------------------------------------------
|
---|
84 |
|
---|
85 | // OAI v2.0 requires metadataPrefix
|
---|
86 | if (this->configuration->getOAIVersion() > 110)
|
---|
87 | {
|
---|
88 | text_t metadataPrefix = params["metadataPrefix"];
|
---|
89 |
|
---|
90 | // Check that the metadataPrefix argument exists
|
---|
91 | if (metadataPrefix == "")
|
---|
92 | {
|
---|
93 | this->errorType = "badArgument";
|
---|
94 | return false;
|
---|
95 | }
|
---|
96 |
|
---|
97 | // Check that the metadataPrefix is a format we support
|
---|
98 | if (this->formatNotSupported(metadataPrefix))
|
---|
99 | {
|
---|
100 | this->errorType = "cannotDisseminateFormat";
|
---|
101 | return false;
|
---|
102 | }
|
---|
103 | }
|
---|
104 |
|
---|
105 | // ----------------------------------------------------------------------------
|
---|
106 | // 4. Check any remaining arguments
|
---|
107 | // ----------------------------------------------------------------------------
|
---|
108 |
|
---|
109 | // Check "from" and "until" arguments
|
---|
110 | if (params["from"] != "" || params["until"] != "")
|
---|
111 | {
|
---|
112 | text_t from = params["from"];
|
---|
113 | text_t until = params["until"];
|
---|
114 |
|
---|
115 | // Check the from date is in the correct format: YYYY-MM-DD
|
---|
116 | if (from != "")
|
---|
117 | {
|
---|
118 | // Must be in the form YYYY-MM-DD
|
---|
119 | if (from.size() != 10 || from[4] != '-' || from[7] != '-')
|
---|
120 | {
|
---|
121 | this->errorType = "badArgument";
|
---|
122 | params.erase("from");
|
---|
123 | }
|
---|
124 | }
|
---|
125 | // Check the until date is in the correct format: YYYY-MM-DD
|
---|
126 | if (until != "")
|
---|
127 | {
|
---|
128 | // Must be in the form YYYY-MM-DD
|
---|
129 | if (until.size() != 10 || until[4] != '-' || until[7] != '-')
|
---|
130 | {
|
---|
131 | this->errorType = "badArgument";
|
---|
132 | params.erase("until");
|
---|
133 | }
|
---|
134 | }
|
---|
135 |
|
---|
136 | if (this->errorType == "badArgument")
|
---|
137 | {
|
---|
138 | return false;
|
---|
139 | }
|
---|
140 |
|
---|
141 | // If both arguments are supplied the from date must be less than or equal to the until date
|
---|
142 | if (from != "" && until != "" && !(from <= until))
|
---|
143 | {
|
---|
144 | this->errorType = "badArgument";
|
---|
145 | return false;
|
---|
146 | }
|
---|
147 | }
|
---|
148 |
|
---|
149 | // Check "set" argument
|
---|
150 | if (params["set"] != "")
|
---|
151 | {
|
---|
152 | // Example set specification: "demo:CL2"
|
---|
153 | text_t set = params["set"];
|
---|
154 |
|
---|
155 | // Extract the collection name from the set specification
|
---|
156 | text_t collection = "";
|
---|
157 | oaiclassifier::toGSDL(collection, set);
|
---|
158 |
|
---|
159 | // Check that the collection is accessible
|
---|
160 | ColInfoResponse_t cinfo;
|
---|
161 | comerror_t err;
|
---|
162 | protocol->get_collectinfo(collection, cinfo, err, cerr);
|
---|
163 | if (err != noError)
|
---|
164 | {
|
---|
165 | this->errorType = "badArgument";
|
---|
166 | return false;
|
---|
167 | }
|
---|
168 |
|
---|
169 | // Check the collection is one that is in the list in the oai.cfg file
|
---|
170 | text_tarray &collections = this->configuration->getCollectionsList();
|
---|
171 | bool collection_found = false;
|
---|
172 | for (int c = 0; c < collections.size(); c++)
|
---|
173 | {
|
---|
174 | if (collections[c] == collection)
|
---|
175 | {
|
---|
176 | collection_found = true;
|
---|
177 | break;
|
---|
178 | }
|
---|
179 | }
|
---|
180 |
|
---|
181 | // The collection was not found
|
---|
182 | if (!collection_found)
|
---|
183 | {
|
---|
184 | this->errorType = "badArgument";
|
---|
185 | return false;
|
---|
186 | }
|
---|
187 |
|
---|
188 | // Check the child set if it was given
|
---|
189 | if (set != "" && !this->check_classifier(protocol, collection, set))
|
---|
190 | {
|
---|
191 | this->errorType = "badArgument";
|
---|
192 | return false;
|
---|
193 | }
|
---|
194 | }
|
---|
195 |
|
---|
196 | // If we've reached here everything must be fine
|
---|
197 | this->errorType = "";
|
---|
198 | return true;
|
---|
199 | }
|
---|
200 |
|
---|
201 | //--------------------------------------------------------------------------------------------------
|
---|
202 |
|
---|
203 | bool listidsaction::output_document(ostream& output, recptproto *protocol, const text_t &collection,
|
---|
204 | const text_t &OID, const text_t &metadataPrefix /* ignored */)
|
---|
205 | {
|
---|
206 | FilterResponse_t response;
|
---|
207 | ResultDocInfo_t doc_info;
|
---|
208 | text_tset metadata;
|
---|
209 | ofstream logout("oai.log", ios::app);
|
---|
210 | text_t lastModified;
|
---|
211 | int oaiVersion = this->configuration->getOAIVersion();
|
---|
212 |
|
---|
213 | get_info(OID, collection, "", metadata, false, protocol, response, logout);
|
---|
214 | doc_info = response.docInfo[0];
|
---|
215 | this->getLastModifiedDate(doc_info, lastModified);
|
---|
216 |
|
---|
217 | // output the record for this document
|
---|
218 | text_t oaiLabel = OID;
|
---|
219 | oaiclassifier::toOAI(collection, oaiLabel);
|
---|
220 |
|
---|
221 | if(oaiVersion <= 110)
|
---|
222 | output << " <identifier>" << oaiLabel << "</identifier>\n";
|
---|
223 | else
|
---|
224 | this->output_record_header(output, oaiLabel, lastModified,
|
---|
225 | doc_info.metadata["memberof"].values, oaiVersion);
|
---|
226 |
|
---|
227 | return true;
|
---|
228 | }
|
---|