<commit_before>package edu.uib.info310;


import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
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.ResponseStatus;
import org.springframework.web.servlet.ModelAndView;

import edu.uib.info310.model.Artist;
import edu.uib.info310.model.Record;
import edu.uib.info310.search.ArtistNotFoundException;
import edu.uib.info310.search.MasterNotFoundException;
import edu.uib.info310.search.Searcher;

/**
 * Sample controller for going to the home page with a message
 */
@Controller
public class HomeController {

	private static final Logger LOGGER = LoggerFactory
			.getLogger(HomeController.class);

	@Autowired
	private Searcher searcher;


	/**
	 * Selects the home page and populates the model with a message
	 */
	@RequestMapping(value = "/", method = RequestMethod.GET)
	public String home(Model model) {
		String helloWrold = null;
		try {
			helloWrold = GetUrl.getContent("http://www.tastekid.com/ask/ws?q=rihanna"); // RIHANNA FUCK YEAH!
		} catch (Exception e1) {
			e1.printStackTrace();
		}
		model.addAttribute("controllerMessage",
				helloWrold);
		return "home";
	}


	@RequestMapping(value = "/search")
	@ResponseStatus(value = HttpStatus.OK)
	public ModelAndView search(@RequestParam String q){
		LOGGER.debug("Artist got search string: " + q);
		ModelAndView mav = new ModelAndView();
		mav.addObject("q", q);
		Artist artist = null;
		try {
			artist = searcher.searchArtist(q);
			mav.addObject("artist", artist);
		} catch (ArtistNotFoundException e) {
			LOGGER.debug("Didn't find an artist with the name " + q);

		}
		LOGGER.debug("Looking for records called: " + q);
		Map<String, Record> records = searcher.searchRecords(q);
		LOGGER.debug("Found " + records.size() + " records" );
		if(records.isEmpty() && artist != null){
			mav.setViewName("artist");
		}else if(records.isEmpty()){
			mav.setViewName("notFound");
		}else if(records.size() == 1){
			Record record = records.values().iterator().next();
			mav = album(record.getName(), record.getArtist().get(0).getName());
		}
		else{
			mav.addObject("records", records);
			mav.setViewName("searchResults");
		}
		
		LOGGER.debug("Returning view: " + mav.getViewName());
		return mav;
	}


	@RequestMapping(value = "/artist")
	@ResponseStatus(value = HttpStatus.OK)
	public ModelAndView artist(@RequestParam String q){
		LOGGER.debug("Artist got search string: " + q);
		ModelAndView mav = new ModelAndView();
		mav.addObject("q", q);
		try {
			mav.addObject("artist", searcher.searchArtist(q));
			mav.setViewName("artist");
		} catch (ArtistNotFoundException e) {
			mav.setViewName("notFound");
		}<commit_msg>Changed type records from Map to List. Added check for null artist before showing the Album view.<commit_after>package edu.uib.info310;


import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
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.ResponseStatus;
import org.springframework.web.servlet.ModelAndView;

import edu.uib.info310.model.Artist;
import edu.uib.info310.model.Record;
import edu.uib.info310.search.ArtistNotFoundException;
import edu.uib.info310.search.MasterNotFoundException;
import edu.uib.info310.search.Searcher;

/**
 * Sample controller for going to the home page with a message
 */
@Controller
public class HomeController {

	private static final Logger LOGGER = LoggerFactory
			.getLogger(HomeController.class);

	@Autowired
	private Searcher searcher;


	/**
	 * Selects the home page and populates the model with a message
	 */
	@RequestMapping(value = "/", method = RequestMethod.GET)
	public String home(Model model) {
		String helloWrold = null;
		try {
			helloWrold = GetUrl.getContent("http://www.tastekid.com/ask/ws?q=rihanna"); // RIHANNA FUCK YEAH!
		} catch (Exception e1) {
			e1.printStackTrace();
		}
		model.addAttribute("controllerMessage",
				helloWrold);
		return "home";
	}


	@RequestMapping(value = "/search")
	@ResponseStatus(value = HttpStatus.OK)
	public ModelAndView search(@RequestParam String q){
		LOGGER.debug("Artist got search string: " + q);
		ModelAndView mav = new ModelAndView();
		mav.addObject("q", q);
		Artist artist = null;
		try {
			artist = searcher.searchArtist(q);
			mav.addObject("artist", artist);
		} catch (ArtistNotFoundException e) {
			LOGGER.debug("Didn't find an artist with the name " + q);

		}
		LOGGER.debug("Looking for records called: " + q);
		List<Record> records = searcher.searchRecords(q);
		LOGGER.debug("Found " + records.size() + " records" );
		if(records.isEmpty() && artist != null){
			mav.setViewName("artist");
		}else if(records.isEmpty()){
			mav.setViewName("notFound");
		}else if(records.size() == 1 && artist == null){
			Record record = records.get(0);
			mav = album(record.getName(), record.getArtist().get(0).getName());
		}
		else{
			mav.addObject("records", records);
			mav.setViewName("searchResults");
		}
		
		LOGGER.debug("Returning view: " + mav.getViewName());
		return mav;
	}


	@RequestMapping(value = "/artist")
	@ResponseStatus(value = HttpStatus.OK)
	public ModelAndView artist(@RequestParam String q){
		LOGGER.debug("Artist got search string: " + q);
		ModelAndView mav = new ModelAndView();
		mav.addObject("q", q);
		try {
			mav.addObject("artist", searcher.searchArtist(q));
			mav.setViewName("artist");
		} catch (ArtistNotFoundException e) {
			mav.setViewName("notFound");
		}
{'fraction_non_alphanumeric': 0.1341305753070459, 'fraction_numerical': 0.007918552036199095, 'mean_word_length': 4.7518587360594795, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1364080', 'n_tokens_mistral': 2173, 'n_tokens_neox': 2004, 'n_words': 421}