init
This commit is contained in:
@@ -0,0 +1,91 @@
|
||||
package com.eactive.eai.common.bizkey;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import com.eactive.eai.common.bizkey.loader.BizKeyLoader;
|
||||
import com.eactive.eai.common.dao.BaseDAO;
|
||||
import com.eactive.eai.common.dao.DAOException;
|
||||
import com.eactive.eai.common.exception.ExceptionUtil;
|
||||
import com.eactive.eai.common.util.Logger;
|
||||
import com.eactive.eai.data.entity.onl.bizkey.BizKey;
|
||||
|
||||
@Service
|
||||
@Transactional
|
||||
public class BizKeyDAO extends BaseDAO {
|
||||
private static Logger logger = Logger.getLogger(Logger.LOGGER_DEFAULT);
|
||||
|
||||
@Autowired
|
||||
private BizKeyLoader bizKeyLoader;
|
||||
|
||||
public Map<String, BizKeyVO> getAllBizKeys() throws Exception {
|
||||
|
||||
try {
|
||||
List<BizKey> bizKeys = bizKeyLoader.findAllOrderByDefault();
|
||||
Map<String, BizKeyVO> msgKeys = new HashMap<>();
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info("[ @@ Load BizKey Configuration - starting >>>>>>>>>>>>>>>>> ]");
|
||||
}
|
||||
for (BizKey bizKey : bizKeys) {
|
||||
String key = bizKey.getId().getEaisvcname() + bizKey.getId().getEtractdstcd();
|
||||
BizKeyVO vo = msgKeys.get(key);
|
||||
|
||||
if (vo == null) {
|
||||
vo = new BizKeyVO(bizKey.getId().getEaisvcname(), bizKey.getId().getEtractdstcd());
|
||||
msgKeys.put(key, vo);
|
||||
}
|
||||
|
||||
vo.addBizKeyFld(bizKey.getMsgdstcd(), bizKey.getBzwkfldname());
|
||||
|
||||
}
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info("[>>Load BizKey Configuration - ended ]");
|
||||
}
|
||||
return msgKeys;
|
||||
|
||||
} catch (Exception e) {
|
||||
throw new DAOException(ExceptionUtil.getErrorCode(e, "RECEAICBM101"));
|
||||
}
|
||||
}
|
||||
|
||||
public Map<String, BizKeyVO> getBizKey(String eaiSvcCd, String exrClsNm) throws Exception {
|
||||
try {
|
||||
Map<String, BizKeyVO> msgKeys = new HashMap<>();
|
||||
Collection<BizKey> bizKeys = bizKeyLoader.findByIdEaisvcnameAndIdEtractdstcd(eaiSvcCd, exrClsNm);
|
||||
logger.info("[ @@ Load BizKey getBizKey Configuration - starting >>>>>>>>>>>>>>>>> ]");
|
||||
|
||||
for (BizKey bizKey : bizKeys) {
|
||||
String key = bizKey.getId().getEaisvcname() + bizKey.getId().getEtractdstcd();
|
||||
BizKeyVO vo = msgKeys.get(key);
|
||||
|
||||
if (vo == null) {
|
||||
vo = new BizKeyVO(eaiSvcCd, exrClsNm);
|
||||
msgKeys.put(key, vo);
|
||||
}
|
||||
|
||||
vo.addBizKeyFld(bizKey.getId().getFldprcssno(), bizKey.getMsgdstcd(), bizKey.getBzwkfldname());
|
||||
}
|
||||
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info("BizKeyFldVO in getBizKey():");
|
||||
for (BizKeyVO vo : msgKeys.values()) {
|
||||
for (BizKeyFldVO fldVO : vo.getAlMsgFlds()) {
|
||||
logger.info("BizKeyFld getBizKey --->> " + fldVO.toString());
|
||||
}
|
||||
}
|
||||
logger.info("[>>Load BizKey getBizKey Configuration - ended ]");
|
||||
}
|
||||
return msgKeys;
|
||||
|
||||
} catch (Exception e) {
|
||||
throw new DAOException(ExceptionUtil.getErrorCode(e, "RECEAICBM205"));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
package com.eactive.eai.common.bizkey;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class BizKeyFldVO implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private int colPssSeq; // 순번 [TSEAIFR03.FldPrcssNo]
|
||||
private String msgTp; // 메시지유형 [TSEAIFR03.MsgDstcd]
|
||||
private String bwkColNm; // 업무필드명 [TSEAIFR03.BzwkFldName]
|
||||
|
||||
public BizKeyFldVO(int colPssSeq, String msgTp, String bwkColNm) {
|
||||
this.colPssSeq = colPssSeq;
|
||||
this.msgTp = msgTp;
|
||||
this.bwkColNm = bwkColNm;
|
||||
}
|
||||
|
||||
public void setColPssSeq(int colPssSeq) {
|
||||
this.colPssSeq = colPssSeq;
|
||||
}
|
||||
|
||||
public int getColPssSeq() {
|
||||
return this.colPssSeq;
|
||||
}
|
||||
|
||||
public void setMsgTp(String msgTp) {
|
||||
this.msgTp = msgTp;
|
||||
}
|
||||
|
||||
public String getMsgTp() {
|
||||
return this.msgTp;
|
||||
}
|
||||
|
||||
public void setBwkColNm(String bwkColNm) {
|
||||
this.bwkColNm = bwkColNm;
|
||||
}
|
||||
|
||||
public String getBwkColNm() {
|
||||
return this.bwkColNm;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("BizKeyFldVO {")
|
||||
.append("colPssSeq=").append(colPssSeq).append(", ")
|
||||
.append("msgTp='").append(msgTp).append("', ")
|
||||
.append("bwkColNm='").append(bwkColNm).append("'")
|
||||
.append("}");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,139 @@
|
||||
package com.eactive.eai.common.bizkey;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.eactive.eai.common.exception.ExceptionUtil;
|
||||
import com.eactive.eai.common.lifecycle.Lifecycle;
|
||||
import com.eactive.eai.common.lifecycle.LifecycleException;
|
||||
import com.eactive.eai.common.lifecycle.LifecycleListener;
|
||||
import com.eactive.eai.common.lifecycle.LifecycleSupport;
|
||||
import com.eactive.eai.common.util.ApplicationContextProvider;
|
||||
import com.eactive.eai.common.util.Logger;
|
||||
|
||||
@Component
|
||||
public class BizKeyManager implements Lifecycle {
|
||||
static Logger logger = Logger.getLogger(Logger.LOGGER_DEFAULT);
|
||||
|
||||
private Map<String, BizKeyVO> messages = new HashMap<>();
|
||||
private LifecycleSupport lifecycle = new LifecycleSupport(this);
|
||||
private boolean started;
|
||||
|
||||
@Autowired
|
||||
private BizKeyDAO bizKeyDAO;
|
||||
|
||||
public static BizKeyManager getInstance() {
|
||||
return ApplicationContextProvider.getContext().getBean(BizKeyManager.class);
|
||||
}
|
||||
|
||||
public void start() throws LifecycleException {
|
||||
if (started)
|
||||
throw new LifecycleException("RECEAICBM201");
|
||||
|
||||
lifecycle.fireLifecycleEvent(STARTING_EVENT, this);
|
||||
|
||||
try {
|
||||
init();
|
||||
} catch (Exception e) {
|
||||
throw new LifecycleException(ExceptionUtil.getErrorCode(e, "RECEAICBM202"));
|
||||
}
|
||||
|
||||
started = true;
|
||||
lifecycle.fireLifecycleEvent(STARTED_EVENT, this);
|
||||
}
|
||||
|
||||
private void init() throws Exception {
|
||||
messages = null;
|
||||
messages = bizKeyDAO.getAllBizKeys();
|
||||
}
|
||||
|
||||
public synchronized void reload() throws Exception {
|
||||
if (logger.isWarn()) {
|
||||
logger.warn("BizKeyManager] reload all Started ...");
|
||||
}
|
||||
init();
|
||||
if (logger.isWarn()) {
|
||||
logger.warn("BizKeyManager] reload all finished ...");
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void reload(String eaiSvcCd, String exrClsNm) throws Exception {
|
||||
Map<String, BizKeyVO> map = bizKeyDAO.getBizKey(eaiSvcCd, exrClsNm);
|
||||
if (map != null) {
|
||||
Iterator<String> it = map.keySet().iterator();
|
||||
|
||||
String key = "";
|
||||
while (it.hasNext()) {
|
||||
key = it.next();
|
||||
messages.put(key, map.get(key));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void stop() throws LifecycleException {
|
||||
if (!started)
|
||||
throw new LifecycleException("RECEAICBM203");
|
||||
|
||||
lifecycle.fireLifecycleEvent(STOPING_EVENT, this);
|
||||
|
||||
messages.clear();
|
||||
|
||||
started = false;
|
||||
lifecycle.fireLifecycleEvent(STOPPED_EVENT, this);
|
||||
}
|
||||
|
||||
public void addLifecycleListener(LifecycleListener listener) {
|
||||
lifecycle.addLifecycleListener(listener);
|
||||
}
|
||||
|
||||
public LifecycleListener[] findLifecycleListeners() {
|
||||
return lifecycle.findLifecycleListeners();
|
||||
}
|
||||
|
||||
public void removeLifecycleListener(LifecycleListener listener) {
|
||||
lifecycle.removeLifecycleListener(listener);
|
||||
}
|
||||
|
||||
public boolean isStarted() {
|
||||
return this.started;
|
||||
}
|
||||
|
||||
public BizKeyVO getBizKey(String code) {
|
||||
return messages.get(code);
|
||||
}
|
||||
|
||||
public BizKeyVO getBizKey(String eaiSvcCd, String exrClsNm) {
|
||||
return messages.get(eaiSvcCd + exrClsNm);
|
||||
}
|
||||
|
||||
public void setBizKey(String code, BizKeyVO msg) {
|
||||
messages.put(code, msg);
|
||||
}
|
||||
|
||||
public void setBizKey(String eaiSvcCd, String exrClsNm, BizKeyVO vo) {
|
||||
messages.put(eaiSvcCd + exrClsNm, vo);
|
||||
}
|
||||
|
||||
public void updateBizKey(String eaiSvcCd, String exrClsNm, BizKeyVO vo) {
|
||||
messages.put(eaiSvcCd + exrClsNm, vo);
|
||||
}
|
||||
|
||||
public void removeBizKey(String code) {
|
||||
messages.remove(code);
|
||||
}
|
||||
|
||||
public String[] getAllKeyNames() {
|
||||
Iterator<String> it = this.messages.keySet().iterator();
|
||||
String[] name = new String[this.messages.size()];
|
||||
for (int i = 0; it.hasNext(); i++) {
|
||||
name[i] = it.next();
|
||||
}
|
||||
Arrays.sort(name);
|
||||
return name;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
package com.eactive.eai.common.bizkey;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class BizKeyVO implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private String eaiSvcCd; // EAI 서비스코드 [TSEAIFR03.EAISvcName]
|
||||
private String exrClsNm; // 추출구분 [TSEAIFR03.EtractDstcd] (추적필드(TR) | ALT-KEY(AK))
|
||||
|
||||
private ArrayList<BizKeyFldVO> alMsgFlds;
|
||||
|
||||
public BizKeyVO() {
|
||||
this("");
|
||||
}
|
||||
|
||||
public BizKeyVO(String eaiSvcCd) {
|
||||
this(eaiSvcCd, "");
|
||||
}
|
||||
|
||||
public BizKeyVO(String eaiSvcCd, String exrClsNm) {
|
||||
this.eaiSvcCd = eaiSvcCd;
|
||||
this.exrClsNm = exrClsNm;
|
||||
this.alMsgFlds = new ArrayList<>();
|
||||
}
|
||||
|
||||
public void setEaiSvcCd(String eaiSvcCd) {
|
||||
this.eaiSvcCd = eaiSvcCd;
|
||||
}
|
||||
|
||||
public String getEaiSvcCd() {
|
||||
return this.eaiSvcCd;
|
||||
}
|
||||
|
||||
public void setExrClsNm(String exrClsNm) {
|
||||
this.exrClsNm = exrClsNm;
|
||||
}
|
||||
|
||||
public String getExrClsNm() {
|
||||
return this.exrClsNm;
|
||||
}
|
||||
|
||||
public BizKeyFldVO getBizKeyFld(int key) {
|
||||
BizKeyFldVO vo = alMsgFlds.get(key);
|
||||
if (vo == null)
|
||||
return null;
|
||||
|
||||
return vo;
|
||||
}
|
||||
|
||||
public void addBizKeyFld(String msgTp, String bwkColNm) {
|
||||
int alSize = this.alMsgFlds.size();
|
||||
this.alMsgFlds.add(new BizKeyFldVO(alSize + 1, msgTp, bwkColNm));
|
||||
}
|
||||
|
||||
public void addBizKeyFld(int colPssSeq, String msgTp, String bwkColNm) {
|
||||
this.alMsgFlds.add(new BizKeyFldVO(colPssSeq, msgTp, bwkColNm));
|
||||
}
|
||||
|
||||
public int getBizKeyFldLength() {
|
||||
return this.alMsgFlds.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "BizKeyFldVO [alMsgFlds=" + printMessageFields() + "]";
|
||||
}
|
||||
|
||||
private String printMessageFields() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
alMsgFlds.forEach( field -> sb.append(field.toString()).append("\n | ") );
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public List<BizKeyFldVO> getAlMsgFlds() {
|
||||
return alMsgFlds;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user