[22739] | 1 | /**********************************************************************
|
---|
| 2 | *
|
---|
| 3 | * identifyaction.cpp --
|
---|
| 4 | *
|
---|
| 5 | * Copyright (C) 2004-2010 The New Zealand Digital Library Project
|
---|
| 6 | *
|
---|
| 7 | * A component of the Greenstone digital library software
|
---|
| 8 | * from the New Zealand Digital Library Project at the
|
---|
| 9 | * University of Waikato, New Zealand.
|
---|
| 10 | *
|
---|
| 11 | * This program is free software; you can redistribute it and/or modify
|
---|
| 12 | * it under the terms of the GNU General Public License as published by
|
---|
| 13 | * the Free Software Foundation; either version 2 of the License, or
|
---|
| 14 | * (at your option) any later version.
|
---|
| 15 | *
|
---|
| 16 | * This program is distributed in the hope that it will be useful,
|
---|
| 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 19 | * GNU General Public License for more details.
|
---|
| 20 | *
|
---|
| 21 | * You should have received a copy of the GNU General Public License
|
---|
| 22 | * along with this program; if not, write to the Free Software
|
---|
| 23 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
| 24 | *
|
---|
| 25 | *********************************************************************/
|
---|
| 26 |
|
---|
[15844] | 27 | #include "identifyaction.h"
|
---|
[24114] | 28 | #include "oaitools.h"
|
---|
[8182] | 29 |
|
---|
[15844] | 30 | bool identifyaction::validateAction(recptproto *protocol, oaiargs ¶ms)
|
---|
[8182] | 31 | {
|
---|
[16711] | 32 | // ----------------------------------------------------------------------------
|
---|
| 33 | // 1. Check for invalid arguments
|
---|
| 34 | // ----------------------------------------------------------------------------
|
---|
| 35 | bool invalid_argument_supplied = false;
|
---|
[15198] | 36 | text_tmap::const_iterator param_iterator = params.begin();
|
---|
| 37 | while (param_iterator != params.end())
|
---|
| 38 | {
|
---|
[16711] | 39 | // Check for arguments that aren't valid for this action
|
---|
[15198] | 40 | if (param_iterator->first != "verb")
|
---|
| 41 | {
|
---|
[16711] | 42 | // We've found an invalid argument
|
---|
| 43 | invalid_argument_supplied = true;
|
---|
| 44 |
|
---|
| 45 | // Delete the invalid argument from the list so it doesn't end up in the <request> tag that is returned
|
---|
[15198] | 46 | params.erase(param_iterator->first);
|
---|
| 47 | }
|
---|
| 48 |
|
---|
| 49 | param_iterator++;
|
---|
| 50 | }
|
---|
[16711] | 51 |
|
---|
| 52 | // If we found an invalid argument it's an error, so don't go any further
|
---|
| 53 | if (invalid_argument_supplied)
|
---|
| 54 | {
|
---|
[8182] | 55 | this->errorType = "badArgument";
|
---|
| 56 | return false;
|
---|
| 57 | }
|
---|
[16711] | 58 |
|
---|
| 59 | // ----------------------------------------------------------------------------
|
---|
| 60 | // 2. Handle any exclusive arguments
|
---|
| 61 | // ----------------------------------------------------------------------------
|
---|
| 62 |
|
---|
| 63 | // None!
|
---|
| 64 |
|
---|
| 65 | // ----------------------------------------------------------------------------
|
---|
| 66 | // 3. Handle any required arguments
|
---|
| 67 | // ----------------------------------------------------------------------------
|
---|
| 68 |
|
---|
| 69 | // None!
|
---|
| 70 |
|
---|
| 71 | // ----------------------------------------------------------------------------
|
---|
| 72 | // 4. Check any remaining arguments
|
---|
| 73 | // ----------------------------------------------------------------------------
|
---|
| 74 |
|
---|
| 75 | // None!
|
---|
| 76 |
|
---|
| 77 | // If we've reached here everything must be fine
|
---|
| 78 | this->errorType = "";
|
---|
[8182] | 79 | return true;
|
---|
| 80 | }
|
---|
| 81 |
|
---|
[15844] | 82 | bool identifyaction::output_content(ostream &output, recptproto *protocol, oaiargs ¶ms)
|
---|
[8182] | 83 | {
|
---|
[20707] | 84 | utf8outconvertclass utf8convert;
|
---|
| 85 |
|
---|
[8182] | 86 | // Get the repository name (some human-readable name for the site, or superset of collections)
|
---|
[22213] | 87 | text_t repositoryName = this->configuration->getRepositoryName();
|
---|
[22287] | 88 | text_t repositoryId = this->configuration->getRepositoryId();
|
---|
[8182] | 89 | // Get admin's email address (i.e. the site maintainer)
|
---|
[22213] | 90 | text_t maintainer = this->configuration->getMaintainer();
|
---|
[8182] | 91 | text_t version = (this->configuration->getOAIVersion() <= 110) ? (text_t)"1.1":(text_t)"2.0";
|
---|
[22287] | 92 | text_t id_version = this->configuration->getRepositoryIdVersion();
|
---|
| 93 |
|
---|
[22213] | 94 | text_t baseURL = this->configuration->getBaseURL();
|
---|
[8182] | 95 |
|
---|
[20707] | 96 | output << utf8convert << " <repositoryName>" << repositoryName << "</repositoryName>\n";
|
---|
| 97 | output << utf8convert << " <baseURL>" << baseURL << "</baseURL>\n";
|
---|
| 98 | output << utf8convert << " <protocolVersion>" << version << "</protocolVersion>\n";
|
---|
| 99 | output << utf8convert << " <adminEmail>" << maintainer << "</adminEmail>\n";
|
---|
[8182] | 100 |
|
---|
| 101 | if(version == "2.0"){
|
---|
| 102 | // earliestDatestamp *should* be the YYYY-MM-DD format of the oldest lastmodified record in the
|
---|
| 103 | // repository, but we're just setting it to be the default oldest possible date - ugly, but judged
|
---|
| 104 | // not to be worth the effort of trolling through all the lastmodified dates (by others with more
|
---|
| 105 | // say than me)
|
---|
[24114] | 106 |
|
---|
| 107 | // The above was before. However, now we mirror GS3 way of dealing with
|
---|
| 108 | // earliestDatestamp by going through the earliestDatestamp field of each OAI
|
---|
| 109 | // collection's build.cfg in order to work out earliestdatestamp of this Repository:
|
---|
| 110 | // by going through all the collections and getting the earliest among the
|
---|
| 111 | // "earliestDatestamp" values stored for each collection in its build.cfg
|
---|
| 112 | // (the earliestDatestamp for a collection has already been extracted from
|
---|
| 113 | // their build.cfg file at this point by collectserver::configure. The field
|
---|
| 114 | // is declared in comtypes.h)
|
---|
| 115 | text_t earliestDatestamp = ""; // do not set default to unix epoch time "1970-01-01" yet
|
---|
| 116 |
|
---|
| 117 | // Get a list of the OAI-enabled collections available
|
---|
| 118 | text_tarray& collections = this->configuration->getCollectionsList();
|
---|
| 119 | if (collections.size() > 0)
|
---|
| 120 | {
|
---|
| 121 | // get the identifier from the params
|
---|
| 122 | text_t identifier = params["identifier"];
|
---|
| 123 | text_t oai_OID_prefix = "oai:"+this->configuration->getRepositoryId()+":";
|
---|
| 124 | identifier.replace(oai_OID_prefix, "");
|
---|
| 125 |
|
---|
| 126 | // Get the current collection from the identifier
|
---|
| 127 | text_t collection_name = "";
|
---|
| 128 | oaiclassifier::toGSDL(collection_name, identifier);
|
---|
| 129 |
|
---|
| 130 | // Find the starting collection
|
---|
| 131 | text_tarray::iterator collection_iterator = collections.begin();
|
---|
| 132 | while (collection_iterator != collections.end())
|
---|
| 133 | {
|
---|
| 134 | if (collection_name == "" || collection_name == *collection_iterator)
|
---|
| 135 | {
|
---|
| 136 | break;
|
---|
| 137 | }
|
---|
| 138 |
|
---|
| 139 | collection_iterator++;
|
---|
| 140 | }
|
---|
| 141 |
|
---|
| 142 | // Now loop through the remaining collections
|
---|
| 143 | // to work out the earliest datestamp
|
---|
| 144 | while (collection_iterator != collections.end())
|
---|
| 145 | {
|
---|
| 146 | collection_name = (*collection_iterator);
|
---|
| 147 |
|
---|
| 148 | ColInfoResponse_t cinfo;
|
---|
| 149 | comerror_t err;
|
---|
| 150 | protocol->get_collectinfo(collection_name, cinfo, err, cerr);
|
---|
| 151 | if (err == noError) {
|
---|
| 152 | text_t eDatestamp = cinfo.earliestDatestamp;
|
---|
| 153 | time_t raw_time = (time_t)eDatestamp.getint();
|
---|
| 154 | eDatestamp = this->parseDatestamp(raw_time);
|
---|
| 155 |
|
---|
| 156 | if(earliestDatestamp == "") { // first earliestdatestamp we've seen for an oai collection
|
---|
| 157 | earliestDatestamp = eDatestamp;
|
---|
| 158 | } else if(eDatestamp < earliestDatestamp) {
|
---|
| 159 | earliestDatestamp = eDatestamp;
|
---|
| 160 | }
|
---|
| 161 | }
|
---|
| 162 | collection_iterator++;
|
---|
| 163 |
|
---|
| 164 | }
|
---|
| 165 | }
|
---|
| 166 |
|
---|
| 167 | // if repository's earliestDatestamp is still unset, default to unix epoch time
|
---|
| 168 | if(earliestDatestamp == "") {
|
---|
| 169 | earliestDatestamp = "1970-01-01";
|
---|
| 170 | }
|
---|
| 171 |
|
---|
| 172 | output << utf8convert << " <earliestDatestamp>"<< earliestDatestamp <<"</earliestDatestamp>\n";
|
---|
[20707] | 173 | output << utf8convert << " <deletedRecord>no</deletedRecord>\n";
|
---|
| 174 | output << utf8convert << " <granularity>YYYY-MM-DD</granularity>\n";
|
---|
[8182] | 175 | }
|
---|
[22287] | 176 | // list the oai identifier
|
---|
| 177 | output << " <description>\n";
|
---|
| 178 | if (id_version == "1.1") {
|
---|
| 179 |
|
---|
| 180 | output << " <oai-identifier xmlns=\"http://www.openarchives.org/OAI/1.1/oai-identifier\"\n";
|
---|
| 181 | output << " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n";
|
---|
[22557] | 182 | output << " xsi:schemaLocation=\"http://www.openarchives.org/OAI/1.1/oai-identifier\n";
|
---|
| 183 | output << " http://www.openarchives.org/OAI/1.1/oai-identifier.xsd\">\n";
|
---|
[22287] | 184 | } else {
|
---|
| 185 |
|
---|
| 186 | output << " <oai-identifier xmlns=\"http://www.openarchives.org/OAI/2.0/oai-identifier\"\n";
|
---|
| 187 | output << " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n";
|
---|
| 188 | output << " xsi:schemaLocation=\"http://www.openarchives.org/OAI/2.0/oai-identifier\n";
|
---|
[22557] | 189 | output << " http://www.openarchives.org/OAI/2.0/oai-identifier.xsd\">\n";
|
---|
[22287] | 190 |
|
---|
| 191 |
|
---|
| 192 | }
|
---|
| 193 |
|
---|
[22557] | 194 | output << " <scheme>oai</scheme>\n";
|
---|
| 195 | output << " <repositoryIdentifier>"<< repositoryId <<"</repositoryIdentifier>\n";
|
---|
| 196 | output << " <delimiter>:</delimiter>\n";
|
---|
| 197 | output << " <sampleIdentifier>oai:"<<repositoryId<<":demo:HASH983080b052e9230b7ccf94</sampleIdentifier>\n";
|
---|
| 198 | output << " </oai-identifier>\n";
|
---|
[22287] | 199 |
|
---|
[8182] | 200 | // list all configuration information
|
---|
| 201 | text_tmap::iterator here = this->configuration->getInformation()->begin();
|
---|
| 202 | text_tmap::iterator end = this->configuration->getInformation()->end();
|
---|
[22557] | 203 | if (here != end) {
|
---|
| 204 | output << " <gsdl xmlns=\"http://www.greenstone.org/namespace/gsdl_oaiinfo/1.0/gsdl_oaiinfo\"\n";
|
---|
| 205 | output << " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n";
|
---|
| 206 | output << " xsi:schemaLocation=\"http://www.greenstone.org/namespace/gsdl_oaiinfo/1.0/gsdl_oaiinfo\n";
|
---|
| 207 | output << " http://www.greenstone.org/namespace/gsdl_oaiinfo/1.0/gsdl_oaiinfo.xsd\">\n";
|
---|
| 208 |
|
---|
| 209 |
|
---|
| 210 | while (here != end) {
|
---|
| 211 | output << utf8convert << " <Metadata name=\"" << here->first << "\">" << here->second << "</Metadata>\n";
|
---|
| 212 | ++here;
|
---|
| 213 | }
|
---|
| 214 | output << " </gsdl>\n";
|
---|
[8182] | 215 | }
|
---|
| 216 |
|
---|
[22557] | 217 | output << utf8convert << " </description>\n";
|
---|
| 218 |
|
---|
[8182] | 219 | return true;
|
---|
| 220 | }
|
---|
| 221 |
|
---|