package pl.pp.controllers;

import org.json.JSONArray;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
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.client.RestTemplate;
import pl.pp.service.dto.ParameterDto;

import java.util.ArrayList;
import java.util.List;


/**
 * Created by dpp on 12/17/16.
 */
@Controller
public class MainPageController {

    private final Logger log = LoggerFactory.getLogger(MainPageController.class);

    @Autowired
    private RestTemplate restTemplate;

    @RequestMapping(value = "/", method = RequestMethod.GET)
    public String greeting(Model model) {
//        log.debug("Start");
//        Authentication auth = SecurityContextHolder.getContext().getAuthentication();
//            log.debug("Auth Getted");
//            String name = auth.getName();
//            String userId = name.charAt(name.length()-1)+"";
//            String accident = restTemplate.getForObject("http://health-keeper-api.gear.host/api/PersonAccident/"+userId, String.class);
//            accident = accident.replaceAll("\\\\", "");
//            accident = accident.substring(1, accident.length()-1);
//
//            JSONObject accidentJson = new JSONObject (accident);
//            model.addAttribute("accident", accidentJson);

        return "mainPage";
    }

    // Login form
    @RequestMapping(path = "/login", method = RequestMethod.GET)
    public String login() {
        return "login";
    }

    // Login form with error
    @RequestMapping(path = "/login-error")
    public String loginError(Model model) {
        model.addAttribute("loginError", true);
        return "login";
    }
}

@@ -1074,40 +1074,9 @@
 ) %7B%0A
-//        log.debug(%22Start%22);%0A//
+%0A
     
@@ -1153,34 +1153,32 @@
 tication();%0A
-//
         
     log.debu
@@ -1169,84 +1169,90 @@
     
-    log.debug(%22Auth Getted%22);%0A//            String name = auth.getName();%0A//
+String name = auth.getName();%0A        if (name.compareTo(%22anonymousUser%22) != 0) %7B%0A
     
@@ -1308,18 +1308,16 @@
 -1)+%22%22;%0A
-//
         
@@ -1444,18 +1444,16 @@
 class);%0A
-//
         
@@ -1500,18 +1500,16 @@
 %22, %22%22);%0A
-//
         
@@ -1571,13 +1571,9 @@
 1);%0A
-//%0A//
+%0A
     
@@ -1633,18 +1633,16 @@
 ident);%0A
-//
         
@@ -1691,16 +1691,25 @@
 tJson);%0A
+        %7D
 %0A       

Handle problems with main page