병렬스트림 사용 시 키정보를 한번만 초기화하도록 수정

master
minkyu1128 3 years ago
parent 01a2a82c42
commit 96327fd687

@ -14,7 +14,6 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;
@Slf4j
@ -24,75 +23,94 @@ public class NiceCiService {
private final NiceCiGenerator niceCiGenerator;
@Value("${contract.nice.ci.type}")
private String type;
@Value("${contract.nice.ci.type}")
private String type;
/**
* CI .
* -.CI: (Connecting Information)
* -. .
* -. .
* -. -> -> CI (88 byte)
* @param siteCode
* @param sitePw
* @param jids
* @return
*/
public ResponseVO findAllBySiteCodeAndSitePwAndJidIn(String siteCode, String sitePw, List<String> jids) {
AtomicInteger i = new AtomicInteger();
return ResponseVO.builder()
.errCode(ErrCd.OK)
.errMsg(ErrCd.OK.getCodeNm())
.resultInfo(
/**
* CI .
* -.CI: (Connecting Information)
* -. .
* -. .
* -. -> -> CI (88 byte)
*
* @param siteCode
* @param sitePw
* @param jids
* @return
*/
public ResponseVO findAllBySiteCodeAndSitePwAndJidIn(String siteCode, String sitePw, List<String> jids) {
/* ========================
* (rest API CI )
* -. .
======================== */
if ("rest".equals(type))
if (!SymmetricKey.isValidStat()) {
ResponseVO responseVO = niceCiGenerator.initialKey();
if (!ErrCd.OK.equals(responseVO.getErrCode()))
return ResponseVO.builder()
.errCode(ErrCd.OK)
.errMsg(ErrCd.OK.getCodeNm())
.resultInfo(jids.stream()
.map(jid -> {
Map<String, Object> m = new HashMap<>();
m.put("key", jid);
m.put("value", responseVO);
return m;
})
.collect(Collectors.toMap(m -> String.valueOf(m.get("key")), m -> m.get("value"), (k1, k2) -> k1)))
.build();
}
return ResponseVO.builder()
.errCode(ErrCd.OK)
.errMsg(ErrCd.OK.getCodeNm())
.resultInfo(
// jids.stream()
jids.parallelStream()
.map(jid -> {
ResponseVO responseVO = null;
try {
/* ========================
* validate
======================== */
if(!Optional.ofNullable(siteCode).isPresent()){
responseVO = ResponseVO.builder().errCode(ErrCd.ERR401).errMsg("사이트코드(은)는 필수조건 입니다.").build();
throw new RuntimeException(responseVO.getErrMsg());
}
if(!Optional.ofNullable(sitePw).isPresent()){
responseVO = ResponseVO.builder().errCode(ErrCd.ERR401).errMsg("사이트 패스워드(은)는 필수조건 입니다.").build();
throw new RuntimeException(responseVO.getErrMsg());
}
if(!Optional.ofNullable(jid).isPresent()){
responseVO = ResponseVO.builder().errCode(ErrCd.ERR401).errMsg("서비스 구분값(주민번호:JID)(은)는 필수조건 입니다.").build();
throw new RuntimeException(responseVO.getErrMsg());
}
jids.parallelStream()
.map(jid -> {
ResponseVO responseVO = null;
try {
/* ========================
* validate
======================== */
if (!Optional.ofNullable(siteCode).isPresent()) {
responseVO = ResponseVO.builder().errCode(ErrCd.ERR401).errMsg("사이트코드(은)는 필수조건 입니다.").build();
throw new RuntimeException(responseVO.getErrMsg());
}
if (!Optional.ofNullable(sitePw).isPresent()) {
responseVO = ResponseVO.builder().errCode(ErrCd.ERR401).errMsg("사이트 패스워드(은)는 필수조건 입니다.").build();
throw new RuntimeException(responseVO.getErrMsg());
}
if (!Optional.ofNullable(jid).isPresent()) {
responseVO = ResponseVO.builder().errCode(ErrCd.ERR401).errMsg("서비스 구분값(주민번호:JID)(은)는 필수조건 입니다.").build();
throw new RuntimeException(responseVO.getErrMsg());
}
/* ========================
* api call
======================== */
if("socket".equals(type)) {
responseVO = Interop.getCI(siteCode, sitePw, jid);
}else if("rest".equals(type)){
if(0 == i.getAndIncrement())
if(!SymmetricKey.isValidStat())
niceCiGenerator.initialKey();
responseVO = niceCiGenerator.getCI(jid, null);
}
/* ========================
* api call
======================== */
if ("socket".equals(type)) {
responseVO = Interop.getCI(siteCode, sitePw, jid);
} else if ("rest".equals(type)) {
responseVO = niceCiGenerator.getCI(jid, null);
}
} catch (Exception e){
log.error(e.getMessage());
} finally {
/* ========================
* result set
======================== */
Map<String, Object> m = new HashMap<>();
m.put("key", jid);
m.put("value", responseVO);
return m;
}
} catch (Exception e) {
log.error(e.getMessage());
} finally {
/* ========================
* result set
======================== */
Map<String, Object> m = new HashMap<>();
m.put("key", jid);
m.put("value", responseVO);
return m;
}
})
.collect(Collectors.toMap(m -> String.valueOf(m.get("key")), m -> m.get("value"), (k1, k2)->k1)))
.build();
}
})
.collect(Collectors.toMap(m -> String.valueOf(m.get("key")), m -> m.get("value"), (k1, k2) -> k1)))
.build();
}
}

Loading…
Cancel
Save