package common.web.controller.rest;

import java.io.PrintWriter;
import java.io.Serializable;
import java.util.*;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import javax.persistence.EntityManager;
import javax.persistence.EntityNotFoundException;
import javax.persistence.PersistenceContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.validation.Valid;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Scope;
//import org.json.JSONObject;
import org.springframework.http.*;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Repository;
import org.springframework.ui.ModelMap;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.ServletRequestBindingException;
import org.springframework.web.bind.ServletRequestUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import common.db.base.exception.DaoException;
import common.db.base.exception.OutOfPageRangeException;
import common.db.base.page.PageObject;
import common.db.model.identity.Role;
import common.db.model.identity.User;
import common.db.repository.jpa.identity.RoleDao;
import common.db.repository.jpa.identity.UserDAO;
import common.db.repository.jpa.identity.impl.RoleDaoImpl;
import common.db.repository.jpa.identity.impl.UserDaoImpl;
import common.security.AuthenticationUser;
import common.security.CustomUserDetailsService;
import common.service.utils.SpringContextHolder;
import common.web.controller.AbstractRestController;
import common.web.model.RequestParamNaming;
import common.web.model.WrappedResponseBody;

/**
 * 用于提供server和client共用的命名
 * @author jjq
 *
 */
@Controller	
@RequestMapping("/rest/common/naming")
//放到Session属性列表中，以便这个属性可以跨请求访问
public class NamingController  extends AbstractRestController {
	
	private AllNamings allNamings;
	
	public NamingController() {
		RequestParamNaming requestParamNaming = new RequestParamNaming();
		SpringContextHolder.getAutowireCapableBeanFactory().autowireBean(requestParamNaming);
		
		allNamings = new AllNamings();
		allNamings.setRequestParamNaming(requestParamNaming);
	}
	
	@RequestMapping(value={"" , "/"},method=RequestMethod.GET)
	@ResponseBody
	public WrappedResponseBody getAll() throws OutOfPageRangeException, DaoException{
		
		return new WrappedResponseBody(allNamings);
	}

}

class AllNamings implements Serializable{
	private RequestParamNaming requestParamNaming ;
	

	public RequestParamNaming getRequestParamNaming() {
		return requestParamNaming;
	}

	public void setRequestParamNaming(RequestParamNaming requestParamNaming) {
		this.requestParamNaming = requestParamNaming;
	}
	
}

@@ -1378,24 +1378,71 @@
 tity.Role;%0D%0A
+import common.db.model.identity.RoleTypeEnum;%0D%0A
 import commo
@@ -2836,16 +2836,407 @@
 ng ;%0D%0A%09%0D
+%0A%09private Map%3CString , String%3E roleTypes = new HashMap%3CString, String%3E();%0D%0A%09%0D%0A%09public AllNamings()%7B%0D%0A%09%09populateRoleTypes();%0D%0A%09%7D%0D%0A%09%0D%0A%09public Map%3CString, String%3E getRoleTypes() %7B%0D%0A%09%09return roleTypes;%0D%0A%09%7D%0D%0A%0D%0A%09/*%0D%0A%09 * %E5%A1%AB%E5%85%85RoleTypeEnum%E4%B8%AD%E7%9A%84%E7%B1%BB%E5%9E%8B%E4%BF%A1%E6%81%AF%0D%0A%09 */%0D%0A%09private void populateRoleTypes()%7B%0D%0A%09%09for (RoleTypeEnum s : RoleTypeEnum.values())%7B%0D%0A%09%09%09roleTypes.put(s.getCode(), s.getDescription());%0D%0A%09%09%7D%0D%0A%09%7D;%0D%0A%09%0D
 %0A%0D%0A%09publ

add Naming-RoleTypeEnum support