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

Last change on this file since 1285 was 1285, checked in by sjboddie, 24 years ago

Removed CVS logging information from source files

  • Property svn:keywords set to Author Date Id Revision
File size: 10.0 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
40// configure should be called for each line in the
41// configuration files to configure the collection server and everything
42// it contains. The configuration should take place just before initialisation.
43void collectserver::configure (const text_t &key, const text_tarray &cfgline) {
44 if (cfgline.size() >= 1) {
45 const text_t &value = cfgline[0];
46 if (key == "gsdlhome") configinfo.gsdlhome = value;
47 else if (key == "gdbmhome") configinfo.gdbmhome = value;
48 else if (key == "collection") {
49 configinfo.collection = value;
50 collectinfo.shortInfo.name = value;
51 } else if (key == "collectdir") configinfo.collectdir = value;
52 else if (key == "host") collectinfo.shortInfo.host = value;
53 else if (key == "port") collectinfo.shortInfo.port = value.getint();
54 else if (key == "public") {
55 if (value == "true") collectinfo.isPublic = true;
56 else collectinfo.isPublic = false;
57 } else if (key == "beta") {
58 if (value == "true") collectinfo.isBeta = true;
59 else collectinfo.isBeta = false;
60 } else if (key == "ccscols") collectinfo.ccsCols = cfgline;
61 else if (key == "builddate") collectinfo.buildDate = value.getint();
62 else if (key == "languages") collectinfo.languages = cfgline;
63 else if (key == "numdocs") collectinfo.numDocs = value.getint();
64 else if (key == "numsections") collectinfo.numSections = value.getint();
65 else if (key == "numwords") collectinfo.numWords = value.getint();
66 else if (key == "numbytes") collectinfo.numBytes = value.getint();
67 else if (key == "collectionmeta" && cfgline.size() == 2)
68 collectinfo.collectionmeta[cfgline[0]] = cfgline[1];
69 else if (key == "format" && cfgline.size() == 2)
70 collectinfo.format[cfgline[0]] = cfgline[1];
71 else if (key == "building" && cfgline.size() == 2)
72 collectinfo.building[cfgline[0]] = cfgline[1];
73 else if (key == "receptionist") collectinfo.receptionist = value;
74 }
75
76 // configure the filters
77 filtermapclass::iterator filter_here = filters.begin();
78 filtermapclass::iterator filter_end = filters.end();
79 while (filter_here != filter_end) {
80 assert ((*filter_here).second.f != NULL);
81 if ((*filter_here).second.f != NULL)
82 (*filter_here).second.f->configure(key, cfgline);
83
84 filter_here++;
85 }
86
87 // configure the sources
88 sourcelistclass::iterator source_here = sources.begin();
89 sourcelistclass::iterator source_end = sources.end();
90 while (source_here != source_end) {
91 assert ((*source_here).s != NULL);
92 if ((*source_here).s != NULL)
93 (*source_here).s->configure(key, cfgline);
94
95 source_here++;
96 }
97}
98
99void collectserver::configure (const text_t &key, const text_t &value) {
100 text_tarray cfgline;
101 cfgline.push_back (value);
102 configure(key, cfgline);
103}
104
105
106bool collectserver::init (ostream &logout) {
107 // init the filters
108 filtermapclass::iterator filter_here = filters.begin();
109 filtermapclass::iterator filter_end = filters.end();
110 while (filter_here != filter_end) {
111 assert ((*filter_here).second.f != NULL);
112 if (((*filter_here).second.f != NULL) &&
113 !(*filter_here).second.f->init(logout)) return false;
114
115 filter_here++;
116 }
117
118 // init the sources
119 sourcelistclass::iterator source_here = sources.begin();
120 sourcelistclass::iterator source_end = sources.end();
121 while (source_here != source_end) {
122 assert ((*source_here).s != NULL);
123 if (((*source_here).s != NULL) &&
124 !(*source_here).s->init(logout)) return false;
125
126 source_here++;
127 }
128
129 return true;
130}
131
132
133void collectserver::get_collectinfo (ColInfoResponse_t &reponse,
134 comerror_t &err, ostream &/*logout*/) {
135 reponse = collectinfo;
136 err = noError;
137}
138
139void collectserver::get_filterinfo (InfoFiltersResponse_t &response,
140 comerror_t &err, ostream &/*logout*/) {
141 response.clear ();
142
143 // get a list of filter names
144 filtermapclass::iterator filter_here = filters.begin();
145 filtermapclass::iterator filter_end = filters.end();
146 while (filter_here != filter_end) {
147 response.filterNames.insert ((*filter_here).first);
148 filter_here++;
149 }
150
151 err = noError;
152}
153
154void collectserver::get_filteroptions (const InfoFilterOptionsRequest_t &request,
155 InfoFilterOptionsResponse_t &response,
156 comerror_t &err, ostream &logout) {
157 outconvertclass text_t2ascii;
158
159 filterclass *thisfilter = filters.getfilter(request.filterName);
160 if (thisfilter != NULL) {
161 thisfilter->get_filteroptions (response, err, logout);
162 } else {
163 response.clear ();
164 err = protocolError;
165 logout << text_t2ascii << "Protocol Error: filter options requested for non-existent\n"
166 << "filter \"" << request.filterName << "\".\n\n";
167 }
168}
169
170void collectserver::filter (FilterRequest_t &request,
171 FilterResponse_t &response,
172 comerror_t &err, ostream &logout) {
173 outconvertclass text_t2ascii;
174
175 // translate any ".fc", ".pr" etc. stuff in the docSet
176 text_t translatedOID;
177 text_tarray translatedOIDs;
178 text_tarray::iterator doc_here = request.docSet.begin();
179 text_tarray::iterator doc_end = request.docSet.end();
180 while (doc_here != doc_end) {
181 if (needs_translating (*doc_here)) {
182 sourcelistclass::iterator source_here = sources.begin();
183 sourcelistclass::iterator source_end = sources.end();
184 while (source_here != source_end) {
185 assert ((*source_here).s != NULL);
186 if (((*source_here).s != NULL) &&
187 ((*source_here).s->translate_OID (*doc_here, translatedOID, err, logout))) {
188 if (err != noError) return;
189 break;
190 }
191 source_here++;
192 }
193 translatedOIDs.push_back (translatedOID);
194 } else {
195 translatedOIDs.push_back (*doc_here);
196 }
197 doc_here ++;
198 }
199 request.docSet = translatedOIDs;
200
201 response.clear();
202
203 filterclass *thisfilter = filters.getfilter(request.filterName);
204 if (thisfilter != NULL) {
205 // filter the data
206 thisfilter->filter (request, response, err, logout);
207
208 // fill in the metadata for each of the OIDs (if it is requested)
209 if (request.filterResultOptions & FRmetadata) {
210 bool processed = false;
211 ResultDocInfo_tarray::iterator resultdoc_here = response.docInfo.begin();
212 ResultDocInfo_tarray::iterator resultdoc_end = response.docInfo.end();
213 while (resultdoc_here != resultdoc_end) {
214 // try each of the sources in turn
215 sourcelistclass::iterator source_here = sources.begin();
216 sourcelistclass::iterator source_end = sources.end();
217 while (source_here != source_end) {
218 assert ((*source_here).s != NULL);
219 if (((*source_here).s != NULL) &&
220 ((*source_here).s->get_metadata(request.requestParams, request.refParams,
221 request.getParents, request.fields,
222 (*resultdoc_here).OID, (*resultdoc_here).metadata,
223 err, logout))) {
224 if (err != noError) return;
225 processed = true;
226 break;
227 }
228 source_here++;
229 }
230 if (!processed) {
231 err = protocolError;
232 return;
233 }
234 resultdoc_here++;
235 }
236 }
237
238 } else {
239 response.clear ();
240 err = protocolError;
241 logout << text_t2ascii << "Protocol Error: filter options requested for non-existent\n"
242 << "filter \"" << request.filterName << "\".\n\n";
243 }
244
245 err = noError;
246}
247
248void collectserver::get_document (const DocumentRequest_t &request,
249 DocumentResponse_t &response,
250 comerror_t &err, ostream &logout) {
251
252 sourcelistclass::iterator source_here = sources.begin();
253 sourcelistclass::iterator source_end = sources.end();
254 while (source_here != source_end) {
255 assert ((*source_here).s != NULL);
256 if (((*source_here).s != NULL) &&
257 ((*source_here).s->get_document (request.OID, response.doc, err, logout))) {
258 if (err != noError) return;
259 break;
260 }
261 source_here++;
262 }
263}
264
265
266bool operator==(const collectserverptr &x, const collectserverptr &y) {
267 return (x.c == y.c);
268}
269
270bool operator<(const collectserverptr &x, const collectserverptr &y) {
271 return (x.c < y.c);
272}
273
274
275// thecollectserver remains the property of the calling code but
276// should not be deleted until it is removed from this list.
277void collectservermapclass::addcollectserver (collectserver *thecollectserver) {
278 // can't add a null collection server
279 assert (thecollectserver != NULL);
280 if (thecollectserver == NULL) return;
281
282 // can't add an collection server with no collection name
283 assert (!(thecollectserver->get_collection_name()).empty());
284 if ((thecollectserver->get_collection_name()).empty()) return;
285
286 collectserverptr cptr;
287 cptr.c = thecollectserver;
288 collectserverptrs[thecollectserver->get_collection_name()] = cptr;
289}
290
291// getcollectserver will return NULL if the collectserver could not be found
292collectserver *collectservermapclass::getcollectserver (const text_t &collection) {
293 // can't find a collection with no name
294 if (collection.empty()) return NULL;
295
296 iterator here = collectserverptrs.find (collection);
297 if (here == collectserverptrs.end()) return NULL;
298
299 return (*here).second.c;
300}
Note: See TracBrowser for help on using the repository browser.