<commit_before>/*
 *  Copyright (C) 2012 <NAME> (Akvo Foundation)
 *
 *  This file is part of Akvo FLOW.
 *
 *  Akvo FLOW is free software: you can redistribute it and modify it under the terms of
 *  the GNU Affero General Public License (AGPL) as published by the Free Software Foundation,
 *  either version 3 of the License or any later version.
 *
 *  Akvo FLOW is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
 *  without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 *  See the GNU Affero General Public License included below for more details.
 *
 *  The full license text can also be seen at <http://www.gnu.org/licenses/agpl.html>.
 */
package org.waterforpeople.mapping.app.web.rest;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.inject.Inject;

import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.waterforpeople.mapping.app.gwt.client.surveyinstance.SurveyInstanceDto;
import org.waterforpeople.mapping.app.util.DtoMarshaller;
import org.waterforpeople.mapping.app.web.rest.dto.SurveyInstancePayload;

import com.gallatinsystems.common.Constants;
import com.gallatinsystems.survey.dao.SurveyDAO;
import org.waterforpeople.mapping.dao.SurveyInstanceDAO;
import com.gallatinsystems.survey.domain.Survey;
import org.waterforpeople.mapping.domain.SurveyInstance;

@Controller
@RequestMapping("/survey_instances")
public class SurveyInstanceRestService {

	@Inject
	private SurveyInstanceDAO surveyInstanceDao;

	@Inject
	private SurveyDAO surveyDao;

	//TODO put in meta information?
	// list all survey instances
	@RequestMapping(method = RequestMethod.GET, value = "")
	@ResponseBody
	public Map<String, List<SurveyInstanceDto>> listSurveyInstances() {
		final Map<String, List<SurveyInstanceDto>> response = new HashMap<String, List<SurveyInstanceDto>>();
		List<SurveyInstanceDto> results = new ArrayList<SurveyInstanceDto>();
		List<SurveyInstance> surveys = surveyInstanceDao.list(Constants.ALL_RESULTS);
		if (surveys != null) {
			for (SurveyInstance s : surveys) {
				SurveyInstanceDto dto = new SurveyInstanceDto();
				DtoMarshaller.copyToDto(s, dto);
				results.add(dto);
			}
		}
		response.put("survey_instances", results);
		return response;
	}

	// find survey instance by id
	@RequestMapping(method = RequestMethod.GET, value = "/{id}")
	@ResponseBody
	public Map<String, SurveyInstanceDto> findSurveyInstanceById(
			@PathVariable("id") Long id) {
		final Map<String, SurveyInstanceDto> response = new HashMap<String, SurveyInstanceDto>();
		SurveyInstance s = surveyInstanceDao.getByKey(id);
		SurveyInstanceDto dto = null;
		if (s != null) {
			dto = new SurveyInstanceDto();
			DtoMarshaller.copyToDto(s, dto);
		}<commit_msg>add beginDate EndDate and cursor to surveyInstanceRestSurvice<commit_after>/*
 *  Copyright (C) 2012 <NAME> (Akvo Foundation)
 *
 *  This file is part of Akvo FLOW.
 *
 *  Akvo FLOW is free software: you can redistribute it and modify it under the terms of
 *  the GNU Affero General Public License (AGPL) as published by the Free Software Foundation,
 *  either version 3 of the License or any later version.
 *
 *  Akvo FLOW is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
 *  without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 *  See the GNU Affero General Public License included below for more details.
 *
 *  The full license text can also be seen at <http://www.gnu.org/licenses/agpl.html>.
 */
package org.waterforpeople.mapping.app.web.rest;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.inject.Inject;

import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.waterforpeople.mapping.app.gwt.client.surveyinstance.SurveyInstanceDto;
import org.waterforpeople.mapping.app.util.DtoMarshaller;
import org.waterforpeople.mapping.app.web.rest.dto.SurveyInstancePayload;

import com.gallatinsystems.common.Constants;
import com.gallatinsystems.survey.dao.SurveyDAO;
import org.waterforpeople.mapping.dao.SurveyInstanceDAO;
import com.gallatinsystems.survey.domain.Survey;
import org.waterforpeople.mapping.domain.SurveyInstance;

@Controller
@RequestMapping("/survey_instances")
public class SurveyInstanceRestService {

	@Inject
	private SurveyInstanceDAO surveyInstanceDao;

	@Inject
	private SurveyDAO surveyDao;

	//TODO put in meta information?
	// list all survey instances
	@RequestMapping(method = RequestMethod.GET, value = "")
	@ResponseBody
	public Map<String, List<SurveyInstanceDto>> listSurveyInstances(
			@RequestParam(value = "beginDate", defaultValue = "") Long beginDate,
			@RequestParam(value = "endDate", defaultValue = "") Long endDate,
			@RequestParam(value = "cursor", defaultValue = "") String cursor) {
		final Map<String, List<SurveyInstanceDto>> response = new HashMap<String, List<SurveyInstanceDto>>();
		List<SurveyInstanceDto> results = new ArrayList<SurveyInstanceDto>();
		List<SurveyInstance> surveys = surveyInstanceDao.list(Constants.ALL_RESULTS);
		if (surveys != null) {
			for (SurveyInstance s : surveys) {
				SurveyInstanceDto dto = new SurveyInstanceDto();
				DtoMarshaller.copyToDto(s, dto);
				results.add(dto);
			}
		}
		response.put("survey_instances", results);
		return response;
	}

	// find survey instance by id
	@RequestMapping(method = RequestMethod.GET, value = "/{id}")
	@ResponseBody
	public Map<String, SurveyInstanceDto> findSurveyInstanceById(
			@PathVariable("id") Long id) {
		final Map<String, SurveyInstanceDto> response = new HashMap<String, SurveyInstanceDto>();
		SurveyInstance s = surveyInstanceDao.getByKey(id);
		SurveyInstanceDto dto = null;
		if (s != null) {
			dto = new SurveyInstanceDto();
			DtoMarshaller.copyToDto(s, dto);
		}
{'fraction_non_alphanumeric': 0.09880646623357002, 'fraction_numerical': 0.0015108022359873092, 'mean_word_length': 5.322827125119389, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '6037665', 'n_tokens_mistral': 2023, 'n_tokens_neox': 1983, 'n_words': 517}