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