package com.eactive.eai.rms.onl.manage.rule.transform;

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Vector;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.collections4.MapUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import com.eactive.eai.agent.command.CommonCommand;
import com.eactive.eai.common.util.StringUtil;
import com.eactive.eai.common.util.SystemUtil;
import com.eactive.eai.rms.common.combo.ComboService;
import com.eactive.eai.rms.common.combo.ComboVo;
import com.eactive.eai.rms.common.context.MonitoringContext;
import com.eactive.eai.rms.common.datasource.DataSourceType;
import com.eactive.eai.rms.common.datasource.DataSourceTypeManager;
import com.eactive.eai.rms.common.login.SessionManager;
import com.eactive.eai.rms.common.spring.BaseController;
import com.eactive.eai.rms.common.spring.LocaleMessage;
import com.eactive.eai.rms.common.util.CamelCaseUtil;
import com.eactive.eai.rms.common.util.CommonUtil;
import com.eactive.eai.rms.common.util.IpUtil;
import com.eactive.eai.rms.common.vo.JsonPageVo;
import com.eactive.eai.rms.onl.common.exception.BizException;
import com.eactive.eai.rms.onl.loader.service.HistoryService;
import com.eactive.eai.rms.onl.loader.service.TransactionLoaderService;
import com.google.gson.Gson;


@Controller
public class TransformController extends BaseController {
    private static final Logger logger = Logger.getLogger(TransformController.class);
    
    @Autowired
	@Qualifier("localeMessage")
	private LocaleMessage localeMessage;
    
    @Autowired
    private TransformManService service;
    
    @Autowired
    private ComboService comboService;   
    
    @Autowired
    @Qualifier("historyService")
    private HistoryService historyService;
    
    @Autowired
    private TransactionLoaderService loaderService;
    
    @Autowired
	@Qualifier("monitoringContext")
	private MonitoringContext monitoringContext;
    
	@RequestMapping(value= "/onl/admin/rule/transformMan.view")
	private String viewList(HttpServletRequest request, @RequestParam(value = "cmd", required = false ) String cmd ) throws Exception {
		if (cmd == null || "LIST".equals(cmd.toUpperCase())){
			cmd = "";
		}else {
			cmd = CamelCaseUtil.converCamelCase(cmd);
		}
		String path = request.getServletPath();
		return path.split("[.]")[0]+cmd;
	}    
    @RequestMapping(value= "/onl/admin/rule/transformMan.json",params = "cmd=LIST_INIT_COMBO")
    public ModelAndView initCombo( HttpServletRequest request,
            HttpServletResponse response,String eaiSvcName) throws Exception {
    	
    	//admin 권한
    	 String  roleId   = SessionManager.getRoleIdString(request);
    	 String isAdmin = "N";
         if(roleId.indexOf("admin") > -1){ //admin 일경우 
         	isAdmin =  "Y";
         }
    	
        List<ComboVo> listFunction   = comboService.getFromFunction();
        
        List listTransform  = service.selectTransformForEaiSvcNameCombo(eaiSvcName);
        List<ComboVo> listCnvsnType	= comboService.getFromCode("CNVSN_TYPE");
        List<ComboVo> listSvrDstcd	= comboService.getFromCode("INOUT_TYPE");
        List<ComboVo> listUseYn   	= comboService.getFromCode("USE_YN");// 사용여부
		Map resultMap = new HashMap();
		resultMap.put("functionRows"	, listFunction);
		resultMap.put("transformRows"	, listTransform);
		resultMap.put("cnvsnType"		, listCnvsnType);
		resultMap.put("svrDstcd"		, listSvrDstcd);
		resultMap.put("isAdmin"			, isAdmin);
		resultMap.put("useYnRows"		, listUseYn);
		
		ModelAndView modelAndView = new ModelAndView("jsonView",resultMap);		
		return modelAndView;            
    } 

	
	
	@RequestMapping(value= "/onl/admin/rule/transformMan.json",params = "cmd=LIST_EAISVCNAME_COMBO")
    public ModelAndView eaiSvcNameCombo( HttpServletRequest request,
            HttpServletResponse response) throws Exception {
    	
//		String eaiBizCode = RecordAuthUtil.getRecordAuthQuery(request);
        List listCnvsnType = comboService.getFromCode("CNVSN_TYPE");
        
        List<ComboVo> listInoutTypeCd = comboService.getFromCode("INOUT_TYPE");//EAI서버구분코드
        List<ComboVo> listUseYn			= comboService.getFromCode("USE_YN");
        
		
		Map resultMap = new HashMap();
		resultMap.put("cnvsnTypeRows"	, listCnvsnType);
		resultMap.put("inoutTypeRows"   , listInoutTypeCd);
		resultMap.put("useYnRows"			, listUseYn);
		
		ModelAndView modelAndView = new ModelAndView("jsonView",resultMap);		
		return modelAndView;            
    } 
//    @RequestMapping(value= "/onl/admin/rule/transformMan.json",params = "cmd=LIST_LAYOUT_COMBO")
//    public ModelAndView layoutCombo( HttpServletRequest request,
//            HttpServletResponse response) throws Exception {
//    	
//		String eaiBizCode = RecordAuthUtil.getRecordAuthQuery(request);
//        List list = service.selectLayoutCombo(eaiBizCode);
//		
//		Map resultMap = new HashMap();
//		resultMap.put("rows"   , list);
//		
//		ModelAndView modelAndView = new ModelAndView("jsonView",resultMap);		
//		return modelAndView;            
//    } 
    @RequestMapping(value= "/onl/admin/rule/transformMan.json",params = "cmd=LIST_FUNCTION_COMBO")
    public ModelAndView functionCombo( HttpServletRequest request,
            HttpServletResponse response) throws Exception {
    	
        List list = service.selectFunctionCombo();
		
		Map resultMap = new HashMap();
		resultMap.put("rows"   , list);
		
		ModelAndView modelAndView = new ModelAndView("jsonView",resultMap);		
		return modelAndView;            
    }     
    @RequestMapping(value= "/onl/admin/rule/transformMan.json",params = "cmd=LIST_TRANSFORM4EAISVCNAME_COMBO")
    public ModelAndView transformForEaiSvcNameCombo( HttpServletRequest request,
            HttpServletResponse response, String eaiSvcName) throws Exception {
    	
        List list = service.selectTransformForEaiSvcNameCombo(eaiSvcName);
		
		Map resultMap = new HashMap();
		resultMap.put("rows"   , list);
		
		ModelAndView modelAndView = new ModelAndView("jsonView",resultMap);		
		return modelAndView;            
    }       
	
	
    @RequestMapping(value= "/onl/admin/rule/transformMan.json",params = "cmd=LIST_LAYOUT_ITEM")
    public ModelAndView listLayoutItem(HttpServletRequest request, HttpServletResponse response,String loutName) throws Exception {
        List list = service.selectLayoutItems(loutName);
        HashMap map = new HashMap();
        map.put("rows", list);
        ModelAndView modelAndView = new ModelAndView("jsonView",map);
        return modelAndView;
    }  
    @RequestMapping(value= "/onl/admin/rule/transformMan.json",params = "cmd=LIST")
    public ModelAndView list( HttpServletRequest request,
            HttpServletResponse response,JsonPageVo pageVo, 
            String searchBizCode, String searchCnvsnName,String searchCnvsnDesc) throws Exception {
    	
    		//String eaiBizCode = RecordAuthUtil.getRecordAuthQuery(request);
    	
            HashMap map = service.selectList(pageVo.getStartNum(), pageVo.getEndNum(),searchBizCode, searchCnvsnName,searchCnvsnDesc);

    		pageVo.setTotalCount((Integer)map.get("totalCount"));
    		
    		Map resultMap = new HashMap();
    		resultMap.put("total"  , pageVo.getTotal());  //전체 페이지수
    		resultMap.put("page"   , pageVo.getPage());   //현재 페이지수
    		resultMap.put("records", pageVo.getTotalCount());//전체 레코드건수	
    		resultMap.put("rows"   , map.get("list"));
    		
    		ModelAndView modelAndView = new ModelAndView("jsonView",resultMap);		
    		return modelAndView;            
    }  
//	@RequestMapping(value= "/onl/admin/common/codeMan.json",params = "cmd=DETAIL")
//	private ModelAndView detail(HttpServletRequest request,
//			HttpServletResponse response,String msg) throws Exception {
//		
//		HashMap map = transformManService.selectDetail(msg);
//
//		ModelAndView modelAndView = new ModelAndView("jsonView",map);	
//		
//		return modelAndView;
//	}
	@RequestMapping(value= "/onl/admin/rule/transformMan.json",params = "cmd=INSERT")
	private String insert(HttpServletRequest request,
			HttpServletResponse response, @RequestParam HashMap param) throws Exception {
		
		service.insert(param);
		
		String cnvsnName = (String)param.get("cnvsnName");
		CommonCommand command = new CommonCommand("com.eactive.eai.agent.transformer.ReloadTransformCommand",cnvsnName);
		agentUtilService.broadcast(command);
		String eaiSvcName = (String)param.get("eaiSvcName");
    	if(eaiSvcName != null && !"".equals(eaiSvcName)){
    		command = new CommonCommand("com.eactive.eai.agent.eaimessage.ReloadEAIMessageCommand",eaiSvcName);
    		agentUtilService.broadcast(command);    
    	}
		
		return null;
		
	}	
		
    @RequestMapping(value= "/onl/admin/rule/transformMan.json",params = "cmd=DELETE")
	private String delete(HttpServletRequest request,
			HttpServletResponse response, String cnvsnName,String eaiSvcName,String cnvsnType ) throws Exception {
    	
    	service.delete(cnvsnName,eaiSvcName,cnvsnType);
		CommonCommand command = new CommonCommand("com.eactive.eai.agent.transformer.RemoveTransformCommand",cnvsnName);
		agentUtilService.broadcast(command);    
    	if(eaiSvcName != null && !"".equals(eaiSvcName)){
    		command = new CommonCommand("com.eactive.eai.agent.eaimessage.ReloadEAIMessageCommand",eaiSvcName);
    		agentUtilService.broadcast(command);    
    	}
		return null;
		
	}	
    @RequestMapping(value= "/onl/admin/rule/transformMan.json",params = "cmd=DELETE_LIST")
	private ModelAndView deleteMulti(HttpServletRequest request,
			HttpServletResponse response, @RequestParam HashMap<String,Object> map ) throws Exception {
		String message = "";
		
		String[] cnvsnNameArr = ((String) map.get("cnvsnNames")).split(",");
		String eaiSvcNamesString = (String) map.get("eaiSvcNames") + ",";
		String cnvsnTypesString = (String) map.get("cnvsnTypes") + ",";
		String[] eaiSvcNameArr = StringUtils.splitPreserveAllTokens(eaiSvcNamesString, ",");
		String[] cnvsnTypeArr = StringUtils.splitPreserveAllTokens(cnvsnTypesString, ",");
		
		int idx = 0;
		for(String cnvsnName : cnvsnNameArr){
			service.delete(cnvsnName,eaiSvcNameArr[idx],cnvsnTypeArr[idx]);
			CommonCommand command = new CommonCommand("com.eactive.eai.agent.transformer.RemoveTransformCommand",cnvsnName);
			agentUtilService.broadcast(command);    
	    	if(eaiSvcNameArr[idx] != null && !"".equals(eaiSvcNameArr[idx])){
	    		command = new CommonCommand("com.eactive.eai.agent.eaimessage.ReloadEAIMessageCommand",eaiSvcNameArr[idx]);
	    		agentUtilService.broadcast(command);    
	    	}
	    	idx++;
		}
		
		message = "총"+idx+"건을 삭제하였습니다";
		
		Map resultMap = new HashMap();
		resultMap.put("message"   , message);
		ModelAndView modelAndView = new ModelAndView("jsonView",resultMap);		
		return modelAndView;
		
		
	}	
    @RequestMapping(value= "/onl/admin/rule/transformMan.json",params = "cmd=LIST_TRANSFORM_SOURCE_RESULT")
    public ModelAndView transformSourceResult( HttpServletRequest request,
            HttpServletResponse response,String cnvsnName) throws Exception {
    	
            List list = service.selectTransformSourceResult(cnvsnName );

    		
            HashMap map = new HashMap();
            map.put("rows", list);
    		
    		ModelAndView modelAndView = new ModelAndView("jsonView",map);		
    		return modelAndView;            
    }     
    @RequestMapping(value= "/onl/admin/rule/transformMan.json",params = "cmd=LIST_TRANSFORM_ITEM")
    public ModelAndView transformItem( HttpServletRequest request,
            HttpServletResponse response,String cnvsnName,String loutName) throws Exception {
    	
//    		String eaiBizCode = RecordAuthUtil.getRecordAuthQuery(request);
    	
            List list = service.selectTransformItems(cnvsnName ,loutName );

    		
            HashMap map = new HashMap();
            map.put("rows", list);
    		
    		ModelAndView modelAndView = new ModelAndView("jsonView",map);		
    		return modelAndView;            
    }    
   
    @RequestMapping(value= "/onl/admin/rule/transformMan.json",params = "cmd=UPDATE")
    public ModelAndView update( HttpServletRequest request,
            HttpServletResponse response, @RequestParam HashMap<String,Object> paramMap  ) throws Exception {
    	String gridData = (String)paramMap.get("gridData");
    	Gson gson = new Gson();
    	HashMap[] list = gson.fromJson(gridData, HashMap[].class);
    	paramMap.put("list", list);
        service.transaction(paramMap);
        String cnvsnName = (String)paramMap.get("cnvsnName");
        String eaiSvcName = (String)paramMap.get("eaiSvcName");
            
		CommonCommand command = new CommonCommand("com.eactive.eai.agent.transformer.ReloadTransformCommand",cnvsnName);
		agentUtilService.broadcast(command);
    	if(eaiSvcName != null && !"".equals(eaiSvcName)){
    		command = new CommonCommand("com.eactive.eai.agent.eaimessage.ReloadEAIMessageCommand",eaiSvcName);
    		agentUtilService.broadcast(command);    
    	}
            
    	return null;            
    }   
    
	@RequestMapping(value= "/onl/admin/rule/transformMan.json",params = "cmd=INITIALIZES")
	public ModelAndView initializes(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		CommonCommand command = new CommonCommand("com.eactive.eai.agent.transformer.ReloadTransformCommand","ALL");
		HashMap returnMap = agentUtilService.broadcast(command);

		HashMap map = new HashMap();
		map.put("message", CommonUtil.getMapString(returnMap, true));

		ModelAndView modelAndView = new ModelAndView("jsonView", map);
		return modelAndView;

	}

	@RequestMapping(value= "/onl/admin/rule/transformMan.json",params = "cmd=INITIALIZE")
	public ModelAndView initialize(HttpServletRequest request,
			HttpServletResponse response, String cnvsnName) throws Exception {
		CommonCommand command = new CommonCommand("com.eactive.eai.agent.transformer.ReloadTransformCommand",cnvsnName);
		HashMap returnMap = agentUtilService.broadcast(command);

		HashMap map = new HashMap();
		map.put("message", CommonUtil.getMapString(returnMap, true));

		ModelAndView modelAndView = new ModelAndView("jsonView", map);
		return modelAndView;
	}    
	
	@RequestMapping(value= "/onl/admin/rule/transformMan.json",params = "cmd=LIST_INITIALIZE")
	public ModelAndView listInitialize(HttpServletRequest request,
			HttpServletResponse response, @RequestParam HashMap<String,Object> paramMap) throws Exception {
		
		String[] chkItemsArr = ((String) paramMap.get("chkItems")).split(",");
		Vector vec = new Vector<>();
		for(String chkItem : chkItemsArr){
			vec.add(chkItem);
		}
		CommonCommand command = new CommonCommand("com.eactive.eai.agent.transformer.ReloadTransformListCommand",vec);
		HashMap returnMap = agentUtilService.broadcast(command);

		HashMap map = new HashMap();
		map.put("message", CommonUtil.getMapString(returnMap, true));

		ModelAndView modelAndView = new ModelAndView("jsonView", map);
		return modelAndView;
	}
	@RequestMapping(value = "/onl/admin/rule/transformMan.json", params = "cmd=LIST_LAYOUT")
	private ModelAndView selectLoutList(HttpServletRequest request,
			JsonPageVo pageVo , @RequestParam HashMap<String,Object> paramMap ) throws Exception {
		
		HashMap map = service.selectLayoutList( pageVo.getStartNum(), pageVo.getEndNum(), paramMap);
		
		pageVo.setTotalCount((Integer)map.get("totalCount"));
		
		Map resultMap = new HashMap();
		resultMap.put("total"  , pageVo.getTotal());  //전체 페이지수
		resultMap.put("page"   , pageVo.getPage());   //현재 페이지수
		resultMap.put("records", pageVo.getTotalCount());//전체 레코드건수	
		resultMap.put("rows"   , map.get("list"));
		
		ModelAndView modelAndView = new ModelAndView("jsonView",resultMap);		
		return modelAndView;
		
	}
	
	@RequestMapping(value="/onl/admin/rule/transformMan.json", params="cmd=CHANGE_EXPORT")
	public ModelAndView exportData(HttpServletRequest request,  @RequestParam HashMap<String,Object> paramMap) throws Exception {
		HashMap<String, Object> resultMap = new HashMap<String, Object>();
		String userId = SessionManager.getUserId(request);
		if (!SystemUtil.isDevServer()){
    		throw new Exception("only support dev server ");
    	}
        try {
        	String cnvsnNames = (String)paramMap.get("cnvsnNames");
        	//취약점소스 수정 2020.08.25
            String[] arrCnvsnNames = null;
            if(cnvsnNames != null){
         	   arrCnvsnNames = cnvsnNames.split("\\,");
         	  paramMap.put("userId", userId);
              paramMap.put("arrCnvsnNames", arrCnvsnNames);
              
              service.exportData(paramMap);
            }
			
			resultMap.put("message", "전송이 성공적으로 완료되었습니다");
        } catch (BizException be) {
			throw new Exception(be.getMessage());
		} catch (Exception e) {
			logger.error(e.getMessage());
			throw new Exception(localeMessage.getString("errors.checklog"));
		}
		
		ModelAndView modelAndView = new ModelAndView("jsonView", resultMap);
		return modelAndView;
	}
	@RequestMapping(value= "/onl/admin/rule/transformMan.excel",params = "cmd=LIST_GRID_TO_EXCEL")
	public ModelAndView listGridToExcel(HttpServletRequest request, HttpServletResponse response, @RequestParam HashMap<String,Object> paramMap) throws Exception {
		HashMap<String,Object> resultMap = new HashMap<String,Object>();
		
		
		HashMap<String, String>[] list2 ;
    	Gson gson = new Gson();
    	if(paramMap.get("gridData")==null){
    		
    		String headersStr = (String) paramMap.get("headersStr"); 
    		headersStr = headersStr.substring(0, headersStr.length()-1);
    		paramMap.put("headersStr", headersStr);
    		
    		@SuppressWarnings("unchecked")
	    	HashMap<String, Object> list = service.selectListToExcel(request,paramMap);
	    	
	    	String jsonStr = gson.toJson(list.get("list"));
	    	list2 = gson.fromJson(jsonStr, HashMap[].class);
	    	
    	}else{
	    	list2=gson.fromJson((String) paramMap.get("gridData"), HashMap[].class);
    	}

		String[] headers = gson.fromJson((String) paramMap.get("header"), String[].class);
		String[] headerTitles = gson.fromJson((String)paramMap.get("headerTitle"), String[].class);
		
		HashMap<String, Object>[] lmerge = null; 
		String merge = (String)paramMap.get("merge");
		if (merge !=null){
			lmerge = gson.fromJson(merge, HashMap[].class);
		}
    	
    	resultMap.put("headers", headers);
    	resultMap.put("headerTitles", headerTitles);
    	resultMap.put("datas", list2);
    	resultMap.put("fileName", (String)paramMap.get("fileName"));
    	resultMap.put("merge", lmerge);
		ModelAndView modelAndView = new ModelAndView("excelView",resultMap);	
        return modelAndView;
    }	
	@RequestMapping(value= "/onl/admin/rule/transformMan.json",params = "cmd=DETAIL_POP")
    public ModelAndView selectCnvsnDetailPop( HttpServletRequest request, HttpServletResponse response, String cnvsnName,String tgt_layout,String src_layout) throws Exception {
    	
            List list = service.selectCnvsnDetailPop(cnvsnName ,tgt_layout,src_layout);
            
            HashMap map = new HashMap();
            map.put("rows", list);
            
    		ModelAndView modelAndView = new ModelAndView("jsonView",map);		
    		return modelAndView;       
    		
    }
	
	@RequestMapping(value = "/onl/admin/rule/transformMan.json", params = "cmd=CLONETOPROD")
	private ModelAndView cloneToProd(HttpServletRequest request, @RequestParam HashMap<String, Object> paramMap)
			throws Exception {
		if (SystemUtil.isProdServer()) {
			throw new Exception("only support dev, stage server");
		}

		HashMap<String, Object> resultMap = new HashMap<String, Object>();
		String userId = SessionManager.getUserId(request);
		String serviceKey = SessionManager.getServiceTypeKey(request);
		String cmTitle = MapUtils.getString(paramMap, "CmTitle", "Deploy Layout");
		String cmDate = StringUtil.getNullStr(paramMap.get("CmDate"));
		String cmTime = StringUtil.getNullStr(paramMap.get("CmTime"));
		String ListTransformName = StringUtil.getNullStr(paramMap.get("ListTransformName"));
		String[] eaiCnvsnNames = ListTransformName.split("\\,");
		String downloadPath = monitoringContext.getStringProperty(MonitoringContext.IOMAP_DOWNLOAD_PATH);
		downloadPath = StringUtils.removeEnd(downloadPath, File.separator) + File.separator + serviceKey
				+ File.separator;
		String targetName = monitoringContext.getStringProperty(MonitoringContext.IOMAP_DEPLOY_TARGET_NAME);
		String targetUrl = monitoringContext.getStringProperty(MonitoringContext.IOMAP_DEPLOY_TARGET_URL);
		targetUrl = StringUtils.removeEnd(targetUrl, "/");

		String userIp = IpUtil.getClientIp(request);

		if (logger.isInfoEnabled()) {
			logger.info("-------------------------------------------");
			logger.info("userId=" + userId);
			logger.info("userIp=" + userIp);
			logger.info("serviceKey=" + serviceKey);
			logger.info("cmDate=" + cmDate);
			logger.info("cmTime=" + cmTime);
			logger.info("ListTransformName=" + ListTransformName);
			logger.info("downloadPath=" + downloadPath);
			logger.info("targetName=" + targetName); // 스테이징, 운영서버
			logger.info("targetUrl=" + targetUrl); // http://127.0.0.1:20100
			logger.info("-------------------------------------------");
		}

		DataSourceType dt = DataSourceTypeManager.getDataSourceType(serviceKey);
		String items = "";

		// 0. 서브 배포 목록 확보
		HashMap<String, ArrayList<HashMap<String, String>>> listMap = historyService.userHistoryListByTransform(dt,
				eaiCnvsnNames);

		if (listMap != null && listMap.size() > 0) {
			// 1. 파일 생성
			try {
				loaderService.makeDataFiles(dt, downloadPath, listMap);
			} catch (Exception e) {
				logger.error(e.getMessage(), e);
				throw new Exception("Make Datafile error:" + e.getMessage());
			}

			// 2. 파일 배포
			try {
				if (StringUtils.isBlank(targetUrl)) {
					throw new Exception("Set EMS property:" + MonitoringContext.IOMAP_DEPLOY_TARGET_URL);
				}

				String url = targetUrl + "/monitoring/loader.do";
				loaderService.deployDataToTargetSystem(url, downloadPath, listMap, serviceKey);
			} catch (Exception e) {
				logger.error(e.getMessage(), e);
				throw new Exception("Deploy to target System(" + targetName + ") error:" + e.getMessage());
			}

			items += historyService.parseSimple(serviceKey, "", listMap);
		}

		// 3. 데이터 적용 또는 스케쥴 등록
		try {
			String url = targetUrl + "/monitoring/loader.do";
			loaderService.scheduleDeployDataApply(url, userId, userIp, serviceKey, cmTitle, cmDate, cmTime, items);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			throw new Exception("Apply DeployData or Apply Schedule error:" + e.getMessage());
		}

		resultMap.put("message", localeMessage.getMessage("ruleDeploy.msg4"));

		ModelAndView modelAndView = new ModelAndView("jsonView", resultMap);
		return modelAndView;
	}
}
