<commit_before>package com.sybit.education.taschengeldboerse.controller;

import com.sybit.education.taschengeldboerse.domain.Schueler;
import com.sybit.education.taschengeldboerse.domain.User;
import com.sybit.education.taschengeldboerse.model.SchuelerForm;
import com.sybit.education.taschengeldboerse.service.UserService;
import javax.validation.Valid;
import org.hibernate.exception.ConstraintViolationException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;

/**
 * Handles requests for the application home page.
 */
@Controller
public class SchuelerController {

    @Autowired
    private UserService userService;

    /**
     * Lade das Formular für die Anlage eines Schülers.
     *
     * @param request needed to get the referring url
     * @return the logical view to be returned
     */
    @RequestMapping(value = "/registrieren/schueler", method = RequestMethod.GET)
    public ModelAndView registrierenFormular(final HttpServletRequest request) {

        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("schuelerForm", new SchuelerForm());

        modelAndView.setViewName("registrieren-schueler");

        return modelAndView;
    }


    /**
     * Speichere neuen Schüler.
     *
     * @param schuelerForm
     * @return the logical view to be returned
     */
    @RequestMapping(value = "/registrieren/schueler", method = RequestMethod.POST)
    public ModelAndView saveForm(@ModelAttribute("schueler") SchuelerForm schuelerForm) {
        ModelAndView modelAndView = new ModelAndView();
        try {

            User user = new User();
            user.setEmail(schuelerForm.getEmail());
            user.setPassword(schuelerForm.getPassword()); //TODO: Überprüfung einbauen
            user.setAuthority("ROLE_SCHUELER");
            user.setEnabled(true);
            
            try {
                userService.addUser(user);
            } catch (IllegalArgumentException e) {
                modelAndView.addObject("addEmailFail", true);
                modelAndView.addObject("emailMessage", e.getMessage());
                modelAndView.setViewName("registrieren-schueler");
                return modelAndView;
            }
            
            Schueler schueler = new Schueler();
            schueler.setAnrede(schuelerForm.getAnrede());
            schueler.setName(schuelerForm.getName());
            schueler.setVorname(schuelerForm.getVorname());
            schueler.setEmail(schuelerForm.getEmail());
            schueler.setGeburtsdatum(schuelerForm.getDOBDay() + "." + schuelerForm.getDOBMonth() + "." + schuelerForm.getDOBYear());
            schueler.setPlz(schuelerForm.getPlz());
            schueler.setWohnort(schuelerForm.getWohnort());
            userService.saveSchueler(schueler);

            modelAndView.setViewName("job-liste");

        } catch (ConstraintViolationException e) {
            modelAndView.addObject("schueler", schuelerForm);
            modelAndView.addObject("addFail", true);
            modelAndView.setViewName("registrieren-schueler");
        } 
        
        return modelAndView;
    }
}
<commit_msg>refactoring code schueler<commit_after>package com.sybit.education.taschengeldboerse.controller;

import com.sybit.education.taschengeldboerse.domain.Schueler;
import com.sybit.education.taschengeldboerse.domain.User;
import com.sybit.education.taschengeldboerse.model.SchuelerForm;
import com.sybit.education.taschengeldboerse.service.UserService;
import javax.validation.Valid;
import org.hibernate.exception.ConstraintViolationException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;

/**
 * Handles requests for the application home page.
 */
@Controller
public class SchuelerController {

    @Autowired
    private UserService userService;

    /**
     * Lade das Formular für die Anlage eines Schülers.
     *
     * @param request needed to get the referring url
     * @return the logical view to be returned
     */
    @RequestMapping(value = "/registrieren/schueler", method = RequestMethod.GET)
    public ModelAndView registrierenFormular(final HttpServletRequest request) {

        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("schuelerForm", new SchuelerForm());

        modelAndView.setViewName("registrieren-schueler");

        return modelAndView;
    }


    /**
     * Speichere neuen Schüler.
     *
     * @param schuelerForm
     * @return the logical view to be returned
     */
    @RequestMapping(value = "/registrieren/schueler", method = RequestMethod.POST)
    public ModelAndView saveForm(@ModelAttribute("schueler") SchuelerForm schuelerForm) {
        ModelAndView modelAndView = new ModelAndView();
        try {

            User user = new User();
            user.setEmail(schuelerForm.getEmail());
            user.setPassword(<PASSWORD>Form.getPassword()); //TODO: Überprüfung einbauen
            user.setAuthority("ROLE_SCHUELER");
            user.setEnabled(true);
            userService.addUser(user);
            
            Schueler schueler = new Schueler();
            schueler.setAnrede(schuelerForm.getAnrede());
            schueler.setName(schuelerForm.getName());
            schueler.setVorname(schuelerForm.getVorname());
            schueler.setEmail(schuelerForm.getEmail());
            schueler.setGeburtsdatum(schuelerForm.getDOBDay() + "." + schuelerForm.getDOBMonth() + "." + schuelerForm.getDOBYear());
            schueler.setPlz(schuelerForm.getPlz());
            schueler.setWohnort(schuelerForm.getWohnort());
            userService.saveSchueler(schueler);

            modelAndView.setViewName("job-liste");
        } catch (IllegalArgumentException e) {
                modelAndView.addObject("addEmailFail", true);
                modelAndView.addObject("emailMessage", e.getMessage());
                modelAndView.setViewName("registrieren-schueler");
        } catch (ConstraintViolationException e) {
            modelAndView.addObject("schueler", schuelerForm);
            modelAndView.addObject("addFail", true);
            modelAndView.setViewName("registrieren-schueler");
        } 
        
        return modelAndView;
    }
}

{'fraction_non_alphanumeric': 0.10024662701291165, 'fraction_numerical': 0.0, 'mean_word_length': 3.148014440433213, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, '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': '4674164', 'n_tokens_mistral': 2039, 'n_tokens_neox': 1996, 'n_words': 317}