package com.athena.meerkat.controller.web;

import java.util.HashMap;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
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 com.athena.meerkat.controller.web.common.model.SimpleJsonResponse;
import com.athena.meerkat.controller.web.entities.DataSource;
import com.athena.meerkat.controller.web.entities.TomcatDomain;
import com.athena.meerkat.controller.web.resources.services.DataSourceService;
import com.athena.meerkat.controller.web.resources.services.ServerService;
import com.athena.meerkat.controller.web.tomcat.services.TomcatDomainService;
import com.athena.meerkat.controller.web.tomcat.services.TomcatInstanceService;

@Controller
@RequestMapping("dashboard")
public class DashboardController {

	private static final Logger logger = LoggerFactory.getLogger(ConsoleController.class);

	@Autowired
	private TomcatDomainService domainService;
	@Autowired
	private TomcatInstanceService tomcatService;
	@Autowired
	private ServerService serverService;
	@Autowired
	private DataSourceService dsService;

	@RequestMapping(value = "/get/stats", method = RequestMethod.GET)
	@ResponseBody
	public SimpleJsonResponse getStats(SimpleJsonResponse json) {
		long domainCount = domainService.getDomainNo();
		long tomcatInstCount = tomcatService.getTomcatInstNo();
		long serverCount = serverService.getServerNo();
		long dsCount = dsService.getDatasourceNo();

		HashMap<String, Long> value = new HashMap<>();
		value.put("domainCount", domainCount);
		value.put("tomcatInstCount", tomcatInstCount);
		value.put("serverCount", serverCount);
		value.put("dsCount", dsCount);
		json.setData(value);

		return json;
	}
}

@@ -65,16 +65,40 @@
 ashMap;%0D
+%0Aimport java.util.List;%0D
 %0A%0D%0Aimpor
@@ -453,24 +453,97 @@
 nseBody;%0D%0A%0D%0A
+import com.athena.meerkat.controller.web.common.model.GridJsonResponse;%0D%0A
 import com.a
@@ -2049,16 +2049,530 @@
 ue);%0D%0A%0D%0A
+%09%09return json;%0D%0A%09%7D%0D%0A%0D%0A%09@RequestMapping(value = %22/get/domain/stats%22, method = RequestMethod.GET)%0D%0A%09@ResponseBody%0D%0A%09public GridJsonResponse getDomainStats(GridJsonResponse json) %7B%0D%0A%09%09List%3CTomcatDomain%3E domains = domainService.getAll();%0D%0A%09%09//List%3CTomcatDomain%3E returnedList = new ArrayList%3C%3E();%0D%0A%09%09//%09%09for (TomcatDomain domain : domains) %7B%0D%0A%09%09//%09%09%09TomcatDomain d = new TomcatDomain();%0D%0A%09%09//%09%09%09d.setName(domain.getName());%0D%0A%09%09//%09%09%09d.setTomcatInstance%0D%0A%09%09//%09%09%09returnedList.add(d);%0D%0A%09%09//%09%09%7D%0D%0A%09%09json.setList(domains);%0D%0A%0D%0A
 %09%09return

load stats chart for domain stats