Gdal Support mac,linux,win os
This commit is contained in:
@@ -34,11 +34,13 @@ import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.io.FilenameUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
@Transactional(readOnly = true)
|
||||
@@ -318,11 +320,34 @@ public class MapSheetMngFileCheckerService {
|
||||
@Transactional
|
||||
public String uploadFile(MultipartFile file, String targetPath, boolean overwrite, Long hstUid) {
|
||||
try {
|
||||
// 파일 유효성 검증
|
||||
if (file == null || file.isEmpty()) {
|
||||
throw new ValidationException("업로드 파일이 비어있습니다.");
|
||||
}
|
||||
if (file.getOriginalFilename() == null || file.getOriginalFilename().isEmpty()) {
|
||||
throw new ValidationException("파일명이 유효하지 않습니다.");
|
||||
}
|
||||
|
||||
Path path = Paths.get(targetPath);
|
||||
if (Files.isDirectory(path)) {
|
||||
|
||||
// targetPath가 존재하지 않으면 파일 경로로 가정하고 부모 디렉토리 생성
|
||||
if (!Files.exists(path)) {
|
||||
// 경로가 확장자로 끝나면 파일로 간주
|
||||
if (targetPath.matches(".*\\.[a-zA-Z]{3,4}$")) {
|
||||
if (path.getParent() != null) {
|
||||
Files.createDirectories(path.getParent());
|
||||
}
|
||||
} else {
|
||||
// 확장자가 없으면 디렉토리로 간주
|
||||
Files.createDirectories(path);
|
||||
path = path.resolve(file.getOriginalFilename());
|
||||
}
|
||||
} else if (Files.isDirectory(path)) {
|
||||
path = path.resolve(file.getOriginalFilename());
|
||||
}
|
||||
if (path.getParent() != null) {
|
||||
|
||||
// 최종 파일의 부모 디렉토리 생성
|
||||
if (path.getParent() != null && !Files.exists(path.getParent())) {
|
||||
Files.createDirectories(path.getParent());
|
||||
}
|
||||
|
||||
@@ -403,8 +428,13 @@ public class MapSheetMngFileCheckerService {
|
||||
saveUploadMeta(path, hstUid);
|
||||
|
||||
return "업로드 성공";
|
||||
} catch (ValidationException | DuplicateFileException e) {
|
||||
// 비즈니스 예외는 그대로 던짐
|
||||
throw e;
|
||||
} catch (IOException e) {
|
||||
throw new IllegalArgumentException("파일 I/O 처리 실패: " + e.getMessage());
|
||||
throw new IllegalArgumentException("파일 I/O 처리 실패: " + e.getMessage(), e);
|
||||
} catch (Exception e) {
|
||||
throw new IllegalArgumentException("파일 업로드 처리 중 오류 발생: " + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -416,8 +446,45 @@ public class MapSheetMngFileCheckerService {
|
||||
boolean overwrite,
|
||||
Long hstUid) {
|
||||
try {
|
||||
log.info(
|
||||
"uploadPair 시작 - targetPath: {}, overwrite: {}, hstUid: {}",
|
||||
targetPath,
|
||||
overwrite,
|
||||
hstUid);
|
||||
|
||||
// 파일 유효성 검증
|
||||
if (tfwFile == null || tfwFile.isEmpty()) {
|
||||
throw new ValidationException("TFW 파일이 비어있습니다.");
|
||||
}
|
||||
if (tifFile == null || tifFile.isEmpty()) {
|
||||
throw new ValidationException("TIF 파일이 비어있습니다.");
|
||||
}
|
||||
if (tfwFile.getOriginalFilename() == null || tfwFile.getOriginalFilename().isEmpty()) {
|
||||
throw new ValidationException("TFW 파일명이 유효하지 않습니다.");
|
||||
}
|
||||
if (tifFile.getOriginalFilename() == null || tifFile.getOriginalFilename().isEmpty()) {
|
||||
throw new ValidationException("TIF 파일명이 유효하지 않습니다.");
|
||||
}
|
||||
|
||||
log.info(
|
||||
"파일명 - TFW: {}, TIF: {}", tfwFile.getOriginalFilename(), tifFile.getOriginalFilename());
|
||||
|
||||
Path basePath = Paths.get(targetPath);
|
||||
|
||||
// targetPath가 존재하지 않으면 디렉토리로 생성
|
||||
if (!Files.exists(basePath)) {
|
||||
log.info("대상 경로가 존재하지 않아 디렉토리 생성: {}", basePath);
|
||||
Files.createDirectories(basePath);
|
||||
}
|
||||
|
||||
// 파일인 경우 부모 디렉토리를 basePath로 사용
|
||||
if (Files.isRegularFile(basePath)) {
|
||||
log.info("대상 경로가 파일이므로 부모 디렉토리 사용");
|
||||
basePath = basePath.getParent();
|
||||
}
|
||||
|
||||
if (Files.isDirectory(basePath)) {
|
||||
log.info("디렉토리 확인됨: {}", basePath);
|
||||
// 디렉토리인 경우 파일명 기준으로 경로 생성
|
||||
Path tfwPath = basePath.resolve(tfwFile.getOriginalFilename());
|
||||
Path tifPath = basePath.resolve(tifFile.getOriginalFilename());
|
||||
@@ -427,9 +494,9 @@ public class MapSheetMngFileCheckerService {
|
||||
if (!tfwBase.equalsIgnoreCase(tifBase)) {
|
||||
throw new ValidationException("TFW/TIF 파일명이 동일한 베이스가 아닙니다.");
|
||||
}
|
||||
// 디렉토리 생성
|
||||
if (tfwPath.getParent() != null) Files.createDirectories(tfwPath.getParent());
|
||||
if (tifPath.getParent() != null) Files.createDirectories(tifPath.getParent());
|
||||
// 디렉토리는 이미 생성되었으므로 추가 생성 불필요
|
||||
// if (tfwPath.getParent() != null) Files.createDirectories(tfwPath.getParent());
|
||||
// if (tifPath.getParent() != null) Files.createDirectories(tifPath.getParent());
|
||||
|
||||
// DB 중복 체크 및 overwrite 처리 (각 파일별)
|
||||
String parentPathStr = basePath.toString();
|
||||
@@ -450,32 +517,51 @@ public class MapSheetMngFileCheckerService {
|
||||
}
|
||||
|
||||
// 파일 저장
|
||||
log.info("파일 저장 시작 - TFW: {}, TIF: {}", tfwPath, tifPath);
|
||||
tfwFile.transferTo(tfwPath.toFile());
|
||||
tifFile.transferTo(tifPath.toFile());
|
||||
log.info("파일 저장 완료");
|
||||
|
||||
// 검증
|
||||
log.info("TFW 파일 검증 시작: {}", tfwPath);
|
||||
boolean tfwOk = FIleChecker.checkTfw(tfwPath.toString());
|
||||
if (!tfwOk) {
|
||||
log.warn("TFW 파일 검증 실패: {}", tfwName);
|
||||
Files.deleteIfExists(tfwPath);
|
||||
Files.deleteIfExists(tifPath);
|
||||
throw new ValidationException("유효하지 않은 TFW 파일입니다 (6줄 숫자 형식 검증 실패): " + tfwName);
|
||||
}
|
||||
log.info("TFW 파일 검증 성공");
|
||||
|
||||
log.info("TIF 파일 검증 시작: {}", tifPath);
|
||||
boolean isValidTif = FIleChecker.cmmndGdalInfo(tifPath.toString());
|
||||
if (!isValidTif) {
|
||||
log.warn("TIF 파일 검증 실패: {}", tifName);
|
||||
Files.deleteIfExists(tfwPath);
|
||||
Files.deleteIfExists(tifPath);
|
||||
throw new ValidationException("유효하지 않은 TIF 파일입니다 (GDAL 검증 실패): " + tifName);
|
||||
}
|
||||
log.info("TIF 파일 검증 성공");
|
||||
|
||||
// 메타 저장 (두 파일 각각 저장)
|
||||
log.info("메타 데이터 저장 시작");
|
||||
saveUploadMeta(tfwPath, hstUid);
|
||||
saveUploadMeta(tifPath, hstUid);
|
||||
log.info("메타 데이터 저장 완료");
|
||||
return "TFW/TIF 페어 업로드 성공";
|
||||
} else {
|
||||
throw new ValidationException("targetPath는 디렉토리여야 합니다.");
|
||||
}
|
||||
} catch (ValidationException | DuplicateFileException e) {
|
||||
// 비즈니스 예외는 그대로 던짐
|
||||
log.warn("업로드 비즈니스 예외 발생: {}", e.getMessage());
|
||||
throw e;
|
||||
} catch (IOException e) {
|
||||
throw new IllegalArgumentException("파일 I/O 처리 실패: " + e.getMessage());
|
||||
log.error("파일 I/O 처리 실패: {}", e.getMessage(), e);
|
||||
throw new IllegalArgumentException("파일 I/O 처리 실패: " + e.getMessage(), e);
|
||||
} catch (Exception e) {
|
||||
log.error("파일 업로드 처리 중 예상치 못한 오류 발생: {}", e.getMessage(), e);
|
||||
throw new IllegalArgumentException("파일 업로드 처리 중 오류 발생: " + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user