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