GDAL Validation FIX

This commit is contained in:
DanielLee
2025-12-12 19:23:27 +09:00
parent 1fc1c728ca
commit 2b71153c2c
4 changed files with 29 additions and 41 deletions

0
login.json Normal file
View File

View File

@@ -142,34 +142,11 @@ public class FIleChecker {
return false;
}
String resStr = "";
boolean hasDriver = false;
// 리눅스/맥용
// ProcessBuilder pb = new ProcessBuilder("sh", "-c", "gdalinfo "+filePath+" | grep -i 'Geo'");
List<String> command = new ArrayList<>();
// 윈도우용
/*
command.add("cmd.exe"); // 윈도우 명령 프롬프트 실행
command.add("/c"); // 명령어를 수행하고 종료한다는 옵션
command.add("gdalinfo");
command.add(filePath);
command.add("|");
command.add("findstr");
command.add("/i");
command.add("Geo");
*/
command.add("sh"); // 리눅스,맥 명령 프롬프트 실행
command.add("-c"); // 명령어를 수행하고 종료한다는 옵션
command.add("gdalinfo");
command.add(filePath);
command.add("|");
command.add("grep");
command.add("-i");
command.add("Geo");
ProcessBuilder processBuilder = new ProcessBuilder(command);
processBuilder.redirectErrorStream(true);
@@ -177,19 +154,17 @@ public class FIleChecker {
try {
Process process = processBuilder.start();
// 인코딩은 윈도우 한글 환경에 맞게 MS949로 지정
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line;
while ((line = reader.readLine()) != null) {
// System.out.println(line);
if (line.contains("Driver: GTiff/GeoTIFF")) {
hasDriver = true;
break;
}
}
int exitCode = process.waitFor();
process.waitFor();
} catch (Exception e) {
e.printStackTrace();

View File

@@ -35,7 +35,6 @@ import java.util.stream.Collectors;
import java.util.stream.Stream;
import lombok.RequiredArgsConstructor;
import org.apache.commons.io.FilenameUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
@@ -49,8 +48,8 @@ public class MapSheetMngFileCheckerService {
private final FileConfig fileConfig;
private final MapSheetMngFileRepository mapSheetMngFileRepository;
@Value("${mapsheet.upload.skipGdalValidation:false}")
private boolean skipGdalValidation;
// @Value("${mapsheet.upload.skipGdalValidation:false}")
// private boolean skipGdalValidation;
public FoldersDto getFolderAll(SrchFoldersDto srchDto) {
@@ -339,9 +338,20 @@ public class MapSheetMngFileCheckerService {
? Paths.get(baseName + ".tif")
: path.getParent().resolve(baseName + ".tif");
// 이미 존재하는 경우 처리
if (Files.exists(path) && !overwrite) {
throw new DuplicateFileException("동일한 파일이 이미 존재합니다: " + path.getFileName());
// DB 중복 체크
String parentPathStr = path.getParent() != null ? path.getParent().toString() : "";
boolean dbExists =
mapSheetMngFileRepository.existsByFileNameAndFilePath(filename, parentPathStr);
// boolean fileExists = Files.exists(path); // 파일 시스템 존재 여부는 체크하지 않음 (DB 기준)
// 이미 존재하는 경우 처리 (DB에만 있는 경우 체크)
if (!overwrite && dbExists) {
throw new DuplicateFileException("동일한 파일이 이미 존재합니다 (DB): " + path.getFileName());
}
// 덮어쓰기인 경우 기존 DB 데이터 삭제 (새로 저장하기 위함)
if (overwrite && dbExists) {
mapSheetMngFileRepository.deleteByFileNameAndFilePath(filename, parentPathStr);
}
// 업로드 파일 저장(덮어쓰기 허용 시 replace)
@@ -367,14 +377,13 @@ public class MapSheetMngFileCheckerService {
}
if ("tif".equals(ext) || "tiff".equals(ext)) {
// GDAL 검증 (플래그에 따라 스킵)
if (!skipGdalValidation) {
// GDAL 검증 (항상 수행)
boolean isValidTif = FIleChecker.cmmndGdalInfo(path.toString());
if (!isValidTif) {
Files.deleteIfExists(path);
throw new ValidationException("유효하지 않은 TIF 파일입니다 (GDAL 검증 실패): " + path.getFileName());
}
}
// TFW 존재/검증
if (!Files.exists(tfwPath)) {
Files.deleteIfExists(path);
@@ -387,7 +396,7 @@ public class MapSheetMngFileCheckerService {
"유효하지 않은 TFW 파일입니다 (6줄 숫자 형식 검증 실패): " + tfwPath.getFileName());
}
saveUploadMeta(path);
return skipGdalValidation ? "TIF 업로드 성공(GDAL 검증 스킵)" : "TIF 업로드 성공";
return "TIF 업로드 성공";
}
// 기타 확장자: 저장만 하고 메타 기록

View File

@@ -3,4 +3,8 @@ package com.kamco.cd.kamcoback.postgres.repository.mapsheet;
import com.kamco.cd.kamcoback.postgres.entity.MapSheetMngFileEntity;
import org.springframework.data.jpa.repository.JpaRepository;
public interface MapSheetMngFileRepository extends JpaRepository<MapSheetMngFileEntity, Long> {}
public interface MapSheetMngFileRepository extends JpaRepository<MapSheetMngFileEntity, Long> {
boolean existsByFileNameAndFilePath(String fileName, String filePath);
void deleteByFileNameAndFilePath(String fileName, String filePath);
}