diff --git a/src/main/java/cokr/xit/adds/biz/iros/service/BizIrosService.java b/src/main/java/cokr/xit/adds/biz/iros/service/BizIrosService.java new file mode 100644 index 0000000..1dc91d4 --- /dev/null +++ b/src/main/java/cokr/xit/adds/biz/iros/service/BizIrosService.java @@ -0,0 +1,24 @@ +package cokr.xit.adds.biz.iros.service; + +import java.util.List; + +import cokr.xit.adds.inf.iros.model.DrugPrdtMcpnDtl; +import cokr.xit.adds.inf.iros.model.DrugPrdtMcpnDtlRequest; + +/** + *
+ * description : 
+ * packageName : cokr.xit.adds.biz.iros.service
+ * fileName    : BizIrosService
+ * author      : limju
+ * date        : 2024-04-29
+ * ======================================================================
+ * 변경일         변경자        변경 내용
+ * ----------------------------------------------------------------------
+ * 2024-04-29   limju       최초 생성
+ *
+ * 
+ */ +public interface BizIrosService { + List getDrugPrdtMcpnDtls(DrugPrdtMcpnDtlRequest dto); +} diff --git a/src/main/java/cokr/xit/adds/biz/iros/service/bean/BizIrosServiceBean.java b/src/main/java/cokr/xit/adds/biz/iros/service/bean/BizIrosServiceBean.java new file mode 100644 index 0000000..1054ea6 --- /dev/null +++ b/src/main/java/cokr/xit/adds/biz/iros/service/bean/BizIrosServiceBean.java @@ -0,0 +1,42 @@ +package cokr.xit.adds.biz.iros.service.bean; + +import java.util.List; + +import org.springframework.stereotype.Service; + +import cokr.xit.adds.biz.iros.service.BizIrosService; +import cokr.xit.adds.inf.iros.model.DrugPrdtMcpnDtl; +import cokr.xit.adds.inf.iros.model.DrugPrdtMcpnDtlRequest; +import cokr.xit.adds.inf.iros.model.IrosResponse; +import cokr.xit.adds.inf.iros.service.InfIrosService; +import cokr.xit.foundation.component.AbstractServiceBean; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; + +/** + *
+ * description : 
+ * packageName : cokr.xit.adds.biz.iros.service.bean
+ * fileName    : BizIrosServiceBean
+ * author      : limju
+ * date        : 2024-04-29
+ * ======================================================================
+ * 변경일         변경자        변경 내용
+ * ----------------------------------------------------------------------
+ * 2024-04-29   limju       최초 생성
+ *
+ * 
+ */ +@Slf4j +@RequiredArgsConstructor +@Service +public class BizIrosServiceBean extends AbstractServiceBean implements BizIrosService { + private final InfIrosService infIrosService; + + @Override + public List getDrugPrdtMcpnDtls(DrugPrdtMcpnDtlRequest dto) { + IrosResponse rslt = infIrosService.getDrugPrdtMcpnDtls(dto); + + return rslt.getResultOrThrow(); + } +} diff --git a/src/main/java/cokr/xit/adds/biz/iros/web/BizIrosController.java b/src/main/java/cokr/xit/adds/biz/iros/web/BizIrosController.java new file mode 100644 index 0000000..9235d2d --- /dev/null +++ b/src/main/java/cokr/xit/adds/biz/iros/web/BizIrosController.java @@ -0,0 +1,46 @@ +package cokr.xit.adds.biz.iros.web; + +import java.util.List; + +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import cokr.xit.adds.biz.iros.service.BizIrosService; +import cokr.xit.adds.core.model.ApiBaseResponse; +import cokr.xit.adds.inf.iros.model.DrugPrdtMcpnDtl; +import cokr.xit.adds.inf.iros.model.DrugPrdtMcpnDtlRequest; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; +import lombok.RequiredArgsConstructor; + +/** + *
+ * description : 
+ * packageName : cokr.xit.adds.biz.iros.web
+ * fileName    : BizIrosController
+ * author      : limju
+ * date        : 2024-04-29
+ * ======================================================================
+ * 변경일         변경자        변경 내용
+ * ----------------------------------------------------------------------
+ * 2024-04-29   limju       최초 생성
+ *
+ * 
+ */ +@Tag(name = "BizIrosController", description = "공공데이타포탈 업무 API") +@RequiredArgsConstructor +@RestController +@RequestMapping("/api/biz/iros/v1") +public class BizIrosController { + private final BizIrosService bizIrosService; + + @Operation(summary = "의약 제품 주성분 상세 정보 조회", description = "의약 제품 주성분 상세 정보 조회") + @PostMapping("/getDrugPrdtMcpnDtls") + public ApiBaseResponse> getDrugPrdtMcpnDtls( + @RequestBody DrugPrdtMcpnDtlRequest dto + ) { + return ApiBaseResponse.of(bizIrosService.getDrugPrdtMcpnDtls(dto)); + } +} diff --git a/src/main/java/cokr/xit/adds/biz/nims/web/BizNimsController.java b/src/main/java/cokr/xit/adds/biz/nims/web/BizNimsController.java index 7bc72d0..d5e37a2 100644 --- a/src/main/java/cokr/xit/adds/biz/nims/web/BizNimsController.java +++ b/src/main/java/cokr/xit/adds/biz/nims/web/BizNimsController.java @@ -14,7 +14,6 @@ import cokr.xit.adds.biz.nims.service.BizNimsService; import cokr.xit.adds.core.model.ApiBaseResponse; import cokr.xit.adds.inf.nims.model.NimsApiDto; import cokr.xit.adds.inf.nims.model.NimsApiRequest; -import cokr.xit.adds.inf.nims.service.InfNimsService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.media.Content; import io.swagger.v3.oas.annotations.media.ExampleObject; @@ -42,7 +41,6 @@ import lombok.RequiredArgsConstructor; @RequestMapping("/api/biz/nims/v1") public class BizNimsController { private final BizNimsService bizNimsService; - private final InfNimsService infNimsService; //------------------------------------------------------------------------------------------------------ // NIMS API CALL diff --git a/src/main/java/cokr/xit/adds/core/spring/config/SpringDocsConfig.java b/src/main/java/cokr/xit/adds/core/spring/config/SpringDocsConfig.java index 63c34a6..83a93f0 100644 --- a/src/main/java/cokr/xit/adds/core/spring/config/SpringDocsConfig.java +++ b/src/main/java/cokr/xit/adds/core/spring/config/SpringDocsConfig.java @@ -94,7 +94,8 @@ public class SpringDocsConfig { return GroupedOpenApi.builder() .group("2. BIZ API interface") .pathsToMatch( - "/api/biz/nims/**" + "/api/biz/nims/**", + "/api/biz/iros/**" ) .build(); } @@ -104,7 +105,8 @@ public class SpringDocsConfig { return GroupedOpenApi.builder() .group("3. Interface API") .pathsToMatch( - "/api/inf/nims/**" + "/api/inf/nims/**", + "/api/inf/iros/**" ) .build(); } diff --git a/src/main/java/cokr/xit/adds/core/util/ApiUtil.java b/src/main/java/cokr/xit/adds/core/util/ApiUtil.java index 5a9378e..163ffea 100644 --- a/src/main/java/cokr/xit/adds/core/util/ApiUtil.java +++ b/src/main/java/cokr/xit/adds/core/util/ApiUtil.java @@ -13,7 +13,9 @@ import javax.validation.ConstraintViolation; import javax.validation.Validator; import org.apache.commons.lang3.ObjectUtils; +import org.apache.commons.lang3.StringUtils; import org.json.simple.JSONObject; +import org.springframework.http.HttpHeaders; import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; @@ -96,7 +98,7 @@ public class ApiUtil { } public static String getUtf8UrlEncoding(final String str) { - if(!org.springframework.util.StringUtils.hasText(str)) return str; + if(!org.springframework.util.StringUtils.hasText(str)) return StringUtils.EMPTY; try { return URLEncoder.encode( @@ -124,6 +126,21 @@ public class ApiUtil { return rslt.body(); } + /** + * irosApi 호출 - x-www-form-urlencoded 방식 + * @param uri String + * @param param String + * @return String + */ + public static String callIrosApi(String uri, String param) { + HttpResponse rslt = new WebClient().get(request -> { + request.header(HttpHeaders.CONTENT_TYPE, "application/json"); + request.contentType(WebClient.Request.ContentType.FORM); + request.uri(uri + param); + }); + return rslt.body(); + } + /** * Object -> class로 변환 * @param obj Object diff --git a/src/main/java/cokr/xit/adds/inf/iros/model/DrugPrdtMcpnDtl.java b/src/main/java/cokr/xit/adds/inf/iros/model/DrugPrdtMcpnDtl.java index 7d15bdb..ca643fe 100644 --- a/src/main/java/cokr/xit/adds/inf/iros/model/DrugPrdtMcpnDtl.java +++ b/src/main/java/cokr/xit/adds/inf/iros/model/DrugPrdtMcpnDtl.java @@ -1,7 +1,6 @@ package cokr.xit.adds.inf.iros.model; -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonAlias; /** *
@@ -18,31 +17,78 @@ import com.fasterxml.jackson.annotation.JsonProperty;
  *
  * 
*/ -@JsonInclude(JsonInclude.Include.NON_EMPTY) +//@JsonInclude(JsonInclude.Include.NON_EMPTY) public record DrugPrdtMcpnDtl( - @JsonProperty("ENTRPS_PRMISN_NO") + /** + * 업체 허가 번호 + */ + @JsonAlias("ENTRPS_PRMISN_NO") String entrpsPrmisnNo, - @JsonProperty("ENTRPS") + + /** + * 제품명 + */ + @JsonAlias("ENTRPS") String entrps, - @JsonProperty("PRDUCT") + + /** + * 제품명(한글) + */ + @JsonAlias("PRDUCT") String prduct, - @JsonProperty("MTRAL_SN") + + /** + * 일련 번호 + */ + @JsonAlias("MTRAL_SN") String mtralSn, - @JsonProperty("MTRAL_CODE") + + /** + * 원료 코드 + */ + @JsonAlias("MTRAL_CODE") String mtralCode, - @JsonProperty("MTRAL_NM") + + /** + * 원료명 + */ + @JsonAlias("MTRAL_NM") String mtralNm, - @JsonProperty("QNT") + + /** + * 분량 + */ + @JsonAlias("QNT") String qnt, - @JsonProperty("INGD_UNIT_CD") + + /** + * 분량 단위 정보 + */ + @JsonAlias("INGD_UNIT_CD") String ingdUnitCd, - @JsonProperty("ITEM_SEQ") + + /** + * 품목 기준 코드 + */ + @JsonAlias("ITEM_SEQ") String itemSeq, - @JsonProperty("MAIN_INGR_ENG") + + /** + * 영문 성분명 + */ + @JsonAlias("MAIN_INGR_ENG") String mainIngrEng, - @JsonProperty("BIZRNO") + + /** + * 사업자 등록 번호 + */ + @JsonAlias("BIZRNO") String bizrno, - @JsonProperty("CPNT_CTNT_CONT") + + /** + * 세부 구성 항목 + */ + @JsonAlias("CPNT_CTNT_CONT") String cpntCtntCont ) { } diff --git a/src/main/java/cokr/xit/adds/inf/iros/model/DrugPrdtMcpnDtlRequest.java b/src/main/java/cokr/xit/adds/inf/iros/model/DrugPrdtMcpnDtlRequest.java index 0d6bd65..b921093 100644 --- a/src/main/java/cokr/xit/adds/inf/iros/model/DrugPrdtMcpnDtlRequest.java +++ b/src/main/java/cokr/xit/adds/inf/iros/model/DrugPrdtMcpnDtlRequest.java @@ -1,12 +1,17 @@ package cokr.xit.adds.inf.iros.model; -import java.util.Objects; +import static io.swagger.v3.oas.annotations.media.Schema.RequiredMode.*; + +import javax.validation.constraints.NotEmpty; +import javax.validation.constraints.Pattern; import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonProperty; -import cokr.xit.adds.core.util.ApiUtil; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.AllArgsConstructor; import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; /** *
@@ -23,108 +28,58 @@ import lombok.Builder;
  *
  * 
*/ +@Schema(name = "DrugPrdtMcpnDtlRequest", description = "의약 제품 주성분 상세 정보 조회 request") @JsonInclude(JsonInclude.Include.NON_EMPTY) +@Data +@NoArgsConstructor +@AllArgsConstructor @Builder public class DrugPrdtMcpnDtlRequest { + @Schema(requiredMode = REQUIRED, title = "서비스 키", description = "서비스 키", example = "0fTkYnZU6XjaAPAp6GzKW9Q6fYq8iaoSH9wKUZwz2PBjRXGM04aUgtO3a61xYGjL8nFZn4fjLGS9XErhMSXq%2Bw%3D%3D") + @NotEmpty(message = "서비스 키는 필수 입니다") private String serviceKey; - private Integer pageNo; - private Integer numOfRows; - private String type; - private String entrpsPrmisnNo; - private String prduct; - private String entrps; - private String bizrno; - - public DrugPrdtMcpnDtlRequest() { - } - public DrugPrdtMcpnDtlRequest( - String serviceKey, - Integer pageNo, - Integer numOfRows, - String type, - String entrpsPrmisnNo, - String prduct, - String entrps, - String bizrno - ) { - this.serviceKey = serviceKey; - this.pageNo = pageNo; - this.numOfRows = numOfRows; - this.type = type; - this.entrpsPrmisnNo = ApiUtil.getUtf8UrlEncoding(entrpsPrmisnNo); - this.prduct = ApiUtil.getUtf8UrlEncoding(prduct); - this.entrps = ApiUtil.getUtf8UrlEncoding(entrps); - this.bizrno = bizrno; - } - - public String serviceKey() { - return serviceKey; - } - public Integer pageNo() { - return pageNo; - } + @Schema(requiredMode = REQUIRED, title = "페이지 번호", description = "페이지 번호", example = "1") + @Pattern(regexp = "[0-9]{1,}", message = "페이지 번호는 필수 입니다") + private String pageNo; - public Integer numOfRows() { - return numOfRows; - } + @Schema(requiredMode = REQUIRED, title = "페이지당 갯수", description = "페이지당 갯수", example = "10") + @Pattern(regexp = "[0-9]{1,}", message = "페이지당 갯수는 필수 입니다") + private String numOfRows; - public String type() { - return type; - } - - @JsonProperty("Entrps_prmisn_no") - public String entrpsPrmisnNo() { - return entrpsPrmisnNo; - } - - @JsonProperty("Prduct") - public String prduct() { - return prduct; - } + @Schema(requiredMode = REQUIRED, title = "타입", description = "타입(json | xml)", allowableValues = {"json", "xml"}, example = "json") + @NotEmpty(message = "타입(json | xml)은 필수 입니다") + private String type; - @JsonProperty("Entrps") - public String entrps() { - return entrps; - } + @Schema(title = "업체허가번호", description = "업체허가번호", example = " ") + private String entrpsPrmisnNo; - @JsonProperty("Bizrno") - public String bizrno() { - return bizrno; - } + @Schema(title = "제품명", description = "제품명", example = "포도당주사액") + private String prduct; - @Override - public boolean equals(Object obj) { - if (obj == this) - return true; - if (obj == null || obj.getClass() != this.getClass()) - return false; - var that = (DrugPrdtMcpnDtlRequest)obj; - return Objects.equals(this.serviceKey, that.serviceKey) && - Objects.equals(this.pageNo, that.pageNo) && - Objects.equals(this.numOfRows, that.numOfRows) && - Objects.equals(this.type, that.type) && - Objects.equals(this.entrpsPrmisnNo, that.entrpsPrmisnNo) && - Objects.equals(this.prduct, that.prduct) && - Objects.equals(this.entrps, that.entrps) && - Objects.equals(this.bizrno, that.bizrno); - } + @Schema(title = "업체명", description = "업체명", example = " ") + private String entrps; - @Override - public int hashCode() { - return Objects.hash(serviceKey, pageNo, numOfRows, type, entrpsPrmisnNo, prduct, entrps, bizrno); - } + @Schema(title = "사업자등록번호", description = "사업자등록번호", example = " ") + private String bizrno; - @Override - public String toString() { - return "DrugPrdtMcpnDtlRequest[" + - "serviceKey=" + serviceKey + ", " + - "pageNo=" + pageNo + ", " + - "numOfRows=" + numOfRows + ", " + - "type=" + type + ", " + - "entrpsPrmisnNo=" + entrpsPrmisnNo + ", " + - "prduct=" + prduct + ", " + - "entrps=" + entrps + ", " + - "bizrno=" + bizrno + ']'; - } + // public DrugPrdtMcpnDtlRequest( + // String serviceKey, + // String pageNo, + // String numOfRows, + // String type, + // String entrpsPrmisnNo, + // String prduct, + // String entrps, + // String bizrno + // ) { + // this.serviceKey = serviceKey; + // this.pageNo = pageNo; + // this.numOfRows = numOfRows; + // this.type = type; + // this.entrpsPrmisnNo = ApiUtil.getUtf8UrlEncoding(entrpsPrmisnNo); + // this.prduct = ApiUtil.getUtf8UrlEncoding(prduct); + // this.entrps = ApiUtil.getUtf8UrlEncoding(entrps); + // this.bizrno = bizrno; + // } } diff --git a/src/main/java/cokr/xit/adds/inf/iros/model/IrosResponse.java b/src/main/java/cokr/xit/adds/inf/iros/model/IrosResponse.java index ab3905a..fd37291 100644 --- a/src/main/java/cokr/xit/adds/inf/iros/model/IrosResponse.java +++ b/src/main/java/cokr/xit/adds/inf/iros/model/IrosResponse.java @@ -1,6 +1,18 @@ package cokr.xit.adds.inf.iros.model; import java.util.List; +import java.util.Objects; + +import org.apache.commons.lang3.ObjectUtils; + +import com.fasterxml.jackson.annotation.JsonIgnore; + +import cokr.xit.adds.core.model.ResultCode; +import cokr.xit.adds.core.spring.exception.ApiCustomException; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; /** *
@@ -17,21 +29,82 @@ import java.util.List;
  *
  * 
*/ -public record IrosResponse( - Header header, - Body body -) { - public static record Header( - String resultCode, - String resultMsg - ) { +@Getter +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class IrosResponse { + Header header; + Body body; + + /** + * API call 성공시 결과 목록 return + * 실패시 ApiCustomException throw + * 결과 코드: 0-성공, 1-실패, 8-인증완료, 9-인증실패 + * @return List or throw ApiCustomException + */ + @JsonIgnore + public List getResultOrThrow() { + if(!ObjectUtils.isEmpty(getResult())) return getResult(); + if("00".equals(header.resultCode)){ + throw ApiCustomException.create(ResultCode.NO_CONTENT); + } + throw Objects.requireNonNull(ApiCustomException.of(header.resultCode, header.resultMsg)); + } + + /** + * API call 성공시 결과 목록 return + * 실패시 null return + * 결과 코드: 0-성공, 1-실패, 8-인증완료, 9-인증실패 + * @return List or null + */ + @JsonIgnore + public List getResultOrNull() { + return getResult(); + } + + private List getResult() { + if("00".equals(header.resultCode)) { + return body.items; + } + return null; + } + + @Getter + @NoArgsConstructor + @AllArgsConstructor + @Builder + public static class Header { + String resultCode; + String resultMsg; } - public static record Body( - String pageNo, - String numOfRows, - String totalCount, - List items - ) { + @Getter + @NoArgsConstructor + @AllArgsConstructor + @Builder + public static class Body { + String pageNo; + String numOfRows; + String totalCount; + List items; } } +// public record IrosResponse( +// Header header, +// Body body +// ) { +// public static record Header( +// String resultCode, +// String resultMsg +// ) { +// } +// +// public static record Body( +// String pageNo, +// String numOfRows, +// String totalCount, +// List items +// ) { +// } +// } diff --git a/src/main/java/cokr/xit/adds/inf/iros/service/InfIrosService.java b/src/main/java/cokr/xit/adds/inf/iros/service/InfIrosService.java index 035fdcf..6a38e54 100644 --- a/src/main/java/cokr/xit/adds/inf/iros/service/InfIrosService.java +++ b/src/main/java/cokr/xit/adds/inf/iros/service/InfIrosService.java @@ -1,5 +1,9 @@ package cokr.xit.adds.inf.iros.service; +import cokr.xit.adds.inf.iros.model.DrugPrdtMcpnDtl; +import cokr.xit.adds.inf.iros.model.DrugPrdtMcpnDtlRequest; +import cokr.xit.adds.inf.iros.model.IrosResponse; + /** *
  * description : 
@@ -15,5 +19,6 @@ package cokr.xit.adds.inf.iros.service;
  *
  * 
*/ -public class InfIrosService { +public interface InfIrosService { + IrosResponse getDrugPrdtMcpnDtls(DrugPrdtMcpnDtlRequest dto); } diff --git a/src/main/java/cokr/xit/adds/inf/iros/service/bean/InfIrosServiceBean.java b/src/main/java/cokr/xit/adds/inf/iros/service/bean/InfIrosServiceBean.java new file mode 100644 index 0000000..41c6a8b --- /dev/null +++ b/src/main/java/cokr/xit/adds/inf/iros/service/bean/InfIrosServiceBean.java @@ -0,0 +1,117 @@ +package cokr.xit.adds.inf.iros.service.bean; + +import java.util.Map; + +import javax.validation.Validation; +import javax.validation.Validator; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Service; + +import com.fasterxml.jackson.core.type.TypeReference; + +import cokr.xit.adds.core.spring.exception.ApiCustomException; +import cokr.xit.adds.core.util.ApiUtil; +import cokr.xit.adds.inf.iros.model.DrugPrdtMcpnDtl; +import cokr.xit.adds.inf.iros.model.DrugPrdtMcpnDtlRequest; +import cokr.xit.adds.inf.iros.model.IrosResponse; +import cokr.xit.adds.inf.iros.service.InfIrosService; +import cokr.xit.foundation.component.AbstractServiceBean; +import cokr.xit.foundation.data.JSON; +import cokr.xit.foundation.data.XML; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; + +/** + *
+ * description : 
+ * packageName : cokr.xit.adds.inf.iros.service.bean
+ * fileName    : InfIrosServiceBean
+ * author      : limju
+ * date        : 2024-04-29
+ * ======================================================================
+ * 변경일         변경자        변경 내용
+ * ----------------------------------------------------------------------
+ * 2024-04-29   limju       최초 생성
+ *
+ * 
+ */ +@Slf4j +@RequiredArgsConstructor +@Service +public class InfIrosServiceBean extends AbstractServiceBean implements InfIrosService { + private static final Validator validator = Validation.buildDefaultValidatorFactory().getValidator(); + private static JSON json = new JSON(); + + @Value("${app.inf.iros.url}") + private String irosUrl; + + @Value("${app.inf.iros.api-key}") + private String irosApiKey; + + @Value("${app.inf.iros.api.drugPrdtMcpnDtlInq}") + private String drugPrdtMcpnDtlInq; + + @Override + public IrosResponse getDrugPrdtMcpnDtls(DrugPrdtMcpnDtlRequest dto) { + dto.setServiceKey(irosApiKey); + ApiUtil.validate(dto, null, validator); + + if(isEmpty(dto.getEntrpsPrmisnNo()) + && isEmpty(dto.getPrduct()) + && isEmpty(dto.getEntrps()) + && isEmpty(dto.getBizrno()) + ) throw ApiCustomException.create("업체허가번호, 제품명, 업체명, 사업자번호 중 하나는 필수 입니다"); + + String params = String.format( + "?serviceKey=%s&pageNo=%s&numOfRows=%s&type=%s&Entrps_prmisn_no=%s&Prduct=%s&Entrps=%s&Bizrno=%s", + dto.getServiceKey(), + dto.getPageNo(), + dto.getNumOfRows(), + dto.getType(), + dto.getEntrpsPrmisnNo(), + dto.getPrduct(), + dto.getEntrps(), + dto.getBizrno()); + + String rslt = ApiUtil.callIrosApi(irosUrl + drugPrdtMcpnDtlInq, params); + IrosResponse result = null; + try { + result = json.parse(rslt, new TypeReference>() {}); + } catch (Exception e) { + + if(!isEmpty(e.getCause())){ + //System.out.println("JsonParseException" + je.getMessage()); + gatewayErrorParsing(rslt); + } + throw ApiCustomException.create(e.getMessage()); + + } + + return result; + } + + /** + *
+     * Gateway Error Parsing
+     *
+     * 
+     *   
+     *     SERVICE ERROR
+     *     SERVICE_KEY_IS_NOT_REGISTERED_ERROR
+     *     30
+     *   
+     * 
+     * @param rslt
+     * 
+ */ + private static void gatewayErrorParsing(String rslt) { + XML xml = new XML(); + Map> map = xml.parse(rslt, Map.class); + Map hMap = map.get("cmmMsgHeader"); + if(!isEmpty(hMap)) { + throw ApiCustomException.create(Integer.valueOf(hMap.get("returnReasonCode")), + String.format("%s[%s]", hMap.get("errMsg"), hMap.get("returnAuthMsg"))); + } + } +} diff --git a/src/main/java/cokr/xit/adds/inf/iros/web/InfIrosController.java b/src/main/java/cokr/xit/adds/inf/iros/web/InfIrosController.java index 6ad3b0d..c1eac57 100644 --- a/src/main/java/cokr/xit/adds/inf/iros/web/InfIrosController.java +++ b/src/main/java/cokr/xit/adds/inf/iros/web/InfIrosController.java @@ -1,5 +1,19 @@ package cokr.xit.adds.inf.iros.web; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import cokr.xit.adds.core.model.ApiBaseResponse; +import cokr.xit.adds.inf.iros.model.DrugPrdtMcpnDtl; +import cokr.xit.adds.inf.iros.model.DrugPrdtMcpnDtlRequest; +import cokr.xit.adds.inf.iros.model.IrosResponse; +import cokr.xit.adds.inf.iros.service.InfIrosService; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; +import lombok.RequiredArgsConstructor; + /** *
  * description : 
@@ -15,6 +29,18 @@ package cokr.xit.adds.inf.iros.web;
  *
  * 
*/ -public class InfIrosController -{ +@Tag(name = "InfIrosController", description = "공공데이타포탈 Interface API - Api Interface call Test(테스트용)") +@RequiredArgsConstructor +@RestController +@RequestMapping("/api/inf/iros/v1") +public class InfIrosController { + private final InfIrosService infIrosService; + + @Operation(summary = "의약 제품 주성분 상세 정보 조회", description = "의약 제품 주성분 상세 정보 조회") + @PostMapping("/getDrugPrdtMcpnDtls") + public ApiBaseResponse> getDrugPrdtMcpnDtls( + @RequestBody DrugPrdtMcpnDtlRequest dto + ) { + return ApiBaseResponse.of(infIrosService.getDrugPrdtMcpnDtls(dto)); + } } diff --git a/src/main/resources/config/application-inf.yml b/src/main/resources/config/application-inf.yml index e649eaa..4f31b79 100644 --- a/src/main/resources/config/application-inf.yml +++ b/src/main/resources/config/application-inf.yml @@ -15,3 +15,8 @@ app: officeinfo: /api/officeinfo.do placeinfoV1: /api/placeinfo_v1.do reportinfo: /api/reportinfo_ggg.do + iros: + url: https://apis.data.go.kr + api-key: 0fTkYnZU6XjaAPAp6GzKW9Q6fYq8iaoSH9wKUZwz2PBjRXGM04aUgtO3a61xYGjL8nFZn4fjLGS9XErhMSXq%2Bw%3D%3D + api: + drugPrdtMcpnDtlInq: /1471000/DrugPrdtPrmsnInfoService05/getDrugPrdtMcpnDtlInq04 diff --git a/src/test/java/cokr/xit/adds/inf/iros/IrosRestfulTest.java b/src/test/java/cokr/xit/adds/inf/iros/IrosRestfulTest.java index ab47c8c..ac893b7 100644 --- a/src/test/java/cokr/xit/adds/inf/iros/IrosRestfulTest.java +++ b/src/test/java/cokr/xit/adds/inf/iros/IrosRestfulTest.java @@ -1,26 +1,21 @@ package cokr.xit.adds.inf.iros; -import java.util.List; +import java.net.http.HttpResponse; -import org.apache.http.Header; -import org.apache.http.impl.client.CloseableHttpClient; -import org.apache.http.impl.client.HttpClients; -import org.apache.http.message.BasicHeader; -import org.assertj.core.api.Assertions; -import org.assertj.core.util.Lists; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; -import org.springframework.boot.test.web.client.TestRestTemplate; -import org.springframework.http.HttpHeaders; -import org.springframework.http.MediaType; -import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; import org.springframework.test.context.junit.jupiter.SpringExtension; +import com.fasterxml.jackson.core.type.TypeReference; + import cokr.xit.adds.inf.iros.model.DrugPrdtMcpnDtl; import cokr.xit.adds.inf.iros.model.DrugPrdtMcpnDtlRequest; import cokr.xit.adds.inf.iros.model.IrosResponse; +import cokr.xit.foundation.data.JSON; +import cokr.xit.foundation.web.WebClient; + /** *
  * description :
@@ -39,43 +34,39 @@ import cokr.xit.adds.inf.iros.model.IrosResponse;
 @ExtendWith(SpringExtension.class)
 @AutoConfigureMockMvc
 public class IrosRestfulTest {
-    private static final String url = "http://apis.data.go.kr/1471000/DrugPrdtPrmsnInfoService05/getDrugPrdtMcpnDtlInq04";
-    private static final String serviceKey = "0fTkYnZU6XjaAPAp6GzKW9Q6fYq8iaoSH9wKUZwz2PBjRXGM04aUgtO3a61xYGjL8nFZn4fjLGS9XErhMSXq+w==";
-
-    TestRestTemplate testRestTemplate = new TestRestTemplate();
+    private static final String uri = "http://apis.data.go.kr/1471000/DrugPrdtPrmsnInfoService05/getDrugPrdtMcpnDtlInq04";
+    private static final String serviceKey = "0fTkYnZU6XjaAPAp6GzKW9Q6fYq8iaoSH9wKUZwz2PBjRXGM04aUgtO3a61xYGjL8nFZn4fjLGS9XErhMSXq%2Bw%3D%3D";
 
     @DisplayName("의약품 성분조회 테스트")
     @Test
     public void testDrugPrdtMcpnDtl() {
-        final List
headers = Lists.newArrayList(new BasicHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)); - final CloseableHttpClient httpClient = HttpClients.custom().setDefaultHeaders(headers).build(); - testRestTemplate.getRestTemplate().setRequestFactory(new HttpComponentsClientHttpRequestFactory(httpClient)); - final DrugPrdtMcpnDtlRequest request = DrugPrdtMcpnDtlRequest.builder() + final DrugPrdtMcpnDtlRequest param = DrugPrdtMcpnDtlRequest.builder() .serviceKey(serviceKey) - .pageNo(1) - .numOfRows(10) + .pageNo("1") + .numOfRows("10") .type("json") - .prduct("중외20%포도당주사액") + .prduct("포도당주사액") .build(); - final String urlParam = String.format( - "?serviceKey=%s&pageNo=%d&numOfRows=%d&type=%s&Prduct=%s", - request.serviceKey(), - request.pageNo(), - request.numOfRows(), - request.type(), - request.prduct()); - final IrosResponse irosResponse = testRestTemplate.getForObject(url + urlParam, IrosResponse.class); - Assertions.assertThat(irosResponse).isNotNull(); - Assertions.assertThat(irosResponse.header().resultCode()).isEqualTo("00"); - Assertions.assertThat(irosResponse.header().resultMsg()).isEqualTo("NORMAL SERVICE."); - Assertions.assertThat(irosResponse.body().pageNo()).isEqualTo("1"); - Assertions.assertThat(irosResponse.body().numOfRows()).isEqualTo("10"); - Assertions.assertThat(irosResponse.body().totalCount()).isEqualTo("1"); - //HttpEntity requestEntity = new HttpEntity<>(request); - //ResponseEntity> forEntity = testRestTemplate.exchange(url, HttpMethod.GET, requestEntity, new ParameterizedTypeReference>() {}); - //Assertions.assertThat(forEntity.getStatusCode()).isEqualTo(HttpStatus.OK); + HttpResponse rslt = new WebClient().get(request -> { + String urlParam = String.format( + "?serviceKey=%s&pageNo=%s&numOfRows=%s&type=%s&Prduct=%s", + param.getServiceKey(), + param.getPageNo(), + param.getNumOfRows(), + param.getType(), + param.getPrduct() + ); + request.header("Content-Type", "application/json"); + request.contentType(WebClient.Request.ContentType.FORM); + request.uri(uri + urlParam); + }); + + IrosResponse parse = new JSON().parse(rslt.body(), + new TypeReference>() { + }); + System.out.println(parse); } }