<commit_before>package br.edu.ufcg.computacao.si1.model.controllers;

import br.edu.ufcg.computacao.si1.model.advertising.Advertising;
import br.edu.ufcg.computacao.si1.model.factories.AdvertisingFactory;
import br.edu.ufcg.computacao.si1.model.forms.AdvertisingForm;
import br.edu.ufcg.computacao.si1.model.services.AdvertisingService;
import br.edu.ufcg.computacao.si1.model.user.LoggedUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Service;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import javax.validation.Valid;
import javax.ws.rs.POST;

/**
 * Created by gersonsales on 16/03/17.
 */
@Controller
public class AdvertisingController {

    @Autowired
    private AdvertisingService advertisingService;

    @RequestMapping(value = "ad/list/advertising", method = RequestMethod.GET)
    public ModelAndView listAdvertising() {
        System.out.println("HERE");
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject(advertisingService.getAll());
        modelAndView.setViewName("ad/advertising_list");

        return modelAndView;
    }

    @RequestMapping(value = "ad/add/advertising", method = RequestMethod.GET)
    public ModelAndView createNewAdvertising(LoggedUser loggedUser) {
        ModelAndView modelAndView = new ModelAndView();

        modelAndView.addObject("types", loggedUser.getPostPermisions());

        modelAndView.setViewName("ad/advertising_register");

        return modelAndView;
    }

    @RequestMapping(value = "ad/add/advertising", method = RequestMethod.POST)
    public ModelAndView addNewAdvertising(LoggedUser loggedUser, @Valid AdvertisingForm advertisingForm, BindingResult bindingResult, RedirectAttributes redirectAttributes) {
        if (bindingResult.hasErrors()) {
            return createNewAdvertising(loggedUser);
        }

        Advertising advertising= AdvertisingFactory.createNewAdvertising(advertisingForm);
        advertisingService.add(advertising);

        redirectAttributes.addFlashAttribute("message", "Message to show");//TODO

        return new ModelAndView("redirect:/ad/add/advertising");
    }

}<commit_msg>doing work<commit_after>package br.edu.ufcg.computacao.si1.model.controllers;

import br.edu.ufcg.computacao.si1.model.advertising.Advertising;
import br.edu.ufcg.computacao.si1.model.factories.AdvertisingFactory;
import br.edu.ufcg.computacao.si1.model.forms.AdvertisingForm;
import br.edu.ufcg.computacao.si1.model.services.AdvertisingService;
import br.edu.ufcg.computacao.si1.model.user.LoggedUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Service;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import javax.validation.Valid;
import javax.ws.rs.POST;
import java.util.concurrent.Semaphore;

/**
 * Created by gersonsales on 16/03/17.
 */
@Controller
public class AdvertisingController {

    @Autowired
    private AdvertisingService advertisingService;

    @RequestMapping(value = "ad/list/advertising", method = RequestMethod.GET)
    public ModelAndView listAdvertising() {
        System.out.println("HERE");
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject(advertisingService.getAll());
        modelAndView.setViewName("ad/advertising_list");

        return modelAndView;
    }

    @RequestMapping(value = "ad/add/advertising", method = RequestMethod.GET)
    public ModelAndView createNewAdvertising(LoggedUser loggedUser) {
        ModelAndView modelAndView = new ModelAndView();

        modelAndView.addObject("types", loggedUser.getPostPermisions());

        modelAndView.setViewName("ad/advertising_register");

        return modelAndView;

    }

    @RequestMapping(value = "ad/add/advertising", method = RequestMethod.POST)
    public ModelAndView addNewAdvertising(LoggedUser loggedUser, @Valid AdvertisingForm advertisingForm, BindingResult bindingResult, RedirectAttributes redirectAttributes) {
        if (bindingResult.hasErrors()) {
            return createNewAdvertising(loggedUser);
        }

        Advertising advertising= AdvertisingFactory.createNewAdvertising(advertisingForm);
        advertisingService.add(advertising);

        redirectAttributes.addFlashAttribute("message", "Message to show");//TODO

        return new ModelAndView("redirect:/ad/add/advertising");
    }

}
{'fraction_non_alphanumeric': 0.10009970089730807, 'fraction_numerical': 0.004785643070787637, 'mean_word_length': 4.726027397260274, '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': '3146130', 'n_tokens_mistral': 1464, 'n_tokens_neox': 1388, 'n_words': 219}