<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.ActionMessages;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionError;

import org.intermine.objectstore.ObjectStore;

/**
 * Action to create a new TemplateQuery from current query.
 *
 * @author <NAME>
 */
public class BuildTemplateAction extends Action
{
    /**
     * Handle submission of the build template form. Build a UserTemplateQuery.
     *
     * @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();
        Profile profile = (Profile) session.getAttribute(Constants.PROFILE);
        ObjectStore os = (ObjectStore) servletContext.getAttribute(Constants.OBJECTSTORE);
        PathQuery query = (PathQuery) session.getAttribute(Constants.TEMPLATE_PATHQUERY);
        BuildTemplateForm tf = (BuildTemplateForm) form;
        TemplateQuery editing = (TemplateQuery) session.getAttribute(Constants.EDITING_TEMPLATE);
        
        TemplateQuery template = TemplateHelper.buildTemplateQuery(tf, query);
        
        if (request.getParameter("preview") != null) {
            request.setAttribute("previewTemplate", template);
            request.setAttribute("showPreview", Boolean.TRUE);
            return mapping.findForward("templateBuilder");
        } else {
            // Create new user template
            session.removeAttribute(Constants.TEMPLATE_PATHQUERY);
            session.removeAttribute(Constants.EDITING_TEMPLATE);
            String key = (editing == null) ? "templateBuilder.templateCreated"
                                           : "templateBuilder.templateUpdated";
            String msg = getResources(request).getMessage(key, template.getName());
            session.setAttribute(Constants.MESSAGE, msg);
            tf.reset();
            // Replace template if needed
            if (editing != null) {
                profile.deleteTemplate(editing.getName());
            }
            profile.saveTemplate(template.getName(), template);
            // If superuser then rebuild shared templates
            if (profile.getUsername() != null
                && profile.getUsername().equals
                    (servletContext.getAttribute(Constants.SUPERUSER_ACCOUNT))) {
                InitialiserPlugin.loadGlobalTemplateQueries(servletContext);
            }
            return mapping.findForward("finish");
        }
    }
}
<commit_msg>checkstyle fix<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 org.intermine.objectstore.ObjectStore;

/**
 * Action to create a new TemplateQuery from current query.
 *
 * @author <NAME>
 */
public class BuildTemplateAction extends Action
{
    /**
     * Handle submission of the build template form. Build a UserTemplateQuery.
     *
     * @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();
        Profile profile = (Profile) session.getAttribute(Constants.PROFILE);
        ObjectStore os = (ObjectStore) servletContext.getAttribute(Constants.OBJECTSTORE);
        PathQuery query = (PathQuery) session.getAttribute(Constants.TEMPLATE_PATHQUERY);
        BuildTemplateForm tf = (BuildTemplateForm) form;
        TemplateQuery editing = (TemplateQuery) session.getAttribute(Constants.EDITING_TEMPLATE);
        
        TemplateQuery template = TemplateHelper.buildTemplateQuery(tf, query);
        
        if (request.getParameter("preview") != null) {
            request.setAttribute("previewTemplate", template);
            request.setAttribute("showPreview", Boolean.TRUE);
            return mapping.findForward("templateBuilder");
        } else {
            // Create new user template
            session.removeAttribute(Constants.TEMPLATE_PATHQUERY);
            session.removeAttribute(Constants.EDITING_TEMPLATE);
            String key = (editing == null) ? "templateBuilder.templateCreated"
                                           : "templateBuilder.templateUpdated";
            String msg = getResources(request).getMessage(key, template.getName());
            session.setAttribute(Constants.MESSAGE, msg);
            tf.reset();
            // Replace template if needed
            if (editing != null) {
                profile.deleteTemplate(editing.getName());
            }
            profile.saveTemplate(template.getName(), template);
            // If superuser then rebuild shared templates
            if (profile.getUsername() != null
                && profile.getUsername().equals
                    (servletContext.getAttribute(Constants.SUPERUSER_ACCOUNT))) {
                InitialiserPlugin.loadGlobalTemplateQueries(servletContext);
            }
            return mapping.findForward("finish");
        }
    }
}

{'fraction_non_alphanumeric': 0.08349043899811473, 'fraction_numerical': 0.0021545919741448962, 'mean_word_length': 2.6335616438356166, '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': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4331418', 'n_tokens_mistral': 1741, 'n_tokens_neox': 1732, 'n_words': 473}