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

Last change on this file since 1860 was 1860, checked in by cs025, 23 years ago

Included CORBA branch for first time

  • Property svn:keywords set to Author Date Id Revision
File size: 10.7 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") 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
128
129bool collectserver::init (ostream &logout) {
130 // init 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->init(logout)) return false;
137
138 filter_here++;
139 }
140
141 // init 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->init(logout)) return false;
148
149 source_here++;
150 }
151
152 return true;
153}
154
155
156void collectserver::get_collectinfo (ColInfoResponse_t &reponse,
157 comerror_t &err, ostream &/*logout*/) {
158 reponse = collectinfo;
159 err = noError;
160}
161
162void collectserver::get_filterinfo (InfoFiltersResponse_t &response,
163 comerror_t &err, ostream &/*logout*/) {
164 response.clear ();
165
166 // get a list of filter names
167 filtermapclass::iterator filter_here = filters.begin();
168 filtermapclass::iterator filter_end = filters.end();
169 while (filter_here != filter_end) {
170 response.filterNames.insert ((*filter_here).first);
171 filter_here++;
172 }
173
174 err = noError;
175}
176
177void collectserver::get_filteroptions (const InfoFilterOptionsRequest_t &request,
178 InfoFilterOptionsResponse_t &response,
179 comerror_t &err, ostream &logout) {
180 outconvertclass text_t2ascii;
181
182 filterclass *thisfilter = filters.getfilter(request.filterName);
183 if (thisfilter != NULL) {
184 thisfilter->get_filteroptions (response, err, logout);
185 } else {
186 response.clear ();
187 err = protocolError;
188 logout << text_t2ascii << "Protocol Error: filter options requested for non-existent\n"
189 << "filter \"" << request.filterName << "\".\n\n";
190 }
191}
192
193void collectserver::filter (FilterRequest_t &request,
194 FilterResponse_t &response,
195 comerror_t &err, ostream &logout) {
196 outconvertclass text_t2ascii;
197
198 // translate any ".fc", ".pr" etc. stuff in the docSet
199 text_t translatedOID;
200 text_tarray translatedOIDs;
201 text_tarray::iterator doc_here = request.docSet.begin();
202 text_tarray::iterator doc_end = request.docSet.end();
203 while (doc_here != doc_end) {
204 if (needs_translating (*doc_here)) {
205 sourcelistclass::iterator source_here = sources.begin();
206 sourcelistclass::iterator source_end = sources.end();
207 while (source_here != source_end) {
208 assert ((*source_here).s != NULL);
209 if (((*source_here).s != NULL) &&
210 ((*source_here).s->translate_OID (*doc_here, translatedOID, err, logout))) {
211 if (err != noError) return;
212 break;
213 }
214 source_here++;
215 }
216 translatedOIDs.push_back (translatedOID);
217 } else {
218 translatedOIDs.push_back (*doc_here);
219 }
220 doc_here ++;
221 }
222 request.docSet = translatedOIDs;
223
224 response.clear();
225
226 filterclass *thisfilter = filters.getfilter(request.filterName);
227 if (thisfilter != NULL) {
228 // filter the data
229 thisfilter->filter (request, response, err, logout);
230
231 // fill in the metadata for each of the OIDs (if it is requested)
232 if (request.filterResultOptions & FRmetadata) {
233 bool processed = false;
234 ResultDocInfo_tarray::iterator resultdoc_here = response.docInfo.begin();
235 ResultDocInfo_tarray::iterator resultdoc_end = response.docInfo.end();
236 while (resultdoc_here != resultdoc_end) {
237 // try each of the sources in turn
238 sourcelistclass::iterator source_here = sources.begin();
239 sourcelistclass::iterator source_end = sources.end();
240 while (source_here != source_end) {
241 assert ((*source_here).s != NULL);
242 if (((*source_here).s != NULL) &&
243 ((*source_here).s->get_metadata(request.requestParams, request.refParams,
244 request.getParents, request.fields,
245 (*resultdoc_here).OID, (*resultdoc_here).metadata,
246 err, logout))) {
247 if (err != noError) return;
248 processed = true;
249 break;
250 }
251 source_here++;
252 }
253 if (!processed) {
254 err = protocolError;
255 return;
256 }
257 resultdoc_here++;
258 }
259 }
260
261 } else {
262 response.clear ();
263 err = protocolError;
264 logout << text_t2ascii << "Protocol Error: filter options requested for non-existent\n"
265 << "filter \"" << request.filterName << "\".\n\n";
266 }
267
268 err = noError;
269}
270
271void collectserver::get_document (const DocumentRequest_t &request,
272 DocumentResponse_t &response,
273 comerror_t &err, ostream &logout) {
274
275 sourcelistclass::iterator source_here = sources.begin();
276 sourcelistclass::iterator source_end = sources.end();
277 while (source_here != source_end) {
278 assert ((*source_here).s != NULL);
279 if (((*source_here).s != NULL) &&
280 ((*source_here).s->get_document (request.OID, response.doc, err, logout))) {
281 if (err != noError) return;
282 break;
283 }
284 source_here++;
285 }
286}
287
288
289bool operator==(const collectserverptr &x, const collectserverptr &y) {
290 return (x.c == y.c);
291}
292
293bool operator<(const collectserverptr &x, const collectserverptr &y) {
294 return (x.c < y.c);
295}
296
297
298// thecollectserver remains the property of the calling code but
299// should not be deleted until it is removed from this list.
300void collectservermapclass::addcollectserver (collectserver *thecollectserver) {
301 // can't add a null collection server
302 assert (thecollectserver != NULL);
303 if (thecollectserver == NULL) return;
304
305 // can't add an collection server with no collection name
306 assert (!(thecollectserver->get_collection_name()).empty());
307 if ((thecollectserver->get_collection_name()).empty()) return;
308
309 collectserverptr cptr;
310 cptr.c = thecollectserver;
311 collectserverptrs[thecollectserver->get_collection_name()] = cptr;
312}
313
314// getcollectserver will return NULL if the collectserver could not be found
315collectserver *collectservermapclass::getcollectserver (const text_t &collection) {
316 // can't find a collection with no name
317 if (collection.empty()) return NULL;
318
319 iterator here = collectserverptrs.find (collection);
320 if (here == collectserverptrs.end()) return NULL;
321
322 return (*here).second.c;
323}
Note: See TracBrowser for help on using the repository browser.