property 설정
This commit is contained in:
+26
-3
@@ -38,15 +38,38 @@
|
|||||||
| | | | | |
|
| | | | | |
|
||||||
|
|
||||||
```sql
|
```sql
|
||||||
|
-- 개발 서버용
|
||||||
insert into EMSADM.TSEAIRM24 (PRPTYGROUPNAME, PRPTYNAME, PRPTY2VAL) values ('Monitoring', 'kjb.eai_batch.url', 'http://172.31.32.111:10230/BATAppWeb/EaiBatCall');
|
insert into EMSADM.TSEAIRM24 (PRPTYGROUPNAME, PRPTYNAME, PRPTY2VAL) values ('Monitoring', 'kjb.eai_batch.url', 'http://172.31.32.111:10230/BATAppWeb/EaiBatCall');
|
||||||
insert into EMSADM.TSEAIRM24 (PRPTYGROUPNAME, PRPTYNAME, PRPTY2VAL) values ('Monitoring', 'kjb.ums.eai_batch.connection_timeout', '5');
|
insert into EMSADM.TSEAIRM24 (PRPTYGROUPNAME, PRPTYNAME, PRPTY2VAL) values ('Monitoring', 'kjb.eai.batch.connection_timeout', '5');
|
||||||
insert into EMSADM.TSEAIRM24 (PRPTYGROUPNAME, PRPTYNAME, PRPTY2VAL) values ('Monitoring', 'kjb.ums.eai_batch.response_timeout', '10');
|
insert into EMSADM.TSEAIRM24 (PRPTYGROUPNAME, PRPTYNAME, PRPTY2VAL) values ('Monitoring', 'kjb.eai.batch.response_timeout', '5');
|
||||||
|
insert into EMSADM.TSEAIRM24 (PRPTYGROUPNAME, PRPTYNAME, PRPTY2VAL) values ('Monitoring', 'kjb.eai.batch.timeout', '10');
|
||||||
|
insert into EMSADM.TSEAIRM24 (PRPTYGROUPNAME, PRPTYNAME, PRPTY2VAL) values ('Monitoring', 'kjb.eai.batch.charset', 'euc-kr');
|
||||||
insert into EMSADM.TSEAIRM24 (PRPTYGROUPNAME, PRPTYNAME, PRPTY2VAL) values ('Monitoring', 'kjb.ums.eai_batch.send_dir', '/Data/eapim/portal/sendmail/snd');
|
insert into EMSADM.TSEAIRM24 (PRPTYGROUPNAME, PRPTYNAME, PRPTY2VAL) values ('Monitoring', 'kjb.ums.eai_batch.send_dir', '/Data/eapim/portal/sendmail/snd');
|
||||||
insert into EMSADM.TSEAIRM24 (PRPTYGROUPNAME, PRPTYNAME, PRPTY2VAL) values ('Monitoring', 'kjb.ums.eai_batch.backup_dir', '/Data/eapim/portal/sendmail/bak');
|
insert into EMSADM.TSEAIRM24 (PRPTYGROUPNAME, PRPTYNAME, PRPTY2VAL) values ('Monitoring', 'kjb.ums.eai_batch.backup_dir', '/Data/eapim/portal/sendmail/bak');
|
||||||
|
insert into EMSADM.TSEAIRM24 (PRPTYGROUPNAME, PRPTYNAME, PRPTY2VAL) values ('Monitoring', 'kjb.ums.eai_batch.error_dir', '/Data/eapim/portal/sendmail/bak');
|
||||||
|
insert into EMSADM.TSEAIRM24 (PRPTYGROUPNAME, PRPTYNAME, PRPTY2VAL) values ('Monitoring', 'kjb.ums.eai_batch.retention_date', '60');
|
||||||
insert into EMSADM.TSEAIRM24 (PRPTYGROUPNAME, PRPTYNAME, PRPTY2VAL) values ('Monitoring', 'kjb.ums.eai_batch.interface_id', 'UAGFF00001UIE');
|
insert into EMSADM.TSEAIRM24 (PRPTYGROUPNAME, PRPTYNAME, PRPTY2VAL) values ('Monitoring', 'kjb.ums.eai_batch.interface_id', 'UAGFF00001UIE');
|
||||||
insert into EMSADM.TSEAIRM24 (PRPTYGROUPNAME, PRPTYNAME, PRPTY2VAL) values ('Monitoring', 'kjb.ums.host_url', 'http://172.31.35.144:9021');
|
insert into EMSADM.TSEAIRM24 (PRPTYGROUPNAME, PRPTYNAME, PRPTY2VAL) values ('Monitoring', 'kjb.ums.host_url', 'http://172.31.35.144:9021');
|
||||||
insert into EMSADM.TSEAIRM24 (PRPTYGROUPNAME, PRPTYNAME, PRPTY2VAL) values ('Monitoring', 'kjb.ums.api_key', '7cca6d58-e4f7-474d-9edd-525806bc99ff');
|
insert into EMSADM.TSEAIRM24 (PRPTYGROUPNAME, PRPTYNAME, PRPTY2VAL) values ('Monitoring', 'kjb.ums.api_key', '7cca6d58-e4f7-474d-9edd-525806bc99ff');
|
||||||
insert into EMSADM.TSEAIRM24 (PRPTYGROUPNAME, PRPTYNAME, PRPTY2VAL) values ('Monitoring', 'kjb.ums.connection_timeout', '5');
|
insert into EMSADM.TSEAIRM24 (PRPTYGROUPNAME, PRPTYNAME, PRPTY2VAL) values ('Monitoring', 'kjb.ums.connection_timeout', '5');
|
||||||
insert into EMSADM.TSEAIRM24 (PRPTYGROUPNAME, PRPTYNAME, PRPTY2VAL) values ('Monitoring', 'kjb.ums.response_timeout', '10');
|
insert into EMSADM.TSEAIRM24 (PRPTYGROUPNAME, PRPTYNAME, PRPTY2VAL) values ('Monitoring', 'kjb.ums.response_timeout', '5');
|
||||||
|
insert into EMSADM.TSEAIRM24 (PRPTYGROUPNAME, PRPTYNAME, PRPTY2VAL) values ('Monitoring', 'kjb.ums.timeout', '10');
|
||||||
|
|
||||||
|
|
||||||
|
-- autogen template
|
||||||
|
insert into EMSADM.TSEAIRM24 (PRPTYGROUPNAME, PRPTYNAME, PRPTY2VAL) values ('Monitoring', 'kjb.eai.batch.url', '');
|
||||||
|
insert into EMSADM.TSEAIRM24 (PRPTYGROUPNAME, PRPTYNAME, PRPTY2VAL) values ('Monitoring', 'kjb.eai.batch.connection_timeout', '5');
|
||||||
|
insert into EMSADM.TSEAIRM24 (PRPTYGROUPNAME, PRPTYNAME, PRPTY2VAL) values ('Monitoring', 'kjb.eai.batch.response_timeout', '5');
|
||||||
|
insert into EMSADM.TSEAIRM24 (PRPTYGROUPNAME, PRPTYNAME, PRPTY2VAL) values ('Monitoring', 'kjb.eai.batch.timeout', '10');
|
||||||
|
insert into EMSADM.TSEAIRM24 (PRPTYGROUPNAME, PRPTYNAME, PRPTY2VAL) values ('Monitoring', 'kjb.eai.batch.charset', 'euc-kr');
|
||||||
|
insert into EMSADM.TSEAIRM24 (PRPTYGROUPNAME, PRPTYNAME, PRPTY2VAL) values ('Monitoring', 'kjb.ums.eai_batch.send_dir', '');
|
||||||
|
insert into EMSADM.TSEAIRM24 (PRPTYGROUPNAME, PRPTYNAME, PRPTY2VAL) values ('Monitoring', 'kjb.ums.eai_batch.backup_dir', '');
|
||||||
|
insert into EMSADM.TSEAIRM24 (PRPTYGROUPNAME, PRPTYNAME, PRPTY2VAL) values ('Monitoring', 'kjb.ums.eai_batch.error_dir', '');
|
||||||
|
insert into EMSADM.TSEAIRM24 (PRPTYGROUPNAME, PRPTYNAME, PRPTY2VAL) values ('Monitoring', 'kjb.ums.eai_batch.interface_id', '');
|
||||||
|
insert into EMSADM.TSEAIRM24 (PRPTYGROUPNAME, PRPTYNAME, PRPTY2VAL) values ('Monitoring', 'kjb.ums.eai_batch.retention_date', '60');
|
||||||
|
insert into EMSADM.TSEAIRM24 (PRPTYGROUPNAME, PRPTYNAME, PRPTY2VAL) values ('Monitoring', 'kjb.ums.host', '');
|
||||||
|
insert into EMSADM.TSEAIRM24 (PRPTYGROUPNAME, PRPTYNAME, PRPTY2VAL) values ('Monitoring', 'kjb.ums.api_key', '');
|
||||||
|
insert into EMSADM.TSEAIRM24 (PRPTYGROUPNAME, PRPTYNAME, PRPTY2VAL) values ('Monitoring', 'kjb.ums.connection_timeout', '5');
|
||||||
|
insert into EMSADM.TSEAIRM24 (PRPTYGROUPNAME, PRPTYNAME, PRPTY2VAL) values ('Monitoring', 'kjb.ums.response_timeout', '5');
|
||||||
|
insert into EMSADM.TSEAIRM24 (PRPTYGROUPNAME, PRPTYNAME, PRPTY2VAL) values ('Monitoring', 'kjb.ums.timeout', '10');
|
||||||
```
|
```
|
||||||
@@ -1,13 +1,13 @@
|
|||||||
package com.eactive.eai.rms.onl.common.service.ums;
|
package com.eactive.eai.rms.onl.common.service.ums;
|
||||||
|
|
||||||
import com.eactive.apim.portal.template.entity.MessageRequest;
|
import com.eactive.apim.portal.template.entity.MessageRequest;
|
||||||
|
import com.eactive.apim.portal.template.repository.MessageRequestRepository;
|
||||||
import com.eactive.eai.rms.data.entity.man.monitoringProperty.service.MonitoringPropertyService;
|
import com.eactive.eai.rms.data.entity.man.monitoringProperty.service.MonitoringPropertyService;
|
||||||
import com.eactive.ext.kjb.common.KjbProperty;
|
import com.eactive.ext.kjb.common.KjbProperty;
|
||||||
import com.eactive.ext.kjb.safedb.KjbSafedbWrapper;
|
import com.eactive.ext.kjb.ums.KjbEmailSendModule;
|
||||||
import com.eactive.ext.kjb.ums.KjbEmailService;
|
|
||||||
import com.eactive.ext.kjb.ums.KjbUmsService;
|
import com.eactive.ext.kjb.ums.KjbUmsService;
|
||||||
|
import com.eactive.ext.kjb.util.KjbPropertyInjector;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.lang3.NotImplementedException;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Qualifier;
|
import org.springframework.beans.factory.annotation.Qualifier;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
@@ -42,19 +42,21 @@ public class UmsDispatchService {
|
|||||||
@PersistenceContext(unitName = "entityManagerFactoryForEMS")
|
@PersistenceContext(unitName = "entityManagerFactoryForEMS")
|
||||||
private EntityManager entityManager;
|
private EntityManager entityManager;
|
||||||
|
|
||||||
// private final KjbEmailService kjbEmailService;
|
private final MessageRequestRepository messageRequestRepository;
|
||||||
// private final KjbSafedbWrapper kjbSafedbWrapper;
|
|
||||||
// private final MonitoringPropertyService monitoringPropertyService;
|
|
||||||
|
|
||||||
private final KjbUmsService kjbUmsService;
|
private final KjbUmsService kjbUmsService;
|
||||||
|
private final KjbEmailSendModule kjbEmailSendModule;
|
||||||
|
private final KjbPropertyInjector kjbPropertyInjector;
|
||||||
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public UmsDispatchService(
|
public UmsDispatchService(
|
||||||
@Qualifier("transactionManagerForEMS") PlatformTransactionManager transactionManager,
|
@Qualifier("transactionManagerForEMS") PlatformTransactionManager transactionManager,
|
||||||
// KjbSafedbWrapper kjbSafedbWrapper,
|
MonitoringPropertyService monitoringPropertyService,
|
||||||
MonitoringPropertyService monitoringPropertyService
|
MessageRequestRepository messageRequestRepository
|
||||||
) {
|
) {
|
||||||
|
this.kjbPropertyInjector = new KjbPropertyInjector(monitoringPropertyService, PROP_GORUP_ID);
|
||||||
|
|
||||||
|
this.messageRequestRepository = messageRequestRepository;
|
||||||
// this.kjbEmailService = kjbEmailService;
|
// this.kjbEmailService = kjbEmailService;
|
||||||
// this.kjbSafedbWrapper = kjbSafedbWrapper;
|
// this.kjbSafedbWrapper = kjbSafedbWrapper;
|
||||||
// this.monitoringPropertyService = monitoringPropertyService;
|
// this.monitoringPropertyService = monitoringPropertyService;
|
||||||
@@ -73,14 +75,17 @@ public class UmsDispatchService {
|
|||||||
|
|
||||||
|
|
||||||
KjbProperty prop = new KjbProperty();
|
KjbProperty prop = new KjbProperty();
|
||||||
prop.setEaiBatchUrl(monitoringPropertyService.getPrpty2ValById(PROP_GORUP_ID, "kjb.ums.eai_batch.url"));
|
// prop.setEaiBatchUrl(monitoringPropertyService.getPrpty2ValById(PROP_GORUP_ID, "kjb.ums.eai_batch.url"));
|
||||||
prop.setUmsEaiBatchSendDir(monitoringPropertyService.getPrpty2ValById(PROP_GORUP_ID, "kjb.ums.eai_batch.send_dir"));
|
// prop.setUmsEaiBatchSendDir(monitoringPropertyService.getPrpty2ValById(PROP_GORUP_ID, "kjb.ums.eai_batch.send_dir"));
|
||||||
prop.setUmsEaiBatchBackupDir(monitoringPropertyService.getPrpty2ValById(PROP_GORUP_ID, "kjb.ums.eai_batch.backup_dir"));
|
// prop.setUmsEaiBatchBackupDir(monitoringPropertyService.getPrpty2ValById(PROP_GORUP_ID, "kjb.ums.eai_batch.backup_dir"));
|
||||||
prop.setUmsEaiBatchInterfaceId(monitoringPropertyService.getPrpty2ValById(PROP_GORUP_ID, "kjb.ums.eai_batch.interface_id"));
|
// prop.setUmsEaiBatchInterfaceId(monitoringPropertyService.getPrpty2ValById(PROP_GORUP_ID, "kjb.ums.eai_batch.interface_id"));
|
||||||
prop.setUmsHostUrl(monitoringPropertyService.getPrpty2ValById(PROP_GORUP_ID, "kjb.ums.host_url"));
|
// prop.setUmsHostUrl(monitoringPropertyService.getPrpty2ValById(PROP_GORUP_ID, "kjb.ums.host_url"));
|
||||||
prop.setUmsApiKey(monitoringPropertyService.getPrpty2ValById(PROP_GORUP_ID, "kjb.ums.api_key"));
|
// prop.setUmsApiKey(monitoringPropertyService.getPrpty2ValById(PROP_GORUP_ID, "kjb.ums.api_key"));
|
||||||
|
prop = kjbPropertyInjector.inject(prop);
|
||||||
|
|
||||||
this.kjbUmsService = new KjbUmsService(prop);
|
this.kjbUmsService = new KjbUmsService(prop);
|
||||||
|
|
||||||
|
this.kjbEmailSendModule = KjbEmailSendModule.getInstance(prop, messageRequestRepository);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@@ -123,6 +128,9 @@ public class UmsDispatchService {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
log.info("No pending messages found");
|
log.info("No pending messages found");
|
||||||
|
|
||||||
|
// 발송 메세지가 없을 때 파일 삭제 처리 진행
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -142,9 +150,8 @@ public class UmsDispatchService {
|
|||||||
kjbUmsService.send(message);
|
kjbUmsService.send(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (KjbEmailService.isAllowChannel(message)) {
|
if (KjbEmailSendModule.isAllowChannel(message)) {
|
||||||
throw new NotImplementedException();
|
kjbEmailSendModule.sendEmail(message);
|
||||||
// kjbEmailService.sendEmail(message);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@@ -1,142 +0,0 @@
|
|||||||
package com.eactive.ext.kjb.ums;
|
|
||||||
|
|
||||||
import com.eactive.apim.portal.template.entity.MessageCode;
|
|
||||||
import com.eactive.apim.portal.template.entity.MessageRequest;
|
|
||||||
import com.eactive.eai.rms.common.base.BaseService;
|
|
||||||
import com.eactive.eai.rms.data.entity.man.monitoringProperty.service.MonitoringPropertyService;
|
|
||||||
import com.eactive.ext.kjb.common.KjbProperty;
|
|
||||||
import com.eactive.ext.kjb.safedb.KjbSafedbWrapper;
|
|
||||||
import com.google.gson.Gson;
|
|
||||||
import com.google.gson.GsonBuilder;
|
|
||||||
import com.google.gson.JsonObject;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
|
||||||
|
|
||||||
import java.io.UnsupportedEncodingException;
|
|
||||||
import java.nio.file.Path;
|
|
||||||
import java.nio.file.Paths;
|
|
||||||
import java.util.Arrays;
|
|
||||||
|
|
||||||
@Service
|
|
||||||
@Transactional(transactionManager = "transactionManagerForEMS")
|
|
||||||
@Slf4j
|
|
||||||
public class KjbEmailService extends BaseService {
|
|
||||||
public final static int[] ALLOW_CHANNELS = { MessageCode.Channels.EMAIL.getValue() };
|
|
||||||
|
|
||||||
public static final String PROP_GORUP_ID = "Monitoring";
|
|
||||||
public static final String PROP_EAI_BATCH_URL = "kjb.ums.eai_batch.url";
|
|
||||||
public static final String PROP_EAI_BATCH_SEND_DIR = "kjb.ums.eai_batch.send_dir";
|
|
||||||
|
|
||||||
|
|
||||||
private final KjbSafedbWrapper kjbSafedbWrapper;
|
|
||||||
|
|
||||||
private final KjbProperty prop;
|
|
||||||
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
public KjbEmailService(MonitoringPropertyService monitoringPropertyService) {
|
|
||||||
this.kjbSafedbWrapper = KjbSafedbWrapper.getInstance();
|
|
||||||
|
|
||||||
KjbProperty prop = new KjbProperty();
|
|
||||||
prop.setEaiBatchUrl(monitoringPropertyService.getPrpty2ValById(PROP_GORUP_ID, PROP_EAI_BATCH_URL));
|
|
||||||
prop.setUmsEaiBatchSendDir(monitoringPropertyService.getPrpty2ValById(PROP_GORUP_ID, PROP_EAI_BATCH_SEND_DIR));
|
|
||||||
prop.setUmsEaiBatchBackupDir(monitoringPropertyService.getPrpty2ValById(PROP_GORUP_ID, "kjb.ums.eai_batch.backup_dir"));
|
|
||||||
prop.setUmsEaiBatchInterfaceId(monitoringPropertyService.getPrpty2ValById(PROP_GORUP_ID, "kjb.ums.eai_batch.interface_id"));
|
|
||||||
prop.setUmsHostUrl(monitoringPropertyService.getPrpty2ValById(PROP_GORUP_ID, "kjb.ums.host_url"));
|
|
||||||
prop.setUmsApiKey(monitoringPropertyService.getPrpty2ValById(PROP_GORUP_ID, "kjb.ums.api_key"));
|
|
||||||
|
|
||||||
this.prop = prop;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static boolean isAllowChannel(MessageRequest message) {
|
|
||||||
for (int channel : ALLOW_CHANNELS) {
|
|
||||||
if ((message.getMessageCode().getChannels() & channel) == channel) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public KjbEmailService(KjbSafedbWrapper kjbSafedbWrapper,
|
|
||||||
KjbProperty property) {
|
|
||||||
this.kjbSafedbWrapper = kjbSafedbWrapper;
|
|
||||||
this.prop = property;
|
|
||||||
|
|
||||||
init();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private void init() {
|
|
||||||
if (prop.getEaiBatchUrl().isEmpty()) {
|
|
||||||
log.warn("{} 가 설정되지 않음. 실제 EAI 배치 연동 없이 동작함", PROP_EAI_BATCH_URL);
|
|
||||||
}
|
|
||||||
|
|
||||||
log.info("EAI Batch URL: {}", prop.getEaiBatchUrl());
|
|
||||||
log.info("EAI Batch Send Dir: {}", prop.getUmsEaiBatchSendDir());
|
|
||||||
|
|
||||||
|
|
||||||
// 디렉토리 검사(쓰기 권한 포함)
|
|
||||||
Path sendDirPath = Paths.get(prop.getUmsEaiBatchSendDir());
|
|
||||||
if (!sendDirPath.toFile().exists()) {
|
|
||||||
// 생성 시도
|
|
||||||
boolean created = sendDirPath.toFile().mkdirs();
|
|
||||||
if (!created) {
|
|
||||||
log.error("EAI_BATCH_SEND_DIR 디렉토리를 생성할 수 없음: {}", prop.getUmsEaiBatchSendDir());
|
|
||||||
throw new IllegalStateException("EAI_BATCH_SEND_DIR 디렉토리를 생성할 수 없음: " + prop.getUmsEaiBatchSendDir());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!sendDirPath.toFile().isDirectory()) {
|
|
||||||
log.error("EAI_BATCH_SEND_DIR 가 디렉토리가 아님: {}", prop.getUmsEaiBatchSendDir());
|
|
||||||
throw new IllegalStateException("EAI_BATCH_SEND_DIR 가 디렉토리가 아님: " + prop.getUmsEaiBatchSendDir());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!sendDirPath.toFile().canWrite()) {
|
|
||||||
log.error("EAI_BATCH_SEND_DIR 에 쓰기 권한이 없음: {}", prop.getUmsEaiBatchSendDir());
|
|
||||||
throw new IllegalStateException("EAI_BATCH_SEND_DIR 에 쓰기 권한이 없음: " + prop.getUmsEaiBatchSendDir());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void sendEmail(MessageRequest messageRequest) {
|
|
||||||
log.debug("sendEmail() called - EAI_BATCH_URL: {}, EAI_BATCH_SEND_DIR: {}", prop.getEaiBatchUrl(), prop.getUmsEaiBatchSendDir());
|
|
||||||
log.debug("MessageRequest ID: {}, Email: {}", messageRequest.getId(), messageRequest.getEmail());
|
|
||||||
|
|
||||||
|
|
||||||
if (StringUtils.isEmpty(messageRequest.getId())) {
|
|
||||||
log.warn("MessageRequest ID is empty");
|
|
||||||
throw new IllegalArgumentException("MessageRequest ID is required");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (StringUtils.isEmpty(messageRequest.getEmail())) {
|
|
||||||
log.warn("MessageRequest Email is empty for ID: {}", messageRequest.getId());
|
|
||||||
throw new IllegalArgumentException("MessageRequest Email is required for ID: " + messageRequest.getId());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
String filename = "EMAIL_" + messageRequest.getId() + ".json";
|
|
||||||
|
|
||||||
JsonObject jsonObject = new JsonObject();
|
|
||||||
jsonObject.addProperty("EMAIL", kjbSafedbWrapper.encryptNotRnnoString(messageRequest.getEmail()));
|
|
||||||
|
|
||||||
|
|
||||||
Gson gson = new GsonBuilder().setPrettyPrinting().create();
|
|
||||||
String jsonString = gson.toJson(jsonObject);
|
|
||||||
byte[] jsonBytes = null;
|
|
||||||
|
|
||||||
try {
|
|
||||||
jsonBytes = jsonString.getBytes("euc-kr");
|
|
||||||
} catch (UnsupportedEncodingException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
log.debug("Generated JSON({} bytes): {}", jsonBytes.length, jsonString);
|
|
||||||
log.debug("euc-kr first 10 bytes: {}...", Arrays.toString(Arrays.copyOfRange(jsonBytes, 0, 10)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,62 @@
|
|||||||
|
package com.eactive.ext.kjb.util;
|
||||||
|
|
||||||
|
import com.eactive.eai.rms.data.entity.man.monitoringProperty.service.MonitoringPropertyService;
|
||||||
|
import com.eactive.ext.kjb.common.KjbProperty;
|
||||||
|
import com.eactive.ext.kjb.common.KjbPropertyValue;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
public class KjbPropertyInjector {
|
||||||
|
private final MonitoringPropertyService monitoringPropertyService;
|
||||||
|
private final String groupId;
|
||||||
|
|
||||||
|
|
||||||
|
public KjbPropertyInjector(MonitoringPropertyService monitoringPropertyService, String groupId) {
|
||||||
|
this.monitoringPropertyService = monitoringPropertyService;
|
||||||
|
this.groupId = groupId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public <T> T inject(T property) {
|
||||||
|
Class<?> clazz = property.getClass();
|
||||||
|
|
||||||
|
for (Field field : clazz.getDeclaredFields()) {
|
||||||
|
KjbPropertyValue anno = field.getAnnotation(KjbPropertyValue.class);
|
||||||
|
|
||||||
|
if (anno != null) {
|
||||||
|
String key = anno.key();
|
||||||
|
String rawValue = monitoringPropertyService.getPropertyValue(groupId, key, anno.defaultValue());
|
||||||
|
Object convertedValue = convertValue(field.getType(), rawValue);
|
||||||
|
|
||||||
|
field.setAccessible(true);
|
||||||
|
try {
|
||||||
|
field.set(property, convertedValue);
|
||||||
|
} catch (IllegalAccessException e) {
|
||||||
|
log.error("Failed to inject property: {} - {}", field.getName(), key, e);
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return property;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private static Object convertValue(Class<?> type, String rawValue) {
|
||||||
|
if (rawValue == null) return null;
|
||||||
|
if (StringUtils.isEmpty(rawValue)) return "";
|
||||||
|
|
||||||
|
if (type == String.class) return rawValue;
|
||||||
|
if (type == Integer.class || type == int.class) return Integer.valueOf(rawValue);
|
||||||
|
if (type == Long.class || type == long.class) return Long.valueOf(rawValue);
|
||||||
|
if (type == Double.class || type == double.class) return Double.valueOf(rawValue);
|
||||||
|
if (type == Boolean.class || type == boolean.class) return Boolean.valueOf(rawValue);
|
||||||
|
if (type == Float.class || type == float.class) return Float.valueOf(rawValue);
|
||||||
|
if (type == Short.class || type == short.class) return Short.valueOf(rawValue);
|
||||||
|
if (type == Byte.class || type == byte.class) return Byte.valueOf(rawValue);
|
||||||
|
|
||||||
|
return rawValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user