<commit_before>package com.jos.dem.vetlog.controller

import static org.springframework.web.bind.annotation.RequestMethod.GET
import static org.springframework.web.bind.annotation.RequestMethod.POST

import org.springframework.beans.factory.annotation.Autowired
import org.springframework.beans.factory.annotation.Value
import org.springframework.web.bind.annotation.RequestParam
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.InitBinder
import org.springframework.web.bind.WebDataBinder
import org.springframework.web.servlet.ModelAndView
import org.springframework.validation.BindingResult
import org.springframework.stereotype.Controller
import javax.validation.Valid

import com.jos.dem.vetlog.model.Pet
import com.jos.dem.vetlog.model.User
import com.jos.dem.vetlog.command.TelephoneCommand
import com.jos.dem.vetlog.service.PetService
import com.jos.dem.vetlog.service.UserService
import com.jos.dem.vetlog.service.TelephoneService
import com.jos.dem.vetlog.validator.TelephoneValidator

import org.slf4j.Logger
import org.slf4j.LoggerFactory

@Controller
@RequestMapping("/telephone")
class TelephoneController {

  @Autowired
  PetService petService
  @Autowired
  UserService userService
  @Autowired
  TelephoneService telephoneService
  @Autowired
  TelephoneValidator telephoneValidator

  @Value('${awsImageUrl}')
  String awsImageUrl

  Logger log = LoggerFactory.getLogger(this.class)

  @InitBinder('telephoneCommand')
	private void initBinder(WebDataBinder binder) {
		binder.addValidators(telephoneValidator)
	}

  @RequestMapping(method = POST, value = "/save")
  ModelAndView save(@Valid TelephoneCommand telephoneCommand, BindingResult bindingResult) {
    log.info "Saving adoption for pet: ${telephoneCommand.uuid}"
    if (bindingResult.hasErrors()) {
      ModelAndView modelAndView = new ModelAndView('telephone/adopt')
      fillPetAndTelephoneCommand(modelAndView, telephoneCommand)
      return modelAndView
    }
    User user = userService.getCurrentUser()
    telephoneService.save(telephoneCommand, user)
    ModelAndView modelAndView = new ModelAndView('redirect:/')
    modelAndView.addObject('message', localeService.getMessage('adoption.email.sent'))
    modelAndView
  }

  @RequestMapping(method = GET, value = "/adopt")
  ModelAndView adopt(TelephoneCommand telephoneCommand){
    log.info "Adoption to pet with uuid: ${telephoneCommand.uuid}"
    ModelAndView modelAndView = new ModelAndView('telephone/adopt')
    fillPetAndTelephoneCommand(modelAndView, telephoneCommand)
  }

  private fillPetAndTelephoneCommand(ModelAndView modelAndView, TelephoneCommand telephoneCommand){
    Pet pet = petService.getPetByUuid(telephoneCommand.uuid)
    modelAndView.addObject('pet', pet)
    modelAndView.addObject('telephoneCommand', telephoneCommand)
    modelAndView.addObject('awsImageUrl', awsImageUrl)
    modelAndView
  }

}
<commit_msg>#62 Adding locale service<commit_after>package com.jos.dem.vetlog.controller

import static org.springframework.web.bind.annotation.RequestMethod.GET
import static org.springframework.web.bind.annotation.RequestMethod.POST

import org.springframework.beans.factory.annotation.Autowired
import org.springframework.beans.factory.annotation.Value
import org.springframework.web.bind.annotation.RequestParam
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.InitBinder
import org.springframework.web.bind.WebDataBinder
import org.springframework.web.servlet.ModelAndView
import org.springframework.validation.BindingResult
import org.springframework.stereotype.Controller
import javax.validation.Valid

import com.jos.dem.vetlog.model.Pet
import com.jos.dem.vetlog.model.User
import com.jos.dem.vetlog.command.TelephoneCommand
import com.jos.dem.vetlog.service.PetService
import com.jos.dem.vetlog.service.UserService
import com.jos.dem.vetlog.service.LocaleService
import com.jos.dem.vetlog.service.TelephoneService
import com.jos.dem.vetlog.validator.TelephoneValidator

import org.slf4j.Logger
import org.slf4j.LoggerFactory

@Controller
@RequestMapping("/telephone")
class TelephoneController {

  @Autowired
  PetService petService
  @Autowired
  UserService userService
  @Autowired
  LocaleService localeService
  @Autowired
  TelephoneService telephoneService
  @Autowired
  TelephoneValidator telephoneValidator

  @Value('${awsImageUrl}')
  String awsImageUrl

  Logger log = LoggerFactory.getLogger(this.class)

  @InitBinder('telephoneCommand')
	private void initBinder(WebDataBinder binder) {
		binder.addValidators(telephoneValidator)
	}

  @RequestMapping(method = POST, value = "/save")
  ModelAndView save(@Valid TelephoneCommand telephoneCommand, BindingResult bindingResult) {
    log.info "Saving adoption for pet: ${telephoneCommand.uuid}"
    if (bindingResult.hasErrors()) {
      ModelAndView modelAndView = new ModelAndView('telephone/adopt')
      fillPetAndTelephoneCommand(modelAndView, telephoneCommand)
      return modelAndView
    }
    User user = userService.getCurrentUser()
    telephoneService.save(telephoneCommand, user)
    ModelAndView modelAndView = new ModelAndView('redirect:/')
    modelAndView.addObject('message', localeService.getMessage('adoption.email.sent'))
    modelAndView
  }

  @RequestMapping(method = GET, value = "/adopt")
  ModelAndView adopt(TelephoneCommand telephoneCommand){
    log.info "Adoption to pet with uuid: ${telephoneCommand.uuid}"
    ModelAndView modelAndView = new ModelAndView('telephone/adopt')
    fillPetAndTelephoneCommand(modelAndView, telephoneCommand)
  }

  private fillPetAndTelephoneCommand(ModelAndView modelAndView, TelephoneCommand telephoneCommand){
    Pet pet = petService.getPetByUuid(telephoneCommand.uuid)
    modelAndView.addObject('pet', pet)
    modelAndView.addObject('telephoneCommand', telephoneCommand)
    modelAndView.addObject('awsImageUrl', awsImageUrl)
    modelAndView
  }

}

{'fraction_non_alphanumeric': 0.08881083793276467, 'fraction_numerical': 0.0010035122930255895, 'mean_word_length': 5.8577981651376145, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '3635198', 'n_tokens_mistral': 1683, 'n_tokens_neox': 1691, 'n_words': 302}