<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 javax.servlet.ServletContext;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import java.util.List;
import java.util.Map;
import java.util.Iterator;

import org.intermine.model.InterMineObject;
import org.intermine.objectstore.query.ConstraintOp;
import org.intermine.web.results.PagedResults;

/**
 * Action to handle submit from the template page.
 *
 * @author <NAME>
 * @author <NAME>
 */
public class TemplateAction extends Action
{
    /**
     * Build a query based on the template and the input from the user.
     *
     * @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,
                                 ActionForm form,
                                 HttpServletRequest request,
                                 HttpServletResponse response)
        throws Exception {
        HttpSession session = request.getSession();
        ServletContext servletContext = session.getServletContext();
        Map templateQueries = (Map) servletContext.getAttribute(Constants.TEMPLATE_QUERIES);
        String queryName = (String) session.getAttribute("queryName");

        TemplateQuery template = (TemplateQuery) templateQueries.get(queryName);
        
        for (Iterator i = template.getNodes().iterator(); i.hasNext();) {
            PathNode node = (PathNode) i.next();
            int j = template.getNodes().indexOf(node);
                String op = (String) ((TemplateForm) form).getAttributeOps("" + (j + 1));
            ConstraintOp constraintOp = ConstraintOp.getOpForIndex(Integer.valueOf(op));
            
            Object constraintValue = ((TemplateForm) form).getParsedAttributeValues("" + (j + 1));
            
            node.getConstraints().set(0, new Constraint(constraintOp, constraintValue));
        }
        
        SessionMethods.loadQuery(template.getQuery(), request.getSession());
        
        form.reset (mapping, request);
        
        return handleTemplateQuery(mapping, form, request, response);
    }
    
    /**
     * Called after the form has been read and the query has been loaded into the session. By
     * default, this method returns forward "query". Override to forward to some other
     * destination or do more processing on the template query.
     *
     * @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
     */
    protected ActionForward handleTemplateQuery(ActionMapping mapping,
                                             ActionForm form,
                                             HttpServletRequest request,
                                             HttpServletResponse response)
        throws Exception {
        return mapping.findForward("query");
    }
}
<commit_msg>Removed unused imports.<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 javax.servlet.ServletContext;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import java.util.Map;
import java.util.Iterator;

import org.intermine.objectstore.query.ConstraintOp;

/**
 * Action to handle submit from the template page.
 *
 * @author <NAME>
 * @author <NAME>
 */
public class TemplateAction extends Action
{
    /**
     * Build a query based on the template and the input from the user.
     *
     * @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,
                                 ActionForm form,
                                 HttpServletRequest request,
                                 HttpServletResponse response)
        throws Exception {
        HttpSession session = request.getSession();
        ServletContext servletContext = session.getServletContext();
        Map templateQueries = (Map) servletContext.getAttribute(Constants.TEMPLATE_QUERIES);
        String queryName = (String) session.getAttribute("queryName");

        TemplateQuery template = (TemplateQuery) templateQueries.get(queryName);
        
        for (Iterator i = template.getNodes().iterator(); i.hasNext();) {
            PathNode node = (PathNode) i.next();
            int j = template.getNodes().indexOf(node);
                String op = (String) ((TemplateForm) form).getAttributeOps("" + (j + 1));
            ConstraintOp constraintOp = ConstraintOp.getOpForIndex(Integer.valueOf(op));
            
            Object constraintValue = ((TemplateForm) form).getParsedAttributeValues("" + (j + 1));
            
            node.getConstraints().set(0, new Constraint(constraintOp, constraintValue));
        }
        
        SessionMethods.loadQuery(template.getQuery(), request.getSession());
        
        form.reset (mapping, request);
        
        return handleTemplateQuery(mapping, form, request, response);
    }
    
    /**
     * Called after the form has been read and the query has been loaded into the session. By
     * default, this method returns forward "query". Override to forward to some other
     * destination or do more processing on the template query.
     *
     * @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
     */
    protected ActionForward handleTemplateQuery(ActionMapping mapping,
                                             ActionForm form,
                                             HttpServletRequest request,
                                             HttpServletResponse response)
        throws Exception {
        return mapping.findForward("query");
    }
}

{'fraction_non_alphanumeric': 0.07813664596273293, 'fraction_numerical': 0.002732919254658385, 'mean_word_length': 2.5545253863134656, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 18, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5523788', 'n_tokens_mistral': 1915, 'n_tokens_neox': 1894, 'n_words': 660}