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