source: main/trunk/greenstone2/runtime-src/src/colservr/comtypes.cpp@ 24114

Last change on this file since 24114 was 24114, checked in by ak19, 13 years ago

Now GS2 works out the earliestDatestamp of the repository in the manner GS3 does it (read each OAI-enabled collection's build.cfg to get the collection's earliestDatestamp field and choose the oldest such date among the OAI collections). Previously GS2 used to always set the earliestDatestamp to the unix epoch of 1970, which, while it would validate, wasn't the right thing to do as it wouldn't help with resumptiontokens and other date based things. Checked that the GS server still validates.

File size: 7.6 KB
Line 
1/**********************************************************************
2 *
3 * comtypes.cpp --
4 * Copyright (C) 1999 The New Zealand Digital Library Project
5 *
6 * A component of the Greenstone digital library software
7 * from the New Zealand Digital Library Project at the
8 * University of Waikato, New Zealand.
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 *
24 *********************************************************************/
25
26#include "comtypes.h"
27
28
29text_t get_comerror_string (comerror_t err) {
30 if (err == noError) return "no error";
31 else if (err == authenticationFailure) return "authentication failure";
32 else if (err == protocolError) return "protocol error";
33 else if (err == configurationError) return "configuration error";
34 else if (err == systemProblem) return "system problem";
35 else if (err == syntaxError) return "query syntax error";
36 return "unknown problem";
37}
38
39
40void ShortColInfo_t::clear() {
41 name.clear();
42 host.clear();
43 port = 0;
44}
45
46/*
47 isPublic now defaults to true most values are default
48 similar to a constructor in a class to make some initializations
49*/
50
51void ColInfoResponse_t::clear () {
52 shortInfo.clear();
53 useBook=false;
54 isPublic=true;
55 isBeta=false;
56 isSegmented=false;
57 isCollectGroup=false;
58 languages.erase(languages.begin(), languages.end());
59 ccsCols.erase(ccsCols.begin(), ccsCols.end());
60 ccsOptions = 0;
61 stemIndexes = 3; // old default was both provided
62 buildDate=0;
63 buildType.clear();
64 earliestDatestamp.clear();
65 numDocs=0;
66 numSections=0;
67 numWords=0;
68 numBytes=0;
69 format.erase(format.begin(), format.end());
70 building.erase(building.begin(), building.end());
71 httpdomain.clear();
72 httpprefix.clear();
73 receptionist.clear();
74
75 // Setting some authentication parameters use with
76 // various parts of the code.
77
78 authenticate.clear(); // turned off by default, individual collection authentication
79 auth_group.clear(); // turned off by default, authentication by groups method
80 public_documents.clear(); // turned off by default, allow access to these documents <list>
81 private_documents.clear(); // turned off by default, disallow access to these documents <list>
82
83}
84
85text_t ColInfoResponse_t::get_collectionmeta(text_t name, text_t lang) {
86 text_t value = collectionmeta[name][lang];
87 if (value.empty()) {
88 value = collectionmeta[name][g_EmptyText];
89 }
90 return value;
91
92}
93
94void InfoFiltersResponse_t::clear () {
95 filterNames.erase(filterNames.begin(), filterNames.end());
96}
97
98
99void InfoFilterOptionsRequest_t::clear () {
100 filterName.clear();
101}
102
103
104void FilterOption_t::clear () {
105 name.clear();
106 type = booleant;
107 repeatable = onePerQuery;
108 defaultValue.clear();
109 validValues.erase(validValues.begin(), validValues.end());
110}
111
112void FilterOption_t::check_defaultValue () {
113 text_tarray::iterator here, end;
114
115 // how the default is interpreted depends on the option type
116 switch (type) {
117 case booleant:
118 case enumeratedt: // has to be one of the validValues
119 here = validValues.begin ();
120 end = validValues.end ();
121 while (here != end) {
122 if (*here == defaultValue) return;
123 ++here;
124 }
125
126 break;
127
128 case integert: // has to be in the validValues range
129 if ((validValues.size() >= 2) &&
130 (validValues[0].getint() <= defaultValue.getint()) &&
131 (validValues[1].getint() >= defaultValue.getint()))
132 return;
133 break;
134
135 case stringt: // any value is valid
136 return;
137 }
138
139 // did not find the defaultValue
140 if (validValues.empty()) defaultValue.clear();
141 else defaultValue = validValues[0];
142}
143
144
145bool operator==(const FilterOption_t &x, const FilterOption_t &y) {
146 return ((x.name == y.name) &&
147 (x.type == y.type) &&
148 (x.repeatable == y.repeatable) &&
149 (x.defaultValue == y.defaultValue) &&
150 (x.validValues == y.validValues));
151}
152
153bool operator<(const FilterOption_t &x, const FilterOption_t &y) {
154 return ((x.name < y.name) ||
155 ((x.name == y.name) &&
156 ((x.type < y.type) ||
157 ((x.type == y.type) &&
158 ((x.repeatable < y.repeatable) ||
159 ((x.repeatable == y.repeatable) &&
160 ((x.defaultValue < y.defaultValue) ||
161 ((x.defaultValue == y.defaultValue) &&
162 (x.validValues < y.validValues)))))))));
163}
164
165
166
167void InfoFilterOptionsResponse_t::clear () {
168 filterOptions.erase(filterOptions.begin(), filterOptions.end());
169}
170
171
172void OptionValue_t::clear () {
173 name.clear();
174 value.clear();
175}
176
177
178void FilterRequest_t::clear () {
179 filterName.clear();
180 filterLang.clear();
181 filterOptions.erase(filterOptions.begin(), filterOptions.end());
182 docSet.erase(docSet.begin(), docSet.end());
183 filterResultOptions = 0;
184 requestParams.clear();
185 refParams.clear();
186 fields.erase(fields.begin(), fields.end());
187 getParents = false;
188}
189
190
191void TermInfo_t::clear () {
192 term.clear();
193 freq = 0;
194 matchTerms.erase (matchTerms.begin(), matchTerms.end());
195}
196
197
198void MetadataInfo_t::clear () {
199 params.clear();
200 isRef = false;
201 values.erase(values.begin(), values.end());
202 if (parent != NULL) {
203 delete parent;
204 parent = NULL;
205 }
206}
207
208MetadataInfo_t::MetadataInfo_t () {parent=NULL;clear();}
209
210// copy constructor
211MetadataInfo_t::MetadataInfo_t (const MetadataInfo_t &x) {
212 params = x.params;
213 isRef = x.isRef;
214 values = x.values;
215 if (x.parent == NULL) parent = NULL;
216 else {
217 parent = new MetadataInfo_t ();
218 *parent = *(x.parent);
219 }
220}
221
222MetadataInfo_t::~MetadataInfo_t () {
223 if (parent != NULL) {
224 delete parent;
225 parent = NULL;
226 }
227}
228
229MetadataInfo_t &MetadataInfo_t::operator=(const MetadataInfo_t &x) {
230 if (&x != this) {
231 params = x.params;
232 isRef = x.isRef;
233 values = x.values;
234 if (x.parent == NULL) parent = NULL;
235 else {
236 parent = new MetadataInfo_t ();
237 *parent = *(x.parent);
238 }
239 }
240 return *this;
241}
242
243void ResultDocInfo_t::clear () {
244 OID.clear ();
245 ranking = 0;
246 result_num = 0;
247 num_terms_matched = 0;
248 num_phrase_match = 0;
249 docFreq.erase(docFreq.begin(), docFreq.end());
250 metadata.erase(metadata.begin(), metadata.end());
251 classifier_metadata_type.erase(classifier_metadata_type.begin(),
252 classifier_metadata_type.end());
253 classifier_metadata_offset = 0;
254
255}
256
257ResultDocInfo_t &ResultDocInfo_t::operator=(const ResultDocInfo_t &x) {
258 OID = x.OID;
259 ranking = x.ranking;
260 result_num = x.result_num;
261 num_terms_matched = x.num_terms_matched;
262 num_phrase_match = x.num_phrase_match;
263 docFreq = x.docFreq;
264 metadata = x.metadata;
265 return *this;
266}
267
268void FilterResponse_t::clear () {
269 error_message = g_EmptyText;
270 numDocs = 0;
271 isApprox = Exact;
272 termInfo.erase (termInfo.begin(), termInfo.end());
273 docInfo.erase (docInfo.begin(), docInfo.end());
274 stopwords.clear();
275}
276
277FilterResponse_t &FilterResponse_t::operator=(const FilterResponse_t &x) {
278 error_message = x.error_message;
279 numDocs = x.numDocs;
280 isApprox = x.isApprox;
281 termInfo = x.termInfo;
282 docInfo = x.docInfo;
283 stopwords = x.stopwords;
284 return *this;
285}
286
287void DocumentRequest_t::clear () {
288 OID.clear();
289 docType.clear();
290 docFormat.clear();
291}
292
293void DocumentResponse_t::clear () {
294 doc.clear();
295}
Note: See TracBrowser for help on using the repository browser.