source: trunk/gsdl/src/colservr/collectserver.cpp@ 4824

Last change on this file since 4824 was 4774, checked in by sjboddie, 21 years ago

No longer show search page (or search form on "about" page) if a collection
doesn't have at least one searchable index. Note that this change includes
the addition of an is_searchable() function to the protocol.

  • Property svn:keywords set to Author Date Id Revision
File size: 12.0 KB
Line 
1
2/**********************************************************************
3 *
4 * collectserver.cpp --
5 * Copyright (C) 1999 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 "collectserver.h"
28#include "infodbclass.h"
29#include "OIDtools.h"
30#include <assert.h>
31
32
33collectserver::collectserver () {
34 configinfo.collection = "null";
35}
36
37collectserver::~collectserver () {
38
39 // clean up the sources
40 sourcelistclass::iterator source_here = sources.begin();
41 sourcelistclass::iterator source_end = sources.end();
42 while (source_here != source_end) {
43 if ((*source_here).s != NULL)
44 delete (*source_here).s;
45 source_here++;
46 }
47 sources.clear();
48
49 // clean up the filters
50 filtermapclass::iterator filter_here = filters.begin();
51 filtermapclass::iterator filter_end = filters.end();
52 while (filter_here != filter_end) {
53 if ((*filter_here).second.f != NULL)
54 delete (*filter_here).second.f;
55 filter_here++;
56 }
57 filters.clear();
58}
59
60// configure should be called for each line in the
61// configuration files to configure the collection server and everything
62// it contains. The configuration should take place just before initialisation.
63void collectserver::configure (const text_t &key, const text_tarray &cfgline) {
64 if (cfgline.size() >= 1) {
65 const text_t &value = cfgline[0];
66 if (key == "gsdlhome") configinfo.gsdlhome = value;
67 else if (key == "gdbmhome") configinfo.gdbmhome = value;
68 else if (key == "collection") {
69 configinfo.collection = value;
70 collectinfo.shortInfo.name = value;
71 } else if (key == "collectdir") configinfo.collectdir = value;
72 else if (key == "host") collectinfo.shortInfo.host = value;
73 else if (key == "port") collectinfo.shortInfo.port = value.getint();
74 else if (key == "public") {
75 if (value == "true") collectinfo.isPublic = true;
76 else collectinfo.isPublic = false;
77 } else if (key == "beta") {
78 if (value == "true") collectinfo.isBeta = true;
79 else collectinfo.isBeta = false;
80 } else if ((key == "ccscols") || (key == "supercollection")) collectinfo.ccsCols = cfgline;
81 else if (key == "builddate") collectinfo.buildDate = value.getint();
82 else if (key == "languages") collectinfo.languages = cfgline;
83 else if (key == "numdocs") collectinfo.numDocs = value.getint();
84 else if (key == "numsections") collectinfo.numSections = value.getint();
85 else if (key == "numwords") collectinfo.numWords = value.getint();
86 else if (key == "numbytes") collectinfo.numBytes = value.getint();
87 else if (key == "collectionmeta" && cfgline.size() == 2)
88 collectinfo.collectionmeta[cfgline[0]] = cfgline[1];
89 else if (key == "format" && cfgline.size() == 2)
90 collectinfo.format[cfgline[0]] = cfgline[1];
91 else if (key == "building" && cfgline.size() == 2)
92 collectinfo.building[cfgline[0]] = cfgline[1];
93 else if (key == "httpdomain") collectinfo.httpdomain = value;
94 else if (key == "httpprefix") collectinfo.httpprefix = value;
95 else if (key == "receptionist") collectinfo.receptionist = value;
96 else if (key == "buildtype") collectinfo.buildType = value;
97 else if (key == "searchtype") { // means buildtype is mgpp
98 collectinfo.buildType = "mgpp";
99 collectinfo.searchTypes = cfgline;
100 }
101 }
102
103 // configure the filters
104 filtermapclass::iterator filter_here = filters.begin();
105 filtermapclass::iterator filter_end = filters.end();
106 while (filter_here != filter_end) {
107 assert ((*filter_here).second.f != NULL);
108 if ((*filter_here).second.f != NULL)
109 (*filter_here).second.f->configure(key, cfgline);
110
111 filter_here++;
112 }
113
114 // configure the sources
115 sourcelistclass::iterator source_here = sources.begin();
116 sourcelistclass::iterator source_end = sources.end();
117 while (source_here != source_end) {
118 assert ((*source_here).s != NULL);
119 if ((*source_here).s != NULL)
120 (*source_here).s->configure(key, cfgline);
121
122 source_here++;
123 }
124}
125
126void collectserver::configure (const text_t &key, const text_t &value) {
127 text_tarray cfgline;
128 cfgline.push_back (value);
129 configure(key, cfgline);
130}
131
132void collectserver::ping (bool &wasSuccess, comerror_t &error, ostream &logout) {
133 // if we've not been properly configured, then it is a foregone
134 // conclusion that we cannot be active
135 if (this->configinfo.collection == "null")
136 {
137 wasSuccess = false;
138 }
139 // if no build date exists, then the collection was probably not built;
140 // ditto if the number of documents is zero, then something is pretty
141 // wrong
142 else if (this->collectinfo.buildDate == 0 ||
143 this->collectinfo.numDocs == 0)
144 {
145 wasSuccess = false;
146 }
147 // it is probably okay
148 else
149 wasSuccess = true;
150}
151
152
153bool collectserver::init (ostream &logout) {
154 // init the filters
155 filtermapclass::iterator filter_here = filters.begin();
156 filtermapclass::iterator filter_end = filters.end();
157 while (filter_here != filter_end) {
158 assert ((*filter_here).second.f != NULL);
159 if (((*filter_here).second.f != NULL) &&
160 !(*filter_here).second.f->init(logout)) return false;
161
162 filter_here++;
163 }
164
165 // init the sources
166 sourcelistclass::iterator source_here = sources.begin();
167 sourcelistclass::iterator source_end = sources.end();
168 while (source_here != source_end) {
169 assert ((*source_here).s != NULL);
170 if (((*source_here).s != NULL) &&
171 !(*source_here).s->init(logout)) return false;
172
173 source_here++;
174 }
175
176 return true;
177}
178
179
180void collectserver::get_collectinfo (ColInfoResponse_t &reponse,
181 comerror_t &err, ostream &/*logout*/) {
182 reponse = collectinfo;
183 err = noError;
184}
185
186void collectserver::get_filterinfo (InfoFiltersResponse_t &response,
187 comerror_t &err, ostream &/*logout*/) {
188 response.clear ();
189
190 // get a list of filter names
191 filtermapclass::iterator filter_here = filters.begin();
192 filtermapclass::iterator filter_end = filters.end();
193 while (filter_here != filter_end) {
194 response.filterNames.insert ((*filter_here).first);
195 filter_here++;
196 }
197
198 err = noError;
199}
200
201void collectserver::get_filteroptions (const InfoFilterOptionsRequest_t &request,
202 InfoFilterOptionsResponse_t &response,
203 comerror_t &err, ostream &logout) {
204 outconvertclass text_t2ascii;
205
206 filterclass *thisfilter = filters.getfilter(request.filterName);
207 if (thisfilter != NULL) {
208 thisfilter->get_filteroptions (response, err, logout);
209 } else {
210 response.clear ();
211 err = protocolError;
212 logout << text_t2ascii << "Protocol Error: filter options requested for non-existent\n"
213 << "filter \"" << request.filterName << "\".\n\n";
214 }
215}
216
217void collectserver::filter (FilterRequest_t &request,
218 FilterResponse_t &response,
219 comerror_t &err, ostream &logout) {
220 outconvertclass text_t2ascii;
221
222 // translate any ".fc", ".pr" etc. stuff in the docSet
223 text_t translatedOID;
224 text_tarray translatedOIDs;
225 text_tarray::iterator doc_here = request.docSet.begin();
226 text_tarray::iterator doc_end = request.docSet.end();
227 while (doc_here != doc_end) {
228 if (needs_translating (*doc_here)) {
229 sourcelistclass::iterator source_here = sources.begin();
230 sourcelistclass::iterator source_end = sources.end();
231 while (source_here != source_end) {
232 assert ((*source_here).s != NULL);
233 if (((*source_here).s != NULL) &&
234 ((*source_here).s->translate_OID (*doc_here, translatedOID, err, logout))) {
235 if (err != noError) return;
236 break;
237 }
238 source_here++;
239 }
240 translatedOIDs.push_back (translatedOID);
241 } else {
242 translatedOIDs.push_back (*doc_here);
243 }
244 doc_here ++;
245 }
246 request.docSet = translatedOIDs;
247
248 response.clear();
249
250 filterclass *thisfilter = filters.getfilter(request.filterName);
251 if (thisfilter != NULL) {
252 // filter the data
253 thisfilter->filter (request, response, err, logout);
254 if (err != noError) return;
255 // fill in the metadata for each of the OIDs (if it is requested)
256 if (request.filterResultOptions & FRmetadata) {
257 bool processed = false;
258 ResultDocInfo_tarray::iterator resultdoc_here = response.docInfo.begin();
259 ResultDocInfo_tarray::iterator resultdoc_end = response.docInfo.end();
260 while (resultdoc_here != resultdoc_end) {
261 // try each of the sources in turn
262 sourcelistclass::iterator source_here = sources.begin();
263 sourcelistclass::iterator source_end = sources.end();
264 while (source_here != source_end) {
265 assert ((*source_here).s != NULL);
266 if (((*source_here).s != NULL) &&
267 ((*source_here).s->get_metadata(request.requestParams, request.refParams,
268 request.getParents, request.fields,
269 (*resultdoc_here).OID, (*resultdoc_here).metadata,
270 err, logout))) {
271 if (err != noError) return;
272 processed = true;
273 break;
274 }
275 source_here++;
276 }
277 if (!processed) {
278 err = protocolError;
279 return;
280 }
281 resultdoc_here++;
282 }
283 }
284
285 } else {
286 response.clear ();
287 err = protocolError;
288 logout << text_t2ascii << "Protocol Error: filter options requested for non-existent\n"
289 << "filter \"" << request.filterName << "\".\n\n";
290 }
291
292 err = noError;
293}
294
295void collectserver::get_document (const DocumentRequest_t &request,
296 DocumentResponse_t &response,
297 comerror_t &err, ostream &logout) {
298
299 sourcelistclass::iterator source_here = sources.begin();
300 sourcelistclass::iterator source_end = sources.end();
301 while (source_here != source_end) {
302 assert ((*source_here).s != NULL);
303 if (((*source_here).s != NULL) &&
304 ((*source_here).s->get_document (request.OID, response.doc, err, logout))) {
305 if (err != noError) return;
306 break;
307 }
308 source_here++;
309 }
310}
311
312void collectserver::is_searchable (bool &issearchable, comerror_t &err,
313 ostream &logout) {
314
315 sourcelistclass::iterator source_here = sources.begin();
316 sourcelistclass::iterator source_end = sources.end();
317 while (source_here != source_end) {
318 assert ((*source_here).s != NULL);
319 if (((*source_here).s != NULL) &&
320 ((*source_here).s->is_searchable (issearchable, err, logout))) {
321 if (err != noError) return;
322 break;
323 }
324 source_here++;
325 }
326}
327
328
329bool operator==(const collectserverptr &x, const collectserverptr &y) {
330 return (x.c == y.c);
331}
332
333bool operator<(const collectserverptr &x, const collectserverptr &y) {
334 return (x.c < y.c);
335}
336
337
338// thecollectserver remains the property of the calling code but
339// should not be deleted until it is removed from this list.
340void collectservermapclass::addcollectserver (collectserver *thecollectserver) {
341 // can't add a null collection server
342 assert (thecollectserver != NULL);
343 if (thecollectserver == NULL) return;
344
345 // can't add an collection server with no collection name
346 assert (!(thecollectserver->get_collection_name()).empty());
347 if ((thecollectserver->get_collection_name()).empty()) return;
348
349 collectserverptr cptr;
350 cptr.c = thecollectserver;
351 collectserverptrs[thecollectserver->get_collection_name()] = cptr;
352}
353
354// getcollectserver will return NULL if the collectserver could not be found
355collectserver *collectservermapclass::getcollectserver (const text_t &collection) {
356 // can't find a collection with no name
357 if (collection.empty()) return NULL;
358
359 iterator here = collectserverptrs.find (collection);
360 if (here == collectserverptrs.end()) return NULL;
361
362 return (*here).second.c;
363}
Note: See TracBrowser for help on using the repository browser.