package controller;

import constant.Urls;
import constant.ViewIds;
import domain.Protocol;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
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.bind.annotation.RequestParam;
import org.springframework.web.servlet.view.RedirectView;
import repository.ProtocolRepository;

import javax.annotation.Resource;

@Controller
public class IndexController {

    ////////////////////////////////////////////////
    // ATTRIBUTES

    private ProtocolRepository protocolRepository;

    ////////////////////////////////////////////////
    // METHODS

    @RequestMapping(Urls.ROOT)
    public RedirectView index() {
        String newProtocolId = protocolRepository.addProtocol(new Protocol());
        return new RedirectView(createProtocolUrl(newProtocolId));
    }

    private String createProtocolUrl(String newProtocolId) {
        return Urls.PROTOCOL + "?id=" + newProtocolId;
    }

    @RequestMapping(Urls.PROTOCOL)
    public String loadProtocol(@RequestParam("id") String protocolId,
                               ModelMap mm) {
        mm.put("protocol", protocolRepository.getById(protocolId));
        return ViewIds.PROTOCOL;
    }

    @RequestMapping(value = Urls.SAVE_PROTOCOL, method = RequestMethod.POST)
    public RedirectView saveProtocol(@ModelAttribute("protocol") Protocol protocol) {
        protocolRepository.updateProtocol(protocol);
        return new RedirectView(createProtocolUrl(protocol.getId()));
    }

    ////////////////////////////////////////////////
    // SETTERS

    @Resource
    public void setProtocolRepository(ProtocolRepository protocolRepository) {
        this.protocolRepository = protocolRepository;
    }
}

@@ -40,57 +40,8 @@
 ls;%0A
-import constant.ViewIds;%0Aimport domain.Protocol;%0A
 impo
@@ -117,399 +117,42 @@
 ork.
-ui.ModelMap;%0Aimport org.springframework.web.bind.annotation.ModelAttribute;%0Aimport org.springframework.web.bind.annotation.RequestMapping;%0Aimport org.springframework.web.bind.annotation.RequestMethod;%0Aimport org.springframework.web.bind.annotation.RequestParam;%0Aimport org.springframework.web.servlet.view.RedirectView;%0Aimport repository.ProtocolRepository;%0A%0Aimport javax.annotation.Resource
+web.bind.annotation.RequestMapping
 ;%0A%0A@
@@ -270,60 +270,8 @@
 ES%0A%0A
-    private ProtocolRepository protocolRepository;%0A%0A
     
@@ -381,1079 +381,123 @@
 lic 
-RedirectView index() %7B%0A        String newProtocolId = protocolRepository.addProtocol(new Protocol());%0A        return new RedirectView(createProtocolUrl(newProtocolId));%0A    %7D%0A%0A    private String createProtocolUrl(String newProtocolId) %7B%0A        return Urls.PROTOCOL + %22?id=%22 + newProtocolId;%0A    %7D%0A%0A    @RequestMapping(Urls.PROTOCOL)%0A    public String loadProtocol(@RequestParam(%22id%22) String protocolId,%0A                               ModelMap mm) %7B%0A        mm.put(%22protocol%22, protocolRepository.getById(protocolId));%0A        return ViewIds.PROTOCOL;%0A    %7D%0A%0A    @RequestMapping(value = Urls.SAVE_PROTOCOL, method = RequestMethod.POST)%0A    public RedirectView saveProtocol(@ModelAttribute(%22protocol%22) Protocol protocol) %7B%0A        protocolRepository.updateProtocol(protocol);%0A        return new RedirectView(createProtocolUrl(protocol.getId()));%0A    %7D%0A%0A    ////////////////////////////////////////////////%0A    // SETTERS%0A%0A    @Resource%0A    public void setProtocolRepository(ProtocolRepository protocolRepository) %7B%0A        this.protocolRepository = protocolRepository;%0A    %7D
+String index() %7B%0A        return %22index%22;%0A    %7D%0A%0A    ////////////////////////////////////////////////%0A    // SETTERS%0A
 %0A%7D%0A

Make IndexController only return index page