source: main/tags/2.10/gsdl/src/colservr/collectserver.cpp@ 32704

Last change on this file since 32704 was 650, checked in by sjboddie, 25 years ago
  • metadata now returns map rather than array
  • redesigned browsing support (although it's not finished so

won't currently work ;-)

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