Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
D
dataport-api
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
강현수
dataport-api
Commits
32a056b9
Commit
32a056b9
authored
Jan 09, 2023
by
강현수
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor : exception modify
parent
a161150f
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
48 additions
and
40 deletions
+48
-40
src/main/java/net/herit/ami/commons/logger/oms/log/OmsLogger.java
.../java/net/herit/ami/commons/logger/oms/log/OmsLogger.java
+4
-1
src/main/java/net/herit/ami/commons/response/BackendServiceStatus.java
.../net/herit/ami/commons/response/BackendServiceStatus.java
+9
-5
src/main/java/net/herit/ami/features/stat/job/SmpEnterConsumeDataJob.java
...t/herit/ami/features/stat/job/SmpEnterConsumeDataJob.java
+1
-1
src/main/java/net/herit/ami/features/stat/service/DefaultConnectService.java
...erit/ami/features/stat/service/DefaultConnectService.java
+26
-19
src/main/java/net/herit/ami/features/stat/service/ResponseService.java
.../net/herit/ami/features/stat/service/ResponseService.java
+0
-1
src/main/java/net/herit/ami/features/stat/service/smp/SmpService.java
...a/net/herit/ami/features/stat/service/smp/SmpService.java
+6
-11
src/main/java/net/herit/ami/features/stat/service/snd/SndService.java
...a/net/herit/ami/features/stat/service/snd/SndService.java
+2
-2
No files found.
src/main/java/net/herit/ami/commons/logger/oms/log/OmsLogger.java
View file @
32a056b9
...
@@ -83,7 +83,10 @@ public class OmsLogger {
...
@@ -83,7 +83,10 @@ public class OmsLogger {
OmsObject
oms
=
LoggerContext
.
getTxLogger
();
OmsObject
oms
=
LoggerContext
.
getTxLogger
();
oms
.
setOmsData
(
key
,
value
);
oms
.
setOmsData
(
key
,
value
);
}
}
public
void
addOmsDatat
(
OmsLogField
key
,
BackendServiceStatus
value
)
{
OmsObject
oms
=
LoggerContext
.
getTxLogger
();
oms
.
setOmsData
(
key
,
String
.
valueOf
(
value
.
getStatusCode
()));
}
public
String
getOmsData
(
OmsLogField
key
)
{
public
String
getOmsData
(
OmsLogField
key
)
{
OmsObject
oms
=
LoggerContext
.
getTxLogger
();
OmsObject
oms
=
LoggerContext
.
getTxLogger
();
return
oms
.
getOmsData
(
key
);
return
oms
.
getOmsData
(
key
);
...
...
src/main/java/net/herit/ami/commons/response/BackendServiceStatus.java
View file @
32a056b9
...
@@ -2,12 +2,16 @@ package net.herit.ami.commons.response;
...
@@ -2,12 +2,16 @@ package net.herit.ami.commons.response;
public
enum
BackendServiceStatus
{
public
enum
BackendServiceStatus
{
SUCCESS
(
200
,
0
,
""
),
SUCCESS
(
200
,
0
,
""
),
INTERNAL_SERVER_ERROR
(
500
,
0
,
"internal server error"
),
NOT_PROVIDE_SERVICE
(
404
,
1
,
"not support : "
),
INVALID_PARAM
(
400
,
2
,
"invalid parameter"
),
DUPLICATED_CONTENTS
(
400
,
3
,
"duplicated contents"
),
RESPONSE_CANNOT_BE_NULL
(
404
,
401
,
"Response Connot Be null"
),
SYSTEM_ERROR
(
500
,
4
,
"Exception"
),
RESPONSE_READ_SYSTEM_ERROR
(
500
,
501
,
"IOException"
),
MAPPER_ERROR
(
500
,
502
,
"Mapper pasing error"
),
JSON_PROCESS_ONE
(
500
,
503
,
"One Day Process JSON process Excetion"
),
INSERT_ERROR
(
500
,
504
,
"INSERT ERROR Parameters"
),
DB_INSERT_ERROR
(
500
,
3
,
"db insert error"
),
SMP_SERVER_RECV_NULL
(
502
,
850
,
"SMP List Null"
),
SND_SERVER_RECV_NULL
(
502
,
850
,
"SMP List Null"
),
;
;
...
...
src/main/java/net/herit/ami/features/stat/job/SmpEnterConsumeDataJob.java
View file @
32a056b9
...
@@ -45,7 +45,7 @@ public class SmpEnterConsumeDataJob extends QuartzJobBeans{
...
@@ -45,7 +45,7 @@ public class SmpEnterConsumeDataJob extends QuartzJobBeans{
call
.
info
(
"callId:{}"
,
callId
);
call
.
info
(
"callId:{}"
,
callId
);
int
resultCount
=
0
;
int
resultCount
=
0
;
for
(
int
i
=
0
;
i
<
areaCd
.
length
;
++
i
)
resultCount
+=
smpService
.
toDo
GetSmpDataAndInsert
(
areaCd
[
i
],
serviceKey
);
for
(
int
i
=
0
;
i
<
areaCd
.
length
;
++
i
)
resultCount
+=
smpService
.
GetSmpDataAndInsert
(
areaCd
[
i
],
serviceKey
);
oms
.
addOmsData
(
OmsLogField
.
R1
,
String
.
valueOf
(
resultCount
));
oms
.
addOmsData
(
OmsLogField
.
R1
,
String
.
valueOf
(
resultCount
));
oms
.
setStatusAndResult
(
BackendServiceStatus
.
SUCCESS
);
oms
.
setStatusAndResult
(
BackendServiceStatus
.
SUCCESS
);
...
...
src/main/java/net/herit/ami/features/stat/service/DefaultConnectService.java
View file @
32a056b9
...
@@ -10,6 +10,7 @@ import net.herit.ami.commons.exception.ExceptionType;
...
@@ -10,6 +10,7 @@ import net.herit.ami.commons.exception.ExceptionType;
import
net.herit.ami.commons.logger.call.log.CallLogger
;
import
net.herit.ami.commons.logger.call.log.CallLogger
;
import
net.herit.ami.commons.logger.oms.field.OmsLogField
;
import
net.herit.ami.commons.logger.oms.field.OmsLogField
;
import
net.herit.ami.commons.logger.oms.log.OmsLogger
;
import
net.herit.ami.commons.logger.oms.log.OmsLogger
;
import
net.herit.ami.commons.response.BackendServiceStatus
;
import
net.herit.ami.commons.util.JsonUtil
;
import
net.herit.ami.commons.util.JsonUtil
;
import
net.herit.ami.features.stat.dto.Holiday.HolidayDataDAO
;
import
net.herit.ami.features.stat.dto.Holiday.HolidayDataDAO
;
import
net.herit.ami.features.stat.dto.response_model.HolidaRootResponse
;
import
net.herit.ami.features.stat.dto.response_model.HolidaRootResponse
;
...
@@ -38,13 +39,9 @@ public class DefaultConnectService implements ConnectionService{
...
@@ -38,13 +39,9 @@ public class DefaultConnectService implements ConnectionService{
@Override
@Override
public
void
connect
(
Response
connect
)
{
public
void
connect
(
Response
connect
)
{
call
.
debug
(
"\n---- Start to Connection And Convert----"
);
call
.
debug
(
"\n---- Start to Connection And Convert----"
);
try
{
validateResponse
(
connect
);
validateResponse
(
connect
);
apiConnectLog
(
connect
);
apiConnectLog
(
connect
);
commonProcess
(
connect
);
commonProcess
(
connect
);
}
catch
(
Exception
e
){
}
}
}
public
void
commonProcess
(
Response
connect
)
throws
CommonException
{
public
void
commonProcess
(
Response
connect
)
throws
CommonException
{
...
@@ -64,7 +61,8 @@ public class DefaultConnectService implements ConnectionService{
...
@@ -64,7 +61,8 @@ public class DefaultConnectService implements ConnectionService{
}
}
}
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
);
throw
new
CommonException
(
ExceptionType
.
EXTERNAL_API_CALL_ERROR
);
oms
.
addOmsData
(
OmsLogField
.
R1
,
getClass
().
getName
());
oms
.
addOmsDatat
(
OmsLogField
.
R2
,
BackendServiceStatus
.
SYSTEM_ERROR
);
}
}
}
}
private
void
apiConnectLog
(
Response
connect
)
{
private
void
apiConnectLog
(
Response
connect
)
{
...
@@ -77,25 +75,26 @@ public class DefaultConnectService implements ConnectionService{
...
@@ -77,25 +75,26 @@ public class DefaultConnectService implements ConnectionService{
call
.
info
(
"\nConnection:\n\n{}"
,
getConnectionLog
(
printRequest
,
printResponse
));
call
.
info
(
"\nConnection:\n\n{}"
,
getConnectionLog
(
printRequest
,
printResponse
));
}
}
private
String
builderResponseBody
(
Response
connect
)
{
private
String
builderResponseBody
(
Response
connect
)
{
StringBuilder
builder
=
new
StringBuilder
();
try
{
try
{
BufferedReader
reader
=
new
BufferedReader
(
connect
.
body
().
asReader
(
Charset
.
defaultCharset
()));
BufferedReader
reader
=
new
BufferedReader
(
connect
.
body
().
asReader
(
Charset
.
defaultCharset
()));
StringBuilder
builder
=
new
StringBuilder
();
String
line
;
String
line
;
while
((
line
=
reader
.
readLine
())
!=
null
){
while
((
line
=
reader
.
readLine
())
!=
null
){
builder
.
append
(
line
);
builder
.
append
(
line
);
}
}
return
builder
.
toString
();
}
catch
(
IOException
e
)
{
}
catch
(
IOException
e
)
{
throw
new
RuntimeException
(
e
);
call
.
error
(
"Error IOException:{} / {} "
,
getClass
().
getName
(),
e
);
oms
.
addOmsData
(
OmsLogField
.
R1
,
getClass
().
getName
());
oms
.
addOmsDatat
(
OmsLogField
.
R2
,
BackendServiceStatus
.
SYSTEM_ERROR
);
}
}
return
builder
.
toString
();
}
}
/*
/*
* oneDayBody : 하나일때 사용
* oneDayBody : 하나일때 사용
* anotherDaybody : 공유일이 많을때 사용하기 위함
* anotherDaybody : 공유일이 많을때 사용하기 위함
* itmeMap : 공유일이 없는 경우를 확인하기 위함
* itmeMap : 공유일이 없는 경우를 확인하기 위함
* */
* */
// 원시타입만 사용해서 보기가 힘든것같습니다 클래스로 래핑하면 좋을것같습니다
private
Map
<
String
,
String
>
segregate
(
String
oneDayBody
)
{
private
Map
<
String
,
String
>
segregate
(
String
oneDayBody
)
{
Map
<
String
,
String
>
buildMap
=
new
HashMap
<>();
Map
<
String
,
String
>
buildMap
=
new
HashMap
<>();
try
{
try
{
...
@@ -107,20 +106,24 @@ public class DefaultConnectService implements ConnectionService{
...
@@ -107,20 +106,24 @@ public class DefaultConnectService implements ConnectionService{
buildMap
.
put
(
"anotherDaybody"
,
anotherDaybody
.
toString
());
buildMap
.
put
(
"anotherDaybody"
,
anotherDaybody
.
toString
());
buildMap
.
put
(
"item"
,
itmeMap
.
get
(
"totalCount"
).
toString
());
buildMap
.
put
(
"item"
,
itmeMap
.
get
(
"totalCount"
).
toString
());
return
buildMap
;
}
catch
(
IOException
e
)
{
}
catch
(
IOException
e
)
{
throw
new
CommonException
(
e
.
getMessage
());
call
.
error
(
"Error IOException:{} / {} "
,
getClass
().
getName
(),
e
);
oms
.
addOmsData
(
OmsLogField
.
R1
,
getClass
().
getName
());
oms
.
addOmsDatat
(
OmsLogField
.
R2
,
BackendServiceStatus
.
MAPPER_ERROR
);
}
}
return
buildMap
;
}
}
// is 접두사는 boolean 리턴 메소드에 주로 쓰이는것으로 압니다. validateResponse 정도가 적당할것같습니다.
private
void
validateResponse
(
Response
connect
)
{
private
void
validateResponse
(
Response
connect
)
{
if
(
JsonUtil
.
isNull
(
connect
)){
if
(
JsonUtil
.
isNull
(
connect
)){
call
.
info
(
"Failed Connect to External Server."
);
call
.
info
(
"Failed Connect to External Server."
);
throw
new
CommonException
(
ExceptionType
.
RESPONSE_CANNOT_BE_NULL
);
oms
.
addOmsData
(
OmsLogField
.
R1
,
getClass
().
getName
());
oms
.
addOmsDatat
(
OmsLogField
.
R2
,
BackendServiceStatus
.
RESPONSE_CANNOT_BE_NULL
);
}
}
if
(
connect
.
body
()
==
null
){
if
(
connect
.
body
()
==
null
){
call
.
info
(
"response of Conntion. {} , {}"
+
connect
,
connect
.
body
());
call
.
info
(
"response of Conntion. {} , {}"
+
connect
,
connect
.
body
());
throw
new
CommonException
(
ExceptionType
.
RESPONSE_CANNOT_BE_NULL
);
oms
.
addOmsData
(
OmsLogField
.
R1
,
getClass
().
getName
());
oms
.
addOmsDatat
(
OmsLogField
.
R2
,
BackendServiceStatus
.
JSON_PROCESS_ONE
);
}
}
}
}
private
void
anotherDayProcess
(
List
<
HolidayDataItem
>
resBody
,
String
count
)
{
private
void
anotherDayProcess
(
List
<
HolidayDataItem
>
resBody
,
String
count
)
{
...
@@ -136,6 +139,8 @@ public class DefaultConnectService implements ConnectionService{
...
@@ -136,6 +139,8 @@ public class DefaultConnectService implements ConnectionService{
successCount
+=
success
;
successCount
+=
success
;
}
else
{
}
else
{
call
.
debug
(
"INSERT ERROR Parameters : "
+
holidayanotherDataDAO
);
call
.
debug
(
"INSERT ERROR Parameters : "
+
holidayanotherDataDAO
);
oms
.
addOmsData
(
OmsLogField
.
R1
,
getClass
().
getName
());
oms
.
addOmsDatat
(
OmsLogField
.
R2
,
BackendServiceStatus
.
INSERT_ERROR
);
}
}
}
}
oms
.
addOmsData
(
OmsLogField
.
R2
,
String
.
valueOf
(
successCount
));
oms
.
addOmsData
(
OmsLogField
.
R2
,
String
.
valueOf
(
successCount
));
...
@@ -154,7 +159,9 @@ public class DefaultConnectService implements ConnectionService{
...
@@ -154,7 +159,9 @@ public class DefaultConnectService implements ConnectionService{
HolidayDataDAO
holidayDataDAO
=
buildHolidayDataDAO
(
mapper
.
readValue
(
objectBody
,
SoloHolidayDataItem
.
class
));
HolidayDataDAO
holidayDataDAO
=
buildHolidayDataDAO
(
mapper
.
readValue
(
objectBody
,
SoloHolidayDataItem
.
class
));
success
=
holidayRepository
.
insertHoliDayData
(
holidayDataDAO
);
success
=
holidayRepository
.
insertHoliDayData
(
holidayDataDAO
);
}
catch
(
JsonProcessingException
e
)
{
}
catch
(
JsonProcessingException
e
)
{
throw
new
CommonException
(
ExceptionType
.
JSON_PROCESS_ONE
);
call
.
error
(
"Excetion {} onlyDayProcess, {}"
,
getClass
().
getName
(),
e
.
getMessage
());
oms
.
addOmsData
(
OmsLogField
.
R1
,
getClass
().
getName
());
oms
.
addOmsDatat
(
OmsLogField
.
R2
,
BackendServiceStatus
.
JSON_PROCESS_ONE
);
}
}
finally
{
finally
{
oms
.
addOmsData
(
OmsLogField
.
R1
,
"1"
);
oms
.
addOmsData
(
OmsLogField
.
R1
,
"1"
);
...
...
src/main/java/net/herit/ami/features/stat/service/ResponseService.java
View file @
32a056b9
...
@@ -17,7 +17,6 @@ public class ResponseService {
...
@@ -17,7 +17,6 @@ public class ResponseService {
private
final
CallLogger
call
;
private
final
CallLogger
call
;
private
final
String
JOB_NAME
=
this
.
getClass
().
getSimpleName
();
private
final
String
JOB_NAME
=
this
.
getClass
().
getSimpleName
();
private
final
DefaultConnectService
defaultconnectService
;
private
final
DefaultConnectService
defaultconnectService
;
// 접근제어자가 없음
private
String
line
=
null
;
private
String
line
=
null
;
public
String
responseXmlToString
(
Response
response
)
{
public
String
responseXmlToString
(
Response
response
)
{
StringBuilder
builder
=
new
StringBuilder
();
StringBuilder
builder
=
new
StringBuilder
();
...
...
src/main/java/net/herit/ami/features/stat/service/smp/SmpService.java
View file @
32a056b9
...
@@ -26,9 +26,7 @@ public class SmpService {
...
@@ -26,9 +26,7 @@ public class SmpService {
private
final
ResponseService
responseService
;
private
final
ResponseService
responseService
;
private
final
SmpEnterFeignClient
smpEnterFeignClient
;
private
final
SmpEnterFeignClient
smpEnterFeignClient
;
// 메소드명의 접두사가 여러개이고(to,Do,Get), Get과 Insert 두가지의 동작을 명시하고있어서 역할을 명확히 알기가 힘듭니다
public
int
GetSmpDataAndInsert
(
int
i
,
String
serviceKey
)
{
public
int
toDoGetSmpDataAndInsert
(
int
i
,
String
serviceKey
)
{
;
// ???
ArrayList
<
SmpDTO
>
smpList
=
getResponseItme
(
i
,
serviceKey
);
ArrayList
<
SmpDTO
>
smpList
=
getResponseItme
(
i
,
serviceKey
);
return
sendSmp
(
smpList
,
i
);
return
sendSmp
(
smpList
,
i
);
...
@@ -37,10 +35,8 @@ public class SmpService {
...
@@ -37,10 +35,8 @@ public class SmpService {
try
{
try
{
JAXBContext
jaxbContext
=
JAXBContext
.
newInstance
(
SmpRoot
.
class
);
JAXBContext
jaxbContext
=
JAXBContext
.
newInstance
(
SmpRoot
.
class
);
Unmarshaller
unmarshaller
=
jaxbContext
.
createUnmarshaller
();
Unmarshaller
unmarshaller
=
jaxbContext
.
createUnmarshaller
();
// 언마샬링 하는 부분과 response 받아오는 부분을 분리해보는건 어떨까요?
String
ResponseXml
=
responseService
.
responseXmlToString
(
smpEnterFeignClient
.
requestConsumeDataByAll
(
area
,
serviceKeys
));
SmpRoot
smpResponse
=
(
SmpRoot
)
unmarshaller
.
unmarshal
(
new
StringReader
(
SmpRoot
smpResponse
=
(
SmpRoot
)
unmarshaller
.
unmarshal
(
new
StringReader
(
ResponseXml
));
responseService
.
responseXmlToString
(
smpEnterFeignClient
.
requestConsumeDataByAll
(
area
,
serviceKeys
))));
return
smpResponse
.
getItem
();
return
smpResponse
.
getItem
();
}
catch
(
JAXBException
e
)
{
}
catch
(
JAXBException
e
)
{
call
.
error
(
"ResponseService class in method explorerSnd JAXBException : {}"
,
e
.
getMessage
());
call
.
error
(
"ResponseService class in method explorerSnd JAXBException : {}"
,
e
.
getMessage
());
...
@@ -60,14 +56,13 @@ public class SmpService {
...
@@ -60,14 +56,13 @@ public class SmpService {
private
SmpDTO
buildSmpDto
(
SmpDTO
smpDTO
)
{
private
SmpDTO
buildSmpDto
(
SmpDTO
smpDTO
)
{
// 잘못된 빌더패턴 사용법인것같습니다.
// 잘못된 빌더패턴 사용법인것같습니다.
return
new
SmpDTO
().
builder
()
return
SmpDTO
.
builder
().
idx
(
smpDTO
.
getIdx
())
.
idx
(
smpDTO
.
getIdx
())
.
areaCd
(
smpDTO
.
getAreaCd
())
.
areaCd
(
smpDTO
.
getAreaCd
())
.
smp
(
smpDTO
.
getSmp
())
.
smp
(
smpDTO
.
getSmp
())
.
tradeHour
(
String
.
format
(
"%02d"
,
Integer
.
parseInt
(
smpDTO
.
getTradeHour
())))
.
tradeHour
(
String
.
format
(
"%02d"
,
Integer
.
parseInt
(
smpDTO
.
getTradeHour
())))
.
tradeDay
(
smpDTO
.
getTradeDay
())
.
tradeDay
(
smpDTO
.
getTradeDay
())
.
created_at
(
smpDTO
.
getCreated_at
())
.
created_at
(
smpDTO
.
getCreated_at
())
.
.
build
();
build
();
}
}
private
int
insertCall
(
SmpDTO
params
){
private
int
insertCall
(
SmpDTO
params
){
...
...
src/main/java/net/herit/ami/features/stat/service/snd/SndService.java
View file @
32a056b9
...
@@ -26,12 +26,12 @@ public class SndService {
...
@@ -26,12 +26,12 @@ public class SndService {
call
.
debug
(
"explorerSnd item pasing : {}"
,
snd
);
call
.
debug
(
"explorerSnd item pasing : {}"
,
snd
);
return
sndRepository
.
insertSnd
(
snd
);
return
sndRepository
.
insertSnd
(
snd
);
}
}
//애도 관심사를 분리하는게 어렵네...
public
SndRoot
xmlToSndRoot
(
String
serviceKeys
)
{
public
SndRoot
xmlToSndRoot
(
String
serviceKeys
)
{
try
{
try
{
JAXBContext
jaxbContext
=
JAXBContext
.
newInstance
(
SndRoot
.
class
);
JAXBContext
jaxbContext
=
JAXBContext
.
newInstance
(
SndRoot
.
class
);
Unmarshaller
unmarshaller
=
jaxbContext
.
createUnmarshaller
();
Unmarshaller
unmarshaller
=
jaxbContext
.
createUnmarshaller
();
return
(
SndRoot
)
unmarshaller
.
unmarshal
(
new
StringReader
(
responseService
.
responseXmlToString
(
sndEnterFeignClient
.
requestConsumeData
(
serviceKeys
))));
String
resString
=
responseService
.
responseXmlToString
(
sndEnterFeignClient
.
requestConsumeData
(
serviceKeys
));
return
(
SndRoot
)
unmarshaller
.
unmarshal
(
new
StringReader
(
resString
));
}
catch
(
JAXBException
e
)
{
}
catch
(
JAXBException
e
)
{
throw
new
CommonException
(
ExceptionType
.
XML_TO_OBJECT_EXCEPTION
);
throw
new
CommonException
(
ExceptionType
.
XML_TO_OBJECT_EXCEPTION
);
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment