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