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

Last change on this file since 2712 was 2712, checked in by sjboddie, 23 years ago

"supercollection" is now a synonym for the "ccscols" collect.cfg option

  • Property svn:keywords set to Author Date Id Revision
File size: 11.4 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 }
98
99 // configure the filters
100 filtermapclass::iterator filter_here = filters.begin();
101 filtermapclass::iterator filter_end = filters.end();
102 while (filter_here != filter_end) {
103 assert ((*filter_here).second.f != NULL);
104 if ((*filter_here).second.f != NULL)
105 (*filter_here).second.f->configure(key, cfgline);
106
107 filter_here++;
108 }
109
110 // configure the sources
111 sourcelistclass::iterator source_here = sources.begin();
112 sourcelistclass::iterator source_end = sources.end();
113 while (source_here != source_end) {
114 assert ((*source_here).s != NULL);
115 if ((*source_here).s != NULL)
116 (*source_here).s->configure(key, cfgline);
117
118 source_here++;
119 }
120}
121
122void collectserver::configure (const text_t &key, const text_t &value) {
123 text_tarray cfgline;
124 cfgline.push_back (value);
125 configure(key, cfgline);
126}
127
128void collectserver::ping (bool &wasSuccess, comerror_t &error, ostream &logout) {
129 // if we've not been properly configured, then it is a foregone
130 // conclusion that we cannot be active
131 if (this->configinfo.collection == "null")
132 {
133 wasSuccess = false;
134 }
135 // if no build date exists, then the collection was probably not built;
136 // ditto if the number of documents is zero, then something is pretty
137 // wrong
138 else if (this->collectinfo.buildDate == 0 ||
139 this->collectinfo.numDocs == 0)
140 {
141 wasSuccess = false;
142 }
143 // it is probably okay
144 else
145 wasSuccess = true;
146}
147
148
149bool collectserver::init (ostream &logout) {
150 // init the filters
151 filtermapclass::iterator filter_here = filters.begin();
152 filtermapclass::iterator filter_end = filters.end();
153 while (filter_here != filter_end) {
154 assert ((*filter_here).second.f != NULL);
155 if (((*filter_here).second.f != NULL) &&
156 !(*filter_here).second.f->init(logout)) return false;
157
158 filter_here++;
159 }
160
161 // init the sources
162 sourcelistclass::iterator source_here = sources.begin();
163 sourcelistclass::iterator source_end = sources.end();
164 while (source_here != source_end) {
165 assert ((*source_here).s != NULL);
166 if (((*source_here).s != NULL) &&
167 !(*source_here).s->init(logout)) return false;
168
169 source_here++;
170 }
171
172 return true;
173}
174
175
176void collectserver::get_collectinfo (ColInfoResponse_t &reponse,
177 comerror_t &err, ostream &/*logout*/) {
178 reponse = collectinfo;
179 err = noError;
180}
181
182void collectserver::get_filterinfo (InfoFiltersResponse_t &response,
183 comerror_t &err, ostream &/*logout*/) {
184 response.clear ();
185
186 // get a list of filter names
187 filtermapclass::iterator filter_here = filters.begin();
188 filtermapclass::iterator filter_end = filters.end();
189 while (filter_here != filter_end) {
190 response.filterNames.insert ((*filter_here).first);
191 filter_here++;
192 }
193
194 err = noError;
195}
196
197void collectserver::get_filteroptions (const InfoFilterOptionsRequest_t &request,
198 InfoFilterOptionsResponse_t &response,
199 comerror_t &err, ostream &logout) {
200 outconvertclass text_t2ascii;
201
202 filterclass *thisfilter = filters.getfilter(request.filterName);
203 if (thisfilter != NULL) {
204 thisfilter->get_filteroptions (response, err, logout);
205 } else {
206 response.clear ();
207 err = protocolError;
208 logout << text_t2ascii << "Protocol Error: filter options requested for non-existent\n"
209 << "filter \"" << request.filterName << "\".\n\n";
210 }
211}
212
213void collectserver::filter (FilterRequest_t &request,
214 FilterResponse_t &response,
215 comerror_t &err, ostream &logout) {
216 outconvertclass text_t2ascii;
217
218 // translate any ".fc", ".pr" etc. stuff in the docSet
219 text_t translatedOID;
220 text_tarray translatedOIDs;
221 text_tarray::iterator doc_here = request.docSet.begin();
222 text_tarray::iterator doc_end = request.docSet.end();
223 while (doc_here != doc_end) {
224 if (needs_translating (*doc_here)) {
225 sourcelistclass::iterator source_here = sources.begin();
226 sourcelistclass::iterator source_end = sources.end();
227 while (source_here != source_end) {
228 assert ((*source_here).s != NULL);
229 if (((*source_here).s != NULL) &&
230 ((*source_here).s->translate_OID (*doc_here, translatedOID, err, logout))) {
231 if (err != noError) return;
232 break;
233 }
234 source_here++;
235 }
236 translatedOIDs.push_back (translatedOID);
237 } else {
238 translatedOIDs.push_back (*doc_here);
239 }
240 doc_here ++;
241 }
242 request.docSet = translatedOIDs;
243
244 response.clear();
245
246 filterclass *thisfilter = filters.getfilter(request.filterName);
247 if (thisfilter != NULL) {
248 // filter the data
249 thisfilter->filter (request, response, err, logout);
250
251 // fill in the metadata for each of the OIDs (if it is requested)
252 if (request.filterResultOptions & FRmetadata) {
253 bool processed = false;
254 ResultDocInfo_tarray::iterator resultdoc_here = response.docInfo.begin();
255 ResultDocInfo_tarray::iterator resultdoc_end = response.docInfo.end();
256 while (resultdoc_here != resultdoc_end) {
257 // try each of the sources in turn
258 sourcelistclass::iterator source_here = sources.begin();
259 sourcelistclass::iterator source_end = sources.end();
260 while (source_here != source_end) {
261 assert ((*source_here).s != NULL);
262 if (((*source_here).s != NULL) &&
263 ((*source_here).s->get_metadata(request.requestParams, request.refParams,
264 request.getParents, request.fields,
265 (*resultdoc_here).OID, (*resultdoc_here).metadata,
266 err, logout))) {
267 if (err != noError) return;
268 processed = true;
269 break;
270 }
271 source_here++;
272 }
273 if (!processed) {
274 err = protocolError;
275 return;
276 }
277 resultdoc_here++;
278 }
279 }
280
281 } else {
282 response.clear ();
283 err = protocolError;
284 logout << text_t2ascii << "Protocol Error: filter options requested for non-existent\n"
285 << "filter \"" << request.filterName << "\".\n\n";
286 }
287
288 err = noError;
289}
290
291void collectserver::get_document (const DocumentRequest_t &request,
292 DocumentResponse_t &response,
293 comerror_t &err, ostream &logout) {
294
295 sourcelistclass::iterator source_here = sources.begin();
296 sourcelistclass::iterator source_end = sources.end();
297 while (source_here != source_end) {
298 assert ((*source_here).s != NULL);
299 if (((*source_here).s != NULL) &&
300 ((*source_here).s->get_document (request.OID, response.doc, err, logout))) {
301 if (err != noError) return;
302 break;
303 }
304 source_here++;
305 }
306}
307
308
309bool operator==(const collectserverptr &x, const collectserverptr &y) {
310 return (x.c == y.c);
311}
312
313bool operator<(const collectserverptr &x, const collectserverptr &y) {
314 return (x.c < y.c);
315}
316
317
318// thecollectserver remains the property of the calling code but
319// should not be deleted until it is removed from this list.
320void collectservermapclass::addcollectserver (collectserver *thecollectserver) {
321 // can't add a null collection server
322 assert (thecollectserver != NULL);
323 if (thecollectserver == NULL) return;
324
325 // can't add an collection server with no collection name
326 assert (!(thecollectserver->get_collection_name()).empty());
327 if ((thecollectserver->get_collection_name()).empty()) return;
328
329 collectserverptr cptr;
330 cptr.c = thecollectserver;
331 collectserverptrs[thecollectserver->get_collection_name()] = cptr;
332}
333
334// getcollectserver will return NULL if the collectserver could not be found
335collectserver *collectservermapclass::getcollectserver (const text_t &collection) {
336 // can't find a collection with no name
337 if (collection.empty()) return NULL;
338
339 iterator here = collectserverptrs.find (collection);
340 if (here == collectserverptrs.end()) return NULL;
341
342 return (*here).second.c;
343}
Note: See TracBrowser for help on using the repository browser.