GDAL Validation FIX
This commit is contained in:
0
login.json
Normal file
0
login.json
Normal file
@@ -142,34 +142,11 @@ public class FIleChecker {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
String resStr = "";
|
|
||||||
boolean hasDriver = false;
|
boolean hasDriver = false;
|
||||||
|
|
||||||
// 리눅스/맥용
|
|
||||||
// ProcessBuilder pb = new ProcessBuilder("sh", "-c", "gdalinfo "+filePath+" | grep -i 'Geo'");
|
|
||||||
|
|
||||||
List<String> command = new ArrayList<>();
|
List<String> command = new ArrayList<>();
|
||||||
|
|
||||||
// 윈도우용
|
|
||||||
/*
|
|
||||||
command.add("cmd.exe"); // 윈도우 명령 프롬프트 실행
|
|
||||||
command.add("/c"); // 명령어를 수행하고 종료한다는 옵션
|
|
||||||
command.add("gdalinfo");
|
command.add("gdalinfo");
|
||||||
command.add(filePath);
|
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 processBuilder = new ProcessBuilder(command);
|
||||||
processBuilder.redirectErrorStream(true);
|
processBuilder.redirectErrorStream(true);
|
||||||
@@ -177,19 +154,17 @@ public class FIleChecker {
|
|||||||
try {
|
try {
|
||||||
Process process = processBuilder.start();
|
Process process = processBuilder.start();
|
||||||
|
|
||||||
// 인코딩은 윈도우 한글 환경에 맞게 MS949로 지정
|
|
||||||
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
|
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
|
||||||
|
|
||||||
String line;
|
String line;
|
||||||
while ((line = reader.readLine()) != null) {
|
while ((line = reader.readLine()) != null) {
|
||||||
// System.out.println(line);
|
|
||||||
if (line.contains("Driver: GTiff/GeoTIFF")) {
|
if (line.contains("Driver: GTiff/GeoTIFF")) {
|
||||||
hasDriver = true;
|
hasDriver = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int exitCode = process.waitFor();
|
process.waitFor();
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
|||||||
@@ -35,7 +35,6 @@ import java.util.stream.Collectors;
|
|||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.apache.commons.io.FilenameUtils;
|
import org.apache.commons.io.FilenameUtils;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
@@ -49,8 +48,8 @@ public class MapSheetMngFileCheckerService {
|
|||||||
private final FileConfig fileConfig;
|
private final FileConfig fileConfig;
|
||||||
private final MapSheetMngFileRepository mapSheetMngFileRepository;
|
private final MapSheetMngFileRepository mapSheetMngFileRepository;
|
||||||
|
|
||||||
@Value("${mapsheet.upload.skipGdalValidation:false}")
|
// @Value("${mapsheet.upload.skipGdalValidation:false}")
|
||||||
private boolean skipGdalValidation;
|
// private boolean skipGdalValidation;
|
||||||
|
|
||||||
public FoldersDto getFolderAll(SrchFoldersDto srchDto) {
|
public FoldersDto getFolderAll(SrchFoldersDto srchDto) {
|
||||||
|
|
||||||
@@ -339,9 +338,20 @@ public class MapSheetMngFileCheckerService {
|
|||||||
? Paths.get(baseName + ".tif")
|
? Paths.get(baseName + ".tif")
|
||||||
: path.getParent().resolve(baseName + ".tif");
|
: path.getParent().resolve(baseName + ".tif");
|
||||||
|
|
||||||
// 이미 존재하는 경우 처리
|
// DB 중복 체크
|
||||||
if (Files.exists(path) && !overwrite) {
|
String parentPathStr = path.getParent() != null ? path.getParent().toString() : "";
|
||||||
throw new DuplicateFileException("동일한 파일이 이미 존재합니다: " + path.getFileName());
|
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)
|
// 업로드 파일 저장(덮어쓰기 허용 시 replace)
|
||||||
@@ -367,14 +377,13 @@ public class MapSheetMngFileCheckerService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ("tif".equals(ext) || "tiff".equals(ext)) {
|
if ("tif".equals(ext) || "tiff".equals(ext)) {
|
||||||
// GDAL 검증 (플래그에 따라 스킵)
|
// GDAL 검증 (항상 수행)
|
||||||
if (!skipGdalValidation) {
|
|
||||||
boolean isValidTif = FIleChecker.cmmndGdalInfo(path.toString());
|
boolean isValidTif = FIleChecker.cmmndGdalInfo(path.toString());
|
||||||
if (!isValidTif) {
|
if (!isValidTif) {
|
||||||
Files.deleteIfExists(path);
|
Files.deleteIfExists(path);
|
||||||
throw new ValidationException("유효하지 않은 TIF 파일입니다 (GDAL 검증 실패): " + path.getFileName());
|
throw new ValidationException("유효하지 않은 TIF 파일입니다 (GDAL 검증 실패): " + path.getFileName());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
// TFW 존재/검증
|
// TFW 존재/검증
|
||||||
if (!Files.exists(tfwPath)) {
|
if (!Files.exists(tfwPath)) {
|
||||||
Files.deleteIfExists(path);
|
Files.deleteIfExists(path);
|
||||||
@@ -387,7 +396,7 @@ public class MapSheetMngFileCheckerService {
|
|||||||
"유효하지 않은 TFW 파일입니다 (6줄 숫자 형식 검증 실패): " + tfwPath.getFileName());
|
"유효하지 않은 TFW 파일입니다 (6줄 숫자 형식 검증 실패): " + tfwPath.getFileName());
|
||||||
}
|
}
|
||||||
saveUploadMeta(path);
|
saveUploadMeta(path);
|
||||||
return skipGdalValidation ? "TIF 업로드 성공(GDAL 검증 스킵)" : "TIF 업로드 성공";
|
return "TIF 업로드 성공";
|
||||||
}
|
}
|
||||||
|
|
||||||
// 기타 확장자: 저장만 하고 메타 기록
|
// 기타 확장자: 저장만 하고 메타 기록
|
||||||
|
|||||||
@@ -3,4 +3,8 @@ package com.kamco.cd.kamcoback.postgres.repository.mapsheet;
|
|||||||
import com.kamco.cd.kamcoback.postgres.entity.MapSheetMngFileEntity;
|
import com.kamco.cd.kamcoback.postgres.entity.MapSheetMngFileEntity;
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
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);
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user