Changeset 31181
- Timestamp:
- 2016-12-08T02:02:55+13:00 (7 years ago)
- Location:
- main/trunk/greenstone3/src/java/org/greenstone/gsdl3/service
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone3/src/java/org/greenstone/gsdl3/service/CollectionGroups.java
r31166 r31181 2 2 3 3 import java.io.File; 4 4 5 import org.apache.log4j.Logger; 5 6 import org.greenstone.gsdl3.util.GSFile; … … 11 12 import org.w3c.dom.Node; 12 13 import org.w3c.dom.NodeList; 14 13 15 import java.util.Set; 14 16 … … 19 21 20 22 import java.util.HashSet; 23 import java.util.Iterator; 21 24 22 25 public class CollectionGroups extends ServiceRack { … … 26 29 27 30 private static final String GROUP_CONTENT = "GroupCurrentContent"; 31 private static final String UNIQUE_COLLECTIONS = "UniqueCollections"; 28 32 29 33 static Logger logger = Logger.getLogger(org.greenstone.gsdl3.service.BerryBasket.class.getName()); … … 35 39 } 36 40 37 String[] _services = { GROUP_CONTENT };41 String[] _services = { GROUP_CONTENT, UNIQUE_COLLECTIONS }; 38 42 39 43 public boolean configure(Element info, Element extra_info) { … … 60 64 61 65 Document doc = XMLConverter.newDOM(); 62 63 66 UserContext userContext = new UserContext(request); 64 67 68 // Prepare basic response 69 Element result = GSXML.createBasicResponse(doc, GSXML.SERVICE_TYPE_GROUPINFO); 70 71 65 72 // Get param list from request 66 73 Element paramList = (Element) GSXML.getChildByTagName(request, GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER); … … 79 86 groupPath = groupPath.replaceAll("(^/+)|(/+$)", ""); 80 87 81 // Get the message router info 82 Element mr_info_message = doc.createElement(GSXML.MESSAGE_ELEM); 83 Element mr_request = GSXML.createBasicRequest(doc, GSXML.REQUEST_TYPE_DESCRIBE, "", userContext); 84 mr_info_message.appendChild(mr_request); 85 Element mr_info_response_message = (Element) this.router.process(mr_info_message); 86 if (mr_info_response_message == null) { 87 logger.error(" couldn't query the message router!"); 88 return null; 89 } 90 Element mr_info_response = (Element) GSXML.getChildByTagName(mr_info_response_message, GSXML.RESPONSE_ELEM); 91 if (mr_info_response == null) { 92 logger.error("couldn't query the message router!"); 93 return null; 94 } 95 96 Element mr_collection_list = (Element) GSXML.getChildByTagName(mr_info_response, 97 GSXML.COLLECTION_ELEM + GSXML.LIST_MODIFIER); 88 Element mrCollectionList = getMRCollectionList(userContext); 89 if (mrCollectionList == null){ 90 result.appendChild(doc.createElement(GSXML.COLLECTION_ELEM + GSXML.LIST_MODIFIER)); 91 return result; 92 } 98 93 //Get current groups and collections 99 94 Element groupContent = getCurrentContent(groupPath); 100 95 101 96 //Get ungrouped collection list 102 Element ungroupedCollections = getUngroupedCollections(mr_collection_list); 103 104 // Prepare basic response 105 Element result = GSXML.createBasicResponse(doc, GSXML.SERVICE_TYPE_GROUPINFO); 106 97 Element ungroupedCollections = getUngroupedCollections(mrCollectionList); 98 107 99 // If groupContent is empty return empty collection list 108 100 if (groupContent == null) { … … 135 127 String collection_name = collection.getAttribute(GSXML.NAME_ATT); 136 128 // Check whether collection from current view exists in message router response 137 Element checkedCollection = GSXML.getNamedElement(mr _collection_list, GSXML.COLLECTION_ELEM,GSXML.NAME_ATT, collection_name);129 Element checkedCollection = GSXML.getNamedElement(mrCollectionList, GSXML.COLLECTION_ELEM,GSXML.NAME_ATT, collection_name); 138 130 if (checkedCollection != null) { 139 131 //Set position value … … 184 176 } 185 177 178 protected Element processUniqueCollections(Element request) { 179 Document doc = XMLConverter.newDOM(); 180 UserContext userContext = new UserContext(request); 181 // Prepare basic response 182 Element result = GSXML.createBasicResponse(doc, GSXML.SERVICE_TYPE_GROUPINFO); 183 Element resultCollections = doc.createElement(GSXML.COLLECTION_ELEM + GSXML.LIST_MODIFIER); 184 result.appendChild(resultCollections); 185 Element mrCollectionList = getMRCollectionList(userContext); 186 //Collections from message router check 187 if (mrCollectionList == null){ 188 logger.error("mrCollectionList is null!"); 189 return result; 190 } 191 //paramList check 192 Element paramList = (Element) GSXML.getChildByTagName(request, GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER); 193 if (paramList == null) { 194 logger.error("UniqueCollections request had no paramList."); 195 return result; 196 } 197 //Add collections from request 198 Set<String> uniq_colls = new HashSet<String>(); 199 Element collParam = GSXML.getNamedElement(paramList, GSXML.PARAM_ELEM, GSXML.NAME_ATT, GSXML.COLLECTION_ELEM); 200 if (collParam != null){ 201 String colls = GSXML.getValue(collParam); 202 if (!colls.isEmpty()) 203 { 204 String[] _colls = colls.split(","); 205 for (int i=0;i < _colls.length;i++){ 206 uniq_colls.add(_colls[i]); 207 } 208 } 209 } 210 //groupParam check 211 Element groupParam = GSXML.getNamedElement(paramList, GSXML.PARAM_ELEM, GSXML.NAME_ATT, GSXML.GROUP_ELEM); 212 if (groupParam == null) { 213 logger.error("UniqueCollections request had no groupParam."); 214 return result; 215 } 216 //Add collections from groups 217 String[] groups = null; 218 groups = GSXML.getValue(groupParam).split(","); 219 for (int i = 0; i < groups.length; i++) { 220 Element groupContent = getCurrentContent(groups[i]); 221 //If group exists 222 if (groupContent != null) { 223 NodeList collectionNodes = GSXML.getChildrenByTagName(groupContent, GSXML.COLLECTION_ELEM); 224 for (int j = 0; j < collectionNodes.getLength(); j++) { 225 String collName = ((Element) collectionNodes.item(j)).getAttribute(GSXML.NAME_ATT); 226 uniq_colls.add(collName); 227 } 228 } 229 230 } 231 //Fill result collectionList 232 for (Iterator<String> iterator = uniq_colls.iterator(); iterator.hasNext();) { 233 String collectionName = (String) iterator.next(); 234 Element checkedCollection = GSXML.getNamedElement(mrCollectionList, GSXML.COLLECTION_ELEM,GSXML.NAME_ATT, collectionName); 235 if (checkedCollection != null){ 236 resultCollections.appendChild(doc.importNode(checkedCollection, true)); 237 } 238 } 239 return result; 240 241 } 242 186 243 private Element getCurrentContent(String path) { 187 244 … … 195 252 path = ""; 196 253 } 254 255 path = path.replaceAll("(/+)", "/"); 256 path = path.replaceAll("(^/+)|(/+$)", ""); 257 197 258 String[] pathSteps = path.split("/"); 198 259 … … 203 264 if (!pathSteps[i].isEmpty()) { 204 265 currentView = GSXML.getNamedElement(currentView, GSXML.GROUP_ELEM, GSXML.NAME_ATT, pathSteps[i]); 266 if (currentView == null){ 267 break; 268 } 205 269 } 206 270 } … … 330 394 return pathInfo; 331 395 } 332 396 private Element getMRCollectionList(UserContext userContext){ 397 Document doc = XMLConverter.newDOM(); 398 // Get the message router info 399 Element mr_info_message = doc.createElement(GSXML.MESSAGE_ELEM); 400 Element mr_request = GSXML.createBasicRequest(doc, GSXML.REQUEST_TYPE_DESCRIBE, "", userContext); 401 mr_info_message.appendChild(mr_request); 402 Element mr_info_response_message = (Element) this.router.process(mr_info_message); 403 if (mr_info_response_message == null) { 404 logger.error(" couldn't query the message router!"); 405 return null; 406 } 407 Element mr_info_response = (Element) GSXML.getChildByTagName(mr_info_response_message, GSXML.RESPONSE_ELEM); 408 if (mr_info_response == null) { 409 logger.error("Message router response is null!"); 410 return null; 411 } 412 413 Element mr_collection_list = (Element) GSXML.getChildByTagName(mr_info_response, GSXML.COLLECTION_ELEM + GSXML.LIST_MODIFIER); 414 415 return mr_collection_list; 416 } 333 417 } -
main/trunk/greenstone3/src/java/org/greenstone/gsdl3/service/CrossCollectionSearch.java
r30958 r31181 48 48 protected static final String QUERY_PARAM = "query"; 49 49 protected static final String COLLECTION_PARAM = "collection"; 50 protected static final String GROUP_PARAM = "group"; 50 51 protected static final String MAXDOCS_PARAM = "maxDocs"; // matches standard maxDocs, but in this case, means max docs per collection 51 52 protected static final String HITS_PER_PAGE_PARAM = "hitsPerPage"; … … 172 173 return result; // Return the empty result 173 174 } 174 175 175 // get the collection list 176 176 String[] colls_list = coll_ids_list_no_all; … … 184 184 } 185 185 } 186 187 colls_list = mergeGroups(userContext, param_list, colls_list); 186 188 187 189 String maxdocs = MAXDOCS_DEFAULT; … … 266 268 267 269 // } 270 271 272 268 273 protected boolean initCollectionList(String lang) 269 274 { … … 489 494 return result; 490 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 491 565 }
Note:
See TracChangeset
for help on using the changeset viewer.