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