root/main/trunk/greenstone2/runtime-src/src/oaiservr/identifyaction.cpp @ 24412

Revision 24412, 7.1 KB (checked in by ak19, 9 years ago)

Fixed a new failure of the OAI validation test of GS2's OAI server: where list records is given an Until date that is earlier than the earliestDatestamp. Needs to return a noRecordsMatch. It does now. The calculation of the earliestDatestamp is now shifted to the oaiaction.cpp superclass and called by both identifyaction and listrecordsaction for the identify and listrecords OAI queries, since these tasks need to work with earliestDatestamp.

  • Property svn:keywords set to Author Date Id Revision
Line 
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
27#include "identifyaction.h"
28#include "oaitools.h"
29
30bool identifyaction::validateAction(recptproto *protocol, oaiargs &params)
31{
32  // ----------------------------------------------------------------------------
33  //  1. Check for invalid arguments
34  // ----------------------------------------------------------------------------
35  bool invalid_argument_supplied = false;
36  text_tmap::const_iterator param_iterator = params.begin();
37  while (param_iterator != params.end())
38  {
39    // Check for arguments that aren't valid for this action
40    if (param_iterator->first != "verb")
41    {
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
46      params.erase(param_iterator->first);
47    }
48
49    param_iterator++;
50  }
51
52  // If we found an invalid argument it's an error, so don't go any further
53  if (invalid_argument_supplied)
54  {
55    this->errorType = "badArgument";
56    return false;
57  }
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 = "";
79  return true;
80}
81
82bool identifyaction::output_content(ostream &output, recptproto *protocol, oaiargs &params)
83{
84  utf8outconvertclass utf8convert;
85
86  // Get the repository name (some human-readable name for the site, or superset of collections)
87  text_t repositoryName = this->configuration->getRepositoryName();
88  text_t repositoryId = this->configuration->getRepositoryId();
89  // Get admin's email address (i.e. the site maintainer)
90  text_t maintainer = this->configuration->getMaintainer();
91  text_t version = (this->configuration->getOAIVersion() <= 110) ? (text_t)"1.1":(text_t)"2.0";
92  text_t id_version = this->configuration->getRepositoryIdVersion();
93 
94  text_t baseURL = this->configuration->getBaseURL();
95 
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";
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)
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   
116    this->calcEarliestDatestamp(protocol, params);  // force the calculation. Sets mEarliestDatestamp member variable
117   
118    output << utf8convert << "  <earliestDatestamp>"<< this->mEarliestDatestamp <<"</earliestDatestamp>\n";
119    output << utf8convert << "  <deletedRecord>no</deletedRecord>\n";
120    output << utf8convert << "  <granularity>YYYY-MM-DD</granularity>\n";
121  }
122  // list the oai identifier
123  output << "  <description>\n";
124  if (id_version == "1.1") {
125
126    output << "    <oai-identifier xmlns=\"http://www.openarchives.org/OAI/1.1/oai-identifier\"\n";
127    output << "        xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n";
128    output << "        xsi:schemaLocation=\"http://www.openarchives.org/OAI/1.1/oai-identifier\n";
129    output << "           http://www.openarchives.org/OAI/1.1/oai-identifier.xsd\">\n";
130  } else {
131
132    output << "    <oai-identifier xmlns=\"http://www.openarchives.org/OAI/2.0/oai-identifier\"\n";
133    output << "      xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n";
134    output << "      xsi:schemaLocation=\"http://www.openarchives.org/OAI/2.0/oai-identifier\n";
135    output << "        http://www.openarchives.org/OAI/2.0/oai-identifier.xsd\">\n";
136
137   
138  }
139
140  output << "      <scheme>oai</scheme>\n";
141  output << "      <repositoryIdentifier>"<< repositoryId <<"</repositoryIdentifier>\n";
142  output << "      <delimiter>:</delimiter>\n";
143  output << "      <sampleIdentifier>oai:"<<repositoryId<<":demo:HASH983080b052e9230b7ccf94</sampleIdentifier>\n";
144  output << "    </oai-identifier>\n";
145
146  // list all configuration information
147  text_tmap::iterator here = this->configuration->getInformation()->begin();
148  text_tmap::iterator end  = this->configuration->getInformation()->end();
149  if (here != end) {
150    output << "    <gsdl xmlns=\"http://www.greenstone.org/namespace/gsdl_oaiinfo/1.0/gsdl_oaiinfo\"\n";
151    output << "       xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n";
152    output << "       xsi:schemaLocation=\"http://www.greenstone.org/namespace/gsdl_oaiinfo/1.0/gsdl_oaiinfo\n";
153    output << "         http://www.greenstone.org/namespace/gsdl_oaiinfo/1.0/gsdl_oaiinfo.xsd\">\n";
154 
155
156    while (here != end) {
157      output << utf8convert << "      <Metadata name=\"" << here->first << "\">" << here->second << "</Metadata>\n";
158      ++here;
159    }
160    output << "    </gsdl>\n";
161  }
162 
163  output << utf8convert << "  </description>\n";
164 
165  return true;
166}
167
Note: See TracBrowser for help on using the browser.