폴더 validation 수정

This commit is contained in:
Harry M. You
2025-12-03 17:45:53 +09:00
parent 527167611b
commit dd975f48d2
3 changed files with 111 additions and 27 deletions

View File

@@ -67,11 +67,8 @@ public class MapSheetMngService {
String parentPath = path.getParent().toString();
String fullPath = path.toAbsolutePath().toString();
boolean isValid = true;
if( NameValidator.containsKorean(folderNm) ||
NameValidator.containsWhitespaceRegex(folderNm) ){
isValid = false;
}
boolean isValid = !NameValidator.containsKorean(folderNm) &&
!NameValidator.containsWhitespaceRegex(folderNm);
File directory = new File(fullPath);
File[] childFolders = directory.listFiles(File::isDirectory);
@@ -82,27 +79,24 @@ public class MapSheetMngService {
}
FileTime time = null;
String lastModified = "";
try {
time = Files.getLastModifiedTime(path);
lastModified = dttmFormat.format(new Date(time.toMillis()));
} catch (IOException e) {
throw new RuntimeException(e);
}
String lastModified = dttmFormat.format(new Date(time.toMillis()));
FolderDto folderDto =
new FolderDto(
folderNm,
parentFolderNm,
parentPath,
fullPath,
depth,
childCnt,
lastModified,
isValid
);
return folderDto;
return new FolderDto(
folderNm,
parentFolderNm,
parentPath,
fullPath,
depth,
childCnt,
lastModified,
isValid
);
})
.collect(Collectors.toList());
@@ -122,9 +116,9 @@ public class MapSheetMngService {
throw new RuntimeException(e);
}
FoldersDto foldersDto = new FoldersDto(dirPath, folderTotCnt, folderErrTotCnt, folderDtoList);
// FoldersDto foldersDto = new FoldersDto(dirPath, folderTotCnt, folderErrTotCnt, folderDtoList);
return foldersDto;
return new FoldersDto(dirPath, folderTotCnt, folderErrTotCnt, folderDtoList);
}
public FilesDto getFilesAll(SrchFilesDto srchDto) {
@@ -161,12 +155,17 @@ public class MapSheetMngService {
// 생성자를 통해 객체를 만들고 리스트에 추가
String fileName = file.getName();
String filePath = file.getAbsolutePath();
String parentPath = file.getParent();
String fullPath = file.getAbsolutePath();
String ext = FilenameUtils.getExtension(fileName);
Path path = Paths.get(parentPath);
String parentFolderNm = path.getFileName().toString();
long fileSize = file.length();
String lastModified = dttmFormat.format(new Date(file.lastModified()));
files.add(new FileDto.Basic(fileName, filePath, ext, fileSize, lastModified));
files.add(new FileDto.Basic(fileName, parentFolderNm, parentPath, fullPath, ext, fileSize, lastModified));
fileTotCnt = fileTotCnt + 1;
fileTotSize = fileTotSize + fileSize;
@@ -181,6 +180,61 @@ public class MapSheetMngService {
return filesDto;
}
public FilesDto getFilesDepthAll(SrchFilesDto srchDto) {
int maxDepth = 20;
Path startPath = Paths.get(srchDto.getDirPath());
String dirPath = srchDto.getDirPath();
String extension = srchDto.getExtension();
List<FileDto.Basic> fileDtoList = new ArrayList<>();
SimpleDateFormat dttmFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
int fileTotCnt = 0;
long fileTotSize = 0;
try (Stream<Path> stream = Files.walk(startPath, maxDepth)) {
fileDtoList =
stream
.filter(Files::isRegularFile)
.map(
path -> {
int depth = path.getNameCount();
String fileNm = path.getFileName().toString();
String ext = FilenameUtils.getExtension(fileNm);
String parentFolderNm = path.getParent().getFileName().toString();
String parentPath = path.getParent().toString();
String fullPath = path.toAbsolutePath().toString();
File file = new File(fullPath);
long fileSize = file.length();
String lastModified = dttmFormat.format(new Date(file.lastModified()));
return new FileDto.Basic(fileNm, parentFolderNm, parentPath, fullPath, ext, fileSize, lastModified);
})
.collect(Collectors.toList());
fileTotCnt = fileDtoList.size();
fileTotSize = fileDtoList.stream()
.mapToLong(FileDto.Basic::getFileSize)
.sum();
} catch (IOException e) {
System.err.println("파일 I/O 오류 발생: " + e.getMessage());
}
FilesDto filesDto = new FilesDto(dirPath, fileTotCnt, fileTotSize, fileDtoList);
return filesDto;
}
public Page<MapSheetMngDto.ErrorDataDto> findMapSheetErrorList(
MapSheetMngDto.@Valid searchReq searchReq) {
return mapSheetMngCoreService.findMapSheetErrorList(searchReq);