<commit_before>package org.intermine.web;

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

import org.intermine.objectstore.ObjectStore;
import org.intermine.web.bag.BagQueryResult;
import org.intermine.web.bag.BagQueryRunner;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.StringReader;

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.apache.struts.action.ActionMessage;
import org.apache.struts.upload.FormFile;

/**
 * An action that makes a bag from text.
 *
 * @author <NAME>
 */

public class BuildBagAction extends InterMineAction
{
    
    /**
     * Action for creating a bag of InterMineObjects or Strings from identifiers in text field.
     *
     * @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();
        BuildBagForm buildBagForm = (BuildBagForm) form;
        ServletContext servletContext = session.getServletContext();
        ObjectStore os = (ObjectStore) servletContext.getAttribute(Constants.OBJECTSTORE);
        String newBagName = buildBagForm.getBagName();
        String type = buildBagForm.getType();

        Map classKeys = (Map) servletContext.getAttribute(Constants.CLASS_KEYS);
        Map bagQueries = (Map) servletContext.getAttribute(Constants.BAG_QUERIES);
        BagQueryRunner bagRunner = new BagQueryRunner(os, classKeys, bagQueries, servletContext);

        int maxBagSize = WebUtil.getIntSessionProperty(session, "max.bag.size", 100000);

        BufferedReader reader = null;

        if (request.getParameter("paste") != null) {
            String trimmedText = buildBagForm.getText().trim();
            if (trimmedText.length() == 0) {
                recordError(new ActionMessage("bagBuild.noBagPaste"), request);
                return mapping.findForward("mymine");
            }
            reader = new BufferedReader(new StringReader(trimmedText));
        } else {
            if (request.getParameter("file") != null) {
                FormFile formFile = buildBagForm.getFormFile();
                if (formFile == null || formFile.getFileName() == null
                                || formFile.getFileName().length() == 0) {<commit_msg>If the user fails to choose a type on the bag upload page, show an error message.<commit_after>package org.intermine.web;

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

import org.intermine.objectstore.ObjectStore;
import org.intermine.web.bag.BagQueryResult;
import org.intermine.web.bag.BagQueryRunner;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.StringReader;

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

import org.apache.commons.lang.StringUtils;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.upload.FormFile;

/**
 * An action that makes a bag from text.
 *
 * @author <NAME>
 */

public class BuildBagAction extends InterMineAction
{
    
    /**
     * Action for creating a bag of InterMineObjects or Strings from identifiers in text field.
     *
     * @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();
        BuildBagForm buildBagForm = (BuildBagForm) form;
        ServletContext servletContext = session.getServletContext();
        ObjectStore os = (ObjectStore) servletContext.getAttribute(Constants.OBJECTSTORE);
        String newBagName = buildBagForm.getBagName();
        String type = buildBagForm.getType();

        if (StringUtils.isEmpty(type)) {
            recordError(new ActionMessage("bagBuild.typeNotSet"), request);
            return mapping.findForward("mymine");
        }
        
        Map classKeys = (Map) servletContext.getAttribute(Constants.CLASS_KEYS);
        Map bagQueries = (Map) servletContext.getAttribute(Constants.BAG_QUERIES);
        BagQueryRunner bagRunner = new BagQueryRunner(os, classKeys, bagQueries, servletContext);

        int maxBagSize = WebUtil.getIntSessionProperty(session, "max.bag.size", 100000);

        BufferedReader reader = null;

        if (request.getParameter("paste") != null) {
            String trimmedText = buildBagForm.getText().trim();
            if (trimmedText.length() == 0) {
                recordError(new ActionMessage("bagBuild.noBagPaste"), request);
                return mapping.findForward("mymine");
            }
            reader = new BufferedReader(new StringReader(trimmedText));
        } else {
            if (request.getParameter("file") != null) {
                FormFile formFile = buildBagForm.getFormFile();
                if (formFile == null || formFile.getFileName() == null
                                || formFile.getFileName().length() == 0) {
{'fraction_non_alphanumeric': 0.08858816964285714, 'fraction_numerical': 0.004464285714285714, 'mean_word_length': 2.9983268265476855, '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': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3017811', 'n_tokens_mistral': 1888, 'n_tokens_neox': 1843, 'n_words': 523}