package com.renren.infra.xweb.web;

import java.util.List;
import java.util.Map;

import javax.servlet.ServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springside.modules.web.Servlets;

import com.renren.infra.xweb.entity.Mario_node_state;
import com.renren.infra.xweb.entity.Mario_zk_info;
import com.renren.infra.xweb.service.Mario_node_stateService;
import com.renren.infra.xweb.service.Mario_zk_infoService;
import com.renren.infra.xweb.util.Const;

@Controller
@RequestMapping("/mario_node_state")
public class Mario_node_stateController {

	@Autowired
	private Mario_zk_infoService zkService;
	@Autowired
	private Mario_node_stateService service;
	@Autowired
	private Mario_zk_infoService zkInfoService;

	@RequestMapping(value = { "", "/list" })
	public String list(
			@RequestParam(value = "page", defaultValue = "1") int pageNumber,
			Model model, ServletRequest request) {

		List<Mario_zk_info> mario_zk_infos = zkService.getAllMario_zk_info();
		model.addAttribute("mario_zk_infos", mario_zk_infos);

		Map<String, Object> searchParams = Servlets.getParametersStartingWith(
				request, "search_");
		if (searchParams.containsKey("path")) {
			searchParams
					.put("path", searchParams.get("path").toString().trim());
		}
		if (!searchParams.containsKey("zk_id")) {
			for (Mario_zk_info mario_zk_info : mario_zk_infos) {
				searchParams.put("zk_id", mario_zk_info.getid().toString());
				break;
			}
		}

		Integer zk_id = Integer.parseInt((String)searchParams.get("zk_id"));
		model.addAttribute("maxStateVersion", service.getMaxStateVersion(zk_id));
		
		Page<Mario_node_state> mario_node_states = service.getMario_node_state(
				searchParams, pageNumber, Const.PAGE_SIZE);
		for (Mario_node_state mario_node_state : mario_node_states) {
			mario_node_state.setCluster_name(zkInfoService.getMario_zk_info(
					mario_node_state.getzk_id()).getzk_name());
		}

		model.addAttribute("mario_node_states", mario_node_states);
		model.addAttribute("searchParams", Servlets
				.encodeParameterStringWithPrefix(searchParams, "search_"));

		return "mario_node_state/mario_node_stateList";
	}
}

@@ -27,24 +27,55 @@
 web.web;%0D%0A%0D%0A
+import java.util.Collections;%0D%0A
 import java.
@@ -257,24 +257,74 @@
 main.Page;%0D%0A
+import org.springframework.data.domain.PageImpl;%0D%0A
 import org.s
@@ -1847,18 +1847,65 @@
 %7D%0D%0A%09%09%7D%0D%0A
+%09%09
 %0D%0A
+%09%09if (searchParams.get(%22zk_id%22) != null) %7B%0D%0A%09
 %09%09Intege
@@ -1964,24 +1964,25 @@
 %22zk_id%22));%0D%0A
+%09
 %09%09model.addA
@@ -2050,16 +2050,17 @@
 );%0D%0A%09%09%0D%0A
+%09
 %09%09Page%3CM
@@ -2126,24 +2126,25 @@
 state(%0D%0A%09%09%09%09
+%09
 searchParams
@@ -2176,16 +2176,17 @@
 SIZE);%0D%0A
+%09
 %09%09for (M
@@ -2242,16 +2242,17 @@
 tes) %7B%0D%0A
+%09
 %09%09%09mario
@@ -2313,24 +2313,25 @@
 info(%0D%0A%09%09%09%09%09
+%09
 mario_node_s
@@ -2369,15 +2369,18 @@
 %0D%0A%09%09
+%09
 %7D%0D%0A
+%09
 %0D%0A%09%09
+%09
 mode
@@ -2432,24 +2432,25 @@
 e_states);%0D%0A
+%09
 %09%09model.addA
@@ -2488,16 +2488,17 @@
 ts%0D%0A%09%09%09%09
+%09
 .encodeP
@@ -2546,24 +2546,185 @@
 earch_%22));%0D%0A
+%09%09%7D else %7B%0D%0A%09%09%09model.addAttribute(%22maxStateVersion%22, 0);%0D%0A%09%09%09model.addAttribute(%22mario_node_states%22,new PageImpl%3CMario_node_state%3E(Collections.EMPTY_LIST));%0D%0A%09%09%7D
 %0D%0A%09%09return %22

fix bug