<commit_before>package edu.ucla.wise.client.admin;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import edu.ucla.wise.commons.DataBank;
import edu.ucla.wise.commons.StudySpace;
import edu.ucla.wise.commons.Survey;
import edu.ucla.wise.commons.WISEApplication;

/*
 Load a new survey and set up its Data tables. 
 (Called via URL request from load.jsp in the admin application)
 */

/**
 * SurveyLoaderServlet class is used to load a new survey and set up its Data tables
 * and also archives old tables.
 * (Called via URL request from load.jsp in the admin application)
 * 
 * @author <NAME>
 * @version 1.0  
 */
@WebServlet("/survey/admin_survey_loader")
public class SurveyLoaderServlet extends HttpServlet {
    static final long serialVersionUID = 1000;

    /**
     * Archives the old survey and sets up new survey.
     *  
     * @param 	req	 HTTP Request.
     * @param 	res	 HTTP Response.
     * @throws 	ServletException and IOException. 
     */
    @Override
    public void service(HttpServletRequest req, HttpServletResponse res)
	    throws ServletException, IOException {

		/* prepare for writing */
		res.setContentType("text/html");
		PrintWriter out = res.getWriter();
		
		out.println("<table border=0>");
		
		/* get the survey name and study ID */
		String surveyName = (String) req.getParameter("SurveyName");
		String studyId = (String) req.getParameter("SID");
		if (surveyName == null || studyId == null) {
		    out.println("<tr><td align=center>SURVEY LOADER ERROR: can't " +
		    		"get the survey name or study id from URL</td></tr></table>");
		    return;
		}
	
		out.println("<tr><td align=center>SURVEY Name:" + surveyName
				+ " STUDY ID: " + studyId + "</td></tr>");
	
		/* get the study space */
		StudySpace studySpace = StudySpace.getSpace(studyId);
		if (studySpace == null) {
		    out.println("<tr><td align=center>SURVEY LOADER ERROR: " +
		    		"can't create study space</td></tr></table>");
		    return;
		}
	
		/* get the survey */
		String surveyID = studySpace.loadSurvey(surveyName);
		Survey survey = studySpace.getSurvey(surveyID);
	
		DataBank db = new DataBank(studySpace);
	
		try {
			
		    /* connect to the database */
			String sql = "DELETE FROM interview_assignment WHERE survey = ?";
			Connection conn = studySpace.getDBConnection();
		   	PreparedStatement stmt = conn.prepareStatement(sql);
	
		    /* create data table - archive old data - copy old data */
		    out.println("<tr><td align=center>Creating new data table.<td></tr>");
		    db.setupSurvey(survey);
	
		    /* delete old data*/
		    //out.println("<tr><td align=center>Deleting data from tables" +
		    //		"update_trail and page_submit.</td></tr>");
		    //db.delete_survey_data(survey);
	
		    /* remove the interview records from table - interview_assignment */
		    out.println("<tr><td align=center>Deleting data from tables " +
		    		"of interview_assignment and interview_session.</td><tr>");
		    
		    stmt.setString(1, surveyID);		    <commit_msg>removed unused imports<commit_after>package edu.ucla.wise.client.admin;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import edu.ucla.wise.commons.DataBank;
import edu.ucla.wise.commons.StudySpace;
import edu.ucla.wise.commons.Survey;
import edu.ucla.wise.commons.WISEApplication;
import edu.ucla.wise.initializer.StudySpaceParametersProvider;
import edu.ucla.wise.studyspace.parameters.StudySpaceParameters;

/*
 Load a new survey and set up its Data tables. 
 (Called via URL request from load.jsp in the admin application)
 */

/**
 * SurveyLoaderServlet class is used to load a new survey and set up its Data tables
 * and also archives old tables.
 * (Called via URL request from load.jsp in the admin application)
 * 
 * @author <NAME>
 * @version 1.0  
 */
@WebServlet("/survey/admin_survey_loader")
public class SurveyLoaderServlet extends HttpServlet {
    static final long serialVersionUID = 1000;

    /**
     * Archives the old survey and sets up new survey.
     *  
     * @param 	req	 HTTP Request.
     * @param 	res	 HTTP Response.
     * @throws 	ServletException and IOException. 
     */
    @Override
    public void service(HttpServletRequest req, HttpServletResponse res)
	    throws ServletException, IOException {

		/* prepare for writing */
		res.setContentType("text/html");
		PrintWriter out = res.getWriter();
		
		out.println("<table border=0>");
		
		/* get the survey name and study ID */
		String surveyName = (String) req.getParameter("SurveyName");
		String studyId = (String) req.getParameter("SID");
		if (surveyName == null || studyId == null) {
		    out.println("<tr><td align=center>SURVEY LOADER ERROR: can't " +
		    		"get the survey name or study id from URL</td></tr></table>");
		    return;
		}
	
		out.println("<tr><td align=center>SURVEY Name:" + surveyName
				+ " STUDY ID: " + studyId + "</td></tr>");
	
		/* get the study space */
		StudySpace studySpace = StudySpace.getSpace(studyId);
		if (studySpace == null) {
		    out.println("<tr><td align=center>SURVEY LOADER ERROR: " +
		    		"can't create study space</td></tr></table>");
		    return;
		}
	
		/* get the survey */
		String surveyID = studySpace.loadSurvey(surveyName);
		Survey survey = studySpace.getSurvey(surveyID);
	
		StudySpaceParameters params = StudySpaceParametersProvider
				.getInstance().getStudySpaceParameters(studySpace.studyName); 
		
		DataBank db = new DataBank(studySpace, params);
	
		try {
			
		    /* connect to the database */
			String sql = "DELETE FROM interview_assignment WHERE survey = ?";
			Connection conn = studySpace.getDBConnection();
		   	PreparedStatement stmt = conn.prepareStatement(sql);
	
		    /* create data table - archive old data - copy old data */
		    out.println("<tr><td align=center>Creating new data table.<td></tr>");
		    db.setupSurvey(survey);
	
		    /* delete old data*/
		    //out.println("<tr><td align=center>Deleting data from tables" +
		    //		"update_trail and page_submit.</td></tr>");
		    //db.delete_survey_data(survey);
	
		    /* remove the interview records from table - interview_assignment */
		    out.println("<tr><td align=center>Deleting data from tables " +
		    		"of interview_assignment and interview_session.</td><tr>");
		    
		    stmt.setString(1, surveyID);		    
{'fraction_non_alphanumeric': 0.11991341991341992, 'fraction_numerical': 0.002308802308802309, 'mean_word_length': 3.491898898250162, 'pattern_counts': {'":': 0, '<': 59, '<?xml version=': 0, '>': 59, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '7388071', 'n_tokens_mistral': 2282, 'n_tokens_neox': 2059, 'n_words': 557}