source: gsdl/trunk/src/oaiservr/listsetsaction.cpp@ 15198

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

Now each action checks for invalid arguments in the params structure and deletes any that aren't valid, so they don't get into the "<request>" tag in the resulting XML and cause OAI validation errors. By DL Consulting Ltd.

  • Property svn:keywords set to Author Date Id Revision
File size: 5.5 KB
Line 
1#include "listsetsaction.h"
2
3#if defined(GSDL_USE_STL_H)
4#include <fstream.h>
5#else
6#include <fstream>
7#endif
8
9#include "OIDtools.h"
10#include "oaitools.h"
11
12bool listsetsaction::validateAction(recptproto *protocol, oaiargs &params)
13{
14 int params_size = params.getSize();
15
16 // Remove any parameters that aren't valid for this action
17 text_tmap::const_iterator param_iterator = params.begin();
18 while (param_iterator != params.end())
19 {
20 if (param_iterator->first != "verb")
21 {
22 params.erase(param_iterator->first);
23 }
24
25 param_iterator++;
26 }
27
28 if(params_size != 1){
29 this->errorType = "badArgument";
30 return false;
31 }
32
33 return true;
34}
35
36bool listsetsaction::output_content(ostream &output, recptproto *protocol, text_tset &collections, oaiargs &params)
37{
38 text_tset::iterator here = collections.begin();
39 text_tset::iterator end = collections.end();
40 while (here != end) {
41 text_t collect = *here;
42 this->output_content(output, protocol, params);
43 ++here;
44 }
45 return true;
46}
47
48bool listsetsaction::output_content(ostream &output, recptproto *protocol, oaiargs &params)
49{
50 // output the total list of classifier points
51
52 // variables required
53 text_t browseOID = "browse";
54 FilterResponse_t response;
55 comerror_t err;
56 text_tarray & collections = this->configuration->getCollectionsList();
57 text_tset metadata;
58 ofstream logout("oai.log", ios::app);
59 text_tarray *result = new text_tarray;
60
61 // get a list of the collections available
62 // protocol->get_collection_list(collections, err, output);
63 if (collections.size() == 0) {
64 logout << "Found *no* OAI collections - check main.cfg for oaicollection items and read the OAI documentation.\n";
65 }
66
67 for(int current_col = 0; current_col < collections.size(); ++current_col) {
68 // output the collection as a set, first, then its children
69 text_t gsdlCollect = collections[current_col];
70
71 output << " <set>" << endl;
72 output << " <setSpec>" << gsdlCollect << "</setSpec>" << endl;;
73 output << " <setName>" << gsdlCollect << "</setName>" << endl;
74 output << " </set>" << endl;
75
76 // get all the children of the (relevant) classifier data structures
77 get_children(browseOID, gsdlCollect, "", metadata, false, protocol, response, logout);
78 // and send them to the "recurse_content" list
79 for (int c = 0; c < response.numDocs; ++c) {
80 this->recurse_content(output, protocol, gsdlCollect, response.docInfo[c].OID, gsdlCollect);
81 }
82 }
83
84 return true;
85}
86
87void listsetsaction::recurse_content(ostream &output, recptproto *protocol, text_t &collection,
88 const text_t &classifier, text_t setHierarchy)
89{
90 // metadata for this call
91 FilterResponse_t response;
92 text_tset metadata;
93 ofstream logout("oai.log", ios::app);
94
95 metadata.insert("contains");
96 metadata.insert("Title");
97 metadata.insert("supportsmemberof");
98
99 // get the document information
100 if (!get_info(classifier, collection, "", metadata, false, protocol, response, logout)) {
101 //cerr << "recurse content: Bad identifier or protocol " << classifier << endl;
102 return;
103 }
104
105 // check for top-level classifiers, check if the set name includes a '.'; if
106 // not, it is a top-level classifier: check for memberof support. Those without
107 // memberof support will not be supported on OAI
108 if (findchar(classifier.begin(), classifier.end(), '.') == classifier.end()) {
109 if (response.docInfo[0].metadata["supportsmemberof"].values.size() > 0) {
110 text_t memberOf = response.docInfo[0].metadata["supportsmemberof"].values[0];
111 if (memberOf != "true") {
112 return;
113 }
114 }
115 else {
116 return;
117 }
118 }
119
120 MetadataInfo_tmap::iterator here = response.docInfo[0].metadata.begin();
121 MetadataInfo_tmap::iterator end = response.docInfo[0].metadata.end();
122 text_t title;
123
124 while (here != end)
125 {
126 // Each set should only have one title - hence we only output one title here
127 // (it is a set title, not a collection)
128 if (here->first == "Title" && here->second.values.size() > 0) {
129 title = here->second.values[0];
130 }
131
132 ++here;
133 }
134
135 // output the xml for this set; use the classifier id for the name
136 // if the title is blank
137 output << " <set>" << endl;
138 text_t oai_classifier = classifier;
139 oaiclassifier::toOAI(collection, oai_classifier);
140 output << " <setSpec>" << oai_classifier << "</setSpec>" << endl;
141 output << " <setName>";
142 // curSet holds the colon-separated sequence of parent sets of the current set
143 text_t curSet;
144 if (!title.empty()) {
145 curSet = setHierarchy + ":" + title;
146 }
147 else {
148 curSet = classifier; // Pretty much never gets here (shouldn't, at least)
149 }
150 output << curSet;
151 output << "</setName>" << endl;
152 output << " </set>" << endl;
153
154 // get the children of this classifier and iterate them
155 get_children(classifier, collection, "", metadata, false, protocol, response, logout);
156 for (int c = 0; c < response.numDocs; ++c) {
157 text_t child = response.docInfo[c].OID;
158
159 if (child == classifier)
160 continue;
161
162 // check for non classifier items and exclude them
163 text_t childHead;
164 text_t::const_iterator start = child.begin();
165 text_t::const_iterator here = child.begin();
166 here += 2;
167 childHead = substr(start, here);
168
169 if (childHead != "CL")
170 continue;
171
172 // Recurse for "proper" classifier children. Pass curSet, the colon-separated list of
173 // parent sets. curSet is pass-by-value, so that as we step out of recursion we remember
174 // old set hierarchies.
175 this->recurse_content(output, protocol, collection, child, curSet);
176 }
177
178 return;
179}
Note: See TracBrowser for help on using the repository browser.