<commit_before>package org.intermine.web;

/*
 * Copyright (C) 2002-2004 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.List;
import java.util.Map;

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

import org.intermine.metadata.Model;
import org.intermine.objectstore.ObjectStore;
import org.intermine.objectstore.ObjectStoreException;
import org.intermine.objectstore.query.Query;
import org.intermine.objectstore.query.ResultsInfo;
import org.intermine.web.results.TableHelper;
import org.intermine.web.results.PagedResults;

/**
 * Helper methods for the ViewChange class.
 *
 * @author <NAME>
 */
public abstract class ViewHelper
{
    /**
     * Create a ResultsInfo object for a query on the request and add it to the request
     *
     * @param request The HTTP request we are currently processing
     * @return the errors that occured during processing or null if there are no errors
     * @throws ObjectStoreException if an error occurs accessing the ObjectStore
     */
    public static ResultsInfo makeEstimate(HttpServletRequest request) throws ObjectStoreException {
        HttpSession session = request.getSession();
        ServletContext servletContext = session.getServletContext();
        ObjectStore os = (ObjectStore) servletContext.getAttribute(Constants.OBJECTSTORE);
        
        return os.estimate(makeQuery(request));
    }

    /**
     * Retrieve the query from the request, run it and save the results by calling
     * TableHelper.makeTable().
     *
     * @param request The HTTP request we are currently processing
     * @return the results of running the query
     * @throws ObjectStoreException if an error occurs accessing the ObjectStore
     */
    public static PagedResults runQuery(HttpServletRequest request) throws ObjectStoreException {
        HttpSession session = request.getSession();
        ServletContext servletContext = session.getServletContext();
        ObjectStore os = (ObjectStore) servletContext.getAttribute(Constants.OBJECTSTORE);
        List view = (List) session.getAttribute(Constants.VIEW);
        Map qNodes = (Map) session.getAttribute(Constants.QUERY);
        Map savedQueries = (Map) session.getAttribute(Constants.SAVED_QUERIES);

        PagedResults pr = TableHelper.makeTable(os, makeQuery(request), view);
        String queryName = SaveQueryHelper.findNewQueryName(savedQueries);
        ResultsInfo resultsInfo = pr.getResults().getInfo();
        SaveQueryAction.saveQuery(request, queryName, qNodes, view, resultsInfo);
        return pr;
    }

    /**
     * Invoke MainHelper#makeQuery using parameters from Session and ServletContext
     * @param request The HTTP request we are currently processing
     * @return Query the returned Query
     */
    public static Query makeQuery(HttpServletRequest request) {
        HttpSession session = request.getSession();
        ServletContext servletContext = session.getServletContext();

        Map qNodes = (Map) session.getAttribute(Constants.QUERY);
        List view = (List) session.getAttribute(Constants.VIEW);
        Model model = (Model) servletContext.getAttribute(Constants.MODEL);
        Map savedBags = (Map) session.getAttribute(Constants.SAVED_BAGS);

        return MainHelper.makeQuery(qNodes, view, model, savedBags);
    }
}<commit_msg>Added a temporary variable for ease of reading.<commit_after>package org.intermine.web;

/*
 * Copyright (C) 2002-2004 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.List;
import java.util.Map;

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

import org.intermine.metadata.Model;
import org.intermine.objectstore.ObjectStore;
import org.intermine.objectstore.ObjectStoreException;
import org.intermine.objectstore.query.Query;
import org.intermine.objectstore.query.ResultsInfo;
import org.intermine.web.results.TableHelper;
import org.intermine.web.results.PagedResults;

/**
 * Helper methods for the ViewChange class.
 *
 * @author <NAME>
 */
public abstract class ViewHelper
{
    /**
     * Create a ResultsInfo object for a query on the request and add it to the request
     *
     * @param request The HTTP request we are currently processing
     * @return the errors that occured during processing or null if there are no errors
     * @throws ObjectStoreException if an error occurs accessing the ObjectStore
     */
    public static ResultsInfo makeEstimate(HttpServletRequest request) throws ObjectStoreException {
        HttpSession session = request.getSession();
        ServletContext servletContext = session.getServletContext();
        ObjectStore os = (ObjectStore) servletContext.getAttribute(Constants.OBJECTSTORE);
        
        return os.estimate(makeQuery(request));
    }

    /**
     * Retrieve the query from the request, run it and save the results by calling
     * TableHelper.makeTable().
     *
     * @param request The HTTP request we are currently processing
     * @return the results of running the query
     * @throws ObjectStoreException if an error occurs accessing the ObjectStore
     */
    public static PagedResults runQuery(HttpServletRequest request) throws ObjectStoreException {
        HttpSession session = request.getSession();
        ServletContext servletContext = session.getServletContext();
        ObjectStore os = (ObjectStore) servletContext.getAttribute(Constants.OBJECTSTORE);
        List view = (List) session.getAttribute(Constants.VIEW);
        Map qNodes = (Map) session.getAttribute(Constants.QUERY);
        Map savedQueries = (Map) session.getAttribute(Constants.SAVED_QUERIES);

        Query q = makeQuery(request);
        PagedResults pr = TableHelper.makeTable(os, q, view);
        String queryName = SaveQueryHelper.findNewQueryName(savedQueries);
        ResultsInfo resultsInfo = pr.getResults().getInfo();
        SaveQueryAction.saveQuery(request, queryName, qNodes, view, resultsInfo);
        return pr;
    }

    /**
     * Invoke MainHelper#makeQuery using parameters from Session and ServletContext
     * @param request The HTTP request we are currently processing
     * @return Query the returned Query
     */
    public static Query makeQuery(HttpServletRequest request) {
        HttpSession session = request.getSession();
        ServletContext servletContext = session.getServletContext();

        Map qNodes = (Map) session.getAttribute(Constants.QUERY);
        List view = (List) session.getAttribute(Constants.VIEW);
        Model model = (Model) servletContext.getAttribute(Constants.MODEL);
        Map savedBags = (Map) session.getAttribute(Constants.SAVED_BAGS);

        return MainHelper.makeQuery(qNodes, view, model, savedBags);
    }
}
{'fraction_non_alphanumeric': 0.08142249073184127, 'fraction_numerical': 0.002196896883152547, 'mean_word_length': 3.684244372990354, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7654827', 'n_tokens_mistral': 1871, 'n_tokens_neox': 1863, 'n_words': 578}