[8182] | 1 | #include "abstractlistaction.h"
|
---|
[20590] | 2 | #include "OIDtools.h"
|
---|
[15428] | 3 | #include "recptprototools.h"
|
---|
[8182] | 4 |
|
---|
| 5 | #include "oaitools.h"
|
---|
| 6 |
|
---|
| 7 |
|
---|
[20590] | 8 | bool abstractlistaction::check_classifier(recptproto *protocol, const text_t &collection, const text_t &set_name)
|
---|
| 9 | {
|
---|
| 10 | text_tset metadata;
|
---|
| 11 | FilterResponse_t response;
|
---|
| 12 | return get_info(set_name, collection, "", metadata, false, protocol, response, *this->logout);
|
---|
| 13 | }
|
---|
| 14 |
|
---|
| 15 |
|
---|
[8182] | 16 | bool abstractlistaction::output_content(ostream &output, recptproto *protocol, oaiargs ¶ms)
|
---|
| 17 | {
|
---|
[20590] | 18 | // Reset variables
|
---|
| 19 | this->output_docs = 0;
|
---|
[8182] | 20 |
|
---|
[20590] | 21 | text_t set_name = params["set"];
|
---|
[20627] | 22 | text_t position = "";
|
---|
[8182] | 23 |
|
---|
[20590] | 24 | // Process the resumptionToken if there is one
|
---|
| 25 | if (params["resumptionToken"] != "")
|
---|
| 26 | {
|
---|
| 27 | ResumptionToken resumption_token(params["resumptionToken"]);
|
---|
| 28 | set_name = resumption_token.getSet();
|
---|
| 29 | position = resumption_token.getPosition();
|
---|
[8182] | 30 | }
|
---|
| 31 |
|
---|
[20590] | 32 | // Case for "set" argument present -- output just the records in the specified set
|
---|
| 33 | if (set_name != "")
|
---|
| 34 | {
|
---|
| 35 | // Separate the collection name and Greenstone classifier OID from the set name
|
---|
| 36 | text_t collection_name = "";
|
---|
| 37 | text_t gsdl_classifier_OID = set_name;
|
---|
| 38 | oaiclassifier::toGSDL(collection_name, gsdl_classifier_OID);
|
---|
[11732] | 39 |
|
---|
[20590] | 40 | // If output_content_for_set() returns false a resumption token has been output, so it's time to stop
|
---|
| 41 | if (output_content_for_set(output, protocol, params, collection_name, gsdl_classifier_OID, set_name) == false)
|
---|
| 42 | {
|
---|
| 43 | return true;
|
---|
| 44 | }
|
---|
| 45 | }
|
---|
[8182] | 46 |
|
---|
[20590] | 47 | // Case for no "set" argument present -- output all records in all collections
|
---|
| 48 | else
|
---|
| 49 | {
|
---|
| 50 | // Get a list of the collections available
|
---|
| 51 | text_tarray& collections = this->configuration->getCollectionsList();
|
---|
| 52 | if (collections.size() == 0)
|
---|
| 53 | {
|
---|
| 54 | return false;
|
---|
| 55 | }
|
---|
[8182] | 56 |
|
---|
[20590] | 57 | // Get the current collection from the position value
|
---|
| 58 | text_t collection_name = "";
|
---|
| 59 | oaiclassifier::toGSDL(collection_name, position);
|
---|
| 60 |
|
---|
| 61 | // Find the starting collection
|
---|
| 62 | text_tarray::iterator collection_iterator = collections.begin();
|
---|
| 63 | while (collection_iterator != collections.end())
|
---|
| 64 | {
|
---|
| 65 | if (collection_name == "" || collection_name == *collection_iterator)
|
---|
| 66 | {
|
---|
| 67 | break;
|
---|
| 68 | }
|
---|
| 69 |
|
---|
| 70 | collection_iterator++;
|
---|
[8182] | 71 | }
|
---|
[20590] | 72 |
|
---|
| 73 | // Now loop through the remaining collections
|
---|
| 74 | while (collection_iterator != collections.end())
|
---|
| 75 | {
|
---|
| 76 | // If output_content_for_set() returns false a resumption token has been output, so it's time to stop
|
---|
| 77 | if (output_content_for_set(output, protocol, params, *collection_iterator, "", "") == false)
|
---|
| 78 | {
|
---|
| 79 | return true;
|
---|
[8182] | 80 | }
|
---|
[20590] | 81 |
|
---|
| 82 | collection_iterator++;
|
---|
[8182] | 83 | }
|
---|
| 84 | }
|
---|
| 85 |
|
---|
[20590] | 86 | // If no records were output throw an error
|
---|
| 87 | if (this->configuration->getOAIVersion() >= 200 && this->output_docs == 0)
|
---|
| 88 | {
|
---|
[8182] | 89 | errorType = "noRecordsMatch";
|
---|
| 90 | this->output_error(output, errorType);
|
---|
| 91 | return false;
|
---|
| 92 | }
|
---|
| 93 |
|
---|
| 94 | return true;
|
---|
| 95 | }
|
---|
| 96 |
|
---|
| 97 |
|
---|
[20590] | 98 | bool abstractlistaction::output_content_for_set(ostream &output, recptproto *protocol, oaiargs ¶ms, text_t collection_name, text_t gsdl_classifier_OID, text_t set_name)
|
---|
| 99 | {
|
---|
| 100 | // Check if the set is actually a collection
|
---|
| 101 | if (gsdl_classifier_OID == "")
|
---|
| 102 | {
|
---|
| 103 | gsdl_classifier_OID = "oai";
|
---|
| 104 | }
|
---|
[8182] | 105 |
|
---|
[20590] | 106 | text_t metadata_prefix = params["metadataPrefix"];
|
---|
| 107 | text_t from = params["from"];
|
---|
| 108 | text_t until = params["until"];
|
---|
| 109 | text_t position = "";
|
---|
[16722] | 110 |
|
---|
[20590] | 111 | // Process the resumptionToken if there is one
|
---|
| 112 | if (params["resumptionToken"] != "")
|
---|
| 113 | {
|
---|
| 114 | ResumptionToken resumption_token(params["resumptionToken"]);
|
---|
| 115 | metadata_prefix = resumption_token.getMetadataPrefix();
|
---|
| 116 | from = resumption_token.getFrom();
|
---|
| 117 | until = resumption_token.getUntil();
|
---|
| 118 | position = resumption_token.getPosition();
|
---|
[8182] | 119 | }
|
---|
[16835] | 120 |
|
---|
[20590] | 121 | // Get the list of identifiers in this collection
|
---|
| 122 | // Collections should not contain too many identifiers otherwise this will use a lot of time and memory
|
---|
[16835] | 123 | text_tset metadata; // Must be empty for efficiency
|
---|
[20590] | 124 | FilterResponse_t identifiers_response;
|
---|
| 125 | get_children(gsdl_classifier_OID, collection_name, "", metadata, false, protocol, identifiers_response, *this->logout);
|
---|
[8182] | 126 |
|
---|
[20590] | 127 | // Find the starting position, if necessary
|
---|
| 128 | ResultDocInfo_tarray::iterator identifier_iterator = identifiers_response.docInfo.begin();
|
---|
| 129 | if (output_docs == 0)
|
---|
| 130 | {
|
---|
| 131 | while (identifier_iterator != identifiers_response.docInfo.end())
|
---|
| 132 | {
|
---|
| 133 | if (position == "" || position == (collection_name + ":" + (*identifier_iterator).OID))
|
---|
| 134 | {
|
---|
| 135 | break;
|
---|
[8182] | 136 | }
|
---|
[11732] | 137 |
|
---|
[20590] | 138 | identifier_iterator++;
|
---|
| 139 | }
|
---|
| 140 | }
|
---|
[11732] | 141 |
|
---|
[20590] | 142 | // Now loop through displaying the next matching records
|
---|
| 143 | while (identifier_iterator != identifiers_response.docInfo.end())
|
---|
| 144 | {
|
---|
| 145 | position = (*identifier_iterator).OID;
|
---|
[8182] | 146 |
|
---|
[20590] | 147 | text_t document_OID = position;
|
---|
| 148 | if (starts_with(document_OID, "oai."))
|
---|
| 149 | {
|
---|
| 150 | document_OID = oaiclassifier::getGSDL_OID(collection_name, document_OID, protocol, *this->logout);
|
---|
[8182] | 151 | }
|
---|
| 152 |
|
---|
[20590] | 153 | // Check this OID is in the (optional) date range specified
|
---|
| 154 | if (this->in_date_range(output, protocol, params, collection_name, document_OID, from, until))
|
---|
| 155 | {
|
---|
| 156 | // If we've output the desired number of records return a resumptionToken and we're done
|
---|
| 157 | if (this->output_docs == this->configuration->resumeAfter())
|
---|
| 158 | {
|
---|
[20628] | 159 | // If a set has been specified, we can use the collection's buildDate in the resumption token
|
---|
| 160 | text_t date_stamp = "";
|
---|
| 161 | if (set_name != "")
|
---|
| 162 | {
|
---|
| 163 | ColInfoResponse_t cinfo;
|
---|
| 164 | comerror_t err;
|
---|
| 165 | protocol->get_collectinfo(collection_name, cinfo, err, cerr);
|
---|
| 166 | date_stamp = cinfo.buildDate;
|
---|
| 167 | }
|
---|
[8182] | 168 |
|
---|
[20628] | 169 | ResumptionToken resumption_token(date_stamp, set_name, metadata_prefix, from, until, collection_name + ":" + position);
|
---|
[8182] | 170 |
|
---|
[20590] | 171 | // Don't add any whitespace around the resumption token as it can confuse harvesters/validators
|
---|
| 172 | output << " <resumptionToken>" << resumption_token.getResumptionTokenString() << "</resumptionToken>" << endl;
|
---|
| 173 | return false;
|
---|
| 174 | }
|
---|
[11732] | 175 |
|
---|
[20590] | 176 | // Otherwise output this record and increment the count
|
---|
| 177 | this->output_document(output, protocol, collection_name, document_OID, metadata_prefix);
|
---|
| 178 | this->output_docs++;
|
---|
[11732] | 179 | }
|
---|
| 180 |
|
---|
[20590] | 181 | identifier_iterator++;
|
---|
| 182 | }
|
---|
[11732] | 183 |
|
---|
[20590] | 184 | return true;
|
---|
[8182] | 185 | }
|
---|
| 186 |
|
---|
[20590] | 187 |
|
---|
| 188 | bool abstractlistaction::in_date_range(ostream &output, recptproto *protocol, oaiargs ¶ms,
|
---|
| 189 | text_t& collection, text_t oai_OID, text_t from, text_t until)
|
---|
[8182] | 190 | {
|
---|
[20590] | 191 | // If no "from" or "until" value is specified every record matches, so we don't need to go any further
|
---|
| 192 | if (from == "" && until == "")
|
---|
| 193 | {
|
---|
| 194 | return true;
|
---|
[8182] | 195 | }
|
---|
| 196 |
|
---|
[20590] | 197 | // Get the datestamp from the document as sections do not have this metadata
|
---|
| 198 | text_t document_OID;
|
---|
| 199 | get_top(oai_OID, document_OID);
|
---|
| 200 |
|
---|
| 201 | // Request the lastmodified value for this document
|
---|
| 202 | text_tset metadata;
|
---|
| 203 | metadata.insert("lastmodified");
|
---|
[21978] | 204 | metadata.insert("gs.OAIDateStamp");
|
---|
[8182] | 205 | FilterResponse_t response;
|
---|
[20590] | 206 | if (!get_info(document_OID, collection, "", metadata, false, protocol, response, *this->logout))
|
---|
| 207 | {
|
---|
[8182] | 208 | return false;
|
---|
| 209 | }
|
---|
| 210 |
|
---|
[20590] | 211 | text_t last_modified_date;
|
---|
| 212 | this->getLastModifiedDate(response.docInfo[0], last_modified_date);
|
---|
[8182] | 213 |
|
---|
[20590] | 214 | // Check this record is not before the "from" value, if it exists
|
---|
| 215 | if (from != "" && last_modified_date < from)
|
---|
| 216 | {
|
---|
| 217 | // Too early
|
---|
[8182] | 218 | return false;
|
---|
| 219 | }
|
---|
| 220 |
|
---|
[20590] | 221 | // Check this record is not after the "until" value, if it exists
|
---|
| 222 | if (until != "" && last_modified_date > until)
|
---|
| 223 | {
|
---|
| 224 | // Too late
|
---|
[8182] | 225 | return false;
|
---|
| 226 | }
|
---|
| 227 |
|
---|
[20590] | 228 | // Just right
|
---|
[8182] | 229 | return true;
|
---|
| 230 | }
|
---|