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

Last change on this file since 543 was 534, checked in by sjboddie, 25 years ago

added gpl notice

  • Property svn:keywords set to Author Date Id Revision
File size: 11.1 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 * $Id: collectserver.cpp 534 1999-09-07 04:57:43Z sjboddie $
26 *
27 *********************************************************************/
28
29/*
30 $Log$
31 Revision 1.15 1999/09/07 04:57:20 sjboddie
32 added gpl notice
33
34 Revision 1.14 1999/08/31 22:34:55 rjmcnab
35 Changes to get compiling on AIX.
36
37 Revision 1.13 1999/08/25 04:50:00 sjboddie
38 changed FilterRequest_t::docSet into an array
39
40 Revision 1.12 1999/08/20 01:05:41 sjboddie
41 fixed a bug (or created another one)
42
43 Revision 1.11 1999/08/03 03:32:53 sjboddie
44 added ability to set receptionist from configuration files
45
46 Revision 1.10 1999/07/08 03:58:44 sjboddie
47 format stuff
48
49 Revision 1.9 1999/06/16 02:00:34 sjboddie
50 Few changes to get getParent filter option to return metadata of
51 parents as well as current OID
52
53 Revision 1.8 1999/05/10 03:43:47 sjboddie
54 lots of changes to lots of files - getting document action going
55
56 Revision 1.7 1999/04/30 02:00:45 sjboddie
57 lots of stuff to do with getting documentaction working
58
59 Revision 1.6 1999/04/06 22:20:29 rjmcnab
60 Got browsefilter working.
61
62 Revision 1.5 1999/03/31 23:44:44 rjmcnab
63 Altered the protocol so that the metadata is part of the filter.
64
65 Revision 1.4 1999/03/09 20:58:50 rjmcnab
66 Added dummy filter and metadata results.
67
68 Revision 1.3 1999/03/08 05:07:42 rjmcnab
69 Made some alterations to fit with the changes to the comtypes. Added the
70 "filteroptdefault" configuration option to alter default filter options.
71
72 Revision 1.2 1999/03/03 23:28:29 sjboddie
73
74 Provided stub functions for the protocol
75
76 Revision 1.1 1999/02/21 22:32:56 rjmcnab
77
78 Initial revision.
79
80 */
81
82
83#include "collectserver.h"
84#include "infodbclass.h"
85#include "OIDtools.h"
86#include <assert.h>
87
88
89collectserver::collectserver () {
90 configinfo.collection = "null";
91}
92
93collectserver::~collectserver () {
94}
95
96// configure should be called for each line in the
97// configuration files to configure the collection server and everything
98// it contains. The configuration should take place just before initialisation.
99void collectserver::configure (const text_t &key, const text_tarray &cfgline) {
100 if (cfgline.size() >= 1) {
101 const text_t &value = cfgline[0];
102 if (key == "gsdlhome") configinfo.gsdlhome = value;
103 else if (key == "collection") {
104 configinfo.collection = value;
105 collectinfo.shortInfo.name = value;
106 } else if (key == "collectdir") configinfo.collectdir = value;
107 else if (key == "host") collectinfo.shortInfo.host = value;
108 else if (key == "port") collectinfo.shortInfo.port = value.getint();
109 else if (key == "public") {
110 if (value == "true") collectinfo.isPublic = true;
111 else collectinfo.isPublic = false;
112 } else if (key == "beta") {
113 if (value == "true") collectinfo.isBeta = true;
114 else collectinfo.isBeta = false;
115 } else if (key == "builddate") collectinfo.buildDate = value.getint();
116 else if (key == "languages") collectinfo.languages = cfgline;
117 else if (key == "numdocs") collectinfo.numDocs = value.getint();
118 else if (key == "numwords") collectinfo.numWords = value.getint();
119 else if (key == "numbytes") collectinfo.numBytes = value.getint();
120 else if (key == "format" && cfgline.size() == 2)
121 collectinfo.format[cfgline[0]] = cfgline[1];
122 else if (key == "receptionist") collectinfo.receptionist = value;
123 }
124
125 // configure the filters
126 filtermapclass::iterator filter_here = filters.begin();
127 filtermapclass::iterator filter_end = filters.end();
128 while (filter_here != filter_end) {
129 assert ((*filter_here).second.f != NULL);
130 if ((*filter_here).second.f != NULL)
131 (*filter_here).second.f->configure(key, cfgline);
132
133 filter_here++;
134 }
135
136 // configure the sources
137 sourcelistclass::iterator source_here = sources.begin();
138 sourcelistclass::iterator source_end = sources.end();
139 while (source_here != source_end) {
140 assert ((*source_here).s != NULL);
141 if ((*source_here).s != NULL)
142 (*source_here).s->configure(key, cfgline);
143
144 source_here++;
145 }
146}
147
148void collectserver::configure (const text_t &key, const text_t &value) {
149 text_tarray cfgline;
150 cfgline.push_back (value);
151 configure(key, cfgline);
152}
153
154
155bool collectserver::init (ostream &logout) {
156 // init the filters
157 filtermapclass::iterator filter_here = filters.begin();
158 filtermapclass::iterator filter_end = filters.end();
159 while (filter_here != filter_end) {
160 assert ((*filter_here).second.f != NULL);
161 if (((*filter_here).second.f != NULL) &&
162 !(*filter_here).second.f->init(logout)) return false;
163
164 filter_here++;
165 }
166
167 // init the sources
168 sourcelistclass::iterator source_here = sources.begin();
169 sourcelistclass::iterator source_end = sources.end();
170 while (source_here != source_end) {
171 assert ((*source_here).s != NULL);
172 if (((*source_here).s != NULL) &&
173 !(*source_here).s->init(logout)) return false;
174
175 source_here++;
176 }
177
178 return true;
179}
180
181
182void collectserver::get_collectinfo (ColInfoResponse_t &reponse,
183 comerror_t &err, ostream &/*logout*/) {
184 reponse = collectinfo;
185 err = noError;
186}
187
188void collectserver::get_filterinfo (InfoFiltersResponse_t &response,
189 comerror_t &err, ostream &/*logout*/) {
190 response.clear ();
191
192 // get a list of filter names
193 filtermapclass::iterator filter_here = filters.begin();
194 filtermapclass::iterator filter_end = filters.end();
195 while (filter_here != filter_end) {
196 response.filterNames.insert ((*filter_here).first);
197 filter_here++;
198 }
199
200 err = noError;
201}
202
203void collectserver::get_filteroptions (const InfoFilterOptionsRequest_t &request,
204 InfoFilterOptionsResponse_t &response,
205 comerror_t &err, ostream &logout) {
206 outconvertclass text_t2ascii;
207
208 filterclass *thisfilter = filters.getfilter(request.filterName);
209 if (thisfilter != NULL) {
210 thisfilter->get_filteroptions (response, err, logout);
211 } else {
212 response.clear ();
213 err = protocolError;
214 logout << text_t2ascii << "Protocol Error: filter options requested for non-existent\n"
215 << "filter \"" << request.filterName << "\".\n\n";
216 }
217}
218
219void collectserver::filter (FilterRequest_t &request,
220 FilterResponse_t &response,
221 comerror_t &err, ostream &logout) {
222 outconvertclass text_t2ascii;
223
224 // translate any ".fc", ".pr" etc. stuff in the docSet
225 text_t translatedOID;
226 text_tarray translatedOIDs;
227 text_tarray::iterator doc_here = request.docSet.begin();
228 text_tarray::iterator doc_end = request.docSet.end();
229 while (doc_here != doc_end) {
230 if (needs_translating (*doc_here)) {
231 sourcelistclass::iterator source_here = sources.begin();
232 sourcelistclass::iterator source_end = sources.end();
233 while (source_here != source_end) {
234 assert ((*source_here).s != NULL);
235 if (((*source_here).s != NULL) &&
236 ((*source_here).s->translate_OID (*doc_here, translatedOID, err, logout))) {
237 if (err != noError) return;
238 break;
239 }
240 source_here++;
241 }
242 translatedOIDs.push_back (translatedOID);
243 } else {
244 translatedOIDs.push_back (*doc_here);
245 }
246 doc_here ++;
247 }
248 request.docSet = translatedOIDs;
249
250 response.clear();
251
252 filterclass *thisfilter = filters.getfilter(request.filterName);
253 if (thisfilter != NULL) {
254 // filter the data
255 thisfilter->filter (request, response, err, logout);
256
257 // fill in the metadata for each of the OIDs (if it is requested)
258 if (request.filterResultOptions & FRmetadata) {
259 bool processed = false;
260 ResultDocInfo_tarray::iterator resultdoc_here = response.docInfo.begin();
261 ResultDocInfo_tarray::iterator resultdoc_end = response.docInfo.end();
262 while (resultdoc_here != resultdoc_end) {
263 // try each of the sources in turn
264 sourcelistclass::iterator source_here = sources.begin();
265 sourcelistclass::iterator source_end = sources.end();
266 while (source_here != source_end) {
267 assert ((*source_here).s != NULL);
268 if (((*source_here).s != NULL) &&
269 ((*source_here).s->get_metadata(request.requestParams, request.refParams,
270 request.getParents, request.fields,
271 (*resultdoc_here).OID, (*resultdoc_here).metadata,
272 err, logout))) {
273 if (err != noError) return;
274 processed = true;
275 break;
276 }
277
278 source_here++;
279 }
280 if (!processed) {
281 err = protocolError;
282 return;
283 }
284 resultdoc_here++;
285 }
286 }
287
288 } else {
289 response.clear ();
290 err = protocolError;
291 logout << text_t2ascii << "Protocol Error: filter options requested for non-existent\n"
292 << "filter \"" << request.filterName << "\".\n\n";
293 }
294
295 err = noError;
296}
297
298void collectserver::get_document (const DocumentRequest_t &request,
299 DocumentResponse_t &response,
300 comerror_t &err, ostream &logout) {
301
302 sourcelistclass::iterator source_here = sources.begin();
303 sourcelistclass::iterator source_end = sources.end();
304 while (source_here != source_end) {
305 assert ((*source_here).s != NULL);
306 if (((*source_here).s != NULL) &&
307 ((*source_here).s->get_document (request.OID, response.doc, err, logout))) {
308 if (err != noError) return;
309 break;
310 }
311 source_here++;
312 }
313}
314
315
316bool operator==(const collectserverptr &x, const collectserverptr &y) {
317 return (x.c == y.c);
318}
319
320bool operator<(const collectserverptr &x, const collectserverptr &y) {
321 return (x.c < y.c);
322}
323
324
325// thecollectserver remains the property of the calling code but
326// should not be deleted until it is removed from this list.
327void collectservermapclass::addcollectserver (collectserver *thecollectserver) {
328 // can't add a null collection server
329 assert (thecollectserver != NULL);
330 if (thecollectserver == NULL) return;
331
332 // can't add an collection server with no collection name
333 assert (!(thecollectserver->get_collection_name()).empty());
334 if ((thecollectserver->get_collection_name()).empty()) return;
335
336 collectserverptr cptr;
337 cptr.c = thecollectserver;
338 collectserverptrs[thecollectserver->get_collection_name()] = cptr;
339}
340
341// getcollectserver will return NULL if the collectserver could not be found
342collectserver *collectservermapclass::getcollectserver (const text_t &collection) {
343 // can't find a collection with no name
344 assert (!collection.empty());
345 if (collection.empty()) return NULL;
346
347 iterator here = collectserverptrs.find (collection);
348 if (here == collectserverptrs.end()) return NULL;
349
350 return (*here).second.c;
351}
352
Note: See TracBrowser for help on using the repository browser.