Changeset 32649


Ignore:
Timestamp:
2018-12-03T13:11:33+13:00 (5 years ago)
Author:
kjdon
Message:

add group info into about page response if we have a group param in the request - it means that we have come to this collection via a group, so rememebr that for teh user. group path info used for breadcrumbs.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/action/PageAction.java

    r32549 r32649  
    55
    66import org.apache.log4j.Logger;
     7import org.greenstone.gsdl3.service.CollectionGroups;
    78import org.greenstone.gsdl3.util.GSParams;
    89import org.greenstone.gsdl3.util.GSPath;
     
    2425    public static final String PREFS_PAGE = "pref";
    2526    public static final String GLI4GS3_PAGE = "gli4gs3";
     27
     28  // this gets set to the groupInfo service name if there is one.
     29  protected String groupInfoServiceName = null;
    2630
    2731    public Node process(Node message_node)
     
    123127            return null;
    124128        }
     129
     130        // import it into our current doc.
     131        info_response = (Element) doc.importNode(info_response, true);
    125132       
    126133        Element resp_service_list = (Element) GSXML.getChildByTagName(info_response, GSXML.SERVICE_ELEM + GSXML.LIST_MODIFIER);
    127        
     134
     135        // TODO - is this true? can we run with no MR services? can't we still query for the collections/MR info?
    128136        if (resp_service_list == null) {
    129137            logger.error("No services available. Couldn't query the message router!");
    130138            return null;
    131139        }
    132         Element groupInfoService = GSXML.getNamedElement(resp_service_list, GSXML.SERVICE_ELEM, GSXML.TYPE_ATT,
    133                 GSXML.SERVICE_TYPE_GROUPINFO);
    134         if (groupInfoService != null) {
    135             // Prepare request for CollectionGroup service to get current
    136             // collections and groups list
    137             Element group_info_message = doc.createElement(GSXML.MESSAGE_ELEM);
    138             Element group_info_request = GSXML.createBasicRequest(doc, GSXML.TO_ATT,
    139                     groupInfoService.getAttribute(GSXML.NAME_ATT), userContext);
    140             group_info_message.appendChild(group_info_request);
    141             //Append group request if exists
    142             Element paramList = (Element) GSXML.getChildByTagName(request, GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER);
    143             if (paramList != null) {
    144                 group_info_request.appendChild(doc.importNode(paramList, true));
    145             }
    146             Element group_info_response_message = (Element) this.mr.process(group_info_message);
    147             Element group_info_response = (Element) GSXML.getChildByTagName(group_info_response_message,
    148                     GSXML.RESPONSE_ELEM);
    149             Element collection_list = (Element) GSXML.getChildByTagName(group_info_response,
    150                     GSXML.COLLECTION_ELEM + GSXML.LIST_MODIFIER);
    151             // Add Collection List from CollectionGroup Service to response
    152             // from message router
    153             info_response = (Element) doc.importNode(info_response, true);
    154             if (collection_list != null) {
    155                 info_response.appendChild(doc.importNode(collection_list, true));
    156             }
    157             Element group_list = (Element) GSXML.getChildByTagName(group_info_response,
    158                     GSXML.GROUP_ELEM + GSXML.LIST_MODIFIER);
    159             if (group_list != null) {
    160                 info_response.appendChild(doc.importNode(group_list, true));
    161             }
    162             Element path_list = (Element) GSXML.getChildByTagName(group_info_response,
    163                     GSXML.PATH_ELEM + GSXML.LIST_MODIFIER);
    164             if (path_list != null) {
    165                 info_response.appendChild(doc.importNode(path_list, true));
    166             }
    167             // Send message to groupInfoType Services
     140
     141        // if we haven't done so already, check for group info type service
     142        if (this.groupInfoServiceName ==  null) {
     143
     144          Element groupInfoService = GSXML.getNamedElement(resp_service_list, GSXML.SERVICE_ELEM, GSXML.NAME_ATT,
     145                                   CollectionGroups.GROUP_CONTENT);
     146         
     147          if (groupInfoService != null) {
     148            this.groupInfoServiceName = CollectionGroups.GROUP_CONTENT;
     149          } else {
     150            this.groupInfoServiceName = "NO_GROUPS";
     151          }
     152        }
     153       
     154        if (!this.groupInfoServiceName.equals("NO_GROUPS")) {
     155
     156          String group = null;
     157          Element cgi_paramList = (Element) GSXML.getChildByTagName(request, GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER);
     158          HashMap<String, Serializable> params = GSXML.extractParams(cgi_paramList, false);
     159          if (params != null) {
     160            group = (String) params.get(GSParams.GROUP);
     161            if (group.equals("")) {
     162              group = null;
     163            }
     164          }
     165         
     166          Element group_info_response = getGroupInfo(group, userContext);
     167
     168          // Add all the needed parts of the response to the main page response
     169          Element collection_list = (Element) GSXML.getChildByTagName(group_info_response,
     170                                          GSXML.COLLECTION_ELEM + GSXML.LIST_MODIFIER);
     171           
     172          if (collection_list != null) {
     173            info_response.appendChild(doc.importNode(collection_list, true));
     174          }
     175          Element group_list = (Element) GSXML.getChildByTagName(group_info_response,
     176                                     GSXML.GROUP_ELEM + GSXML.LIST_MODIFIER);
     177          if (group_list != null) {
     178            info_response.appendChild(doc.importNode(group_list, true));
     179          }
     180          Element path_list = (Element) GSXML.getChildByTagName(group_info_response,
     181                                    GSXML.PATH_ELEM + GSXML.LIST_MODIFIER);
     182          if (path_list != null) {
     183            info_response.appendChild(doc.importNode(path_list, true));
     184          }
     185         
    168186        } else {
     187         
    169188            // If no service with type SERVICE_TYPE_GROUPINFO could be provided
    170189            // request message router for all available collections
     
    187206        // elements but for now, we'll just get it all
    188207        Element collection_list = (Element) GSXML.getChildByTagName(info_response, GSXML.COLLECTION_ELEM + GSXML.LIST_MODIFIER);
    189         //logger.debug(GSXML.xmlNodeToString(collection_list));
    190208        if (collection_list != null)
    191209        {
     
    227245    } // homePage
    228246
     247  /** sends a request to GroupCurrentContent service to get group info. null group will give top level info,
     248      otherwise will just give info for specified group */
     249  protected Element getGroupInfo(String group, UserContext userContext) {
     250    Document doc = XMLConverter.newDOM();
     251    // collections and groups list
     252    Element group_info_message = doc.createElement(GSXML.MESSAGE_ELEM);
     253    Element group_info_request = GSXML.createBasicRequest(doc, GSXML.TO_ATT,
     254                              groupInfoServiceName, userContext);
     255    group_info_message.appendChild(group_info_request);
     256    if (group != null) {
     257      Element param_list = doc.createElement(GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER);
     258      GSXML.addParameterToList(param_list, GSParams.GROUP, group);
     259      group_info_request.appendChild(param_list);
     260    }
     261    // send off the request
     262    Element group_info_response_message = (Element) this.mr.process(group_info_message);
     263    Element group_info_response = (Element) GSXML.getChildByTagName(group_info_response_message,
     264                                    GSXML.RESPONSE_ELEM);
     265    return group_info_response;
     266  }
     267 
    229268  protected Element aboutOrPrefsPage(Element request, String page_name)
    230269    {
     
    302341
    303342        Element response = (Element) GSXML.getChildByTagName(coll_about_response, GSXML.RESPONSE_ELEM);
     343
     344        // is this collection part of a group?
     345        String group = (String) params.get(GSParams.GROUP);
     346        if (group != null && !group.equals("")) {
     347          // ...yes it is. get the group path info
     348          Element group_info_response = getGroupInfo(group, userContext);
     349          Element path_list = (Element) GSXML.getChildByTagName(group_info_response,
     350                                    GSXML.PATH_ELEM + GSXML.LIST_MODIFIER);
     351          if (path_list != null) {
     352            response.appendChild(response.getOwnerDocument().importNode(path_list, true));
     353          }
     354        }
     355       
    304356        //add the site metadata
    305357        addSiteMetadata(response, userContext);
Note: See TracChangeset for help on using the changeset viewer.