영상관리 수정 반영

This commit is contained in:
Moon
2025-12-19 13:55:55 +09:00
parent dfe5ef50fc
commit 988ba96a7a
9 changed files with 326 additions and 200 deletions

View File

@@ -32,6 +32,8 @@ import org.geotools.gce.geotiff.GeoTiffReader;
public class FIleChecker {
static SimpleDateFormat dttmFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
public static boolean isValidFile(String pathStr) {
Path path = Paths.get(pathStr);
@@ -210,7 +212,7 @@ public class FIleChecker {
String line;
while ((line = reader.readLine()) != null) {
System.out.println("gdalinfo 출력: " + line);
// System.out.println("gdalinfo 출력: " + line);
if (line.contains("Driver: GTiff/GeoTIFF")) {
hasDriver = true;
break;
@@ -254,34 +256,131 @@ public class FIleChecker {
return hasDriver;
}
@Schema(name = "File Basic", description = "파일 기본 정보")
@Getter
public static class Basic {
private final String fileNm;
private final String parentFolderNm;
private final String parentPath;
private final String fullPath;
private final String extension;
private final long fileSize;
private final String lastModified;
public Basic(
String fileNm,
String parentFolderNm,
String parentPath,
String fullPath,
String extension,
long fileSize,
String lastModified) {
this.fileNm = fileNm;
this.parentFolderNm = parentFolderNm;
this.parentPath = parentPath;
this.fullPath = fullPath;
this.extension = extension;
this.fileSize = fileSize;
this.lastModified = lastModified;
public static boolean mkDir(String dirPath)
{
Path uploadTargetPath = Paths.get(dirPath);
try {
Files.createDirectories(uploadTargetPath);
} catch (IOException e) {
return false;
}
return true;
}
public static List<Folder> getFolderAll(String dirPath, String sortType, int maxDepth) {
Path startPath = Paths.get(dirPath);
List<Folder> folderList = List.of();
try (Stream<Path> stream = Files.walk(startPath, maxDepth)) {
folderList =
stream
.filter(Files::isDirectory)
.filter(p -> !p.toString().equals(dirPath))
.map(
path -> {
int depth = path.getNameCount();
String folderNm = path.getFileName().toString();
String parentFolderNm = path.getParent().getFileName().toString();
String parentPath = path.getParent().toString();
String fullPath = path.toAbsolutePath().toString();
boolean isValid =
!NameValidator.containsKorean(folderNm)
&& !NameValidator.containsWhitespaceRegex(folderNm);
File file = new File(fullPath);
int childCnt = getChildFolderCount(file);
String lastModified = getLastModified(file);
return new Folder(
folderNm,
parentFolderNm,
parentPath,
fullPath,
depth,
childCnt,
lastModified,
isValid);
})
.collect(Collectors.toList());
if (sortType.equals("name") || sortType.equals("name asc")) {
folderList.sort(
Comparator.comparing(
Folder::getFolderNm, CASE_INSENSITIVE_ORDER // 대소문자 구분 없이
));
} else if (sortType.equals("name desc")) {
folderList.sort(
Comparator.comparing(
Folder::getFolderNm, CASE_INSENSITIVE_ORDER // 대소문자 구분 없이
)
.reversed());
} else if (sortType.equals("dttm desc")) {
folderList.sort(
Comparator.comparing(
Folder::getLastModified, CASE_INSENSITIVE_ORDER // 대소문자 구분 없이
)
.reversed());
} else {
folderList.sort(
Comparator.comparing(
Folder::getLastModified, CASE_INSENSITIVE_ORDER // 대소문자 구분 없이
));
}
} catch (IOException e) {
throw new RuntimeException(e);
}
return folderList;
}
public static List<Folder> getFolderAll(String dirPath) {
return getFolderAll(dirPath, "name", 1);
}
public static List<Folder> getFolderAll(String dirPath, String sortType) {
return getFolderAll(dirPath, sortType, 1);
}
public static int getChildFolderCount(String dirPath) {
File directory = new File(dirPath);
File[] childFolders = directory.listFiles(File::isDirectory);
int childCnt = 0;
if (childFolders != null) {
childCnt = childFolders.length;
}
return childCnt;
}
public static int getChildFolderCount(File directory) {
File[] childFolders = directory.listFiles(File::isDirectory);
int childCnt = 0;
if (childFolders != null) {
childCnt = childFolders.length;
}
return childCnt;
}
public static String getLastModified(String dirPath) {
File file = new File(dirPath);
return dttmFormat.format(new Date(file.lastModified()));
}
public static String getLastModified(File file) {
return dttmFormat.format(new Date(file.lastModified()));
}
public static List<Basic> getFilesFromAllDepth(
@@ -303,10 +402,7 @@ public class FIleChecker {
List<Basic> fileList = new ArrayList<>();
SimpleDateFormat dttmFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
// int fileTotCnt = 0;
// long fileTotSize = 0;
Predicate<Path> isTarget =
Predicate<Path> isTargetName =
p -> {
if (targetFileNm == null
|| targetFileNm.trim().isEmpty()
@@ -328,7 +424,7 @@ public class FIleChecker {
|| extension.equals("*")
|| targetExtensions.contains(extractExtension(p)))
.sorted(getFileComparator(sortType))
.filter(isTarget)
.filter(isTargetName)
.skip(startPos)
.limit(limit)
.map(
@@ -357,6 +453,15 @@ public class FIleChecker {
return fileList;
}
public static List<Basic> getFilesFromAllDepth(
String dir,
String targetFileNm,
String extension) {
return FIleChecker.getFilesFromAllDepth(
dir, targetFileNm, extension, 100, "name", 0, 100);
}
public static Long getFileTotSize(List<FIleChecker.Basic> files) {
Long fileTotSize = 0L;
@@ -367,6 +472,21 @@ public class FIleChecker {
return fileTotSize;
}
public static boolean checkExtensions(String fileName, String ext)
{
if( fileName == null )return false;
if (!fileName
.substring(fileName.lastIndexOf('.') + 1)
.toLowerCase()
.equals(ext)) {
return false;
}
return true;
}
public static Set<String> createExtensionSet(String extensionString) {
if (extensionString == null || extensionString.isBlank()) {
return Set.of();
@@ -420,11 +540,6 @@ public class FIleChecker {
}
}
/**
* gdalinfo 실행 파일 경로를 찾습니다.
*
* @return gdalinfo 경로 (찾지 못하면 null)
*/
private static String findGdalinfoPath() {
// 일반적인 설치 경로 확인
String[] possiblePaths = {
@@ -443,12 +558,6 @@ public class FIleChecker {
return null;
}
/**
* 명령어가 사용 가능한지 확인합니다.
*
* @param command 명령어 경로
* @return 사용 가능 여부
*/
private static boolean isCommandAvailable(String command) {
try {
ProcessBuilder pb = new ProcessBuilder(command, "--version");
@@ -469,4 +578,66 @@ public class FIleChecker {
return false;
}
}
@Schema(name = "Folder", description = "폴더 정보")
@Getter
public static class Folder {
private final String folderNm;
private final String parentFolderNm;
private final String parentPath;
private final String fullPath;
private final int depth;
private final long childCnt;
private final String lastModified;
private final Boolean isValid;
public Folder(
String folderNm,
String parentFolderNm,
String parentPath,
String fullPath,
int depth,
long childCnt,
String lastModified,
Boolean isValid) {
this.folderNm = folderNm;
this.parentFolderNm = parentFolderNm;
this.parentPath = parentPath;
this.fullPath = fullPath;
this.depth = depth;
this.childCnt = childCnt;
this.lastModified = lastModified;
this.isValid = isValid;
}
}
@Schema(name = "File Basic", description = "파일 기본 정보")
@Getter
public static class Basic {
private final String fileNm;
private final String parentFolderNm;
private final String parentPath;
private final String fullPath;
private final String extension;
private final long fileSize;
private final String lastModified;
public Basic(
String fileNm,
String parentFolderNm,
String parentPath,
String fullPath,
String extension,
long fileSize,
String lastModified) {
this.fileNm = fileNm;
this.parentFolderNm = parentFolderNm;
this.parentPath = parentPath;
this.fullPath = fullPath;
this.extension = extension;
this.fileSize = fileSize;
this.lastModified = lastModified;
}
}
}