package org.intermine.web.struts;

/*
 * Copyright (C) 2002-2009 FlyMine
 *
 * This code may be freely distributed and modified under the
 * terms of the GNU Lesser General Public Licence.  This should
 * be distributed with the code.  See the LICENSE file for more
 * information or http://www.gnu.org/copyleft/lesser.html.
 *
 */

import java.util.Map;
import java.util.Properties;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.intermine.api.bag.BagManager;
import org.intermine.api.search.SearchRepository;
import org.intermine.api.search.WebSearchable;
import org.intermine.web.logic.Constants;
import org.intermine.web.logic.session.SessionMethods;

/**
 * Display the query builder (if there is a curernt query) or redirect to project.sitePrefix.
 *
 * @author Tom Riley
 */
public class BeginAction extends InterMineAction
{
   /**
    * Either display the query builder or redirect to project.sitePrefix.
    *
    * @param mapping The ActionMapping used to select this instance
    * @param form The optional ActionForm bean for this request (if any)
    * @param request The HTTP request we are processing
    * @param response The HTTP response we are creating
    * @return an ActionForward object defining where control goes next
    *
    * @exception Exception if the application business logic throws
    *  an exception
    */
   public ActionForward execute(ActionMapping mapping,
                                @SuppressWarnings("unused") ActionForm form,
                                HttpServletRequest request,
                                @SuppressWarnings("unused") HttpServletResponse response)
       throws Exception {

       HttpSession session = request.getSession();
       ServletContext servletContext = session.getServletContext();
       SearchRepository searchRepository = SessionMethods.getGlobalSearchRepository(servletContext);
       BagManager bagManager = SessionMethods.getBagManager(servletContext);
       
       if (request.getParameter("GALAXY_URL") != null) {
           request.getSession().setAttribute("GALAXY_URL", request.getParameter("GALAXY_URL"));
           SessionMethods.recordMessage("Welcome to FlyMine, GALAXY users. ", session);
       }

       Integer bagCount = bagManager.getGlobalBags().size();
       Map<String, ? extends WebSearchable> webSearchables =
           searchRepository.getWebSearchableMap("template");
       Integer templateCount = webSearchables.size();

       /* count number of templates and bags */
       request.setAttribute("bagCount", bagCount);
       request.setAttribute("templateCount", templateCount);

       Properties properties = (Properties) request.getSession()
                               .getServletContext().getAttribute(Constants.WEB_PROPERTIES);
       String[] beginQueryClasses = (properties.get("begin.query.classes").toString())
                                   .split("[ ,]+");
       request.setAttribute("beginQueryClasses", beginQueryClasses);
       return mapping.findForward("begin");
   }
}

@@ -330,30 +330,8 @@
 */%0A%0A
-import java.util.Map;%0A
 impo
@@ -734,78 +734,32 @@
 api.
-search.SearchRepository;%0Aimport org.intermine.api.search.WebSearchable
+template.TemplateManager
 ;%0Aim
@@ -1975,186 +1975,8 @@
 ();%0A
-       SearchRepository searchRepository = SessionMethods.getGlobalSearchRepository(servletContext);%0A       BagManager bagManager = SessionMethods.getBagManager(servletContext);%0A
     
@@ -2241,229 +2241,311 @@
     
-Integer bagCount = bagManager.getGlobalBags().size();%0A       Map%3CString, ? extends WebSearchable%3E webSearchables =%0A           searchRepository.getWebSearchableMap(%22template%22);%0A       Integer templateCount = webSearchables
+BagManager bagManager = SessionMethods.getBagManager(servletContext);%0A       Integer bagCount = bagManager.getGlobalBags().size();%0A       %0A       TemplateManager templateManager = SessionMethods.getTemplateManager(servletContext);%0A       Integer templateCount = templateManager.getValidGlobalTemplates()
 .siz
@@ -2759,65 +2759,9 @@
 es) 
-request.getSession()%0A                               .getS
+s
 ervl
@@ -2769,18 +2769,16 @@
 tContext
-()
 .getAttr

Remove use of SearchRepository.