주석 보완

master
mjkhan21 1 year ago
parent f07de8e92b
commit d8351e8466

@ -12,9 +12,29 @@ import cokr.xit.foundation.AbstractComponent;
import cokr.xit.foundation.Assert; import cokr.xit.foundation.Assert;
import cokr.xit.foundation.data.JSON; import cokr.xit.foundation.data.JSON;
/** . /** . conf/file-job.conf .
* <p> conf/file-job.conf . * <p>file-job.conf JSON .
* * <pre><code> {
* "dirs": { //용도별 최상위 디렉토리 경로
* "receive": "수신 파일 최상위 디렉토리",
* "send": "전송 파일 최상위 디렉토리",
* "working": "파일 작업 최상위 디렉토리",
* "success": "작업을 완료한 파일의 최상위 디렉토리",
* "fail": "작업 실패한 파일의 최상위 디렉토리"
* },
* "dirCodes": { // 기관별 디렉토리 코드
* "기관1 키": "기관1 코드",
* "기관2 키": "기관2 코드",
* ...
* },
* "jobs": [ // 작업별 설정 정보
* {
* "name": "작업 이름",
* "dirCode": "기관별 디렉토리 코드, dicCodes에 설정한 키를 설정",
* ... //작업별 설정 정보(key-value pair)
* },
* ]
* }</code></pre>
* @author mjkhan * @author mjkhan
*/ */
public class JobConf extends AbstractComponent { public class JobConf extends AbstractComponent {
@ -84,10 +104,17 @@ public class JobConf extends AbstractComponent {
return ifEmpty(dirCodes != null ? dirCodes.get(key) : null, ""); return ifEmpty(dirCodes != null ? dirCodes.get(key) : null, "");
} }
/**key .
* @param dirCodes
*/
public void setDirCodes(Map<String, String> dirCodes) { public void setDirCodes(Map<String, String> dirCodes) {
this.dirCodes = dirCodes; this.dirCodes = dirCodes;
} }
/** key .
* @param key .
* @return key
*/
public Map<String, String> getJob(String key) { public Map<String, String> getJob(String key) {
if (jobMap == null) { if (jobMap == null) {
if (jobs == null) if (jobs == null)
@ -99,10 +126,18 @@ public class JobConf extends AbstractComponent {
return Assert.ifEmpty(jobMap.get(key), Collections::emptyMap); return Assert.ifEmpty(jobMap.get(key), Collections::emptyMap);
} }
/**key .
* @param jobs key
*/
public void setJobs(List<Map<String, String>> jobs) { public void setJobs(List<Map<String, String>> jobs) {
this.jobs = jobs; this.jobs = jobs;
} }
/** key .
* @param jobName
* @param key
* @return key
*/
public String getJobConf(String jobName, String key) { public String getJobConf(String jobName, String key) {
Map<String, String> job = getJob(jobName); Map<String, String> job = getJob(jobName);
return Assert.ifEmpty(job.get(key), () -> getDefault(key)); return Assert.ifEmpty(job.get(key), () -> getDefault(key));
@ -112,12 +147,28 @@ public class JobConf extends AbstractComponent {
return String.join(File.separator, str); return String.join(File.separator, str);
} }
/** .
* @param jobName
* @param dir
* <ul><li>receive - </li>
* <li>send - </li>
* </ul>
* @return
*/
public String getDir(String jobName, String dir) { public String getDir(String jobName, String dir) {
String org = getJob(jobName).get("dirCode"); String org = getJob(jobName).get("dirCode");
String code = getDirCode(org); String code = getDirCode(org);
return path(getDir(dir), code); return path(getDir(dir), code);
} }
/** .
* @param jobName
* @param dir
* <ul><li>receive - </li>
* <li>send - </li>
* </ul>
* @return
*/
public String getWorkingDir(String jobName, String dir) { public String getWorkingDir(String jobName, String dir) {
String org = getJob(jobName).get("dirCode"); String org = getJob(jobName).get("dirCode");
String code = getDirCode(org); String code = getDirCode(org);
@ -127,6 +178,10 @@ public class JobConf extends AbstractComponent {
*/ */
} }
/** .
* @param jobName
* @return
*/
public String getSuccessDir(String jobName) { public String getSuccessDir(String jobName) {
String org = getJob(jobName).get("dirCode"); String org = getJob(jobName).get("dirCode");
String code = getDirCode(org); String code = getDirCode(org);
@ -136,6 +191,10 @@ public class JobConf extends AbstractComponent {
*/ */
} }
/** .
* @param jobName
* @return
*/
public String getFailDir(String jobName) { public String getFailDir(String jobName) {
String org = getJob(jobName).get("dirCode"); String org = getJob(jobName).get("dirCode");
String code = getDirCode(org); String code = getDirCode(org);

@ -1,3 +1,4 @@
/** . /** service bean .
* <p> {@link JobConf conf/file-job.conf} .
*/ */
package cokr.xit.interfaces.filejob; package cokr.xit.interfaces.filejob;

@ -4,16 +4,16 @@ import java.io.File;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.function.Predicate; import java.util.function.Predicate;
import java.util.stream.Collectors;
import java.util.stream.Stream; import java.util.stream.Stream;
import cokr.xit.foundation.AbstractComponent; import cokr.xit.foundation.AbstractComponent;
import cokr.xit.interfaces.filejob.JobConf; import cokr.xit.interfaces.filejob.JobConf;
/** /** Bean
* @author mjkhan * @author mjkhan
*/ */
public abstract class FileJobBean extends AbstractComponent { public abstract class FileJobBean extends AbstractComponent {
@ -142,6 +142,12 @@ public abstract class FileJobBean extends AbstractComponent {
this.cause = rootCause(cause); this.cause = rootCause(cause);
return setSuccess(this.cause == null); return setSuccess(this.cause == null);
} }
public static List<Path> getPaths(List<FileStatus> fileStatus) {
return !isEmpty(fileStatus) ?
fileStatus.stream().map(FileStatus::getPath).toList() :
Collections.emptyList();
}
} }
/** . /** .
@ -201,7 +207,7 @@ public abstract class FileJobBean extends AbstractComponent {
*/ */
protected List<Path> getFilePaths(String dir, Predicate<Path> filter) { protected List<Path> getFilePaths(String dir, Predicate<Path> filter) {
try (Stream<Path> walk = Files.list(Paths.get(dir))) { try (Stream<Path> walk = Files.list(Paths.get(dir))) {
return walk.filter(ifEmpty(filter, path -> true)).collect(Collectors.toList()); return walk.filter(ifEmpty(filter, path -> true)).toList();
} catch (Exception e) { } catch (Exception e) {
throw runtimeException(e); throw runtimeException(e);
} }
@ -237,15 +243,19 @@ public abstract class FileJobBean extends AbstractComponent {
} }
/** , . /** , .
* @param filter . .
* @return * @return
*/ */
protected List<Path> getReceivedFilePaths() { protected List<Path> getReceivedFilePaths(Predicate<Path> filter) {
String receiveDir = receiveDir(), String receiveDir = receiveDir(),
workingDir = receiveWorkingDir(); workingDir = receiveWorkingDir();
Predicate<Path> test = ifEmpty(filter, Files::isRegularFile);
List<Path> paths = getFilePaths(receiveDir, test);
if (paths.isEmpty()) return Collections.emptyList();
List<Path> paths = getFilePaths(receiveDir, Files::isRegularFile);
move(paths, workingDir); move(paths, workingDir);
return getFilePaths(workingDir, null); return getFilePaths(workingDir, test);
} }
} }

@ -0,0 +1,51 @@
{
"dirs": {
"receive": "C:\\workspace\\ESB_AGENT\\RCV", /* 수신 파일 최상위 디렉토리 */
"send": "C:\\workspace\\ESB_AGENT\\SND", /* 전송 파일 최상위 디렉토리 */
"working": "C:\\workspace\\xit\\filesite\\work", /* 파일 작업 최상위 디렉토리 */
"success": "C:\\workspace\\xit\\filesite\\success", /* 작업 완료한 파일의 최상위 디렉토리 */
"fail": "C:\\workspace\\xit\\filesite\\fail" /* 작업 실패한 파일의 최상위 디렉토리 */
},
"dirCodes": {
"smg": "CG131000000768", /* 국민신문고 기관코드 */
"epost": "CG144523401150" /* epost 기관코드 */
},
"defaults": {
"charset": "euc-kr",
"fetchSize": 100
},
"jobs": [
{ /* 국민신문고 수신 */
"name": "smg-in",
"dirCode": "smg", /* <-- dirCodes */
"infoType": "100",
"alert": "http://localhost:8080/xit-filegate/api/smg/petition/receive.do" /* 업무 통보 url */
},
{ /* 국민신문고 전송 */
"name": "smg-out",
"dirCode": "smg", /* <-- dirCodes */
"alert": "http://localhost:8080/xit-filegate/api/smg/petition/reply.do" /* 업무 통보 url */
},
{ /* epost 전자우편 신청 전송 */
"name": "epost-send-request",
"dirCode": "epost", /* <-- dirCodes */
"conOrg": "YICT", /* 외부기관 구분코드 */
"rceptId": "40219", /* 접수우체국 국기호 */
"attachmentDir": "", /* 원본 첨부파일 디렉토리 경로 */
"txtFilename": "POSDF5$send_{yyyyMMddHHmmssSSS}.txt",
"zipFilename": "POSDF5${conKey}.zip"
},
{ /* epost 전자우편 신청 수신 결과 */
"name": "epost-receive-result",
"dirCode": "epost" /* <-- dirCodes */
}
]
}
Loading…
Cancel
Save