Commit c1b44f4b authored by hyunchu's avatar hyunchu

refactoring

parent 32a056b9
...@@ -10,10 +10,7 @@ public enum BackendServiceStatus { ...@@ -10,10 +10,7 @@ public enum BackendServiceStatus {
RESPONSE_READ_SYSTEM_ERROR(500, 501, "IOException"), RESPONSE_READ_SYSTEM_ERROR(500, 501, "IOException"),
MAPPER_ERROR(500, 502, "Mapper pasing error"), MAPPER_ERROR(500, 502, "Mapper pasing error"),
JSON_PROCESS_ONE(500, 503 ,"One Day Process JSON process Excetion"), JSON_PROCESS_ONE(500, 503 ,"One Day Process JSON process Excetion"),
INSERT_ERROR(500, 504 ,"INSERT ERROR Parameters"), INSERT_ERROR(500, 504 ,"INSERT ERROR Parameters");
;
private int statusCode; private int statusCode;
private int detailCode; private int detailCode;
......
...@@ -33,6 +33,8 @@ public class DefaultConnectService implements ConnectionService{ ...@@ -33,6 +33,8 @@ public class DefaultConnectService implements ConnectionService{
private final HolidayRepository holidayRepository; private final HolidayRepository holidayRepository;
private final OmsLogger oms; private final OmsLogger oms;
private final ObjectMapper mapper = new ObjectMapper(); private final ObjectMapper mapper = new ObjectMapper();
private static final int MULTIPLE_ITEMS = 1;
private static final int SINGLE_ITEM = 1;
// 이 메소드는 CommonExeption을 던지는데, 이 메소드를 호출하는 부분에서는 예외처리를 안해주는것같아요 // 이 메소드는 CommonExeption을 던지는데, 이 메소드를 호출하는 부분에서는 예외처리를 안해주는것같아요
// 그렇다면 던지기보다는 책임을지고 예외처리를 하는게 어떨까 싶습니다 // 그렇다면 던지기보다는 책임을지고 예외처리를 하는게 어떨까 싶습니다
...@@ -47,24 +49,26 @@ public class DefaultConnectService implements ConnectionService{ ...@@ -47,24 +49,26 @@ public class DefaultConnectService implements ConnectionService{
public void commonProcess(Response connect) throws CommonException{ public void commonProcess(Response connect) throws CommonException{
try { try {
Map<String, String> map = segregate(builderResponseBody(connect)); Map<String, String> map = segregate(builderResponseBody(connect));
int totalCount = Integer.parseInt(map.get("item")); int totalCount = extractTotalCount(map);
if(totalCount > 1){ if (totalCount > MULTIPLE_ITEMS) {
HolidaRootResponse resBody = mapper.readValue(map.get("anotherDaybody"), HolidaRootResponse.class); HolidaRootResponse resBody = mapper.readValue(map.get("anotherDaybody"), HolidaRootResponse.class);
// 메시지 체인2
anotherDayProcess(resBody.getHolidayData(), resBody.getHolidayTotalCount()); anotherDayProcess(resBody.getHolidayData(), resBody.getHolidayTotalCount());
}else if(totalCount == 1){ } else if (totalCount == SINGLE_ITEM) {
onlyDayProcess(map.get("oneDayBody")); onlyDayProcess(map.get("oneDayBody"));
}else { } else {
oms.addOmsData(OmsLogField.R1, "0"); oms.addOmsData(OmsLogField.R1, "0");
oms.addOmsData(OmsLogField.R2, "0"); oms.addOmsData(OmsLogField.R2, "0");
} }
}catch (Exception ex){ } catch (Exception ex) {
call.error("Error Occurred with External Server request. cause: ", ex); call.error("Error Occurred with External Server request. cause: ", ex);
oms.addOmsData(OmsLogField.R1, getClass().getName()); oms.addOmsData(OmsLogField.R1, getClass().getName());
oms.addOmsDatat(OmsLogField.R2, BackendServiceStatus.SYSTEM_ERROR); oms.addOmsDatat(OmsLogField.R2, BackendServiceStatus.SYSTEM_ERROR);
} }
} }
private int extractTotalCount(Map<String, String> map) {
return Integer.parseInt(map.get("item"));
}
private void apiConnectLog(Response connect) { private void apiConnectLog(Response connect) {
final String printRequest = connect.request().toString(); final String printRequest = connect.request().toString();
final String printResponse = connect.toBuilder() final String printResponse = connect.toBuilder()
...@@ -99,11 +103,11 @@ public class DefaultConnectService implements ConnectionService{ ...@@ -99,11 +103,11 @@ public class DefaultConnectService implements ConnectionService{
Map<String, String> buildMap = new HashMap<>(); Map<String, String> buildMap = new HashMap<>();
try { try {
Map<String,Map<String,Object>> anotherDaybody = mapper.readValue(oneDayBody, new TypeReference<Map<String,Map<String,Object>>>() {}); Map<String,Map<String,Object>> multipleDaysBody = mapper.readValue(oneDayBody, new TypeReference<Map<String,Map<String,Object>>>() {});
Map<String, Object> itmeMap = mapper.readValue(mapper.writeValueAsString(anotherDaybody.get("response").get("body")), new TypeReference<Map<String,Object>>(){}); Map<String, Object> itmeMap = mapper.readValue(mapper.writeValueAsString(multipleDaysBody.get("response").get("body")), new TypeReference<Map<String,Object>>(){});
buildMap.put("oneDayBody", oneDayBody); buildMap.put("oneDayBody", oneDayBody);
buildMap.put("anotherDaybody", anotherDaybody.toString()); buildMap.put("anotherDaybody", multipleDaysBody.toString());
buildMap.put("item", itmeMap.get("totalCount").toString()); buildMap.put("item", itmeMap.get("totalCount").toString());
......
...@@ -32,7 +32,6 @@ public class ResponseService { ...@@ -32,7 +32,6 @@ public class ResponseService {
} catch (IOException ex){ } catch (IOException ex){
call.error("Exceprion point {} , massge ",JOB_NAME, ex.getMessage()); call.error("Exceprion point {} , massge ",JOB_NAME, ex.getMessage());
// CommonExeption을 던져도 받아서 처리해주는 부분은 없는것같아요
throw new CommonException(ExceptionType.RESPONE_CAUSE_EXCEPTION); throw new CommonException(ExceptionType.RESPONE_CAUSE_EXCEPTION);
} }
} }
......
...@@ -16,6 +16,7 @@ import javax.xml.bind.JAXBException; ...@@ -16,6 +16,7 @@ import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller; import javax.xml.bind.Unmarshaller;
import java.io.StringReader; import java.io.StringReader;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List;
@Service @Service
@RequiredArgsConstructor @RequiredArgsConstructor
...@@ -26,12 +27,11 @@ public class SmpService { ...@@ -26,12 +27,11 @@ public class SmpService {
private final ResponseService responseService; private final ResponseService responseService;
private final SmpEnterFeignClient smpEnterFeignClient; private final SmpEnterFeignClient smpEnterFeignClient;
public int GetSmpDataAndInsert(int i, String serviceKey) { public int GetSmpDataAndInsert(int area, String serviceKey) {
ArrayList<SmpDTO> smpList = getResponseItme(i, serviceKey); List<SmpDTO> smpList = getResponseItmes(area, serviceKey);
return sendSmp(smpList, area);
return sendSmp(smpList, i);
} }
private ArrayList<SmpDTO> getResponseItme(int area, String serviceKeys) { private List<SmpDTO> getResponseItmes(int area, String serviceKeys) {
try { try {
JAXBContext jaxbContext = JAXBContext.newInstance(SmpRoot.class); JAXBContext jaxbContext = JAXBContext.newInstance(SmpRoot.class);
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
...@@ -39,12 +39,12 @@ public class SmpService { ...@@ -39,12 +39,12 @@ public class SmpService {
SmpRoot smpResponse = (SmpRoot) unmarshaller.unmarshal( new StringReader(ResponseXml)); SmpRoot smpResponse = (SmpRoot) unmarshaller.unmarshal( new StringReader(ResponseXml));
return smpResponse.getItem(); return smpResponse.getItem();
} catch (JAXBException e) { } catch (JAXBException e) {
call.error("ResponseService class in method explorerSnd JAXBException : {}", e.getMessage()); call.error("JAXBException occurred in getResponseItems method of SmpService: {}", e.getMessage());
throw new CommonException(e.getMessage()); throw new CommonException(e.getMessage());
} }
} }
private int sendSmp(ArrayList<SmpDTO> smpList, int areaCd) { private int sendSmp(List<SmpDTO> smpList, int areaCd) {
int insertCount = 0; int insertCount = 0;
for(SmpDTO value : smpList){ for(SmpDTO value : smpList){
...@@ -55,7 +55,6 @@ public class SmpService { ...@@ -55,7 +55,6 @@ public class SmpService {
} }
private SmpDTO buildSmpDto(SmpDTO smpDTO) { private SmpDTO buildSmpDto(SmpDTO smpDTO) {
// 잘못된 빌더패턴 사용법인것같습니다.
return SmpDTO.builder().idx(smpDTO.getIdx()) return SmpDTO.builder().idx(smpDTO.getIdx())
.areaCd(smpDTO.getAreaCd()) .areaCd(smpDTO.getAreaCd())
.smp(smpDTO.getSmp()) .smp(smpDTO.getSmp())
...@@ -65,12 +64,13 @@ public class SmpService { ...@@ -65,12 +64,13 @@ public class SmpService {
build(); build();
} }
private int insertCall(SmpDTO params){ private int insertCall(SmpDTO params){
int success = 0; int success = 0;
try { try {
success = smpRepository.insertSmp(params); success = smpRepository.insertSmp(params);
}catch (Exception e){ }catch (Exception e){
oms.setStatusAndResult(BackendServiceStatus.DB_INSERT_ERROR); oms.setStatusAndResult(BackendServiceStatus.INSERT_ERROR);
} }
return success; return success;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment