<commit_before>/*
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.asual.summer.sample.web;

import java.util.Arrays;

import javax.validation.Valid;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
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.view.RedirectView;

import com.asual.summer.core.ResponseFormat;
import com.asual.summer.sample.domain.License;
import com.asual.summer.sample.domain.Status;
import com.asual.summer.sample.domain.Technology;

/**
 * 
 * @author <NAME>
 *
 */
@Controller
@RequestMapping("/technology")
public class TechnologyController {
	
    @RequestMapping(method=RequestMethod.GET)
    @ResponseFormat("*")
    public ModelAndView list() {
        return new ModelAndView("/list", new ModelMap(Technology.list()));
    }
    
    @RequestMapping(method=RequestMethod.POST)
    public ModelAndView persist(@Valid @ModelAttribute Technology technology) {
    	technology.persist();
        return new ModelAndView(new RedirectView("/technology/" + technology.getValue(), true));
    }
    
    @RequestMapping(value="/{value}", method=RequestMethod.GET)
    @ResponseFormat({"json", "xml"})
    public ModelAndView view(@PathVariable("value") String value) {
        return new ModelAndView("/view", new ModelMap(Technology.find(value)));
    }

    @RequestMapping(value="/{value}", method=RequestMethod.PUT)
    public ModelAndView merge(@Valid @ModelAttribute Technology technology) {
    	technology.merge();
        return new ModelAndView(new RedirectView("/technology/" + technology.getValue(), true));
    }
    
    @RequestMapping(value="/{value}", method=RequestMethod.DELETE)
    public ModelAndView remove(@Valid @ModelAttribute Technology technology) {
    	technology.remove();
        return new ModelAndView(new RedirectView("/technology", true));
    }
    
    @RequestMapping("/add")
    public ModelAndView add() {
        ModelMap model = new ModelMap();
    	model.addAllAttributes(Arrays.asList(new Technology(), License.list(), Status.list()));
        return new ModelAndView("/add", model);
    }
    
    @RequestMapping("/{value}/edit")
    public ModelAndView edit(@PathVariable("value") String value) {
    	ModelMap model = new ModelMap();
    	model.addAllAttributes(Arrays.asList(Technology.find(value), License.list(), Status.list()));
        return new ModelAndView("/edit", model);
    }
    
}<commit_msg>Controller improvements.<commit_after>/*
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.asual.summer.sample.web;

import java.util.Arrays;

import javax.validation.Valid;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
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.view.RedirectView;

import com.asual.summer.core.ResponseFormat;
import com.asual.summer.core.ViewNotFoundException;
import com.asual.summer.sample.domain.License;
import com.asual.summer.sample.domain.Status;
import com.asual.summer.sample.domain.Technology;

/**
 * 
 * @author <NAME>
 *
 */
@Controller
@RequestMapping("/technology")
public class TechnologyController {
	
    @RequestMapping(method=RequestMethod.GET)
    @ResponseFormat("*")
    public ModelAndView list() {
        return new ModelAndView("/list", new ModelMap(Technology.list()));
    }
    
    @RequestMapping(method=RequestMethod.POST)
    public ModelAndView persist(@Valid @ModelAttribute Technology technology) {
    	technology.persist();
        return new ModelAndView(new RedirectView("/technology/" + technology.getValue(), true));
    }
    
    @RequestMapping(value="/{value}", method=RequestMethod.GET)
    @ResponseFormat({"json", "xml"})
    public ModelAndView view(@PathVariable("value") String value) {
    	Technology technology = Technology.find(value);
    	if (technology == null) {
    		throw new ViewNotFoundException();
    	}
        return new ModelAndView("/view", new ModelMap(technology));
    }
    
    @RequestMapping(value="/{value}", method=RequestMethod.PUT)
    public ModelAndView merge(@Valid @ModelAttribute Technology technology) {
    	technology.merge();
        return new ModelAndView(new RedirectView("/technology/" + technology.getValue(), true));
    }
    
    @RequestMapping(value="/{value}", method=RequestMethod.DELETE)
    public ModelAndView remove(@Valid @ModelAttribute Technology technology) {
    	technology.remove();
        return new ModelAndView(new RedirectView("/technology", true));
    }
    
    @RequestMapping("/add")
    public ModelAndView add() {
        ModelMap model = new ModelMap();
    	model.addAllAttributes(Arrays.asList(new Technology(), License.list(), Status.list()));
        return new ModelAndView("/add", model);
    }
    
    @RequestMapping("/{value}/edit")
    public ModelAndView edit(@PathVariable("value") String value) {
    	Technology technology = Technology.find(value);
    	if (technology == null) {
    		throw new ViewNotFoundException();
    	}
    	ModelMap model = new ModelMap();
    	model.addAllAttributes(Arrays.asList(technology, License.list(), Status.list()));
        return new ModelAndView("/edit", model);
    }
    
}
{'fraction_non_alphanumeric': 0.11922679651763317, 'fraction_numerical': 0.0011804633318577543, 'mean_word_length': 4.177998472116119, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 2}, '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': '3438597', 'n_tokens_mistral': 1841, 'n_tokens_neox': 1795, 'n_words': 453}