source: main/trunk/greenstone3/src/java/org/greenstone/gsdl3/service/CrossCollectionSearch.java@ 31181

Last change on this file since 31181 was 31181, checked in by Georgiy Litvinov, 7 years ago

Added java code to use groups in cross collection search

  • Property svn:keywords set to Author Date Id Revision
File size: 24.0 KB
Line 
1/*
2 * CrossCollectionSearch.java
3 * Copyright (C) 2002 New Zealand Digital Library, http://www.nzdl.org
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19package org.greenstone.gsdl3.service;
20
21import java.util.ArrayList;
22import java.util.HashMap;
23import java.util.Iterator;
24import java.util.Map;
25import java.util.Set;
26
27import org.apache.log4j.Logger;
28import org.greenstone.gsdl3.util.GSPath;
29import org.greenstone.gsdl3.util.GSXML;
30import org.greenstone.gsdl3.util.UserContext;
31import org.greenstone.gsdl3.util.XMLConverter;
32
33import org.w3c.dom.Document;
34import org.w3c.dom.Element;
35import org.w3c.dom.Node;
36import org.w3c.dom.NodeList;
37
38/**
39 * This ServiceRack gets specified in siteConfig.xml. So it is loaded by the MessaegRouter, and two services get activated: TextQuery, DocumentMetadataRetrieve.
40These are located at MR level, not inside a collection. QueryAction will send messages to "TextQuery", rather than eg "mgppdemo/TextQuery".
41These two services will requery the MR for search results/document metadata based on collections or documents listed.
42 */
43
44public class CrossCollectionSearch extends ServiceRack
45{
46
47 static Logger logger = Logger.getLogger(org.greenstone.gsdl3.service.CrossCollectionSearch.class.getName());
48 protected static final String QUERY_PARAM = "query";
49 protected static final String COLLECTION_PARAM = "collection";
50 protected static final String GROUP_PARAM = "group";
51 protected static final String MAXDOCS_PARAM = "maxDocs"; // matches standard maxDocs, but in this case, means max docs per collection
52 protected static final String HITS_PER_PAGE_PARAM = "hitsPerPage";
53 protected static final String MAXDOCS_DEFAULT = "20";
54 // the services on offer - these proxy the actual collection ones
55 protected static final String TEXT_QUERY_SERVICE = "TextQuery";
56 protected static final String DOCUMENT_METADATA_RETRIEVE_SERVICE = "DocumentMetadataRetrieve";
57
58 protected String[] coll_ids_list = null;
59 protected String[] coll_ids_list_no_all = null;
60 // maps lang to coll names list
61 protected HashMap<String, String[]> coll_names_map = null;
62
63 //protected String[] coll_names_list = null;
64
65 /** constructor */
66 public CrossCollectionSearch()
67 {
68 }
69
70 public boolean configure(Element info, Element extra_info)
71 {
72 // any parameters? colls to include??
73 logger.info("Configuring CrossCollectionSearch...");
74 // query service
75 Element ccs_service = this.desc_doc.createElement(GSXML.SERVICE_ELEM);
76 ccs_service.setAttribute(GSXML.TYPE_ATT, GSXML.SERVICE_TYPE_QUERY);
77 ccs_service.setAttribute(GSXML.NAME_ATT, TEXT_QUERY_SERVICE);
78 this.short_service_info.appendChild(ccs_service);
79
80 // metadata service
81 Element dmr_service = this.desc_doc.createElement(GSXML.SERVICE_ELEM);
82 dmr_service.setAttribute(GSXML.TYPE_ATT, GSXML.SERVICE_TYPE_RETRIEVE);
83 dmr_service.setAttribute(GSXML.NAME_ATT, DOCUMENT_METADATA_RETRIEVE_SERVICE);
84 this.short_service_info.appendChild(dmr_service);
85
86 // get any format info
87 Element format_info = (Element) GSXML.getChildByTagName(info, GSXML.FORMAT_ELEM);
88 if (format_info != null)
89 {
90 this.format_info_map.put(TEXT_QUERY_SERVICE, this.desc_doc.importNode(format_info, true));
91 }
92 else
93 {
94 // add in a default format statement
95 //"xmlns:gsf='" + GSXML.GSF_NAMESPACE + "' xmlns:xsl='" + GSXML.XSL_NAMESPACE + "
96 String format_string = "<format "+GSXML.STD_NAMESPACES_ATTS + "><gsf:template match='documentNode'><td><a><xsl:attribute name='href'>?a=d&amp;c=<xsl:value-of select='@collection'/>&amp;d=<xsl:value-of select='@nodeID'/><xsl:if test=\"@nodeType='leaf'\">&amp;sib=1</xsl:if>&amp;dt=<xsl:value-of select='@docType'/>&amp;p.a=q&amp;p.s=" + TEXT_QUERY_SERVICE + "&amp;p.c=";
97 if (this.cluster_name != null)
98 {
99 format_string += this.cluster_name;
100 }
101 format_string += "</xsl:attribute><gsf:icon/></a></td><td><gsf:metadata name='Title'/> (<xsl:value-of select='@collection'/>) </td></gsf:template></format>";
102 this.format_info_map.put(TEXT_QUERY_SERVICE, this.desc_doc.importNode(this.converter.getDOM(format_string).getDocumentElement(), true));
103 }
104 return true;
105 }
106
107 protected Element getServiceDescription(Document doc, String service, String lang, String subset)
108 {
109 if (service.equals(TEXT_QUERY_SERVICE))
110 {
111
112 Element ccs_service = doc.createElement(GSXML.SERVICE_ELEM);
113 ccs_service.setAttribute(GSXML.TYPE_ATT, GSXML.SERVICE_TYPE_QUERY);
114 ccs_service.setAttribute(GSXML.NAME_ATT, TEXT_QUERY_SERVICE);
115
116 // display info
117 if (subset == null || subset.equals(GSXML.DISPLAY_TEXT_ELEM + GSXML.LIST_MODIFIER))
118 {
119 ccs_service.appendChild(GSXML.createDisplayTextElement(doc, GSXML.DISPLAY_TEXT_NAME, getTextString(TEXT_QUERY_SERVICE + ".name", lang)));
120 ccs_service.appendChild(GSXML.createDisplayTextElement(doc, GSXML.DISPLAY_TEXT_SUBMIT, getTextString(TEXT_QUERY_SERVICE + ".submit", lang)));
121 ccs_service.appendChild(GSXML.createDisplayTextElement(doc, GSXML.DISPLAY_TEXT_DESCRIPTION, getTextString(TEXT_QUERY_SERVICE + ".description", lang)));
122 }
123 // param info
124 if (subset == null || subset.equals(GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER))
125 {
126 Element param_list = doc.createElement(GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER);
127 // collection list
128 if (coll_ids_list == null)
129 {
130 initCollectionList(lang);
131 }
132 if (!coll_names_map.containsKey(lang))
133 {
134 addCollectionNames(lang);
135 }
136 Element param = GSXML.createParameterDescription(doc, COLLECTION_PARAM, getTextString("param." + COLLECTION_PARAM, lang), GSXML.PARAM_TYPE_ENUM_MULTI, "all", coll_ids_list, coll_names_map.get(lang));
137 param_list.appendChild(param);
138 // max docs param
139 param = GSXML.createParameterDescription(doc, MAXDOCS_PARAM, getTextString("param." + MAXDOCS_PARAM, lang), GSXML.PARAM_TYPE_INTEGER, MAXDOCS_DEFAULT, null, null);
140 param_list.appendChild(param);
141 // query param
142 param = GSXML.createParameterDescription(doc, QUERY_PARAM, getTextString("param." + QUERY_PARAM, lang), GSXML.PARAM_TYPE_STRING, null, null, null);
143 param_list.appendChild(param);
144 ccs_service.appendChild(param_list);
145 }
146
147 logger.debug("service description=" + this.converter.getPrettyString(ccs_service));
148 return ccs_service;
149 }
150 // these ones are probably never called, but put them here just in case
151 Element service_elem = doc.createElement(GSXML.SERVICE_ELEM);
152 service_elem.setAttribute(GSXML.TYPE_ATT, GSXML.SERVICE_TYPE_RETRIEVE);
153 service_elem.setAttribute(GSXML.NAME_ATT, service);
154 return service_elem;
155
156 }
157
158 protected Element processTextQuery(Element request)
159 {
160 // Create a new (empty) result message
161 Document result_doc = XMLConverter.newDOM();
162 Element result = result_doc.createElement(GSXML.RESPONSE_ELEM);
163 result.setAttribute(GSXML.FROM_ATT, TEXT_QUERY_SERVICE);
164 result.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_PROCESS);
165
166 UserContext userContext = new UserContext(request);
167
168 // Get the parameters of the request
169 Element param_list = (Element) GSXML.getChildByTagName(request, GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER);
170 if (param_list == null)
171 {
172 logger.error("TextQuery request had no paramList.");
173 return result; // Return the empty result
174 }
175 // get the collection list
176 String[] colls_list = coll_ids_list_no_all;
177 Element coll_param = GSXML.getNamedElement(param_list, GSXML.PARAM_ELEM, GSXML.NAME_ATT, COLLECTION_PARAM);
178 if (coll_param != null)
179 {
180 String coll_list = GSXML.getValue(coll_param);
181 if (!coll_list.equals("all") && !coll_list.equals(""))
182 {
183 colls_list = coll_list.split(",");
184 }
185 }
186
187 colls_list = mergeGroups(userContext, param_list, colls_list);
188
189 String maxdocs = MAXDOCS_DEFAULT;
190 Element maxdocs_param = GSXML.getNamedElement(param_list, GSXML.PARAM_ELEM, GSXML.NAME_ATT, MAXDOCS_PARAM);
191 if (maxdocs_param != null) {
192 maxdocs = GSXML.getValue(maxdocs_param);
193 }
194
195 Document msg_doc = XMLConverter.newDOM();
196 Element query_message = msg_doc.createElement(GSXML.MESSAGE_ELEM);
197 // we are sending the same request to each collection - build up the to
198 // attribute for the request
199 StringBuffer to_att = new StringBuffer();
200 for (int i = 0; i < colls_list.length; i++)
201 {
202 if (i > 0)
203 {
204 to_att.append(",");
205 }
206 to_att.append(GSPath.appendLink(colls_list[i], "TextQuery"));
207
208 }
209 // send the query to all colls
210 Element query_request = GSXML.createBasicRequest(msg_doc, GSXML.REQUEST_TYPE_PROCESS, to_att.toString(), userContext);
211 query_message.appendChild(query_request);
212 // should we add params individually?
213 Element new_param_list = msg_doc.createElement(GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER);
214 query_request.appendChild(new_param_list);
215 new_param_list.appendChild(msg_doc.importNode(GSXML.getNamedElement(param_list, GSXML.PARAM_ELEM, GSXML.NAME_ATT, QUERY_PARAM), true));
216
217 // for cross coll search, we only want maxdocs from each collection
218 // some colls use maxdocs, some use hits per page so lets send both
219 new_param_list.appendChild(GSXML.createParameter(msg_doc, MAXDOCS_PARAM, maxdocs));
220 new_param_list.appendChild(GSXML.createParameter(msg_doc, HITS_PER_PAGE_PARAM, maxdocs));
221 Element query_result = (Element) this.router.process(query_message);
222
223 // create the doc list for the response
224 Element doc_node_list = result_doc.createElement(GSXML.DOC_NODE_ELEM + GSXML.LIST_MODIFIER);
225 result.appendChild(doc_node_list);
226
227 NodeList responses = query_result.getElementsByTagName(GSXML.RESPONSE_ELEM);
228 int num_docs = 0;
229 for (int k = 0; k < responses.getLength(); k++)
230 {
231 String coll_name = GSPath.removeLastLink(((Element) responses.item(k)).getAttribute(GSXML.FROM_ATT));
232 NodeList nodes = ((Element) responses.item(k)).getElementsByTagName(GSXML.DOC_NODE_ELEM);
233 if (nodes == null || nodes.getLength() == 0)
234 continue;
235 num_docs += nodes.getLength();
236 Element last_node = null;
237 Element this_node = null;
238 for (int n = 0; n < nodes.getLength(); n++)
239 {
240 this_node = (Element) nodes.item(n);
241 this_node.setAttribute("collection", coll_name);
242 if (k == 0)
243 {
244
245 doc_node_list.appendChild(result_doc.importNode(this_node, true));
246 }
247 else
248 {
249 if (last_node == null)
250 {
251 last_node = (Element) GSXML.getChildByTagName(doc_node_list, GSXML.DOC_NODE_ELEM);
252 }
253 last_node = GSXML.insertIntoOrderedList(doc_node_list, GSXML.DOC_NODE_ELEM, last_node, this_node, "rank", true);
254 }
255
256 }
257 }
258 // just send back num docs returned. Too hard to work out number of matches etc as each index type
259 // does it differently
260 Element metadata_list = result_doc.createElement(GSXML.METADATA_ELEM + GSXML.LIST_MODIFIER);
261 result.appendChild(metadata_list);
262 GSXML.addMetadata(metadata_list, "numDocsReturned", "" + num_docs);
263 return result;
264 }
265
266 // protected Element processAdvTextQuery(Element request)
267 // {
268
269 // }
270
271
272
273 protected boolean initCollectionList(String lang)
274 {
275 UserContext userContext = new UserContext();
276 userContext.setLanguage(lang);
277 userContext.setUserID("");
278
279 // first, get the message router info
280 Document msg_doc = XMLConverter.newDOM();
281 Element coll_list_message = msg_doc.createElement(GSXML.MESSAGE_ELEM);
282 Element coll_list_request = GSXML.createBasicRequest(msg_doc, GSXML.REQUEST_TYPE_DESCRIBE, "", userContext); // uid
283 coll_list_message.appendChild(coll_list_request);
284 logger.debug("coll list request = " + this.converter.getPrettyString(coll_list_request));
285 Element coll_list_response = (Element) this.router.process(coll_list_message);
286 if (coll_list_response == null)
287 {
288 logger.error("couldn't query the message router!");
289 return false;
290 }
291 logger.debug("coll list response = " + this.converter.getPrettyString(coll_list_response));
292 // second, get some info from each collection. we want the coll name
293 // and whether its got a text query service
294
295 NodeList colls = coll_list_response.getElementsByTagName(GSXML.COLLECTION_ELEM);
296 // we can send the same request to multiple collections at once by using a comma separated list
297 Element metadata_message = msg_doc.createElement(GSXML.MESSAGE_ELEM);
298 StringBuffer colls_sb = new StringBuffer();
299 for (int i = 0; i < colls.getLength(); i++)
300 {
301 Element c = (Element) colls.item(i);
302 String name = c.getAttribute(GSXML.NAME_ATT);
303 if (i != 0)
304 {
305 colls_sb.append(",");
306 }
307 colls_sb.append(name);
308 //Element metadata_request = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_DESCRIBE, name, userContext);
309 //metadata_message.appendChild(metadata_request);
310 }
311
312 Element metadata_request = GSXML.createBasicRequest(msg_doc, GSXML.REQUEST_TYPE_DESCRIBE, colls_sb.toString(), userContext);
313 metadata_message.appendChild(metadata_request);
314 logger.debug("metadata request = " + this.converter.getPrettyString(metadata_message));
315 Element metadata_response = (Element) this.router.process(metadata_message);
316 logger.debug("metadata response = " + this.converter.getPrettyString(metadata_response));
317 NodeList coll_responses = metadata_response.getElementsByTagName(GSXML.RESPONSE_ELEM);
318 ArrayList<String> valid_colls = new ArrayList<String>();
319 ArrayList<String> valid_coll_names = new ArrayList<String>();
320 for (int i = 0; i < coll_responses.getLength(); i++)
321 {
322 Element response = (Element) coll_responses.item(i);
323 Element coll = (Element) GSXML.getChildByTagName(response, GSXML.COLLECTION_ELEM);
324 Element service_list = (Element) GSXML.getChildByTagName(coll, GSXML.SERVICE_ELEM + GSXML.LIST_MODIFIER);
325 if (service_list == null)
326 continue;
327 Element query_service = GSXML.getNamedElement(service_list, GSXML.SERVICE_ELEM, GSXML.NAME_ATT, TEXT_QUERY_SERVICE); // should be AbstractTextSearch.TEXT_QUERY_SERVICE
328 if (query_service == null)
329 continue;
330 // use the name of the response in case we are talking to a remote collection, not the name of the collection.
331 String coll_id = response.getAttribute(GSXML.FROM_ATT);
332 String coll_name = getDisplayText(coll, GSXML.DISPLAY_TEXT_NAME, lang, "en");
333 valid_colls.add(coll_id);
334 valid_coll_names.add(coll_name);
335 }
336
337 this.coll_names_map = new HashMap<String, String[]>();
338
339 // ids no all has the list without 'all' option.
340 this.coll_ids_list_no_all = new String[1];
341 this.coll_ids_list_no_all = valid_colls.toArray(coll_ids_list_no_all);
342
343 valid_colls.add(0, "all");
344 valid_coll_names.add(0, getTextString("param." + COLLECTION_PARAM + ".all", lang));
345
346 this.coll_ids_list = new String[1];
347 this.coll_ids_list = valid_colls.toArray(coll_ids_list);
348
349 String[] coll_names_list = new String[1];
350 coll_names_list = valid_coll_names.toArray(coll_names_list);
351 this.coll_names_map.put(lang, coll_names_list);
352 return true;
353 }
354
355 protected void addCollectionNames(String lang)
356 {
357
358 UserContext userContext = new UserContext();
359 userContext.setLanguage(lang);
360 userContext.setUserID("");
361
362 ArrayList<String> coll_names = new ArrayList<String>();
363 coll_names.add(getTextString("param." + COLLECTION_PARAM + ".all", lang));
364
365 // need to request MR for collection descriptions
366 Document msg_doc = XMLConverter.newDOM();
367 Element metadata_message = msg_doc.createElement(GSXML.MESSAGE_ELEM);
368
369 // get a comma separated list of coll ids to send to MR
370 // the first item is the place holder for 'all'
371 StringBuffer colls_sb = new StringBuffer();
372 for (int i = 1; i < coll_ids_list.length; i++)
373 {
374 if (i != 1)
375 {
376 colls_sb.append(",");
377 }
378 colls_sb.append(coll_ids_list[i]);
379 }
380 Element metadata_request = GSXML.createBasicRequest(msg_doc, GSXML.REQUEST_TYPE_DESCRIBE, colls_sb.toString(), userContext);
381 // param_list to request just displayTextList
382 Element param_list = msg_doc.createElement(GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER);
383 Element param = GSXML.createParameter(msg_doc, GSXML.SUBSET_PARAM, GSXML.DISPLAY_TEXT_ELEM + GSXML.LIST_MODIFIER);
384 param_list.appendChild(param);
385 metadata_request.appendChild(param_list);
386 metadata_message.appendChild(metadata_request);
387 logger.debug("coll names metadata request = " + this.converter.getPrettyString(metadata_message));
388 Element metadata_response = (Element) this.router.process(metadata_message);
389 logger.debug("coll names metadata response = " + this.converter.getPrettyString(metadata_response));
390 NodeList coll_responses = metadata_response.getElementsByTagName(GSXML.RESPONSE_ELEM);
391 for (int i = 0; i < coll_responses.getLength(); i++)
392 {
393 Element response = (Element) coll_responses.item(i);
394 Element coll = (Element) GSXML.getChildByTagName(response, GSXML.COLLECTION_ELEM);
395 String coll_name = getDisplayText(coll, GSXML.DISPLAY_TEXT_NAME, lang, "en");
396 coll_names.add(coll_name);
397 }
398
399 String[] coll_names_list = new String[1];
400 coll_names_list = coll_names.toArray(coll_names_list);
401 this.coll_names_map.put(lang, coll_names_list);
402
403 }
404
405 protected Element processDocumentMetadataRetrieve(Element request)
406 {
407 // Create a new (empty) result message
408 Document result_doc = XMLConverter.newDOM();
409 Element result = result_doc.createElement(GSXML.RESPONSE_ELEM);
410 result.setAttribute(GSXML.FROM_ATT, DOCUMENT_METADATA_RETRIEVE_SERVICE);
411 result.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_PROCESS);
412
413 UserContext userContext = new UserContext(request);
414 // Get the parameters of the request
415 Element param_list = (Element) GSXML.getChildByTagName(request, GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER);
416 if (param_list == null)
417 {
418 logger.error("DocumentMetadataRetrieve request had no paramList.");
419 return result; // Return the empty result
420 }
421
422 NodeList query_doc_list = request.getElementsByTagName(GSXML.DOC_NODE_ELEM);
423 if (query_doc_list.getLength() == 0)
424 {
425 logger.error("DocumentMetadataRetrieve request had no documentNodes.");
426 return result; // Return the empty result
427 }
428
429 // the resulting doc node list
430 Element result_node_list = result_doc.createElement(GSXML.DOC_NODE_ELEM + GSXML.LIST_MODIFIER);
431 result.appendChild(result_node_list);
432
433
434 // organise the nodes into collection lists
435 HashMap<String, Node> coll_map = new HashMap<String, Node>();
436
437 for (int i = 0; i < query_doc_list.getLength(); i++)
438 {
439 Element doc_node = (Element) query_doc_list.item(i);
440 String coll_name = doc_node.getAttribute("collection");
441 Element coll_items = (Element) coll_map.get(coll_name);
442 if (coll_items == null)
443 {
444 coll_items = result_doc.createElement(GSXML.DOC_NODE_ELEM + GSXML.LIST_MODIFIER);
445 coll_map.put(coll_name, coll_items);
446 }
447 coll_items.appendChild(result_doc.importNode(doc_node, true));
448 }
449
450 // create teh individual requests
451 Document msg_doc = XMLConverter.newDOM();
452 Element meta_request_message = msg_doc.createElement(GSXML.MESSAGE_ELEM);
453
454 Set mapping_set = coll_map.entrySet();
455 Iterator iter = mapping_set.iterator();
456
457 while (iter.hasNext())
458 {
459 Map.Entry e = (Map.Entry) iter.next();
460 String cname = (String) e.getKey();
461 Element doc_nodes = (Element) e.getValue();
462 Element meta_request = GSXML.createBasicRequest(msg_doc, GSXML.REQUEST_TYPE_PROCESS, GSPath.appendLink(cname, DOCUMENT_METADATA_RETRIEVE_SERVICE), userContext);
463 meta_request.appendChild(msg_doc.importNode(doc_nodes, true));
464 meta_request.appendChild(msg_doc.importNode(param_list, true));
465 meta_request_message.appendChild(meta_request);
466
467 }
468
469 Node meta_result_node = this.router.process(meta_request_message);
470 Element meta_result = GSXML.nodeToElement(meta_result_node);
471
472 // now need to put the doc nodes back in the right order
473 // go through the original list again. keep an element pointer to
474 // the next element in each collections list
475 NodeList meta_responses = meta_result.getElementsByTagName(GSXML.RESPONSE_ELEM);
476 for (int i = 0; i < meta_responses.getLength(); i++)
477 {
478 String collname = GSPath.removeLastLink(((Element) meta_responses.item(i)).getAttribute(GSXML.FROM_ATT));
479 Element first_elem = (Element) GSXML.getNodeByPath(meta_responses.item(i), "documentNodeList/documentNode");
480 coll_map.put(collname, first_elem);
481 }
482
483 for (int i = 0; i < query_doc_list.getLength(); i++)
484 {
485 Element doc_node = (Element) query_doc_list.item(i);
486 Element new_node = (Element) result_doc.importNode(doc_node, false);
487 result_node_list.appendChild(new_node);
488 String coll_name = doc_node.getAttribute("collection");
489
490 Element meta_elem = (Element) coll_map.get(coll_name);
491 GSXML.mergeMetadataLists(new_node, meta_elem);
492 coll_map.put(coll_name, meta_elem.getNextSibling());
493 }
494 return result;
495 }
496
497 private String[] mergeGroups(UserContext userContext, Element paramList, String[] collArray){
498 Document doc = XMLConverter.newDOM();
499 Element groupParam = GSXML.getNamedElement(paramList, GSXML.PARAM_ELEM, GSXML.NAME_ATT, GROUP_PARAM);
500 Element collParam = GSXML.getNamedElement(paramList, GSXML.PARAM_ELEM, GSXML.NAME_ATT, COLLECTION_PARAM);
501 //Group param not null and coll param null or not 'all'
502 if (groupParam != null && (collParam == null || !GSXML.getValue(collParam).equals("all")))
503 {
504 //GroupInfo service to get uniq collections
505 String uniqCollServiceName = "UniqueCollections";
506 Element infoResponse = getMRInfo(userContext);
507 Element serviceList = (Element) GSXML.getChildByTagName(infoResponse, GSXML.SERVICE_ELEM + GSXML.LIST_MODIFIER);
508 if (serviceList == null) {
509 logger.error("Service list is null!");
510 return collArray;
511 }
512 Element groupInfoService = GSXML.getNamedElement(serviceList, GSXML.SERVICE_ELEM, GSXML.NAME_ATT, uniqCollServiceName);
513 if (groupInfoService == null){
514 logger.error("UniqueCollections service unavailable; Check your groupConfig.xml");
515 return collArray;
516 }
517 Element groupQueryMessage = doc.createElement(GSXML.MESSAGE_ELEM);
518 Element groupQueryRequest = GSXML.createBasicRequest(doc, GSXML.REQUEST_TYPE_PROCESS, uniqCollServiceName, userContext);
519 groupQueryMessage.appendChild(groupQueryRequest);
520 Element groupParamList = doc.createElement(GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER);
521 groupQueryRequest.appendChild(groupParamList);
522 if (collParam != null){
523 groupParamList.appendChild(doc.importNode(GSXML.getNamedElement(paramList, GSXML.PARAM_ELEM, GSXML.NAME_ATT, GSXML.COLLECTION_ELEM), true));
524 }
525 groupParamList.appendChild(doc.importNode(GSXML.getNamedElement(paramList, GSXML.PARAM_ELEM, GSXML.NAME_ATT, GSXML.GROUP_ELEM), true));
526 Element groupQueryResult = (Element) this.router.process(groupQueryMessage);
527 Element groupQueryResonse = (Element) GSXML.getChildByTagName(groupQueryResult, GSXML.RESPONSE_ELEM);
528 Element collList = (Element) GSXML.getChildByTagName(groupQueryResonse, GSXML.COLLECTION_ELEM + GSXML.LIST_MODIFIER);
529 NodeList collections = GSXML.getChildrenByTagName(collList, GSXML.COLLECTION_ELEM);
530 collArray = new String[collections.getLength()];
531 for (int i = 0; i < collections.getLength(); i++){
532 String collName = ((Element) collections.item(i)).getAttribute(GSXML.NAME_ATT);
533 collArray[i] = collName;
534 }
535 return collArray;
536 }
537 return collArray;
538
539 }
540 private Element getMRInfo(UserContext userContext){
541 Document doc = XMLConverter.newDOM();
542 Element infoMessage = doc.createElement(GSXML.MESSAGE_ELEM);
543 Element infoRequest = GSXML.createBasicRequest(doc, GSXML.REQUEST_TYPE_DESCRIBE, "", userContext);
544 Element paramList = doc.createElement(GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER);
545 infoRequest.appendChild(paramList);
546 GSXML.addParameterToList(paramList, GSXML.SUBSET_PARAM, GSXML.SERVICE_ELEM + GSXML.LIST_MODIFIER);
547 infoMessage.appendChild(infoRequest);
548 Element responseMessage = (Element) this.router.process(infoMessage);
549 if (responseMessage == null)
550 {
551 logger.error("couldn't query the message router!");
552 return null;
553 }
554 Element infoResponse = (Element) GSXML.getChildByTagName(responseMessage, GSXML.RESPONSE_ELEM);
555 if (infoResponse == null)
556 {
557 logger.error("response from message router is null!");
558 return null;
559 }
560
561 return infoResponse;
562
563 }
564
565}
Note: See TracBrowser for help on using the repository browser.