[11014] | 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 | */
|
---|
| 19 | package org.greenstone.gsdl3.service;
|
---|
| 20 |
|
---|
[26577] | 21 | import java.util.ArrayList;
|
---|
| 22 | import java.util.HashMap;
|
---|
| 23 | import java.util.Iterator;
|
---|
| 24 | import java.util.Map;
|
---|
| 25 | import java.util.Set;
|
---|
| 26 |
|
---|
| 27 | import org.apache.log4j.Logger;
|
---|
| 28 | import org.greenstone.gsdl3.util.GSPath;
|
---|
[11014] | 29 | import org.greenstone.gsdl3.util.GSXML;
|
---|
[24993] | 30 | import org.greenstone.gsdl3.util.UserContext;
|
---|
[11014] | 31 | import org.w3c.dom.Element;
|
---|
[16688] | 32 | import org.w3c.dom.Node;
|
---|
[11014] | 33 | import org.w3c.dom.NodeList;
|
---|
| 34 |
|
---|
| 35 | /**
|
---|
[24979] | 36 | *
|
---|
[11014] | 37 | * @author <a href="mailto:[email protected]">Katherine Don</a>
|
---|
| 38 | */
|
---|
| 39 |
|
---|
[24979] | 40 | public class CrossCollectionSearch extends ServiceRack
|
---|
| 41 | {
|
---|
[11014] | 42 |
|
---|
[24979] | 43 | static Logger logger = Logger.getLogger(org.greenstone.gsdl3.service.CrossCollectionSearch.class.getName());
|
---|
| 44 | protected static final String QUERY_PARAM = "query";
|
---|
| 45 | protected static final String COLLECTION_PARAM = "collection";
|
---|
[11014] | 46 |
|
---|
[24979] | 47 | // the services on offer - these proxy the actual collection ones
|
---|
| 48 | protected static final String TEXT_QUERY_SERVICE = "TextQuery";
|
---|
| 49 | protected static final String DOCUMENT_METADATA_RETRIEVE_SERVICE = "DocumentMetadataRetrieve";
|
---|
[11014] | 50 |
|
---|
[24979] | 51 | protected String[] coll_ids_list = null;
|
---|
| 52 | protected String[] coll_ids_list_no_all = null;
|
---|
[26577] | 53 | // maps lang to coll names list
|
---|
| 54 | protected HashMap<String, String[]> coll_names_map = null;
|
---|
[11014] | 55 |
|
---|
[26577] | 56 | //protected String[] coll_names_list = null;
|
---|
| 57 |
|
---|
[24979] | 58 | /** constructor */
|
---|
| 59 | public CrossCollectionSearch()
|
---|
| 60 | {
|
---|
| 61 | }
|
---|
[11014] | 62 |
|
---|
[24979] | 63 | public boolean configure(Element info, Element extra_info)
|
---|
| 64 | {
|
---|
| 65 | // any parameters? colls to include??
|
---|
| 66 | logger.info("Configuring CrossCollectionSearch...");
|
---|
| 67 | // query service
|
---|
| 68 | Element ccs_service = this.doc.createElement(GSXML.SERVICE_ELEM);
|
---|
| 69 | ccs_service.setAttribute(GSXML.TYPE_ATT, GSXML.SERVICE_TYPE_QUERY);
|
---|
| 70 | ccs_service.setAttribute(GSXML.NAME_ATT, TEXT_QUERY_SERVICE);
|
---|
| 71 | this.short_service_info.appendChild(ccs_service);
|
---|
[11014] | 72 |
|
---|
[24979] | 73 | // metadata service
|
---|
| 74 | Element dmr_service = this.doc.createElement(GSXML.SERVICE_ELEM);
|
---|
| 75 | dmr_service.setAttribute(GSXML.TYPE_ATT, GSXML.SERVICE_TYPE_RETRIEVE);
|
---|
| 76 | dmr_service.setAttribute(GSXML.NAME_ATT, DOCUMENT_METADATA_RETRIEVE_SERVICE);
|
---|
| 77 | this.short_service_info.appendChild(dmr_service);
|
---|
| 78 |
|
---|
| 79 | // get any format info
|
---|
| 80 | Element format_info = (Element) GSXML.getChildByTagName(info, GSXML.FORMAT_ELEM);
|
---|
| 81 | if (format_info != null)
|
---|
| 82 | {
|
---|
| 83 | this.format_info_map.put(TEXT_QUERY_SERVICE, this.doc.importNode(format_info, true));
|
---|
| 84 | }
|
---|
| 85 | else
|
---|
| 86 | {
|
---|
| 87 | // add in a default format statement
|
---|
[26055] | 88 | String format_string = "<format xmlns:gsf='" + GSXML.GSF_NAMESPACE + "' xmlns:xsl='" + GSXML.XSL_NAMESPACE + "'><gsf:template match='documentNode'><td><a><xsl:attribute name='href'>?a=d&c=<xsl:value-of select='@collection'/>&d=<xsl:value-of select='@nodeID'/><xsl:if test=\"@nodeType='leaf'\">&sib=1</xsl:if>&dt=<xsl:value-of select='@docType'/>&p.a=q&p.s=" + TEXT_QUERY_SERVICE + "&p.c=";
|
---|
[24979] | 89 | if (this.cluster_name != null)
|
---|
| 90 | {
|
---|
| 91 | format_string += this.cluster_name;
|
---|
| 92 | }
|
---|
| 93 | format_string += "</xsl:attribute><gsf:icon/></a></td><td><gsf:metadata name='Title'/> (<xsl:value-of select='@collection'/>) </td></gsf:template></format>";
|
---|
| 94 | this.format_info_map.put(TEXT_QUERY_SERVICE, this.doc.importNode(this.converter.getDOM(format_string).getDocumentElement(), true));
|
---|
| 95 | }
|
---|
| 96 | return true;
|
---|
[11014] | 97 | }
|
---|
| 98 |
|
---|
[24979] | 99 | protected Element getServiceDescription(String service, String lang, String subset)
|
---|
| 100 | {
|
---|
| 101 | if (service.equals(TEXT_QUERY_SERVICE))
|
---|
| 102 | {
|
---|
[11014] | 103 |
|
---|
[24979] | 104 | Element ccs_service = this.doc.createElement(GSXML.SERVICE_ELEM);
|
---|
| 105 | ccs_service.setAttribute(GSXML.TYPE_ATT, GSXML.SERVICE_TYPE_QUERY);
|
---|
| 106 | ccs_service.setAttribute(GSXML.NAME_ATT, TEXT_QUERY_SERVICE);
|
---|
| 107 |
|
---|
| 108 | // display info
|
---|
| 109 | if (subset == null || subset.equals(GSXML.DISPLAY_TEXT_ELEM + GSXML.LIST_MODIFIER))
|
---|
| 110 | {
|
---|
| 111 | ccs_service.appendChild(GSXML.createDisplayTextElement(this.doc, GSXML.DISPLAY_TEXT_NAME, getTextString(TEXT_QUERY_SERVICE + ".name", lang)));
|
---|
| 112 | ccs_service.appendChild(GSXML.createDisplayTextElement(this.doc, GSXML.DISPLAY_TEXT_SUBMIT, getTextString(TEXT_QUERY_SERVICE + ".submit", lang)));
|
---|
| 113 | ccs_service.appendChild(GSXML.createDisplayTextElement(this.doc, GSXML.DISPLAY_TEXT_DESCRIPTION, getTextString(TEXT_QUERY_SERVICE + ".description", lang)));
|
---|
| 114 | }
|
---|
| 115 | // param info
|
---|
| 116 | if (subset == null || subset.equals(GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER))
|
---|
| 117 | {
|
---|
| 118 | Element param_list = this.doc.createElement(GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER);
|
---|
| 119 | // collection list
|
---|
| 120 | if (coll_ids_list == null)
|
---|
| 121 | {
|
---|
[26406] | 122 | initCollectionList(lang);
|
---|
[24979] | 123 | }
|
---|
[26577] | 124 | if (!coll_names_map.containsKey(lang))
|
---|
| 125 | {
|
---|
| 126 | addCollectionNames(lang);
|
---|
[26406] | 127 | }
|
---|
| 128 | Element param = GSXML.createParameterDescription(this.doc, COLLECTION_PARAM, getTextString("param." + COLLECTION_PARAM, lang), GSXML.PARAM_TYPE_ENUM_MULTI, "all", coll_ids_list, coll_names_map.get(lang));
|
---|
[24979] | 129 | param_list.appendChild(param);
|
---|
| 130 | // query param
|
---|
| 131 | param = GSXML.createParameterDescription(this.doc, QUERY_PARAM, getTextString("param." + QUERY_PARAM, lang), GSXML.PARAM_TYPE_STRING, null, null, null);
|
---|
| 132 | param_list.appendChild(param);
|
---|
| 133 | ccs_service.appendChild(param_list);
|
---|
| 134 | }
|
---|
| 135 |
|
---|
| 136 | logger.debug("service description=" + this.converter.getPrettyString(ccs_service));
|
---|
| 137 | return ccs_service;
|
---|
[11014] | 138 | }
|
---|
[24979] | 139 | // these ones are probably never called, but put them here just in case
|
---|
| 140 | Element service_elem = this.doc.createElement(GSXML.SERVICE_ELEM);
|
---|
| 141 | service_elem.setAttribute(GSXML.TYPE_ATT, GSXML.SERVICE_TYPE_RETRIEVE);
|
---|
| 142 | service_elem.setAttribute(GSXML.NAME_ATT, service);
|
---|
| 143 | return service_elem;
|
---|
| 144 |
|
---|
[11014] | 145 | }
|
---|
| 146 |
|
---|
[24979] | 147 | protected Element processTextQuery(Element request)
|
---|
| 148 | {
|
---|
| 149 | // Create a new (empty) result message
|
---|
| 150 | Element result = this.doc.createElement(GSXML.RESPONSE_ELEM);
|
---|
| 151 | result.setAttribute(GSXML.FROM_ATT, TEXT_QUERY_SERVICE);
|
---|
| 152 | result.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_PROCESS);
|
---|
[11014] | 153 |
|
---|
[24993] | 154 | UserContext userContext = new UserContext(request);
|
---|
[26577] | 155 |
|
---|
[24979] | 156 | // Get the parameters of the request
|
---|
| 157 | Element param_list = (Element) GSXML.getChildByTagName(request, GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER);
|
---|
| 158 | if (param_list == null)
|
---|
| 159 | {
|
---|
| 160 | logger.error("TextQuery request had no paramList.");
|
---|
| 161 | return result; // Return the empty result
|
---|
| 162 | }
|
---|
[11014] | 163 |
|
---|
[24979] | 164 | // get the collection list
|
---|
| 165 | String[] colls_list = coll_ids_list_no_all;
|
---|
| 166 | Element coll_param = GSXML.getNamedElement(param_list, GSXML.PARAM_ELEM, GSXML.NAME_ATT, COLLECTION_PARAM);
|
---|
| 167 | if (coll_param != null)
|
---|
| 168 | {
|
---|
| 169 | String coll_list = GSXML.getValue(coll_param);
|
---|
| 170 | if (!coll_list.equals("all") && !coll_list.equals(""))
|
---|
| 171 | {
|
---|
| 172 | colls_list = coll_list.split(",");
|
---|
| 173 | }
|
---|
| 174 | }
|
---|
[11014] | 175 |
|
---|
[24979] | 176 | Element query_message = this.doc.createElement(GSXML.MESSAGE_ELEM);
|
---|
| 177 | // we are sending the same request to each collection - build up the to
|
---|
| 178 | // attribute for the request
|
---|
| 179 | StringBuffer to_att = new StringBuffer();
|
---|
| 180 | for (int i = 0; i < colls_list.length; i++)
|
---|
| 181 | {
|
---|
| 182 | if (i > 0)
|
---|
| 183 | {
|
---|
| 184 | to_att.append(",");
|
---|
| 185 | }
|
---|
| 186 | to_att.append(GSPath.appendLink(colls_list[i], "TextQuery"));
|
---|
[11014] | 187 |
|
---|
[24979] | 188 | }
|
---|
| 189 | // send the query to all colls
|
---|
[24993] | 190 | Element query_request = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_PROCESS, to_att.toString(), userContext);
|
---|
[24979] | 191 | query_message.appendChild(query_request);
|
---|
| 192 | // should we add params individually?
|
---|
| 193 | Element new_param_list = this.doc.createElement(GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER);
|
---|
| 194 | query_request.appendChild(new_param_list);
|
---|
| 195 | new_param_list.appendChild(this.doc.importNode(GSXML.getNamedElement(param_list, GSXML.PARAM_ELEM, GSXML.NAME_ATT, QUERY_PARAM), true));
|
---|
| 196 | Element query_result = (Element) this.router.process(query_message);
|
---|
[11014] | 197 |
|
---|
[24979] | 198 | // gather up the data from each response
|
---|
| 199 | int numDocsMatched = 0;
|
---|
| 200 | int numDocsReturned = 0;
|
---|
[11014] | 201 |
|
---|
[24979] | 202 | //term info??
|
---|
[11014] | 203 |
|
---|
[24979] | 204 | NodeList metadata = query_result.getElementsByTagName(GSXML.METADATA_ELEM);
|
---|
| 205 | for (int j = 0; j < metadata.getLength(); j++)
|
---|
| 206 | {
|
---|
| 207 | Element meta = (Element) metadata.item(j);
|
---|
| 208 | if (meta.getAttribute(GSXML.NAME_ATT).equals("numDocsReturned"))
|
---|
| 209 | {
|
---|
| 210 | numDocsReturned += Integer.parseInt(GSXML.getValue(meta));
|
---|
| 211 | }
|
---|
| 212 | else if (meta.getAttribute(GSXML.NAME_ATT).equals("numDocsMatched"))
|
---|
| 213 | {
|
---|
| 214 | numDocsMatched += Integer.parseInt(GSXML.getValue(meta));
|
---|
| 215 | }
|
---|
[11014] | 216 | }
|
---|
| 217 |
|
---|
[24979] | 218 | Element metadata_list = this.doc.createElement(GSXML.METADATA_ELEM + GSXML.LIST_MODIFIER);
|
---|
| 219 | result.appendChild(metadata_list);
|
---|
| 220 | GSXML.addMetadata(this.doc, metadata_list, "numDocsReturned", "" + numDocsReturned);
|
---|
| 221 | //GSXML.addMetadata(this.doc, metadata_list, "numDocsMatched", ""+numDocsMatched);
|
---|
[11014] | 222 |
|
---|
[24979] | 223 | Element doc_node_list = this.doc.createElement(GSXML.DOC_NODE_ELEM + GSXML.LIST_MODIFIER);
|
---|
| 224 | result.appendChild(doc_node_list);
|
---|
[11014] | 225 |
|
---|
[24979] | 226 | NodeList responses = query_result.getElementsByTagName(GSXML.RESPONSE_ELEM);
|
---|
[13978] | 227 |
|
---|
[24979] | 228 | for (int k = 0; k < responses.getLength(); k++)
|
---|
| 229 | {
|
---|
| 230 | String coll_name = GSPath.removeLastLink(((Element) responses.item(k)).getAttribute(GSXML.FROM_ATT));
|
---|
| 231 | NodeList nodes = ((Element) responses.item(k)).getElementsByTagName(GSXML.DOC_NODE_ELEM);
|
---|
| 232 | if (nodes == null || nodes.getLength() == 0)
|
---|
| 233 | continue;
|
---|
| 234 | Element last_node = null;
|
---|
| 235 | Element this_node = null;
|
---|
| 236 | for (int n = 0; n < nodes.getLength(); n++)
|
---|
| 237 | {
|
---|
| 238 | this_node = (Element) nodes.item(n);
|
---|
| 239 | this_node.setAttribute("collection", coll_name);
|
---|
| 240 | if (k == 0)
|
---|
| 241 | {
|
---|
[13978] | 242 |
|
---|
[24979] | 243 | doc_node_list.appendChild(this.doc.importNode(this_node, true));
|
---|
| 244 | }
|
---|
| 245 | else
|
---|
| 246 | {
|
---|
| 247 | if (last_node == null)
|
---|
| 248 | {
|
---|
| 249 | last_node = (Element) GSXML.getChildByTagName(doc_node_list, GSXML.DOC_NODE_ELEM);
|
---|
| 250 | }
|
---|
| 251 | last_node = GSXML.insertIntoOrderedList(doc_node_list, GSXML.DOC_NODE_ELEM, last_node, this_node, "rank", true);
|
---|
| 252 | }
|
---|
[13978] | 253 |
|
---|
[24979] | 254 | }
|
---|
| 255 | }
|
---|
| 256 | return result;
|
---|
[11014] | 257 | }
|
---|
[13978] | 258 |
|
---|
[24979] | 259 | // protected Element processAdvTextQuery(Element request)
|
---|
| 260 | // {
|
---|
[13978] | 261 |
|
---|
[24979] | 262 | // }
|
---|
[26406] | 263 | protected boolean initCollectionList(String lang)
|
---|
[24979] | 264 | {
|
---|
[24993] | 265 | UserContext userContext = new UserContext();
|
---|
[26406] | 266 | userContext.setLanguage(lang);
|
---|
[24993] | 267 | userContext.setUserID("");
|
---|
| 268 |
|
---|
[24979] | 269 | // first, get the message router info
|
---|
| 270 | Element coll_list_message = this.doc.createElement(GSXML.MESSAGE_ELEM);
|
---|
[24993] | 271 | Element coll_list_request = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_DESCRIBE, "", userContext); // uid
|
---|
[24979] | 272 | coll_list_message.appendChild(coll_list_request);
|
---|
| 273 | logger.debug("coll list request = " + this.converter.getPrettyString(coll_list_request));
|
---|
| 274 | Element coll_list_response = (Element) this.router.process(coll_list_message);
|
---|
| 275 | if (coll_list_response == null)
|
---|
| 276 | {
|
---|
| 277 | logger.error("couldn't query the message router!");
|
---|
| 278 | return false;
|
---|
| 279 | }
|
---|
| 280 | logger.debug("coll list response = " + this.converter.getPrettyString(coll_list_response));
|
---|
| 281 | // second, get some info from each collection. we want the coll name
|
---|
| 282 | // and whether its got a text query service
|
---|
[13978] | 283 |
|
---|
[24979] | 284 | NodeList colls = coll_list_response.getElementsByTagName(GSXML.COLLECTION_ELEM);
|
---|
[26406] | 285 | // we can send the same request to multiple collections at once by using a comma separated list
|
---|
[24979] | 286 | Element metadata_message = this.doc.createElement(GSXML.MESSAGE_ELEM);
|
---|
[26406] | 287 | StringBuffer colls_sb = new StringBuffer();
|
---|
[24979] | 288 | for (int i = 0; i < colls.getLength(); i++)
|
---|
| 289 | {
|
---|
| 290 | Element c = (Element) colls.item(i);
|
---|
| 291 | String name = c.getAttribute(GSXML.NAME_ATT);
|
---|
[26577] | 292 | if (i != 0)
|
---|
| 293 | {
|
---|
| 294 | colls_sb.append(",");
|
---|
[26406] | 295 | }
|
---|
| 296 | colls_sb.append(name);
|
---|
| 297 | //Element metadata_request = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_DESCRIBE, name, userContext);
|
---|
| 298 | //metadata_message.appendChild(metadata_request);
|
---|
[24979] | 299 | }
|
---|
[26578] | 300 |
|
---|
[26406] | 301 | Element metadata_request = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_DESCRIBE, colls_sb.toString(), userContext);
|
---|
| 302 | metadata_message.appendChild(metadata_request);
|
---|
[24979] | 303 | logger.debug("metadata request = " + this.converter.getPrettyString(metadata_message));
|
---|
| 304 | Element metadata_response = (Element) this.router.process(metadata_message);
|
---|
| 305 | logger.debug("metadata response = " + this.converter.getPrettyString(metadata_response));
|
---|
| 306 | NodeList coll_responses = metadata_response.getElementsByTagName(GSXML.RESPONSE_ELEM);
|
---|
[25635] | 307 | ArrayList<String> valid_colls = new ArrayList<String>();
|
---|
| 308 | ArrayList<String> valid_coll_names = new ArrayList<String>();
|
---|
[24979] | 309 | for (int i = 0; i < coll_responses.getLength(); i++)
|
---|
| 310 | {
|
---|
| 311 | Element response = (Element) coll_responses.item(i);
|
---|
| 312 | Element coll = (Element) GSXML.getChildByTagName(response, GSXML.COLLECTION_ELEM);
|
---|
| 313 | Element service_list = (Element) GSXML.getChildByTagName(coll, GSXML.SERVICE_ELEM + GSXML.LIST_MODIFIER);
|
---|
| 314 | if (service_list == null)
|
---|
| 315 | continue;
|
---|
| 316 | Element query_service = GSXML.getNamedElement(service_list, GSXML.SERVICE_ELEM, GSXML.NAME_ATT, TEXT_QUERY_SERVICE); // should be AbstractTextSearch.TEXT_QUERY_SERVICE
|
---|
| 317 | if (query_service == null)
|
---|
| 318 | continue;
|
---|
| 319 | // use the name of the response in case we are talking to a remote collection, not the name of the collection.
|
---|
| 320 | String coll_id = response.getAttribute(GSXML.FROM_ATT);
|
---|
[26577] | 321 | String coll_name = GSXML.getDisplayText(coll, GSXML.DISPLAY_TEXT_NAME, lang, "en");
|
---|
[24979] | 322 | valid_colls.add(coll_id);
|
---|
| 323 | valid_coll_names.add(coll_name);
|
---|
| 324 | }
|
---|
| 325 |
|
---|
[26578] | 326 | this.coll_names_map = new HashMap<String, String[]>();
|
---|
| 327 |
|
---|
[24979] | 328 | // ids no all has the list without 'all' option.
|
---|
| 329 | this.coll_ids_list_no_all = new String[1];
|
---|
[25635] | 330 | this.coll_ids_list_no_all = valid_colls.toArray(coll_ids_list_no_all);
|
---|
[24979] | 331 |
|
---|
| 332 | valid_colls.add(0, "all");
|
---|
[26406] | 333 | valid_coll_names.add(0, getTextString("param." + COLLECTION_PARAM + ".all", lang));
|
---|
| 334 |
|
---|
[24979] | 335 | this.coll_ids_list = new String[1];
|
---|
[25635] | 336 | this.coll_ids_list = valid_colls.toArray(coll_ids_list);
|
---|
[26406] | 337 |
|
---|
| 338 | String[] coll_names_list = new String[1];
|
---|
| 339 | coll_names_list = valid_coll_names.toArray(coll_names_list);
|
---|
| 340 | this.coll_names_map.put(lang, coll_names_list);
|
---|
[24979] | 341 | return true;
|
---|
[11014] | 342 | }
|
---|
| 343 |
|
---|
[26577] | 344 | protected void addCollectionNames(String lang)
|
---|
| 345 | {
|
---|
[26406] | 346 |
|
---|
[26577] | 347 | UserContext userContext = new UserContext();
|
---|
| 348 | userContext.setLanguage(lang);
|
---|
| 349 | userContext.setUserID("");
|
---|
[26406] | 350 |
|
---|
[26577] | 351 | ArrayList<String> coll_names = new ArrayList<String>();
|
---|
| 352 | coll_names.add(getTextString("param." + COLLECTION_PARAM + ".all", lang));
|
---|
[26406] | 353 |
|
---|
[26577] | 354 | // need to request MR for collection descriptions
|
---|
| 355 | Element metadata_message = this.doc.createElement(GSXML.MESSAGE_ELEM);
|
---|
[26406] | 356 |
|
---|
[26577] | 357 | // get a comma separated list of coll ids to send to MR
|
---|
| 358 | // the first item is the place holder for 'all'
|
---|
| 359 | StringBuffer colls_sb = new StringBuffer();
|
---|
| 360 | for (int i = 1; i < coll_ids_list.length; i++)
|
---|
| 361 | {
|
---|
| 362 | if (i != 1)
|
---|
| 363 | {
|
---|
| 364 | colls_sb.append(",");
|
---|
| 365 | }
|
---|
| 366 | colls_sb.append(coll_ids_list[i]);
|
---|
| 367 | }
|
---|
| 368 | Element metadata_request = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_DESCRIBE, colls_sb.toString(), userContext);
|
---|
| 369 | // param_list to request just displayTextList
|
---|
| 370 | Element param_list = this.doc.createElement(GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER);
|
---|
| 371 | Element param = GSXML.createParameter(this.doc, GSXML.SUBSET_PARAM, GSXML.DISPLAY_TEXT_ELEM + GSXML.LIST_MODIFIER);
|
---|
| 372 | param_list.appendChild(param);
|
---|
| 373 | metadata_request.appendChild(param_list);
|
---|
| 374 | metadata_message.appendChild(metadata_request);
|
---|
| 375 | logger.debug("coll names metadata request = " + this.converter.getPrettyString(metadata_message));
|
---|
| 376 | Element metadata_response = (Element) this.router.process(metadata_message);
|
---|
| 377 | logger.debug("coll names metadata response = " + this.converter.getPrettyString(metadata_response));
|
---|
| 378 | NodeList coll_responses = metadata_response.getElementsByTagName(GSXML.RESPONSE_ELEM);
|
---|
| 379 | for (int i = 0; i < coll_responses.getLength(); i++)
|
---|
| 380 | {
|
---|
| 381 | Element response = (Element) coll_responses.item(i);
|
---|
| 382 | Element coll = (Element) GSXML.getChildByTagName(response, GSXML.COLLECTION_ELEM);
|
---|
| 383 | String coll_name = GSXML.getDisplayText(coll, GSXML.DISPLAY_TEXT_NAME, lang, "en");
|
---|
| 384 | coll_names.add(coll_name);
|
---|
| 385 | }
|
---|
[26406] | 386 |
|
---|
[26577] | 387 | String[] coll_names_list = new String[1];
|
---|
| 388 | coll_names_list = coll_names.toArray(coll_names_list);
|
---|
| 389 | this.coll_names_map.put(lang, coll_names_list);
|
---|
[26406] | 390 |
|
---|
[26577] | 391 | }
|
---|
[26406] | 392 |
|
---|
[24979] | 393 | protected Element processDocumentMetadataRetrieve(Element request)
|
---|
| 394 | {
|
---|
| 395 | // Create a new (empty) result message
|
---|
| 396 | Element result = this.doc.createElement(GSXML.RESPONSE_ELEM);
|
---|
| 397 | result.setAttribute(GSXML.FROM_ATT, DOCUMENT_METADATA_RETRIEVE_SERVICE);
|
---|
| 398 | result.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_PROCESS);
|
---|
| 399 |
|
---|
[24993] | 400 | UserContext userContext = new UserContext(request);
|
---|
[24979] | 401 | // Get the parameters of the request
|
---|
| 402 | Element param_list = (Element) GSXML.getChildByTagName(request, GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER);
|
---|
| 403 | if (param_list == null)
|
---|
| 404 | {
|
---|
| 405 | logger.error("DocumentMetadataRetrieve request had no paramList.");
|
---|
| 406 | return result; // Return the empty result
|
---|
| 407 | }
|
---|
| 408 |
|
---|
| 409 | NodeList query_doc_list = request.getElementsByTagName(GSXML.DOC_NODE_ELEM);
|
---|
| 410 | if (query_doc_list.getLength() == 0)
|
---|
| 411 | {
|
---|
| 412 | logger.error("DocumentMetadataRetrieve request had no documentNodes.");
|
---|
| 413 | return result; // Return the empty result
|
---|
| 414 | }
|
---|
| 415 |
|
---|
| 416 | // the resulting doc node list
|
---|
| 417 | Element result_node_list = this.doc.createElement(GSXML.DOC_NODE_ELEM + GSXML.LIST_MODIFIER);
|
---|
| 418 | result.appendChild(result_node_list);
|
---|
| 419 |
|
---|
| 420 | // get all the metadata params
|
---|
| 421 | Element new_param_list = this.doc.createElement(GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER);
|
---|
| 422 | Element param = GSXML.createParameter(this.doc, "metadata", "Title");
|
---|
| 423 | new_param_list.appendChild(param);
|
---|
| 424 |
|
---|
| 425 | // organise the nodes into collection lists
|
---|
[25635] | 426 | HashMap<String, Node> coll_map = new HashMap<String, Node>();
|
---|
[24979] | 427 |
|
---|
| 428 | for (int i = 0; i < query_doc_list.getLength(); i++)
|
---|
| 429 | {
|
---|
| 430 | Element doc_node = (Element) query_doc_list.item(i);
|
---|
| 431 | String coll_name = doc_node.getAttribute("collection");
|
---|
| 432 | Element coll_items = (Element) coll_map.get(coll_name);
|
---|
| 433 | if (coll_items == null)
|
---|
| 434 | {
|
---|
| 435 | coll_items = this.doc.createElement(GSXML.DOC_NODE_ELEM + GSXML.LIST_MODIFIER);
|
---|
| 436 | coll_map.put(coll_name, coll_items);
|
---|
| 437 | }
|
---|
| 438 | coll_items.appendChild(this.doc.importNode(doc_node, true));
|
---|
| 439 | }
|
---|
| 440 |
|
---|
| 441 | // create teh individual requests
|
---|
| 442 | Element meta_request_message = this.doc.createElement(GSXML.MESSAGE_ELEM);
|
---|
| 443 | Set mapping_set = coll_map.entrySet();
|
---|
| 444 | Iterator iter = mapping_set.iterator();
|
---|
| 445 |
|
---|
| 446 | while (iter.hasNext())
|
---|
| 447 | {
|
---|
| 448 | Map.Entry e = (Map.Entry) iter.next();
|
---|
| 449 | String cname = (String) e.getKey();
|
---|
| 450 | Element doc_nodes = (Element) e.getValue();
|
---|
[24993] | 451 | Element meta_request = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_PROCESS, GSPath.appendLink(cname, DOCUMENT_METADATA_RETRIEVE_SERVICE), userContext);
|
---|
[24979] | 452 | meta_request.appendChild(doc_nodes);
|
---|
| 453 | meta_request.appendChild(new_param_list.cloneNode(true));
|
---|
| 454 | meta_request_message.appendChild(meta_request);
|
---|
| 455 |
|
---|
| 456 | }
|
---|
| 457 |
|
---|
| 458 | Node meta_result_node = this.router.process(meta_request_message);
|
---|
| 459 | Element meta_result = this.converter.nodeToElement(meta_result_node);
|
---|
| 460 |
|
---|
| 461 | // now need to put the doc nodes back in the right order
|
---|
| 462 | // go through the original list again. keep an element pointer to
|
---|
| 463 | // the next element in each collections list
|
---|
| 464 | NodeList meta_responses = meta_result.getElementsByTagName(GSXML.RESPONSE_ELEM);
|
---|
| 465 | for (int i = 0; i < meta_responses.getLength(); i++)
|
---|
| 466 | {
|
---|
| 467 | String collname = GSPath.removeLastLink(((Element) meta_responses.item(i)).getAttribute(GSXML.FROM_ATT));
|
---|
| 468 | Element first_elem = (Element) GSXML.getNodeByPath(meta_responses.item(i), "documentNodeList/documentNode");
|
---|
| 469 | coll_map.put(collname, first_elem);
|
---|
| 470 | }
|
---|
| 471 |
|
---|
| 472 | for (int i = 0; i < query_doc_list.getLength(); i++)
|
---|
| 473 | {
|
---|
| 474 | Element doc_node = (Element) query_doc_list.item(i);
|
---|
| 475 | Element new_node = (Element) this.doc.importNode(doc_node, false);
|
---|
| 476 | result_node_list.appendChild(new_node);
|
---|
| 477 | String coll_name = doc_node.getAttribute("collection");
|
---|
| 478 |
|
---|
| 479 | Element meta_elem = (Element) coll_map.get(coll_name);
|
---|
| 480 | GSXML.mergeMetadataLists(new_node, meta_elem);
|
---|
| 481 | coll_map.put(coll_name, meta_elem.getNextSibling());
|
---|
| 482 | }
|
---|
| 483 | return result;
|
---|
[11014] | 484 | }
|
---|
| 485 | }
|
---|