package com.javahonk.controller;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;


@Controller
public class SpringMVCController {
	
	private static final Logger logger = Logger.getLogger(SpringMVCController.class);
	
	@RequestMapping(value = "/firstPage")
	public String firstPage(ModelMap model) {
		
		logger.info("Log4j info is working");
        logger.warn("Log4j warn is working");       
        logger.debug("Log4j debug is working");
        logger.error("Log4j error is working");
        System.out.println("System out is working");
		model.addAttribute("message", "Spring MVC AngularJS RESTFul Service");
		
		return "index";		
	}
	
	@RequestMapping(value = "/angularServiceCall",method=RequestMethod.POST)
	public String angularServiceCall(ModelMap model) {
		
		model.addAttribute("message", "Spring MVC AngularJS");		
		return "AngularJSService";		
	}
	
	@RequestMapping(value = "/angularServicePostCall", method=RequestMethod.POST)
	public @ResponseBody String angularServicePostCall(@RequestBody String indexData) {
		
		String value[] = indexData.split("/n");
		for (String string : value) {
			String splitVlue[] = string.split(",");
			for (String string2 : splitVlue) {
				System.out.println(string2);
			}
		}
		return "Success";		
	}

	

}
