<commit_before>package gov.healthit.chpl.web.controller;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

import gov.healthit.chpl.dao.EntityRetrievalException;
import gov.healthit.chpl.domain.CertifiedProductDownloadDetails;
import gov.healthit.chpl.domain.CertifiedProductDownloadResponse;
import gov.healthit.chpl.domain.CertifiedProductSearchDetails;
import gov.healthit.chpl.domain.PopulateSearchOptions;
import gov.healthit.chpl.domain.SearchRequest;
import gov.healthit.chpl.domain.SearchResponse;
import gov.healthit.chpl.dto.CertifiedProductDTO;
import gov.healthit.chpl.domain.KeyValueModel;
import gov.healthit.chpl.manager.CertificationBodyManager;
import gov.healthit.chpl.manager.CertifiedProductDetailsManager;
import gov.healthit.chpl.manager.CertifiedProductManager;
import gov.healthit.chpl.manager.CertifiedProductSearchManager;
import gov.healthit.chpl.manager.SearchMenuManager;

import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
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.springframework.web.bind.annotation.RestController;

@RestController
public class SearchViewController {
	
	
	@Autowired
	private SearchMenuManager searchMenuManager;
	
	@Autowired
	private CertificationBodyManager certificationBodyManager;
	
	@Autowired
	private CertifiedProductSearchManager certifiedProductSearchManager;
	
	@Autowired
	private CertifiedProductDetailsManager certifiedProductDetailsManager;
	
	@Autowired
	private CertifiedProductManager cpManager;
	
	private static final Logger logger = LogManager.getLogger(SearchViewController.class);

	
	@RequestMapping(value="/certified_product_details", method=RequestMethod.GET,
			produces="application/json; charset=utf-8")
	public @ResponseBody CertifiedProductSearchDetails getCertifiedProductDetails(@RequestParam("productId") Long id) throws EntityRetrievalException{
		
		CertifiedProductSearchDetails product = certifiedProductDetailsManager.getCertifiedProductDetails(id);
		return product;
	}

	/**
	 * don't want this to be accessible right now, but am leaving the code in here because we will need it at some point.
	 */
	@RequestMapping(value="/downloadSome", method=RequestMethod.GET,
			produces="application/xml")
	public ResponseEntity<CertifiedProductDownloadResponse> downloadSome() throws EntityRetrievalException {
		List<CertifiedProductDTO> someCertifiedProducts = new ArrayList<CertifiedProductDTO>();
		someCertifiedProducts.add(cpManager.getById(1L));
		someCertifiedProducts.add(cpManager.getById(2L));
		someCertifiedProducts.add(cpManager.getById(3L));
		someCertifiedProducts.add(cpManager.getById(4L));
		someCertifiedProducts.add(cpManager.getById(5L));
		someCertifiedProducts.add(cpManager.getById(6L));
		someCertifiedProducts.add(cpManager.getById(7L));
		someCertifiedProducts.add(cpManager.getById(8L));
		someCertifiedProducts.add(cpManager.getById(9L));
		someCertifiedProducts.add(cpManager.getById(10L));
		
		CertifiedProductDownloadResponse result = new CertifiedProductDownloadResponse();
		for(CertifiedProductDTO cp : someCertifiedProducts) {
			try {
				//CertifiedProductDownloadDetails details = certifiedProductDetailsManager.getCertifiedProductDownloadDetails(cp.getId());
				CertifiedProductDownloadDetails details = certifiedProductDetailsManager.getCertifiedProductDownloadDetails(cp.getId());
				result.getProducts().add(details);
			} catch(EntityRetrievalException ex) {
				logger.error("Could not certified product details for certified product " + cp.getId());
			}
		}
		
		HttpHeaders responseHeaders = new HttpHeaders();
		responseHeaders.setContentDispositionFormData("attachment", "certified_products.xml");
	    return new ResponseEntity<CertifiedProductDownloadResponse>(result, responseHeaders, HttpStatus.OK);
	}
	
	@RequestMapping(value="/search", method=RequestMethod.GET,
			produces={"application/json; charset=utf-8", "application/xml"})<commit_msg>development: OCD-421: add numRecords parameter<commit_after>package gov.healthit.chpl.web.controller;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

import gov.healthit.chpl.dao.EntityRetrievalException;
import gov.healthit.chpl.domain.CertifiedProductDownloadDetails;
import gov.healthit.chpl.domain.CertifiedProductDownloadResponse;
import gov.healthit.chpl.domain.CertifiedProductSearchDetails;
import gov.healthit.chpl.domain.PopulateSearchOptions;
import gov.healthit.chpl.domain.SearchRequest;
import gov.healthit.chpl.domain.SearchResponse;
import gov.healthit.chpl.dto.CertifiedProductDTO;
import gov.healthit.chpl.domain.KeyValueModel;
import gov.healthit.chpl.manager.CertificationBodyManager;
import gov.healthit.chpl.manager.CertifiedProductDetailsManager;
import gov.healthit.chpl.manager.CertifiedProductManager;
import gov.healthit.chpl.manager.CertifiedProductSearchManager;
import gov.healthit.chpl.manager.SearchMenuManager;

import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
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.springframework.web.bind.annotation.RestController;

@RestController
public class SearchViewController {
	
	
	@Autowired
	private SearchMenuManager searchMenuManager;
	
	@Autowired
	private CertificationBodyManager certificationBodyManager;
	
	@Autowired
	private CertifiedProductSearchManager certifiedProductSearchManager;
	
	@Autowired
	private CertifiedProductDetailsManager certifiedProductDetailsManager;
	
	@Autowired
	private CertifiedProductManager cpManager;
	
	private static final Logger logger = LogManager.getLogger(SearchViewController.class);

	
	@RequestMapping(value="/certified_product_details", method=RequestMethod.GET,
			produces="application/json; charset=utf-8")
	public @ResponseBody CertifiedProductSearchDetails getCertifiedProductDetails(@RequestParam("productId") Long id) throws EntityRetrievalException{
		
		CertifiedProductSearchDetails product = certifiedProductDetailsManager.getCertifiedProductDetails(id);
		return product;
	}

	@RequestMapping(value="/download", method=RequestMethod.GET,
			produces="application/xml")
	public ResponseEntity<CertifiedProductDownloadResponse> downloadSome(
			@RequestParam(value ="numRecords", defaultValue = "10", required = false) int numRecords) throws EntityRetrievalException {
		List<CertifiedProductDTO> someCertifiedProducts = new ArrayList<CertifiedProductDTO>();
		
		for(int i = 0; i < numRecords; i++) {
			someCertifiedProducts.add(cpManager.getById(new Long(i+1)));
		}
		
		CertifiedProductDownloadResponse result = new CertifiedProductDownloadResponse();
		for(CertifiedProductDTO cp : someCertifiedProducts) {
			try {
				//CertifiedProductDownloadDetails details = certifiedProductDetailsManager.getCertifiedProductDownloadDetails(cp.getId());
				CertifiedProductDownloadDetails details = certifiedProductDetailsManager.getCertifiedProductDownloadDetails(cp.getId());
				result.getProducts().add(details);
			} catch(EntityRetrievalException ex) {
				logger.error("Could not certified product details for certified product " + cp.getId());
			}
		}
		
		HttpHeaders responseHeaders = new HttpHeaders();
		responseHeaders.setContentDispositionFormData("attachment", "certified_products.xml");
	    return new ResponseEntity<CertifiedProductDownloadResponse>(result, responseHeaders, HttpStatus.OK);
	}
	
	@RequestMapping(value="/search", method=RequestMethod.GET,
			produces={"application/json; charset=utf-8", "application/xml"})
{'fraction_non_alphanumeric': 0.09135977337110482, 'fraction_numerical': 0.003068932955618508, 'mean_word_length': 7.498495486459378, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 6}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 24, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4674573', 'n_tokens_mistral': 2444, 'n_tokens_neox': 2307, 'n_words': 378}