parent
4b91f5fe1a
commit
6d3c29787c
@ -0,0 +1,6 @@
|
||||
package com.bsmlab.dfx.agent.config.constant;
|
||||
|
||||
public enum MessageType {
|
||||
SAVE_DB_DATA,
|
||||
SAVE_FILE;
|
||||
}
|
||||
@ -0,0 +1,5 @@
|
||||
package com.bsmlab.dfx.agent.config.constant;
|
||||
|
||||
public enum ProcessStatusType {
|
||||
READ;
|
||||
}
|
||||
@ -0,0 +1,133 @@
|
||||
package com.bsmlab.dfx.agent.support;
|
||||
|
||||
import com.bsmlab.dfx.agent.config.constant.MessageType;
|
||||
import com.bsmlab.dfx.agent.config.constant.ProcessStatusType;
|
||||
import com.bsmlab.dfx.agent.listener.dto.ReceiveMessageDto;
|
||||
import com.bsmlab.dfx.agent.support.exception.IllegalMessageException;
|
||||
import com.bsmlab.dfx.agent.support.exception.InCompleteMessageException;
|
||||
import com.bsmlab.dfx.agent.support.exception.NullMessageException;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.apache.commons.lang3.EnumUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
public class MessageUtils {
|
||||
private MessageUtils() {};
|
||||
|
||||
public static ReceiveMessageDto toReceiveMessageDto(String messageJsonString) throws IllegalMessageException, NullMessageException, InCompleteMessageException {
|
||||
ReceiveMessageDto receiveMessageDto = null;
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
Map<String, Object> map = null;
|
||||
try {
|
||||
map = objectMapper.readValue(messageJsonString, new TypeReference<HashMap<String, Object>>() {});
|
||||
if(map == null) {
|
||||
throw new NullMessageException("");
|
||||
}
|
||||
if(map.get("sender") == null) {
|
||||
throw new InCompleteMessageException("sender 엘리먼트를 찾을 수 없습니다.");
|
||||
}
|
||||
else if(map.get("sender") instanceof Map){
|
||||
throw new InCompleteMessageException("sender 엘리먼트의 데이터가 객체타입이 아닙니다.");
|
||||
}
|
||||
Map<String, Object> senderMap = (Map<String, Object>)map.get("sender");
|
||||
String senderHostId;
|
||||
if(senderMap.get("host-id") == null) {
|
||||
throw new InCompleteMessageException("sender.host-id 엘리먼트를 찾을 수 없습니다.");
|
||||
}
|
||||
else if(StringUtils.isBlank(String.valueOf(senderMap.get("host-id")))) {
|
||||
throw new InCompleteMessageException("sender.host-id 값을 찾을 수 없습니다.");
|
||||
}
|
||||
else {
|
||||
senderHostId = String.valueOf(senderMap.get("host-id"));
|
||||
}
|
||||
long senderTimestamp = 0;
|
||||
if(senderMap.get("timestamp") == null) {
|
||||
throw new InCompleteMessageException("sender.timestamp 엘리먼트를 찾을 수 없습니다.");
|
||||
}
|
||||
else if(StringUtils.isBlank(String.valueOf(senderMap.get("timestamp")))) {
|
||||
throw new InCompleteMessageException("sender.timestamp 값을 찾을 수 없습니다.");
|
||||
}
|
||||
else {
|
||||
String senderTimeStampString = String.valueOf(senderMap.get("host-id"));
|
||||
try {
|
||||
senderTimestamp = Long.parseLong(senderTimeStampString);
|
||||
} catch (NumberFormatException e) {
|
||||
throw new InCompleteMessageException("sender.timestamp 값의 형식이 숫자형식이 아닙니다. " + senderTimeStampString);
|
||||
}
|
||||
}
|
||||
String messageUuid;
|
||||
if(map.get("message-uuid") == null) {
|
||||
throw new InCompleteMessageException("message-uuid 엘리먼트를 찾을 수 없습니다.");
|
||||
}
|
||||
else if(StringUtils.isBlank(String.valueOf(map.get("message-uuid")))) {
|
||||
throw new InCompleteMessageException("message-uuid 값을 찾을 수 없습니다.");
|
||||
}
|
||||
else {
|
||||
messageUuid = String.valueOf(map.get("message-uuid"));
|
||||
try {
|
||||
UUID.fromString(messageUuid);
|
||||
}
|
||||
catch (IllegalArgumentException e) {
|
||||
throw new InCompleteMessageException("message-uuid 값의 형식이 숫자형식이 아닙니다. " + messageUuid);
|
||||
}
|
||||
}
|
||||
long receivedTimestamp = System.currentTimeMillis();
|
||||
if(map.get("recipient") == null) {
|
||||
throw new InCompleteMessageException("recipient 엘리먼트를 찾을 수 없습니다.");
|
||||
}
|
||||
else if(map.get("recipient") instanceof Map){
|
||||
throw new InCompleteMessageException("recipient 엘리먼트의 데이터가 객체타입이 아닙니다.");
|
||||
}
|
||||
Map<String, Object> recipientMap = (Map<String, Object>)map.get("recipient");
|
||||
//TODO recipient
|
||||
String recipientHostId;
|
||||
if(recipientMap.get("host-id") == null) {
|
||||
throw new InCompleteMessageException("recipient.host-id 엘리먼트를 찾을 수 없습니다.");
|
||||
}
|
||||
else if(StringUtils.isBlank(String.valueOf(recipientMap.get("host-id")))) {
|
||||
throw new InCompleteMessageException("recipient.host-id 값을 찾을 수 없습니다.");
|
||||
}
|
||||
else {
|
||||
recipientHostId = String.valueOf(recipientMap.get("host-id"));
|
||||
}
|
||||
String recipientDropBoxId;
|
||||
if(recipientMap.get("drop-box-id") == null) {
|
||||
throw new InCompleteMessageException("recipient.drop-box-id 엘리먼트를 찾을 수 없습니다.");
|
||||
}
|
||||
else if(StringUtils.isBlank(String.valueOf(recipientMap.get("drop-box-id")))) {
|
||||
throw new InCompleteMessageException("recipient.drop-box-id 값을 찾을 수 없습니다.");
|
||||
}
|
||||
else {
|
||||
recipientDropBoxId = String.valueOf(recipientMap.get("drop-box-id"));
|
||||
}
|
||||
String messageType;
|
||||
if(map.get("message-type") == null) {
|
||||
throw new InCompleteMessageException("message-type 엘리먼트를 찾을 수 없습니다.");
|
||||
}
|
||||
else if(StringUtils.isBlank(String.valueOf(map.get("message-type")))) {
|
||||
throw new InCompleteMessageException("message-type 값을 찾을 수 없습니다.");
|
||||
}
|
||||
else {
|
||||
messageType = String.valueOf(map.get("message-type"));
|
||||
if(!EnumUtils.isValidEnum(MessageType.class, messageType)) {
|
||||
throw new InCompleteMessageException("message-type 값이 옳바르지 않습니다. " + messageType);
|
||||
}
|
||||
}
|
||||
receiveMessageDto = ReceiveMessageDto.builder()
|
||||
.senderHostId(senderHostId).senderTimestamp(senderTimestamp)
|
||||
.messageUuid(messageUuid).messageType(messageType).receivedTimestamp(receivedTimestamp)
|
||||
.recipientHostId(recipientHostId).recipientDropBox(recipientDropBoxId)
|
||||
.data(messageJsonString).processStatus(ProcessStatusType.READ.name())
|
||||
.build();
|
||||
}
|
||||
catch(JsonProcessingException e) {
|
||||
throw new IllegalMessageException(e.getMessage());
|
||||
}
|
||||
return receiveMessageDto;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,19 @@
|
||||
package com.bsmlab.dfx.agent.support.exception;
|
||||
|
||||
public class DfxException extends Exception {
|
||||
protected String additionalMessage;
|
||||
|
||||
public DfxException(String additionalMessage) {
|
||||
this.additionalMessage = additionalMessage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMessage() {
|
||||
return "cannot find message contents. " + this.additionalMessage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLocalizedMessage() {
|
||||
return "파싱한 메시지의 내용을 찾을 수 없습니다. " + this.additionalMessage;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,17 @@
|
||||
package com.bsmlab.dfx.agent.support.exception;
|
||||
|
||||
public class IllegalMessageException extends DfxException {
|
||||
public IllegalMessageException(String additionalMessage) {
|
||||
super(additionalMessage);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMessage() {
|
||||
return "cannot parse json message." + this.additionalMessage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLocalizedMessage() {
|
||||
return "json 메시지를 파싱할 수 없습니다." + this.additionalMessage;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,17 @@
|
||||
package com.bsmlab.dfx.agent.support.exception;
|
||||
|
||||
public class InCompleteMessageException extends DfxException {
|
||||
public InCompleteMessageException(String additionalMessage) {
|
||||
super(additionalMessage);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMessage() {
|
||||
return "incomplete message." + this.additionalMessage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLocalizedMessage() {
|
||||
return "메시지가 불완전합니다." + this.additionalMessage;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,17 @@
|
||||
package com.bsmlab.dfx.agent.support.exception;
|
||||
|
||||
public class NullMessageException extends DfxException {
|
||||
public NullMessageException(String addtitionalMessage) {
|
||||
super(addtitionalMessage);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMessage() {
|
||||
return "cannot find message contents." + this.additionalMessage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLocalizedMessage() {
|
||||
return "파싱한 메시지의 내용을 찾을 수 없습니다." + this.additionalMessage;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,10 @@
|
||||
|
||||
ooo. ooooo o o .oo o
|
||||
8 `8. 8 `b d' .P 8 8
|
||||
8 `8 o8oo `bd' .P 8 .oPYo. .oPYo. odYo. o8P
|
||||
8 8 8 .PY. oPooo8 8 8 8oooo8 8' `8 8
|
||||
8 .P 8 .P Y. .P 8 8 8 8. 8 8 8
|
||||
8ooo' 8 .P Y. .P 8 `YooP8 `Yooo' 8 8 8
|
||||
.....:::..::::..::::..:::..:::::..:....8 :.....:..::..::..:
|
||||
::::::::::::::::::::::::::::::::::::ooP'.::::::::::::::::::
|
||||
::::::::::::::::::::::::::::::::::::...::::::::::::::::::::
|
||||
@ -1,12 +1,18 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper>
|
||||
<insert id="com.bsmlab.dfx.agent.listener.dto.ListenerMapper.insertReceiveMessage" parameterType="map">
|
||||
<mapper namespace="com.bsmlab.dfx.agent.listener.dto.ListenerMapper">
|
||||
<select id="selectReceiveMessageCountByPk" parameterType="com.bsmlab.dfx.agent.listener.dto.ReceiveMessageDto" resultType="int">
|
||||
SELECT COUNT(*) AS COUNTER
|
||||
FROM TB_RECEIVE_MESSAGE
|
||||
WHERE SENDER_HOST_ID = #{senderHostId}
|
||||
AND MESSAGE_UUID = #{messageUuid}
|
||||
</select>
|
||||
<insert id="insertReceiveMessage" parameterType="com.bsmlab.dfx.agent.listener.dto.ReceiveMessageDto">
|
||||
INSERT INTO TB_RECEIVE_MESSAGE (
|
||||
SENDER_HOST_ID, MESSAGE_UUID, RECEIVED_TIMESTAMP, MESSAGE_TYPE, DATA, PROCESS_STATUS
|
||||
SENDER_HOST_ID, SENDER_TIMESTAMP, MESSAGE_UUID, MESSAGE_TYPE, RECEIVED_TIMESTAMP, RECIPIENT_HOST_ID, RECIPIENT_DROP_BOX, DATA, PROCESS_STATUS
|
||||
)
|
||||
VALUES (
|
||||
#{SENDER_HOST_ID}, #{MESSAGE_UUID}, #{RECEIVED_TIMESTAMP}, #{MESSAGE_TYPE}, #{DATA}, #{PROCESS_STATUS}
|
||||
#{senderHostId}, #{senderTimestamp}, #{messageUuid}, #{messageType}, #{receivedTimestamp}, #{recipientHostId}, #{recipientDropBox}, #{data: CLOB}, #{processStatus}
|
||||
);
|
||||
</insert>
|
||||
</mapper>
|
||||
Loading…
Reference in new issue