Changeset 31285 for main


Ignore:
Timestamp:
2017-01-13T03:46:43+13:00 (7 years ago)
Author:
Georgiy Litvinov
Message:

Java code for hierarchy view in cross collection search

Location:
main/trunk/greenstone3
Files:
3 edited
1 copied

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone3/CollectionGroups.java

    r31265 r31285  
    6565        Document doc = XMLConverter.newDOM();
    6666        UserContext userContext = new UserContext(request);
    67 
     67       
     68        NodeList collList;
     69        NodeList groupList;
     70        int collIndex = 0;
     71        int grpIndex = 0;
     72        boolean hierarchy = true;
     73       
    6874      // Prepare basic response
    6975        Element result = GSXML.createBasicResponse(doc, GSXML.SERVICE_TYPE_GROUPINFO);
    70        
     76        Element result_collection_list = doc.createElement(GSXML.COLLECTION_ELEM + GSXML.LIST_MODIFIER);
     77        result.appendChild(result_collection_list);
     78        Element result_group_list = doc.createElement(GSXML.GROUP_ELEM + GSXML.LIST_MODIFIER);
     79        result.appendChild(result_group_list);
    7180       
    7281        // Get param list from request
     
    8190                groupPath = paramGroup.getAttribute(GSXML.VALUE_ATT);
    8291            }
     92            Element paramHierarchy = GSXML.getNamedElement(paramList, GSXML.PARAM_ELEM, GSXML.NAME_ATT, GSXML.HIERARCHY_ELEM);
     93                if (paramHierarchy != null){
     94                    hierarchy = true;
     95                }
    8396        }
    8497        //Remove leading, ending / and dupliclated /
     
    88101        Element mrCollectionList = getMRCollectionList(userContext);
    89102        if (mrCollectionList == null){
    90             result.appendChild(doc.createElement(GSXML.COLLECTION_ELEM + GSXML.LIST_MODIFIER));
    91103            return result;
    92104        }
    93105        //Get current groups and collections
    94         Element groupContent = getCurrentContent(groupPath);
     106        Element currentContent = getCurrentContent(groupPath);
     107        if (currentContent != null){
     108            currentContent = (Element) doc.importNode(currentContent, true);
     109        }
    95110   
    96111        //Get ungrouped collection list
    97         Element ungroupedCollections = getUngroupedCollections(mrCollectionList);
    98        
    99         // If groupContent is empty return empty collection list
    100         if (groupContent == null) {
    101             // If config file is broken
    102             if (hierarchy == null || groupDesc == null) {
    103                 //Get ungrouped collection list
    104                 result.appendChild(doc.importNode(ungroupedCollections, true));
     112        Element ungroupedCollectionsList = getUngroupedCollections(mrCollectionList);
     113       
     114        if (currentContent != null){
     115            if (hierarchy){
     116                collList = currentContent.getElementsByTagName(GSXML.COLLECTION_ELEM);
     117                groupList = currentContent.getElementsByTagName(GSXML.GROUP_ELEM);
    105118            } else {
    106                 //If config is ok, but in this group no any collection or group
    107                 result.appendChild(doc.createElement(GSXML.COLLECTION_ELEM + GSXML.LIST_MODIFIER));
    108             }
    109             return result;
    110         }
    111         NodeList currentContent = groupContent.getChildNodes();
    112         if (currentContent != null && currentContent.getLength() > 0) {
    113             // Create CollectionList element in response
    114             Element result_collection_list = doc.createElement(GSXML.COLLECTION_ELEM + GSXML.LIST_MODIFIER);
    115             result.appendChild(result_collection_list);
    116             Element result_group_list = doc.createElement(GSXML.GROUP_ELEM + GSXML.LIST_MODIFIER);
    117             result.appendChild(result_group_list);
    118             // Iterate over collections from current view
    119             // i represents current position in groupConfig.xml
    120             int i;
    121             for (i=0; i < currentContent.getLength(); i++) {
    122                 //logger.warn("NODE CuR Content" + GSXML.xmlNodeToString(currentContent.item(i)));
    123                
    124                 if (currentContent.item(i).getNodeName() == GSXML.COLLECTION_ELEM) {
    125                    
    126                     Element collection = (Element) currentContent.item(i);
    127                     String collection_name = collection.getAttribute(GSXML.NAME_ATT);
    128                     // Check whether collection from current view exists in message router response
    129                     Element checkedCollection = GSXML.getNamedElement(mrCollectionList, GSXML.COLLECTION_ELEM,GSXML.NAME_ATT, collection_name);
    130                     if (checkedCollection != null) {
    131                         //Set position value
    132                         checkedCollection.setAttribute(GSXML.POSITION_ATT, String.valueOf(i));
    133                         // Add collection to response
    134                         result_collection_list.appendChild(doc.importNode(checkedCollection, true));
     119                collList = GSXML.getChildrenByTagName(currentContent, GSXML.COLLECTION_ELEM);
     120                groupList = GSXML.getChildrenByTagName(currentContent, GSXML.GROUP_ELEM);
     121            }
     122            //Check collection list for existence
     123            int collListLenght = collList.getLength();
     124            for (collIndex = 0; collIndex < collListLenght; collIndex++) {
     125                Element currentCollection = (Element) collList.item(collIndex);
     126                String collection_name = currentCollection.getAttribute(GSXML.NAME_ATT);
     127                Element checkedCollection = GSXML.getNamedElement(mrCollectionList, GSXML.COLLECTION_ELEM,GSXML.NAME_ATT, collection_name);
     128                if (checkedCollection != null) {
     129                    //Set position value
     130                    if (!hierarchy){
     131                        int position = GSXML.getNodeIndex(currentCollection);
     132                        checkedCollection.setAttribute(GSXML.POSITION_ATT, Integer.toString(position));
    135133                    }
    136                    
    137                     //Iterate over groups in current view
    138                 } else if (currentContent.item(i).getNodeName() == GSXML.GROUP_ELEM) {
    139                     Element currentGroup = (Element) currentContent.item(i);
    140                     String currentGroupName = currentGroup.getAttribute(GSXML.NAME_ATT);
    141                     //Get group description
    142                     Element group = getGroupDescription(currentGroupName);
     134                    // Add collection to response
     135                    result_collection_list.appendChild(doc.importNode(checkedCollection, true));
     136                } else {
     137                    //remove collection from currentContent
     138                    currentCollection.getParentNode().removeChild(currentCollection);
     139                    collIndex--;
     140                    collListLenght--;
     141                }
     142            }
     143            //check group
     144            int groupListLenght = groupList.getLength();
     145            for (grpIndex = 0; grpIndex < groupListLenght; grpIndex++) {
     146                Element currentGroup = (Element) groupList.item(grpIndex);
     147                String currentGroupName = currentGroup.getAttribute(GSXML.NAME_ATT);
     148                Element groupDescription = getGroupDescription(currentGroupName);
     149                if (groupDescription != null) {
    143150                    //Set position value
    144                     if (group != null) {
    145                         group.setAttribute(GSXML.POSITION_ATT, String.valueOf(i));
    146                         result_group_list.appendChild(doc.importNode(group, true));
     151                    if (!hierarchy){
     152                        int position = GSXML.getNodeIndex(currentGroup);
     153                        groupDescription.setAttribute(GSXML.POSITION_ATT, Integer.toString(position));
    147154                    }
    148 
    149                 }
    150 
    151             }
     155                    result_group_list.appendChild(doc.importNode(groupDescription, true));
     156                } else {
     157                    //remove group from currentContent
     158                    currentGroup.getParentNode().removeChild(currentGroup);
     159                    grpIndex--;
     160                    groupListLenght--;
     161                }
     162            }
     163            logger.error("Group list lenght " + groupListLenght+ " result_group_list is " + GSXML.elementToString(result_group_list, true));
     164           
     165        }
    152166            //Add ungrouped collections if groupPath /+ or "" or null
    153167            if (groupPath.isEmpty()) {
    154168               
    155                
    156169                //Add each ungrouped collection to the collection list in loop
    157                 NodeList ungroupedCollectionNodes = GSXML.getChildrenByTagName(ungroupedCollections, GSXML.COLLECTION_ATT);
     170                NodeList ungroupedCollectionNodes = GSXML.getChildrenByTagName(ungroupedCollectionsList, GSXML.COLLECTION_ATT);
    158171                if (ungroupedCollectionNodes != null) {
    159                     for (int j = 0; j < ungroupedCollectionNodes.getLength(); j++) {
    160                         //logger.warn("UNGROUPED COLL ELEM" + GSXML.xmlNodeToString(ungroupedCollections).intern());
    161                         Element ungroupedCollection = (Element) doc.importNode(ungroupedCollectionNodes.item(j), true);
    162                         ungroupedCollection.setAttribute(GSXML.POSITION_ATT, String.valueOf(i++));
     172                    for (int k = 0; k < ungroupedCollectionNodes.getLength(); k++) {
     173                        Element ungroupedCollection = (Element) doc.importNode(ungroupedCollectionNodes.item(k), true);
     174                        if (!hierarchy){
     175                            ungroupedCollection.setAttribute(GSXML.POSITION_ATT, String.valueOf(grpIndex + collIndex++));
     176                        }
    163177                        result_collection_list.appendChild(ungroupedCollection);
     178                        if (hierarchy){
     179                           
     180                            currentContent.appendChild(doc.importNode(ungroupedCollectionNodes.item(k), true));
     181                        }
    164182                    }
    165183                }
    166184               
    167185            } else {
    168                 Element groupDescription = getPathInfo(groupPath);
    169                 if (groupContent != null){
    170                     result.appendChild(doc.importNode(groupDescription, true));
    171                 }
    172             }
    173         }
    174 
     186                Element pathInfo = getPathInfo(groupPath);
     187                if (currentContent != null){
     188                    result.appendChild(doc.importNode(pathInfo, true));
     189                }
     190            }
     191        if (hierarchy){
     192            result.appendChild(currentContent);
     193        }
     194            logger.error("currentContent is " + GSXML.elementToString(currentContent, true));
    175195        return result;
    176196    }
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/action/QueryAction.java

    r30476 r31285  
    1111import org.greenstone.gsdl3.util.GSXSLT;
    1212import org.greenstone.gsdl3.util.UserContext;
     13import org.greenstone.gsdl3.util.XMLConverter;
    1314import org.w3c.dom.Document;
    1415import org.w3c.dom.Element;
     
    100101            if (request_type.indexOf("d") != -1) {
    101102              page_response.appendChild(service_description);
     103              addCollectionsHierarchy(page_response,userContext);
    102104            }
    103105            //}
     
    284286        addInterfaceOptions(page_response);
    285287        return page_response;
     288    }
     289
     290    private void addCollectionsHierarchy(Element page_response, UserContext userContext) {
     291        Document doc = page_response.getOwnerDocument();
     292        String collectionsHierarchy = "CollectionsHierarchy";
     293        if (checkServiceAvailable(userContext, collectionsHierarchy)){
     294            Element groupQueryMessage = doc.createElement(GSXML.MESSAGE_ELEM);
     295            Element groupQueryRequest = GSXML.createBasicRequest(doc, GSXML.REQUEST_TYPE_PROCESS, collectionsHierarchy, userContext);
     296            groupQueryMessage.appendChild(groupQueryRequest);
     297            Element groupQueryResult = (Element) this.mr.process(groupQueryMessage);
     298            if (groupQueryResult == null){
     299                return;
     300            }
     301            Element groupQueryResponse = (Element) GSXML.getChildByTagName(groupQueryResult, GSXML.RESPONSE_ELEM);
     302            if (groupQueryResponse == null){
     303                return;
     304            }
     305            Element hierarchy = (Element) GSXML.getChildByTagName(groupQueryResponse, GSXML.HIERARCHY_ELEM);
     306            page_response.appendChild(doc.importNode(hierarchy, true));
     307        }
     308       
     309       
     310    }
     311
     312    private boolean checkServiceAvailable(UserContext userContext, String collectionsHierarchy) {
     313       
     314        Document doc = XMLConverter.newDOM();
     315        Element infoMessage = doc.createElement(GSXML.MESSAGE_ELEM);
     316        Element infoRequest = GSXML.createBasicRequest(doc, GSXML.REQUEST_TYPE_DESCRIBE, "", userContext);
     317        Element paramList = doc.createElement(GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER);
     318        infoRequest.appendChild(paramList);
     319        GSXML.addParameterToList(paramList, GSXML.SUBSET_PARAM, GSXML.SERVICE_ELEM + GSXML.LIST_MODIFIER);
     320        infoMessage.appendChild(infoRequest);
     321        Element responseMessage = (Element) this.mr.process(infoMessage);
     322        if (responseMessage == null)
     323        {
     324            logger.error("couldn't query the message router!");
     325            return false;
     326        }
     327        NodeList serviceLists = responseMessage.getElementsByTagName(GSXML.SERVICE_ELEM + GSXML.LIST_MODIFIER);
     328        if (serviceLists == null || serviceLists.getLength() == 0){
     329            logger.error("No service List in response message from message router!");
     330            return false;
     331        }
     332        Element serviceList = (Element) serviceLists.item(0);
     333        Element groupInfoService = GSXML.getNamedElement(serviceList, GSXML.SERVICE_ELEM, GSXML.NAME_ATT, collectionsHierarchy);
     334        if (groupInfoService == null){
     335            logger.error("service " + collectionsHierarchy + " unavailable");
     336            return false;
     337        }
     338        return true;
    286339    }
    287340
     
    375428    return true;
    376429  }
     430 
    377431}
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/service/CollectionGroups.java

    r31181 r31285  
    3030    private static final String GROUP_CONTENT = "GroupCurrentContent";
    3131    private static final String UNIQUE_COLLECTIONS = "UniqueCollections";
     32    private static final String COLLECTIONS_HIERARCHY = "CollectionsHierarchy";
    3233
    3334    static Logger logger = Logger.getLogger(org.greenstone.gsdl3.service.BerryBasket.class.getName());
     
    3940    }
    4041
    41     String[] _services = { GROUP_CONTENT, UNIQUE_COLLECTIONS };
     42    String[] _services = { GROUP_CONTENT, UNIQUE_COLLECTIONS, COLLECTIONS_HIERARCHY };
    4243
    4344    public boolean configure(Element info, Element extra_info) {
     
    5657        }
    5758        // Load group configuration from file
    58         readGroupConfiguration();
    59 
    60         return true;
     59        return readGroupConfiguration();
    6160    }
    6261
     
    8685        groupPath = groupPath.replaceAll("(^/+)|(/+$)", "");
    8786
    88         Element mrCollectionList = getMRCollectionList(userContext);
     87        Element mrCollectionList = getAvailableCollectionList(userContext);
    8988        if (mrCollectionList == null){
    9089            result.appendChild(doc.createElement(GSXML.COLLECTION_ELEM + GSXML.LIST_MODIFIER));
     
    9291        }
    9392        //Get current groups and collections
    94         Element groupContent = getCurrentContent(groupPath);
     93        Element groupContent = getRawCurrentContent(groupPath);
    9594   
    9695        //Get ungrouped collection list
     
    9998        // If groupContent is empty return empty collection list
    10099        if (groupContent == null) {
    101             // If config file is broken
    102             if (hierarchy == null || groupDesc == null) {
    103                 //Get ungrouped collection list
    104                 result.appendChild(doc.importNode(ungroupedCollections, true));
    105             } else {
    106                 //If config is ok, but in this group no any collection or group
    107                 result.appendChild(doc.createElement(GSXML.COLLECTION_ELEM + GSXML.LIST_MODIFIER));
    108             }
     100            result.appendChild(doc.createElement(GSXML.COLLECTION_ELEM + GSXML.LIST_MODIFIER));
    109101            return result;
    110102        }
     
    139131                    Element currentGroup = (Element) currentContent.item(i);
    140132                    String currentGroupName = currentGroup.getAttribute(GSXML.NAME_ATT);
    141                     //Get group description
    142                     Element group = getGroupDescription(currentGroupName);
    143                     //Set position value
    144                     if (group != null) {
    145                         group.setAttribute(GSXML.POSITION_ATT, String.valueOf(i));
    146                         result_group_list.appendChild(doc.importNode(group, true));
    147                     }
    148 
     133                    Element groupDescription = getGroupDescription(currentGroupName);
     134                   
     135                    groupDescription.setAttribute(GSXML.POSITION_ATT, String.valueOf(i));
     136                    result_group_list.appendChild(doc.importNode(groupDescription, true));
    149137                }
    150138
     
    152140            //Add ungrouped collections if groupPath /+ or "" or null
    153141            if (groupPath.isEmpty()) {
    154                
    155142               
    156143                //Add each ungrouped collection to the collection list in loop
     
    183170        Element resultCollections = doc.createElement(GSXML.COLLECTION_ELEM + GSXML.LIST_MODIFIER);
    184171        result.appendChild(resultCollections);
    185         Element mrCollectionList = getMRCollectionList(userContext);
     172        Element mrCollectionList = getAvailableCollectionList(userContext);
    186173        //Collections from message router check
    187174        if (mrCollectionList == null){
     
    218205        groups = GSXML.getValue(groupParam).split(",");
    219206        for (int i = 0; i < groups.length; i++) {
    220             Element groupContent = getCurrentContent(groups[i]);
     207            Element groupContent = getRawCurrentContent(groups[i]);
    221208            //If group exists
    222209            if (groupContent != null) {
     
    241228    }
    242229   
    243     private Element getCurrentContent(String path) {
    244 
    245         if (hierarchy == null || groupDesc == null) {
    246             return null;
    247         }
    248        
    249         Document doc = XMLConverter.newDOM();
    250        
     230    protected Element processCollectionsHierarchy(Element request){
     231       
     232        Document doc = XMLConverter.newDOM();
     233        UserContext userContext = new UserContext(request);
     234        // Prepare basic response
     235        Element result = GSXML.createBasicResponse(doc, GSXML.SERVICE_TYPE_GROUPINFO);
     236        String currentPath = "";
     237        Element currentContent = getRawCurrentContent(currentPath);
     238        if (currentContent == null){
     239            return result;
     240        }
     241        Element searchableCollectionList = getSearchableCollectionList(userContext);
     242        if (searchableCollectionList == null){
     243            return result;
     244        }
     245       
     246        //Get ungrouped collection list
     247        sanitizeCurrentContent(currentContent, searchableCollectionList);
     248        addGroupInfo(currentContent, currentPath);
     249        addUngroupedCollections(currentContent, searchableCollectionList);
     250        result.appendChild(doc.importNode(currentContent, true));
     251        return result;
     252    }
     253   
     254    private void addGroupInfo(Element currentContent, String groupPath) {
     255        NodeList groups = GSXML.getChildrenByTagName(currentContent,GSXML.GROUP_ELEM);
     256        for (int i=0;i<groups.getLength();i++){
     257            Element group = (Element) groups.item(i);
     258            String name = group.getAttribute(GSXML.NAME_ATT);
     259            String newPath = groupPath + "/" + name;
     260            group.setAttribute(GSXML.PATH_ATT, newPath);
     261            Element groupDescription = getGroupDescription(name);
     262            Element titleEl = (Element) GSXML.getChildByTagName(groupDescription, GSXML.TITLE_ELEM);
     263            String title = titleEl.getTextContent();
     264            group.setAttribute(GSXML.TITLE_ELEM, title  );
     265            addGroupInfo(group, newPath);
     266        }
     267       
     268    }
     269
     270    private Element getRawCurrentContent(String path) {
     271
    251272        if (path == null) {
    252273             path = "";
    253274        }
    254        
     275
     276        Document doc = XMLConverter.newDOM();
    255277        path = path.replaceAll("(/+)", "/");
    256278        path = path.replaceAll("(^/+)|(/+$)", "");
     
    259281
    260282       
    261         Element currentView = (Element) hierarchy.cloneNode(true);
     283        Element currentContent = (Element) hierarchy.cloneNode(true);
    262284        // Get the current view
    263285        for (int i = 0; i < pathSteps.length; i++) {
    264286            if (!pathSteps[i].isEmpty()) {
    265                 currentView = GSXML.getNamedElement(currentView, GSXML.GROUP_ELEM, GSXML.NAME_ATT, pathSteps[i]);
    266                 if (currentView == null){
     287                currentContent = GSXML.getNamedElement(currentContent, GSXML.GROUP_ELEM, GSXML.NAME_ATT, pathSteps[i]);
     288                if (currentContent == null){
    267289                    break;
    268290                }
    269291            }
    270292        }
    271         if (currentView == null || !currentView.hasChildNodes()) {
     293        if (currentContent == null || !currentContent.hasChildNodes()) {
    272294            // Return to the main page
    273295            return null;
    274296        }
    275         return currentView;
    276     }
    277 
    278     private void readGroupConfiguration() {
     297        return currentContent;
     298    }
     299   
     300    private void sanitizeCurrentContent(Element currentContent, Element checkedCollectionList){
     301        if (currentContent == null){
     302            return;
     303        }
     304        NodeList nodes = currentContent.getElementsByTagName(GSXML.COLLECTION_ELEM);
     305        for (int i = 0; i < nodes.getLength(); i++) {
     306            Element element = (Element) nodes.item(i);
     307            String name = element.getAttribute(GSXML.NAME_ATT);
     308            Element checkedCollection = GSXML.getNamedElement(checkedCollectionList, GSXML.COLLECTION_ELEM, GSXML.NAME_ATT, name);
     309            if (checkedCollection == null) {
     310                element.getParentNode().removeChild(element);
     311                i--;
     312            }
     313        }
     314    }
     315   
     316    private void addUngroupedCollections(Element currentContent, Element availableCollections){
     317        if (currentContent == null){
     318            return;
     319        }
     320        Document doc = currentContent.getOwnerDocument();
     321        NodeList collectionList = availableCollections.getElementsByTagName(GSXML.COLLECTION_ELEM);
     322        for (int i = 0; i < collectionList.getLength();i++){
     323            Element collection = (Element) collectionList.item(i);
     324            String name = collection.getAttribute(GSXML.NAME_ATT);
     325            NodeList foundCollection = GSXML.getNamedElements(currentContent, GSXML.COLLECTION_ELEM, GSXML.NAME_ATT, name);
     326            if (foundCollection.getLength() == 0){
     327                Element ungroupedCollection = doc.createElement(GSXML.COLLECTION_ELEM);
     328                ungroupedCollection.setAttribute(GSXML.NAME_ATT, name);
     329                currentContent.appendChild(ungroupedCollection);
     330            }
     331        }
     332       
     333    }
     334
     335    private boolean readGroupConfiguration() {
    279336
    280337        File configFile = new File(GSFile.groupConfigFile(site_home));
     
    282339        if (!configFile.exists()) {
    283340            logger.info("Groups config file " + configFile.getPath() + " does not exist.");
    284             return;
     341            return false;
    285342        }
    286343        // Try to read and catch exception if it fails
     
    301358            logger.error("Error occurred while trying to remove emtpy nodes from groupConfig.xml");
    302359            e.printStackTrace();
     360            return false;
    303361        } 
    304362       
    305363        hierarchy = (Element) GSXML.getChildByTagName(content, GSXML.HIERARCHY_ELEM);
    306364        groupDesc = (Element) GSXML.getChildByTagName(content, GSXML.GROUP_DESC_ELEM);
     365        if (hierarchy == null || groupDesc == null){
     366            logger.error("Error processing groups configuration. Check groupConfig.xml");
     367            return false;
     368        }
     369        verifyGroupDescription();
     370        return true;
     371    }
     372
     373    private void verifyGroupDescription() {
     374        Document doc = groupDesc.getOwnerDocument();
     375        NodeList groups = hierarchy.getElementsByTagName(GSXML.GROUP_ELEM);
     376        for (int i = 0; i < groups.getLength(); i++) {
     377            Element group = (Element) groups.item(i);
     378            String name = group.getAttribute(GSXML.NAME_ATT);
     379            Element foundDescription = GSXML.getNamedElement(groupDesc, GSXML.GROUP_ELEM, GSXML.NAME_ATT, name);
     380            if (foundDescription == null){
     381                Element defaultDescription = doc.createElement(GSXML.GROUP_ELEM);
     382                defaultDescription.setAttribute(GSXML.NAME_ATT, name);
     383                Element groupTitle = doc.createElement(GSXML.TITLE_ELEM);
     384                groupTitle.setTextContent(name);
     385                defaultDescription.appendChild(groupTitle);
     386                groupDesc.appendChild(defaultDescription);
     387            }
     388        }
     389       
    307390    }
    308391
    309392    private Element getGroupDescription(String name) {
    310         if (groupDesc != null) {
    311             Element description = (Element) GSXML.getNamedElement(groupDesc, GSXML.GROUP_ELEM, GSXML.NAME_ATT, name);
    312             if (description != null) {
    313                 return description;
    314             }
     393        Element description = (Element) GSXML.getNamedElement(groupDesc, GSXML.GROUP_ELEM, GSXML.NAME_ATT, name);
     394        if (description == null) {
    315395            logger.error("GroupDescription is not defined. Check your groupConfig.xml");
    316         }
    317            
    318         logger.error("No group descriptions found. Check your groupConfig.xml");
    319         return null;
     396        }
     397        return description;
    320398    }
    321399
    322400    private Element getUngroupedCollections(Element mr_collection_list) {
    323401       
    324         if (groupDesc == null || hierarchy == null) {
    325             logger.error("No group descriptions in groupConfig.xml. Check your groupConfig.xml");
    326             //return mr_collection_list
    327             return mr_collection_list;
    328         }
    329402        Document doc = XMLConverter.newDOM();
    330403        // Create Set
     
    366439    private Element getPathInfo(String path) {
    367440
    368         if (hierarchy == null || groupDesc == null) {
    369             return null;
    370         }
    371        
    372441        Document doc = XMLConverter.newDOM();
    373442       
     
    387456                    pathStepDescription.setAttribute(GSXML.POSITION_ATT, String.valueOf(i));
    388457                    pathStepDescription.setAttribute(GSXML.PATH_ATT, currentPath);
    389                     pathInfo.appendChild(doc.importNode(pathStepDescription, true));
    390                 }
     458                }
     459                pathInfo.appendChild(doc.importNode(pathStepDescription, true));
    391460            }
    392461        }
     
    394463        return pathInfo;
    395464    }
    396     private Element getMRCollectionList(UserContext userContext){
     465    private Element getAvailableCollectionList(UserContext userContext){
    397466        Document doc = XMLConverter.newDOM();
    398467        // Get the message router info
     
    415484        return mr_collection_list;
    416485    }
     486    private Element getSearchableCollectionList(UserContext userContext){
     487        Document doc = XMLConverter.newDOM();
     488        Element collectionList = doc.createElement(GSXML.COLLECTION_ELEM + GSXML.LIST_MODIFIER);
     489        // Get the message router info
     490        Element mr_info_message = doc.createElement(GSXML.MESSAGE_ELEM);
     491        Element mr_request = GSXML.createBasicRequest(doc, GSXML.REQUEST_TYPE_DESCRIBE, "TextQuery" , userContext);
     492        mr_info_message.appendChild(mr_request);
     493        Element mr_info_response_message = (Element) this.router.process(mr_info_message);
     494        if (mr_info_response_message == null) {
     495            logger.error(" couldn't query the message router!");
     496            return null;
     497        }
     498        NodeList options = mr_info_response_message.getElementsByTagName(GSXML.PARAM_OPTION_ELEM);
     499        for (int i = 0; i < options.getLength(); i++) {
     500            Element option = (Element) options.item(i);
     501            String name = option.getAttribute(GSXML.NAME_ATT);
     502            if (name.equals("all")){
     503                continue;
     504            }
     505            Element collection = doc.createElement(GSXML.COLLECTION_ELEM);
     506            collection.setAttribute(GSXML.NAME_ATT, name);
     507            collectionList.appendChild(collection);
     508        }
     509        return collectionList;
     510    }
    417511}
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/service/CrossCollectionSearch.java

    r31262 r31285  
    533533            groupParamList.appendChild(doc.importNode(GSXML.getNamedElement(paramList, GSXML.PARAM_ELEM, GSXML.NAME_ATT, GSXML.GROUP_ELEM), true));
    534534            Element groupQueryResult = (Element) this.router.process(groupQueryMessage);
    535             Element groupQueryResonse = (Element) GSXML.getChildByTagName(groupQueryResult, GSXML.RESPONSE_ELEM);
    536             Element collList = (Element) GSXML.getChildByTagName(groupQueryResonse, GSXML.COLLECTION_ELEM + GSXML.LIST_MODIFIER);
     535            Element groupQueryResponse = (Element) GSXML.getChildByTagName(groupQueryResult, GSXML.RESPONSE_ELEM);
     536            Element collList = (Element) GSXML.getChildByTagName(groupQueryResponse, GSXML.COLLECTION_ELEM + GSXML.LIST_MODIFIER);
    537537            NodeList collections = GSXML.getChildrenByTagName(collList, GSXML.COLLECTION_ELEM);
    538538            collArray = new String[collections.getLength()];
Note: See TracChangeset for help on using the changeset viewer.