APIS api 추가
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
package com.eactive.eai.rms.onl.apim.obp;
|
||||
|
||||
import com.eactive.eai.rms.common.datasource.DataSourceContextHolder;
|
||||
import com.eactive.eai.rms.common.datasource.DataSourceTypeManager;
|
||||
import com.eactive.eai.rms.onl.apim.common.BaseRestController;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* OBP API 목록 조회 REST Controller
|
||||
*
|
||||
* <p>TSEAIHE01과 TSEAIHS04를 조인하여 API 정보를 JSON으로 제공</p>
|
||||
*
|
||||
* @see BaseRestController 세션 체크 우회 및 JSON 유틸리티 제공
|
||||
*/
|
||||
@Controller
|
||||
public class ObpApiController extends BaseRestController {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(ObpApiController.class);
|
||||
|
||||
private final ObpApiService obpApiService;
|
||||
|
||||
public ObpApiController(ObpApiService obpApiService) {
|
||||
this.obpApiService = obpApiService;
|
||||
}
|
||||
|
||||
/**
|
||||
* 전체 API 목록 조회
|
||||
*
|
||||
* @param pretty true면 JSON 들여쓰기 적용
|
||||
* @return JSON Array
|
||||
*/
|
||||
@RequestMapping(
|
||||
value = "/kjb/apis.json",
|
||||
produces = JSON_CONTENT_TYPE
|
||||
)
|
||||
@ResponseBody
|
||||
public String getApis(
|
||||
@RequestParam(value = "pretty", required = false) Boolean pretty) {
|
||||
log.debug("OBP API 목록 조회 요청: pretty={}", pretty);
|
||||
long startTime = System.currentTimeMillis();
|
||||
|
||||
// APIGW 데이터소스 강제 설정
|
||||
DataSourceContextHolder.setDataSourceType(
|
||||
DataSourceTypeManager.getDataSourceType(DataSourceTypeManager.APIGW));
|
||||
|
||||
try {
|
||||
List<ObpApiDTO> apis = obpApiService.findAllApis();
|
||||
|
||||
String json = toJson(apis, pretty);
|
||||
|
||||
long elapsed = System.currentTimeMillis() - startTime;
|
||||
log.info("OBP API 목록 조회 완료: count={}, size={}, elapsed={}ms",
|
||||
apis.size(), getFormattedJsonSize(json), elapsed);
|
||||
|
||||
return json;
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("OBP API 목록 조회 실패", e);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package com.eactive.eai.rms.onl.apim.obp;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* OBP API 목록 조회 DTO
|
||||
*
|
||||
* <p>TSEAIHE01과 TSEAIHS04 테이블을 조인하여 API 정보를 제공</p>
|
||||
*/
|
||||
@Getter
|
||||
@Builder
|
||||
public class ObpApiDTO {
|
||||
|
||||
/**
|
||||
* API ID (TSEAIHE01.EAISVCNAME)
|
||||
*/
|
||||
private final String id;
|
||||
|
||||
/**
|
||||
* API 이름 (TSEAIHE01.EAISVCDESC)
|
||||
*/
|
||||
private final String name;
|
||||
|
||||
/**
|
||||
* 활성화 여부 (TSEAIHE01.USEYN = '1' -> true)
|
||||
*/
|
||||
private final boolean enabled;
|
||||
|
||||
/**
|
||||
* API URL (TSEAIHS04.APIFULLPATH에서 '|' 이후 부분)
|
||||
*/
|
||||
private final String url;
|
||||
|
||||
/**
|
||||
* HTTP Method (TSEAIHS04.APIFULLPATH에서 '|' 이전 부분)
|
||||
*/
|
||||
private final String method;
|
||||
|
||||
/**
|
||||
* 인증 타입 (TSEAIHE01.AUTHTYPE)
|
||||
*/
|
||||
private final String authType;
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
package com.eactive.eai.rms.onl.apim.obp;
|
||||
|
||||
import com.eactive.eai.data.entity.onl.message.QEAIMessageEntity;
|
||||
import com.eactive.eai.data.entity.onl.stdmessage.QStandardMessageInfo;
|
||||
import com.querydsl.core.Tuple;
|
||||
import com.querydsl.jpa.impl.JPAQueryFactory;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.PersistenceContext;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* OBP API 목록 조회 Service
|
||||
*
|
||||
* <p>APIGW 데이터소스의 TSEAIHE01, TSEAIHS04 테이블에서 API 정보 조회</p>
|
||||
*/
|
||||
@Service
|
||||
public class ObpApiService {
|
||||
|
||||
@PersistenceContext
|
||||
private EntityManager entityManager;
|
||||
|
||||
private JPAQueryFactory getQueryFactory() {
|
||||
return new JPAQueryFactory(entityManager);
|
||||
}
|
||||
|
||||
/**
|
||||
* 전체 API 목록 조회
|
||||
*
|
||||
* @return API 목록
|
||||
*/
|
||||
public List<ObpApiDTO> findAllApis() {
|
||||
QEAIMessageEntity he01 = QEAIMessageEntity.eAIMessageEntity;
|
||||
QStandardMessageInfo hs04 = QStandardMessageInfo.standardMessageInfo;
|
||||
|
||||
List<Tuple> results = getQueryFactory()
|
||||
.select(
|
||||
he01.eaisvcname,
|
||||
he01.eaisvcdesc,
|
||||
he01.useyn,
|
||||
he01.authtype,
|
||||
hs04.apifullpath
|
||||
)
|
||||
.from(he01)
|
||||
.leftJoin(hs04).on(he01.eaisvcname.eq(hs04.eaisvcname))
|
||||
.orderBy(he01.eaisvcname.asc())
|
||||
.fetch();
|
||||
|
||||
return results.stream()
|
||||
.map(this::toDto)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tuple을 DTO로 변환
|
||||
*/
|
||||
private ObpApiDTO toDto(Tuple tuple) {
|
||||
QEAIMessageEntity he01 = QEAIMessageEntity.eAIMessageEntity;
|
||||
QStandardMessageInfo hs04 = QStandardMessageInfo.standardMessageInfo;
|
||||
|
||||
String eaisvcname = tuple.get(he01.eaisvcname);
|
||||
String eaisvcdesc = tuple.get(he01.eaisvcdesc);
|
||||
String useyn = tuple.get(he01.useyn);
|
||||
String authtype = tuple.get(he01.authtype);
|
||||
String apifullpath = tuple.get(hs04.apifullpath);
|
||||
|
||||
// APIFULLPATH 파싱: "POST|/mapi/kjbank/..." -> method="POST", url="/mapi/kjbank/..."
|
||||
String method = null;
|
||||
String url = null;
|
||||
if (StringUtils.isNotBlank(apifullpath) && apifullpath.contains("|")) {
|
||||
int pipeIndex = apifullpath.indexOf('|');
|
||||
method = apifullpath.substring(0, pipeIndex);
|
||||
url = apifullpath.substring(pipeIndex + 1);
|
||||
}
|
||||
|
||||
// USEYN이 "1"이면 enabled = true
|
||||
boolean enabled = "1".equals(useyn);
|
||||
|
||||
return ObpApiDTO.builder()
|
||||
.id(eaisvcname)
|
||||
.name(eaisvcdesc)
|
||||
.enabled(enabled)
|
||||
.url(url)
|
||||
.method(method)
|
||||
.authType(authtype)
|
||||
.build();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user