Changeset 31343


Ignore:
Timestamp:
2017-01-24T03:31:12+13:00 (7 years ago)
Author:
Georgiy Litvinov
Message:

Additional method to pass group path inside s1.collection param instead of using s1.group param (also works). Required by query page collection&groups select menu.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/service/CrossCollectionSearch.java

    r31285 r31343  
    505505    private String[] mergeGroups(UserContext userContext, Element paramList, String[] collArray){
    506506        Document doc = XMLConverter.newDOM();
    507         Element groupParam = GSXML.getNamedElement(paramList, GSXML.PARAM_ELEM, GSXML.NAME_ATT, GROUP_PARAM);
     507       
     508        Element groupParamList = extractGroupParams(paramList, collArray, doc);     
     509       
    508510        Element collParam = GSXML.getNamedElement(paramList, GSXML.PARAM_ELEM, GSXML.NAME_ATT, COLLECTION_PARAM);
    509         //Group param not null and coll param null or not 'all'
    510         if (groupParam != null && (collParam == null || !GSXML.getValue(collParam).equals("all")))
     511        boolean allSelected = GSXML.getValue(collParam).matches(".*\\ball\\b.*");
     512        //Group param not empty and coll param null or not 'all'
     513        if ( allSelected || !groupParamList.hasChildNodes())
    511514        {   
    512             //GroupInfo service to get uniq collections
    513             String uniqCollServiceName = "UniqueCollections";
    514             Element infoResponse = getMRInfo(userContext);
    515             Element serviceList = (Element) GSXML.getChildByTagName(infoResponse, GSXML.SERVICE_ELEM + GSXML.LIST_MODIFIER);
    516             if (serviceList == null) {
    517                 logger.error("Service list is null!");
    518                 return collArray;
    519             }
    520             Element groupInfoService = GSXML.getNamedElement(serviceList, GSXML.SERVICE_ELEM, GSXML.NAME_ATT,   uniqCollServiceName);
    521             if (groupInfoService == null){
    522                 logger.error("UniqueCollections service unavailable; Check your groupConfig.xml");
    523                 return collArray;
    524             }
    525             Element groupQueryMessage = doc.createElement(GSXML.MESSAGE_ELEM);
    526             Element groupQueryRequest = GSXML.createBasicRequest(doc, GSXML.REQUEST_TYPE_PROCESS, uniqCollServiceName, userContext);
    527             groupQueryMessage.appendChild(groupQueryRequest);
    528             Element groupParamList = doc.createElement(GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER);
    529             groupQueryRequest.appendChild(groupParamList);
    530             if (collParam != null){
    531                 groupParamList.appendChild(doc.importNode(GSXML.getNamedElement(paramList, GSXML.PARAM_ELEM, GSXML.NAME_ATT, GSXML.COLLECTION_ELEM), true));   
    532             }
    533             groupParamList.appendChild(doc.importNode(GSXML.getNamedElement(paramList, GSXML.PARAM_ELEM, GSXML.NAME_ATT, GSXML.GROUP_ELEM), true));
    534             Element groupQueryResult = (Element) this.router.process(groupQueryMessage);
    535             Element groupQueryResponse = (Element) GSXML.getChildByTagName(groupQueryResult, GSXML.RESPONSE_ELEM);
    536             Element collList = (Element) GSXML.getChildByTagName(groupQueryResponse, GSXML.COLLECTION_ELEM + GSXML.LIST_MODIFIER);
    537             NodeList collections = GSXML.getChildrenByTagName(collList, GSXML.COLLECTION_ELEM);
    538             collArray = new String[collections.getLength()];
    539             for (int i = 0; i < collections.getLength(); i++){
    540                 String collName = ((Element) collections.item(i)).getAttribute(GSXML.NAME_ATT);
    541                 collArray[i] = collName;
    542             }
    543515            return collArray;
    544516        }
     517        //GroupInfo service to get uniq collections
     518        String uniqCollServiceName = "UniqueCollections";
     519        Element infoResponse = getMRInfo(userContext);
     520        Element serviceList = (Element) GSXML.getChildByTagName(infoResponse, GSXML.SERVICE_ELEM + GSXML.LIST_MODIFIER);
     521        if (serviceList == null) {
     522            logger.error("Service list is null!");
     523            return collArray;
     524        }
     525        Element groupInfoService = GSXML.getNamedElement(serviceList, GSXML.SERVICE_ELEM, GSXML.NAME_ATT,   uniqCollServiceName);
     526        if (groupInfoService == null){
     527            logger.error("UniqueCollections service unavailable; Check your groupConfig.xml");
     528            return collArray;
     529        }
     530        Element groupQueryMessage = doc.createElement(GSXML.MESSAGE_ELEM);
     531        Element groupQueryRequest = GSXML.createBasicRequest(doc, GSXML.REQUEST_TYPE_PROCESS, uniqCollServiceName, userContext);
     532        groupQueryMessage.appendChild(groupQueryRequest);
     533        groupQueryRequest.appendChild(groupParamList);
     534        if (collParam != null){
     535            groupParamList.appendChild(doc.importNode(GSXML.getNamedElement(paramList, GSXML.PARAM_ELEM, GSXML.NAME_ATT, GSXML.COLLECTION_ELEM), true));   
     536        }
     537        Element groupQueryResult = (Element) this.router.process(groupQueryMessage);
     538        Element groupQueryResponse = (Element) GSXML.getChildByTagName(groupQueryResult, GSXML.RESPONSE_ELEM);
     539        Element collList = (Element) GSXML.getChildByTagName(groupQueryResponse, GSXML.COLLECTION_ELEM + GSXML.LIST_MODIFIER);
     540        NodeList collections = GSXML.getChildrenByTagName(collList, GSXML.COLLECTION_ELEM);
     541        collArray = new String[collections.getLength()];
     542        for (int i = 0; i < collections.getLength(); i++){
     543            String collName = ((Element) collections.item(i)).getAttribute(GSXML.NAME_ATT);
     544            collArray[i] = collName;
     545        }
    545546        return collArray;
    546547       
    547548    }
     549
     550    private Element extractGroupParams(Element paramList, String[] collArray, Document doc) {
     551        Element groupParamList = doc.createElement(GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER);
     552        Element groupParam = null;
     553        Element groupNode = GSXML.getNamedElement(paramList, GSXML.PARAM_ELEM, GSXML.NAME_ATT, GROUP_PARAM);
     554        if (groupNode != null){
     555            groupParam = (Element) doc.importNode(groupNode, true);
     556            groupParamList.appendChild(groupParam);
     557        } else {
     558            groupParam = doc.createElement(GSXML.PARAM_ELEM);
     559            groupParam.setAttribute(GSXML.NAME_ATT, GSXML.GROUP_ELEM);
     560            groupParamList.appendChild(groupParam);
     561        }
     562        String prefix = GSXML.GROUP_ELEM + "/";
     563        for (int i = 0; i < collArray.length; i++) {
     564            String collectionParam = collArray[i];
     565            if (collectionParam.startsWith(prefix)){
     566                String value = groupParam.getAttribute(GSXML.VALUE_ATT);
     567                value += "," + collectionParam.substring(prefix.length() - 1 );
     568                groupParam.setAttribute(GSXML.VALUE_ATT, value);
     569            }
     570        }
     571        return groupParamList;
     572    }
     573   
    548574    private Element getMRInfo(UserContext userContext){
    549575        Document doc = XMLConverter.newDOM();
Note: See TracChangeset for help on using the changeset viewer.