폴더 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

@@ -68,6 +68,27 @@ public class MapSheetMngApiController {
return ApiResponseDto.createOK(mapSheetMngService.getFilesAll(srchDto));
}
@Operation(summary = "파일목록 조회", description = "파일목록 조회")
@ApiResponses(
value = {
@ApiResponse(
responseCode = "200",
description = "조회 성공",
content =
@Content(
mediaType = "application/json",
schema = @Schema(implementation = CommonCodeDto.Basic.class))),
@ApiResponse(responseCode = "404", description = "코드를 찾을 수 없음", content = @Content),
@ApiResponse(responseCode = "500", description = "서버 오류", content = @Content)
})
@PostMapping("/file-all-list")
public ApiResponseDto<FilesDto> getAllFiles(@RequestBody SrchFilesDto srchDto) {
return ApiResponseDto.createOK(mapSheetMngService.getFilesDepthAll(srchDto));
}
/**
* 오류데이터 목록 조회
*

View File

@@ -23,10 +23,15 @@ public class FileDto {
@NoArgsConstructor
@AllArgsConstructor
public static class SrchFilesDto {
@Schema(description = "디렉토리경로", example = "/data")
@NotNull private String dirPath;
@Schema(description = "전체(*), cpg,dbf,geojson등", example = "*")
@NotNull private String extension;
@Schema(description = "파일명(name), 최종수정일(date)", example = "name")
@NotNull private String sortType;
@Schema(description = "파일시작위치", example = "1")
@NotNull private Integer startPos;
@Schema(description = "파일종료위치", example = "100")
@NotNull private Integer endPos;
}
@@ -86,15 +91,19 @@ public class FileDto {
public static class Basic {
private final String fileNm;
private final String filePath;
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 filePath, String extension, long fileSize, String lastModified) {
String fileNm, String parentFolderNm, String parentPath, String fullPath, String extension, long fileSize, String lastModified) {
this.fileNm = fileNm;
this.filePath = filePath;
this.parentFolderNm = parentFolderNm;
this.parentPath = parentPath;
this.fullPath = fullPath;
this.extension = extension;
this.fileSize = fileSize;
this.lastModified = lastModified;

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);