This commit is contained in:
Rinjae
2025-09-05 18:57:45 +09:00
commit aacc1a389e
1229 changed files with 167963 additions and 0 deletions
@@ -0,0 +1,97 @@
package com.eactive.eai.message.layout;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import com.eactive.eai.common.util.Logger;
import com.eactive.eai.message.StandardItem;
import com.eactive.eai.message.StandardMessage;
import com.eactive.eai.message.StandardMessageUtil;
public class CsvFileReader implements LayoutReader {
static Logger logger = Logger.getLogger(Logger.LOGGER_DEFAULT);
String COMMA_DELIMITER = ",";
String COMMENT_HEADER = "#";
public CsvFileReader() {
}
private BufferedReader getReader(String filePath) throws Exception {
BufferedReader reader = null;
if(logger.isInfoEnabled()) logger.info("getReader from filepath. read file = " + filePath);
try {
reader = new BufferedReader(new FileReader(filePath));
return reader;
}
catch(Exception ex) {
if(logger.isWarnEnabled()) {
// logger.warn("getReader failed. read file = " +filePath, ex);
logger.warn("getReader failed. read file = " +filePath +", " + ex.getMessage());
}
}
try {
if(logger.isInfoEnabled()) logger.info("getReader from classpath. read file = " + filePath);
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
reader = new BufferedReader(new InputStreamReader(classLoader.getResourceAsStream(filePath)) );
return reader;
}
catch(Exception ex) {
if(logger.isWarnEnabled()) {
// logger.warn("getReader failed. read classpath file = " + filePath, ex);
logger.warn("getReader failed. read classpath file = " + filePath + ", " + ex.getMessage());
}
}
throw new Exception("file not found : " + filePath);
}
@Override
public ArrayList<StandardItem> parse(String filePath) throws Exception {
if(logger.isInfoEnabled()) logger.info("CsvFileReader read file = " + filePath);
ArrayList<StandardItem> list = new ArrayList<StandardItem>();
int lineNo = 0;
try (BufferedReader br = getReader(filePath)) {
String line;
while ((line = br.readLine()) != null) {
lineNo++;
if(line.startsWith(COMMENT_HEADER)) {
if(logger.isDebugEnabled()) logger.debug(String.format("SKIP comment %s : %s", lineNo, line) );
continue;
}
if(logger.isDebugEnabled()) logger.debug(String.format("Parsing line %s : %s", lineNo, line) );
String[] values = line.split(COMMA_DELIMITER, StandardItem.ITEM_COUNT);
StandardItem item = new StandardItem(values);
list.add(item);
}
}
catch(Exception ex) {
throw new Exception(String.format("csv file %s parsing error lineNo=%d", filePath, lineNo), ex);
}
return list;
}
public static void main(String[] args) {
ArrayList<StandardItem> list = null;
String filePath = "./resources/standard-layout.csv";
try {
LayoutReader reader = new CsvFileReader();
list = (ArrayList<StandardItem>) reader.parse(filePath);
}
catch(Exception ex) {
ex.printStackTrace();
return;
}
StandardMessage message = null;;
try {
message = StandardMessageUtil.generate(list);
logger.debug("@toCSVString\n" + message.toCSVString());
logger.debug("@toString\n" + message.toString());
logger.debug("@toJson\n" + message.toJson());
} catch (Exception e) {
e.printStackTrace();
}
}
}
@@ -0,0 +1,64 @@
package com.eactive.eai.message.layout;
import java.util.ArrayList;
import java.util.Collection;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import com.eactive.eai.common.stdmessage.loader.StandardMessageLayoutDeployLoader;
import com.eactive.eai.common.stdmessage.loader.StandardMessageLayoutLoader;
import com.eactive.eai.common.util.Logger;
import com.eactive.eai.data.entity.onl.stdmessage.StandardMessageLayoutDeploy;
import com.eactive.eai.data.entity.onl.stdmessage.StandardMessageLayoutItem;
import com.eactive.eai.message.StandardItem;
@Component
@Transactional
public class DatabaseReader implements LayoutReader {
static Logger logger = Logger.getLogger(Logger.LOGGER_DEFAULT);
@Autowired
private StandardMessageLayoutDeployLoader standardMessageLayoutDeployLoader;
@Autowired
private StandardMessageLayoutLoader standardMessageLayoutLoader;
@Override
public ArrayList<StandardItem> parse(String layoutName) throws Exception {
logger.info("DB Reader Init");
boolean isMaster = false;
String targetLayoutName = null;
if(StringUtils.isBlank(layoutName)){
StandardMessageLayoutDeploy deploy = standardMessageLayoutDeployLoader.findFirst();
if(deploy != null){
targetLayoutName = deploy.getLayoutName();
isMaster = true;
}
}else{
targetLayoutName = layoutName;
}
ArrayList<StandardItem> list = new ArrayList<>();
if(StringUtils.isNotBlank(targetLayoutName)){
//로그 적재 시 사용 될 표준전문 레아이아웃 명을 저장한다(현재 로그저장 아키텍처 개선방안이 없어 임시로 작성한 코드이다)
// SUB 표준전문 로딩으로 로직 수정함.
if(isMaster) {
System.setProperty("STANDARD_LAYOUT_NAME", targetLayoutName);
logger.info("DB Reader Target Layout Name - {}", targetLayoutName);
}
Collection<StandardMessageLayoutItem> entityList = standardMessageLayoutLoader.getById(targetLayoutName)
.getStandardMessageLayoutItems();
for (StandardMessageLayoutItem entityItem : entityList) {
StandardItem item = new StandardItem(entityItem);
list.add(item);
}
}
return list;
}
}
@@ -0,0 +1,9 @@
package com.eactive.eai.message.layout;
import java.util.ArrayList;
import com.eactive.eai.message.StandardItem;
public interface LayoutReader {
public ArrayList<StandardItem> parse(String fileParh) throws Exception;
}