feat/infer_dev_260211 #142
@@ -5,7 +5,11 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.*;
|
import java.util.HashSet;
|
||||||
|
import java.util.LinkedHashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
@@ -13,8 +17,7 @@ import org.springframework.http.HttpStatus;
|
|||||||
import org.springframework.web.server.ResponseStatusException;
|
import org.springframework.web.server.ResponseStatusException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* GeoJSON 파일의 "features[].properties.scene_id" 값들이 "요청한 도엽번호 목록(requestedMapSheetNums)"과 정확히 일치하는지
|
* GeoJSON 파일의 "features[].properties.scene_id" 값들이 "요청한 도엽번호 목록(requestedMapSheetNums)"과 정확히 일치하는지 검증하는 유틸.
|
||||||
* 검증하는 유틸.
|
|
||||||
*
|
*
|
||||||
* <p>핵심 목적: - 요청한 도엽번호를 기반으로 GeoJSON을 생성했는데, 실제 결과 파일에 누락/추가/중복/빈값(scene_id 없음) 등이 발생했는지 빠르게 잡아내기.
|
* <p>핵심 목적: - 요청한 도엽번호를 기반으로 GeoJSON을 생성했는데, 실제 결과 파일에 누락/추가/중복/빈값(scene_id 없음) 등이 발생했는지 빠르게 잡아내기.
|
||||||
*
|
*
|
||||||
@@ -23,19 +26,22 @@ import org.springframework.web.server.ResponseStatusException;
|
|||||||
*/
|
*/
|
||||||
public class GeoJsonValidator {
|
public class GeoJsonValidator {
|
||||||
|
|
||||||
/** GeoJSON 파싱용 ObjectMapper (정적 1개로 재사용) */
|
/**
|
||||||
|
* GeoJSON 파싱용 ObjectMapper (정적 1개로 재사용)
|
||||||
|
*/
|
||||||
private static final ObjectMapper om = new ObjectMapper();
|
private static final ObjectMapper om = new ObjectMapper();
|
||||||
|
|
||||||
/** 로그 출력용 */
|
/**
|
||||||
|
* 로그 출력용
|
||||||
|
*/
|
||||||
private static final Logger log = LogManager.getLogger(GeoJsonValidator.class);
|
private static final Logger log = LogManager.getLogger(GeoJsonValidator.class);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param geojsonPath GeoJSON 파일 경로(문자열)
|
* @param geojsonPath GeoJSON 파일 경로(문자열)
|
||||||
* @param requestedMapSheetNums "요청한 도엽번호" 리스트 (중복/공백/NULL 포함 가능)
|
* @param requestedMapSheetNums "요청한 도엽번호" 리스트 (중복/공백/NULL 포함 가능)
|
||||||
* <p>동작 개요: 1) 파일 존재/크기 검증 2) 요청 도엽번호 목록 정리(Trim + 공백 제거 + 중복 제거) 3) GeoJSON 파싱 후 features 배열
|
* <p>동작 개요: 1) 파일 존재/크기 검증 2) 요청 도엽번호 목록 정리(Trim + 공백 제거 + 중복 제거) 3) GeoJSON 파싱 후 features 배열
|
||||||
* 확보 4) features에서 scene_id 추출하여 유니크 set 구성 5) requested vs found 비교: - missing: requested -
|
* 확보 4) features에서 scene_id 추출하여 유니크 set 구성 5) requested vs found 비교: - missing: requested - found - extra : found - requested - duplicates: GeoJSON
|
||||||
* found - extra : found - requested - duplicates: GeoJSON 내부에서 scene_id 중복 등장 - nullIdCount:
|
* 내부에서 scene_id 중복 등장 - nullIdCount: scene_id가 null/blank 인 feature 개수 6) 이상 있으면 422로 실패 처리
|
||||||
* scene_id가 null/blank 인 feature 개수 6) 이상 있으면 422로 실패 처리
|
|
||||||
*/
|
*/
|
||||||
public static void validateWithRequested(String geojsonPath, List<String> requestedMapSheetNums) {
|
public static void validateWithRequested(String geojsonPath, List<String> requestedMapSheetNums) {
|
||||||
|
|
||||||
@@ -170,7 +176,7 @@ public class GeoJsonValidator {
|
|||||||
// properties가 있고 scene_id가 null이 아니면 텍스트로 읽음
|
// properties가 있고 scene_id가 null이 아니면 텍스트로 읽음
|
||||||
// 없으면 null 처리
|
// 없으면 null 처리
|
||||||
String sceneId =
|
String sceneId =
|
||||||
(props != null && props.hasNonNull("scene_id")) ? props.get("scene_id").asText() : null;
|
(props != null && props.hasNonNull("scene_id")) ? props.get("scene_id").asText().trim() : null;
|
||||||
|
|
||||||
// scene_id가 없거나 빈값이면 "정상적으로 도엽번호가 들어오지 않은 feature"로 카운트
|
// scene_id가 없거나 빈값이면 "정상적으로 도엽번호가 들어오지 않은 feature"로 카운트
|
||||||
if (sceneId == null || sceneId.isBlank()) {
|
if (sceneId == null || sceneId.isBlank()) {
|
||||||
@@ -178,6 +184,7 @@ public class GeoJsonValidator {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
foundUnique.add(sceneId);
|
||||||
// foundUnique.add(sceneId)가 false면 "이미 같은 값이 있었다"는 뜻 => 중복
|
// foundUnique.add(sceneId)가 false면 "이미 같은 값이 있었다"는 뜻 => 중복
|
||||||
// if (!foundUnique.add(sceneId)) {
|
// if (!foundUnique.add(sceneId)) {
|
||||||
// duplicates.add(sceneId);
|
// duplicates.add(sceneId);
|
||||||
@@ -233,9 +240,13 @@ public class GeoJsonValidator {
|
|||||||
// if (!duplicates.isEmpty())
|
// if (!duplicates.isEmpty())
|
||||||
// log.warn("duplicates sample: {}", duplicates.stream().limit(20).toList());
|
// log.warn("duplicates sample: {}", duplicates.stream().limit(20).toList());
|
||||||
|
|
||||||
if (!missing.isEmpty()) log.warn("missing sample: {}", missing.stream().limit(50).toList());
|
if (!missing.isEmpty()) {
|
||||||
|
log.warn("missing sample: {}", missing.stream().limit(50).toList());
|
||||||
|
}
|
||||||
|
|
||||||
if (!extra.isEmpty()) log.warn("extra sample: {}", extra.stream().limit(50).toList());
|
if (!extra.isEmpty()) {
|
||||||
|
log.warn("extra sample: {}", extra.stream().limit(50).toList());
|
||||||
|
}
|
||||||
|
|
||||||
// =========================================================
|
// =========================================================
|
||||||
// 6) 실패 조건 판정
|
// 6) 실패 조건 판정
|
||||||
|
|||||||
Reference in New Issue
Block a user