티스토리 뷰

Programming/Nexacro

Nexacro - Controller 호출

파란크리스마스 2017. 11. 26. 18:49
728x90

출처 : 전자정부 표준프레임워크 3.2 기반 넥사크로 플랫폼 개발자 가이드

Nexacro - 서버 호출 Button 이벤트

this.Button00_onclick = function(obj:Button,  e:nexacro.ClickEventInfo)
{
	var sSvcID          = "list";                   
    var sController     = "blueController.do";
    var sInDatasets     = "";  
    var sOutDatasets    = "";
    var sArgs="";
    
    // 서비스 아이디
    var strSvcID = {id:sSvcID, outDatasets:sOutDatasets};
    
    // 서비스 변수 값 가지고 오기
    var sSvcUrl = application.services["svcurl"].url;
    // 서버 호출 주소 생성
    var strURL = sSvcUrl + sController;

    // Ex.core.tran(this, sSvcID, sController, sInDatasets, sOutDatasets, sArgs);
    this.transaction(strSvcID, strURL, sInDatasets, sOutDatasets, sArgs, "received", true, false);
}

this.received = function(id, code, message)
{
    alert(code);
}

Server - Controller 클래스 생성

package bizservice.nexa.cmmn.map.controller;

import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import egovframework.rte.cmmn.ria.nexacro.NexacroConstant;
import egovframework.rte.cmmn.ria.nexacro.map.DataSetMap;
import egovframework.rte.cmmn.ria.nexacro.map.NexacroMapDTO;

@Controller
public class BlueController {

	protected Log logger = LogFactory.getLog(this.getClass());

	@RequestMapping("/blueController.do")
	public ModelAndView operate(NexacroMapDTO xpDto, Model model) throws Exception {

		ModelAndView mav = new ModelAndView("nexacroMapView");

		try {
			DataSetMap tranInfo 				= xpDto.getTranInfoMap();
			Map <String, Object> inVar 			= xpDto.getInVariableMap();
			Map <String, DataSetMap> inDataset 	= xpDto.getInDataSetMap();
			Map <String, Object> outVar 		= xpDto.getOutVariableMap();
			Map <String, DataSetMap> outDataset = xpDto.getOutDataSetMap();
			
			System.out.println("tranInfo : " + tranInfo);
			System.out.println("inVar : " + inVar);
			System.out.println("inDataset : " + inDataset);
			System.out.println("outVar : " + outVar);
			System.out.println("outDataset : " + outDataset);
			
			mav.addObject(NexacroConstant.ERROR_CODE, "0");
			mav.addObject(NexacroConstant.ERROR_MSG, "");

		} catch (Exception e) {
			e.printStackTrace();
			mav.addObject(NexacroConstant.ERROR_CODE, "-1");
			mav.addObject(NexacroConstant.ERROR_MSG, e.toString());
		}
		return mav;
	}
}

서버 로그

tranInfo : egovframework.rte.cmmn.ria.nexacro.map.DataSetMap@10c2d26
inVar : {PAGE={}, serverType=local, USER={}}
inDataset : {}
outVar : {}
outDataset : {}

Nexacro - 서버 호출 Button 이벤트 - 파라미터 구성 추가

this.Button00_onclick = function(obj:Button,  e:nexacro.ClickEventInfo)
{
	var sSvcID          = "list";                   
    var sController     = "blueController.do";
    var sInDatasets     = "";  
    var sOutDatasets    = "";
    
    ///////////////////////////////////////////////////////////////////////////////////////////////////
    // 파라미터 구성
    var sArgs="";
    sArgs += Ex.util.setParam("method","getList");
    sArgs += application.gfn_setParam("sqlId","blueDAO.getList");
    sArgs += Ex.util.setParam("inputClass","bizservice.nexa.domain.Dept");
    sArgs += Ex.util.setParam("outputClass","bizservice.nexa.domain.Dept");
    
    // 서비스 아이디
    var strSvcID = {id:sSvcID, outDatasets:sOutDatasets};
    
    // 서비스 변수 값 가지고 오기
    var sSvcUrl = application.services["svcurl"].url;
    // 서버 호출 주소 생성
    var strURL = sSvcUrl + sController;

    // Ex.core.tran(this, sSvcID, sController, sInDatasets, sOutDatasets, sArgs);
    this.transaction(strSvcID, strURL, sInDatasets, sOutDatasets, sArgs, "received", true, false);
}

Server - 서버 로그

tranInfo : egovframework.rte.cmmn.ria.nexacro.map.DataSetMap@1a80f5c
inVar : {PAGE={}, method=getList sqlId=blueDAO.getListVO inputClass=bizservice.nexa.domain.Dept outputClass=bizservice.nexa.domain.Dept , serverType=local, USER={}}
inDataset : {}
outVar : {}
outDataset : {}

Nexacro - application 내장 함수 만들기

호출 과정을 정리 해본것으로 실제 사용시 Eco, Ex 라이브러리를 사용 필요

스크립트 창 열기

this.gv_op = "OP";

this.gfn_isNull = function(value)
{
    return value === null;
}
 
this.gfn_isUndefined = function(value)
{
    return value === undefined;
}
 
/**
 * 공백으로치환
 * @param {string} 체크할  파리미터명
 * @return {string} 공백으로 치환값
 * @example
 *    trace(Eco.isEmpty("")); (output) ""
 * @memberOf Ex.util
 */    
this.gfn_isReplaceEmpty = function(strArg)
{
      if( this.gfn_isNull(strArg) || this.gfn_isUndefined(strArg)) return "";
       else
       return strArg;
}
 
this.gfn_setParam = function (p_name, p_value)
{          
    return p_name + "="+this.gfn_isReplaceEmpty(p_value)+ " ";
}

this.gfn_transaction = function(obj, svcID, sController, inDatasets, outDatasets, argument, callbackFunc)
{
    // Service ID Merge
    var strSvcID = {id:svcID, callbackFunc:callbackFunc, outDatasets:outDatasets};
    var strInDatasets = inDatasets;
    var strOutDatasets = outDatasets;
    var strArgument = argument;
    var strCallbackFunc = callbackFunc;
    
    // 서비스 변수 값 가지고 오기
    var sSvcUrl = this.services["svcurl"].url;
    // 서버 호출 주소 생성
    var strURL = sSvcUrl + sController;

    // 
    obj.transaction(strSvcID, strURL, strInDatasets, strOutDatasets, strArgument, strCallbackFunc, true, false);
}

Nexacro - 서버 호출 Button 이벤트

this.Button00_onclick = function(obj:Button,  e:nexacro.ClickEventInfo)
{
	var sSvcID          = "list";                   
    var sController     = "blueController.do";
    var sInDatasets     = "";  
    var sOutDatasets    = "";
    
     ///////////////////////////////////////////////////////////////////////////////////////////////////
    // 2015.06.12 VO방식 테스트
    var sArgs="";
    sArgs += application.gfn_setParam("method","getList");
    sArgs += application.gfn_setParam("sqlId","blueDAO.getList");
    sArgs += application.gfn_setParam("inputClass","bizservice.nexa.domain.Dept");
    sArgs += application.gfn_setParam("outputClass","bizservice.nexa.domain.Dept");
    
    //
    application.gfn_transaction(this, sSvcID, sController, sInDatasets, sOutDatasets, sArgs, "received");
}

this.received = function(id, code, message)
{
    alert(code);
}

Server - 서비스 구현

서비스 인터페이스

package bizservice.nexa.cmmn.map.service;

import java.util.Map;

import egovframework.rte.cmmn.ria.nexacro.map.DataSetMap;

public interface BlueService {

	void getList(
			DataSetMap tranInfo,
			Map<String, Object> inVar, Map<String, DataSetMap> inDataset,
			Map<String, Object> outVar, Map<String, DataSetMap> outDataset) throws Exception;
}

서비스 구현

package bizservice.nexa.cmmn.map.service;

import java.util.Map;

import org.springframework.stereotype.Service;

import egovframework.rte.cmmn.ria.nexacro.map.DataSetMap;

@Service("blueService")
public class BlueServiceImpl implements BlueService {

	public void getList(DataSetMap tranInfo,
			Map<String, Object> inVar, Map<String, DataSetMap> inDataset,
			Map<String, Object> outVar, Map<String, DataSetMap> outDataset)
		throws Exception 
	{
		// DAO 호출 구현
	}
}

서비스 호출 Controller 구현

package bizservice.nexa.cmmn.map.controller;

import java.lang.reflect.Method;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import bizservice.nexa.cmmn.map.service.BlueService;
import egovframework.rte.cmmn.ria.nexacro.NexacroConstant;
import egovframework.rte.cmmn.ria.nexacro.map.DataSetMap;
import egovframework.rte.cmmn.ria.nexacro.map.NexacroMapDTO;

@Controller
public class BlueController {

	protected Log logger = LogFactory.getLog(this.getClass());
	
	@Resource(name="blueService")
	BlueService blueService;

	@RequestMapping("/blueController.do")
	public ModelAndView operate(NexacroMapDTO xpDto, Model model) throws Exception {

		ModelAndView mav = new ModelAndView("nexacroMapView");

		try {
			DataSetMap tranInfo 				= xpDto.getTranInfoMap();
			Map <String, Object> inVar 			= xpDto.getInVariableMap();
			Map <String, DataSetMap> inDataset 	= xpDto.getInDataSetMap();
			Map <String, Object> outVar 		= xpDto.getOutVariableMap();
			Map <String, DataSetMap> outDataset = xpDto.getOutDataSetMap();
			
			for (Map map : tranInfo.getRowMaps()) {
				System.out.println("tranInfo.map : " + map);
			}
			System.out.println("inVar : " + inVar);
			System.out.println("inDataset : " + inDataset);
			System.out.println("outVar : " + outVar);
			System.out.println("outDataset : " + outDataset);
			
			// 서비스 객체
			Object bean = blueService;
			Method method = getMethod(bean, (String)inVar.get("method"));
			
			try{
				// 메소드 호출
				method.invoke(bean, new Object[] {tranInfo, inVar, inDataset, outVar, outDataset});
			} catch (Exception e){
				Throwable te = e.getCause();
				logger.debug("Can not invoke a dispatch method name", te);
				throw new Exception(te.getMessage(), te);
			}
			
			mav.addObject(NexacroConstant.ERROR_CODE, "0");
			mav.addObject(NexacroConstant.ERROR_MSG, "");

		} catch (Exception e) {
			e.printStackTrace();
			mav.addObject(NexacroConstant.ERROR_CODE, "-1");
			mav.addObject(NexacroConstant.ERROR_MSG, e.toString());
		}
		return mav;
	}
	
	private Method getMethod(Object bean, String methodName) throws Exception{
		Method[] methods = bean.getClass().getMethods();

		for(int i = 0 ; i < methods.length ; i++) {
			if( methods[i].getName().equals(methodName)) {
				return methods[i];
			}
		}
		throw new Exception("Cann't find " + methodName + ".");
	}
}

Server - 서비스 구현 - DAO 호출

package bizservice.nexa.cmmn.map.service;

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

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import bizservice.nexa.cmmn.map.dao.BlueDAO;
import egovframework.rte.cmmn.ria.nexacro.map.DataSetMap;

@Service("blueService")
public class BlueServiceImpl implements BlueService {
	
	@Resource(name="sqlMapBlueDAO")
	BlueDAO blueDAO;

	public void getList(DataSetMap tranInfo,
			Map<String, Object> inVar, Map<String, DataSetMap> inDataset,
			Map<String, Object> outVar, Map<String, DataSetMap> outDataset)
		throws Exception 
	{
		// DAO 호출 구현
		// List<Map> records = blueDAO.getList("blueDAO.getList", inVar);
		List<Map> records = blueDAO.getList((String)inVar.get("sqlId"), inVar);
		System.out.println("records = " + records.size());
			
		DataSetMap outDsMap = new DataSetMap();
		outDsMap.setRowMaps(records);
		outDataset.put("output1", outDsMap);
	}
}

DAO 인터페이스

package bizservice.nexa.cmmn.map.dao;

import java.util.List;

import bizservice.nexa.exception.NexaDaoException;

public interface BlueDAO {

	public List getList(String queryId, Object objVo) throws NexaDaoException;

}

DAO 인터페이스 구현

package bizservice.nexa.cmmn.map.dao;

import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Repository;

import bizservice.nexa.exception.NexaDaoException;
import egovframework.rte.psl.dataaccess.EgovAbstractDAO;

@Repository("sqlMapBlueDAO")
public class SqlMapBlueDAO extends EgovAbstractDAO implements BlueDAO {

	public List getList(String queryId, Object objVo) throws NexaDaoException {
		List<Object> list = new ArrayList();
		list = getSqlMapClientTemplate().queryForList(queryId, objVo);
		return list;
	}

}

SQL Map 파일 생성 - nexacroplatform\src\main\resources\egovframework\sqlmap\bizservice\sample\Blue.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sqlMap PUBLIC "-//iBATIS.com//DTD SQL Map 2.0//EN" "http://www.ibatis.com/dtd/sql-map-2.dtd">

<sqlMap namespace="Blue">

	<!-- code -->
	<select id="blueDAO.getList" parameterClass="java.util.HashMap" resultClass="java.util.HashMap">
		SELECT *
		  FROM XP_DEPT
	</select>

</sqlMap>

추가한 SQL Map 파일 Config에 추가 - nexacroplatform\src\main\resources\egovframework\sqlmap\bizservice\sql-map-config.xml

<sqlMap resource="egovframework/sqlmap/bizservice/sample/Blue.xml" />
댓글
300x250
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
«   2024/11   »
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
글 보관함