<commit_before>package org.ohmage.request.survey;

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

import org.apache.log4j.Logger;
import org.ohmage.annotator.ErrorCodes;
import org.ohmage.exception.ServiceException;
import org.ohmage.exception.ValidationException;
import org.ohmage.request.InputKeys;
import org.ohmage.request.UserRequest;
import org.ohmage.service.SurveyResponseServices;
import org.ohmage.service.UserSurveyResponseServices;
import org.ohmage.validator.SurveyResponseValidators;

/**
 * <p>Deletes a survey response and any images associated with it. The 
 * requesting user must be the owner of the survey response and the campaign
 * must be running or they must be a supervisor in the campaign to which the
 * survey response belongs.</p>
 * <table border="1">
 *   <tr>
 *     <td>Parameter Name</td>
 *     <td>Description</td>
 *     <td>Required</td>
 *   </tr>
 *   <tr>
 *     <td>{@value org.ohmage.request.InputKeys#AUTH_TOKEN}</td>
 *     <td>The requesting user's authentication token.</td>
 *     <td>true</td>
 *   </tr>
 *   <tr>
 *     <td>{@value org.ohmage.request.InputKeys#CLIENT}</td>
 *     <td>A string describing the client that is making this request.</td>
 *     <td>true</td>
 *   </tr>
 *   <tr>
 *     <td>{@value org.ohmage.request.InputKeys#SURVEY_ID}</td>
 *     <td>The survey response's unique identifier.</td>
 *     <td>true</td>
 *   </tr>
 * </table>
 * 
 * @author <NAME>
 */
public class SurveyResponseDeleteRequest extends UserRequest {
	private static final Logger LOGGER = Logger.getLogger(SurveyResponseDeleteRequest.class);
	
	private final Long surveyResponseId;
	
	/**
	 * Creates a survey response delete request.
	 * 
	 * @param httpRequest The HttpServletRequest with the parameters for this
	 * 					  request.
	 */
	public SurveyResponseDeleteRequest(HttpServletRequest httpRequest) {
		super(httpRequest, TokenLocation.PARAMETER);
		
		LOGGER.info("Creating a survey response delete request.");
		
		Long tSurveyResponseId = null;
		
		if(! isFailed()) {
			try {
				String[] surveyIds = getParameterValues(InputKeys.SURVEY_ID);
				if(surveyIds.length == 0) {
					setFailed(ErrorCodes.SURVEY_INVALID_SURVEY_ID, "Missing the required survey ID: " + InputKeys.SURVEY_ID);
					throw new ValidationException("Missing the required survey ID: " + InputKeys.SURVEY_ID);
				}
				else if(surveyIds.length > 1) {
					setFailed(ErrorCodes.SURVEY_INVALID_SURVEY_ID, "Multiple survey ID parameters were given.");
					throw new ValidationException("Multiple survey ID parameters were given.");
				}
				else {
					tSurveyResponseId = SurveyResponseValidators.validateSurveyId(this, surveyIds[0]);
					
					if(tSurveyResponseId == null) {
						setFailed(ErrorCodes.SURVEY_INVALID_SURVEY_ID, "Missing the required survey ID: " + InputKeys.SURVEY_ID);
						throw new ValidationException("Missing the required survey ID: " + InputKeys.SURVEY_ID);
					}
				}
			}
			catch(ValidationException e) {
				LOGGER.info(e.toString());
			}
		}
		
		surveyResponseId = tSurveyResponseId;<commit_msg>Survey response delete takes in a parmaeter under a slightly different name.<commit_after>package org.ohmage.request.survey;

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

import org.apache.log4j.Logger;
import org.ohmage.annotator.ErrorCodes;
import org.ohmage.exception.ServiceException;
import org.ohmage.exception.ValidationException;
import org.ohmage.request.InputKeys;
import org.ohmage.request.UserRequest;
import org.ohmage.service.SurveyResponseServices;
import org.ohmage.service.UserSurveyResponseServices;
import org.ohmage.validator.SurveyResponseValidators;

/**
 * <p>Deletes a survey response and any images associated with it. The 
 * requesting user must be the owner of the survey response and the campaign
 * must be running or they must be a supervisor in the campaign to which the
 * survey response belongs.</p>
 * <table border="1">
 *   <tr>
 *     <td>Parameter Name</td>
 *     <td>Description</td>
 *     <td>Required</td>
 *   </tr>
 *   <tr>
 *     <td>{@value org.ohmage.request.InputKeys#AUTH_TOKEN}</td>
 *     <td>The requesting user's authentication token.</td>
 *     <td>true</td>
 *   </tr>
 *   <tr>
 *     <td>{@value org.ohmage.request.InputKeys#CLIENT}</td>
 *     <td>A string describing the client that is making this request.</td>
 *     <td>true</td>
 *   </tr>
 *   <tr>
 *     <td>{@value org.ohmage.request.InputKeys#SURVEY_ID}</td>
 *     <td>The survey response's unique identifier.</td>
 *     <td>true</td>
 *   </tr>
 * </table>
 * 
 * @author <NAME>
 */
public class SurveyResponseDeleteRequest extends UserRequest {
	private static final Logger LOGGER = Logger.getLogger(SurveyResponseDeleteRequest.class);
	
	private final Long surveyResponseId;
	
	/**
	 * Creates a survey response delete request.
	 * 
	 * @param httpRequest The HttpServletRequest with the parameters for this
	 * 					  request.
	 */
	public SurveyResponseDeleteRequest(HttpServletRequest httpRequest) {
		super(httpRequest, TokenLocation.PARAMETER);
		
		LOGGER.info("Creating a survey response delete request.");
		
		Long tSurveyResponseId = null;
		
		if(! isFailed()) {
			try {
				String[] surveyIds = getParameterValues(InputKeys.SURVEY_KEY);
				if(surveyIds.length == 0) {
					setFailed(ErrorCodes.SURVEY_INVALID_SURVEY_ID, "Missing the required survey ID: " + InputKeys.SURVEY_KEY);
					throw new ValidationException("Missing the required survey ID: " + InputKeys.SURVEY_KEY);
				}
				else if(surveyIds.length > 1) {
					setFailed(ErrorCodes.SURVEY_INVALID_SURVEY_ID, "Multiple survey ID parameters were given.");
					throw new ValidationException("Multiple survey ID parameters were given.");
				}
				else {
					tSurveyResponseId = SurveyResponseValidators.validateSurveyId(this, surveyIds[0]);
					
					if(tSurveyResponseId == null) {
						setFailed(ErrorCodes.SURVEY_INVALID_SURVEY_ID, "Missing the required survey ID: " + InputKeys.SURVEY_KEY);
						throw new ValidationException("Missing the required survey ID: " + InputKeys.SURVEY_KEY);
					}
				}
			}
			catch(ValidationException e) {
				LOGGER.info(e.toString());
			}
		}
		
		surveyResponseId = tSurveyResponseId;
{'fraction_non_alphanumeric': 0.11243638676844783, 'fraction_numerical': 0.0015903307888040711, 'mean_word_length': 3.9402985074626864, 'pattern_counts': {'":': 0, '<': 77, '<?xml version=': 0, '>': 79, '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': '1462101', 'n_tokens_mistral': 2155, 'n_tokens_neox': 1923, 'n_words': 458}