package fiiadmission.view.controller;

import com.sun.deploy.net.HttpResponse;
import io.swagger.models.Model;
import org.apache.catalina.servlet4preview.http.HttpServletRequest;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.servlet.ModelAndView;
import validator.IValidator;
import validator.Validator;
import fiiadmission.view.Model.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

/**
 * Created by rusub on 5/14/2017.
 */
@Controller
public class AdminController {

    IValidator validator = new Validator();
    @RequestMapping(value = "/delete_teacher", method = RequestMethod.GET)
    public ModelAndView getTeachers(HttpServletRequest req, HttpServletResponse rep){
        return new ModelAndView("profesori");
    }

    @RequestMapping(value = "/delete", method = RequestMethod.POST)
    public void save(HttpServletRequest req){
        Map map = req.getParameterMap();
        if(validator.isValid(map)){
            //return 
        }
    }

    @RequestMapping(value = "/candidati", method = RequestMethod.GET)
    public ModelAndView loadTable(String error, org.springframework.ui.Model model, HttpServletRequest req, HttpServletResponse rep) throws IOException {
        RestTemplate template = new RestTemplate();
        ResponseEntity<List<CandidatForm>> candidatResponse;
        candidatResponse = template.exchange("http://localhost:9999/model/candidati_formuri", HttpMethod.GET,
                null, new ParameterizedTypeReference<List<CandidatForm>>() {
                });
        List<CandidatForm> candidates = candidatResponse.getBody();

        model.addAttribute("message", "TEST SIMPLU!");

        List<String> list = getList();
        ModelAndView modelAndView = new ModelAndView("/tabel_candidati");
        modelAndView.addObject("lists", list);

        model.addAttribute("listValue");
        return modelAndView;
    }

    private List<String> getList() {

        List<String> list = new ArrayList<String>();
        list.add("List A");
        list.add("List B");
        list.add("List C");
        list.add("List D");
        list.add("List 1");
        list.add("List 2");
        list.add("List 3");

        return list;
    }
}

@@ -68,24 +68,148 @@
 tpResponse;%0A
+import fiiadmission.ServerProperties;%0Aimport fiiadmission.dto.ProfessorEntity;%0Aimport fiiadmission.dto.SuccessReasonEntity;%0A
 import io.sw
@@ -858,24 +858,49 @@
 IValidator;%0A
+import validator.Mapper;%0A
 import valid
@@ -1250,24 +1250,25 @@
 alidator();%0A
+%0A
     @Request
@@ -1289,22 +1289,17 @@
 = %22/
-delete_teacher
+operation
 %22, m
@@ -1312,34 +1312,35 @@
 = RequestMethod.
-GE
+POS
 T)%0A    public Mo
@@ -1354,19 +1354,17 @@
 iew 
-getTeachers
+operation
 (Htt
@@ -1386,35 +1386,412 @@
  req
-, HttpServletResponse rep)%7B
+)%7B%0A        Map map = req.getParameterMap();%0A%0A        Map%3CString, String%3E test = Mapper.changeToSingle(map);%0A        RestTemplate template = new RestTemplate();%0A        if (test.get(%22button%22).equals(%22delete%22)) %7B%0A            ResponseEntity%3CSuccessReasonEntity%3E nume = template.postForEntity(ServerProperties.middleUrl + %22/remove_professor%22,%0A                    test.get(%22pcnp%22), SuccessReasonEntity.class);
 %0A   
@@ -1791,24 +1791,28 @@
 s);%0A        
+    
 return new M
@@ -1828,218 +1828,813 @@
 ew(%22
-profesori%22);%0A
+redirect:/delete_teacher%22);%0A    
     %7D%0A
-%0A
     
-@RequestMapping(value = %22/delete%22, method = RequestMethod.POST)%0A    public void save(HttpServletRequest req)%7B%0A        Map map = req.getParameterMap();%0A        if(validator.isValid(map))%7B
+    if (test.get(%22button%22).equals(%22add%22)) %7B%0A            test.remove(%22button%22);%0A            ResponseEntity%3CSuccessReasonEntity%3E nume = template.postForEntity(ServerProperties.middleUrl + %22/add_professor%22,%0A                    test, SuccessReasonEntity.class);%0A            return new ModelAndView(%22redirect:/delete_teacher%22);%0A        %7D%0A%0A        if (test.get(%22button%22).equals(%22see teachers%22)) %7B%0A            ResponseEntity%3CList%3CProfessorEntity%3E%3E professorResponse =%0A                    template.exchange(ServerProperties.middleUrl + %22/get_professors%22,%0A                            HttpMethod.POST, null, new ParameterizedTypeReference%3CList%3CProfessorEntity%3E%3E() %7B%0A                            %7D);%0A            List%3CProfessorEntity%3E professors = professorResponse.getBody();
 %0A   
@@ -2646,27 +2646,134 @@
     
-//
 return 
-%0A        %7D
+new ModelAndView(%22redirect:/tabel_profesori%22);%0A        %7D%0A%0A        return  new ModelAndView(%22redirect:/delete_teacher%22);
 %0A   

add si delete professor