폴더 validation 수정
This commit is contained in:
@@ -68,6 +68,27 @@ public class MapSheetMngApiController {
|
|||||||
return ApiResponseDto.createOK(mapSheetMngService.getFilesAll(srchDto));
|
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));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 오류데이터 목록 조회
|
* 오류데이터 목록 조회
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -23,10 +23,15 @@ public class FileDto {
|
|||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public static class SrchFilesDto {
|
public static class SrchFilesDto {
|
||||||
|
@Schema(description = "디렉토리경로", example = "/data")
|
||||||
@NotNull private String dirPath;
|
@NotNull private String dirPath;
|
||||||
|
@Schema(description = "전체(*), cpg,dbf,geojson등", example = "*")
|
||||||
@NotNull private String extension;
|
@NotNull private String extension;
|
||||||
|
@Schema(description = "파일명(name), 최종수정일(date)", example = "name")
|
||||||
@NotNull private String sortType;
|
@NotNull private String sortType;
|
||||||
|
@Schema(description = "파일시작위치", example = "1")
|
||||||
@NotNull private Integer startPos;
|
@NotNull private Integer startPos;
|
||||||
|
@Schema(description = "파일종료위치", example = "100")
|
||||||
@NotNull private Integer endPos;
|
@NotNull private Integer endPos;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -86,15 +91,19 @@ public class FileDto {
|
|||||||
public static class Basic {
|
public static class Basic {
|
||||||
|
|
||||||
private final String fileNm;
|
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 String extension;
|
||||||
private final long fileSize;
|
private final long fileSize;
|
||||||
private final String lastModified;
|
private final String lastModified;
|
||||||
|
|
||||||
public Basic(
|
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.fileNm = fileNm;
|
||||||
this.filePath = filePath;
|
this.parentFolderNm = parentFolderNm;
|
||||||
|
this.parentPath = parentPath;
|
||||||
|
this.fullPath = fullPath;
|
||||||
this.extension = extension;
|
this.extension = extension;
|
||||||
this.fileSize = fileSize;
|
this.fileSize = fileSize;
|
||||||
this.lastModified = lastModified;
|
this.lastModified = lastModified;
|
||||||
|
|||||||
@@ -67,11 +67,8 @@ public class MapSheetMngService {
|
|||||||
String parentPath = path.getParent().toString();
|
String parentPath = path.getParent().toString();
|
||||||
String fullPath = path.toAbsolutePath().toString();
|
String fullPath = path.toAbsolutePath().toString();
|
||||||
|
|
||||||
boolean isValid = true;
|
boolean isValid = !NameValidator.containsKorean(folderNm) &&
|
||||||
if( NameValidator.containsKorean(folderNm) ||
|
!NameValidator.containsWhitespaceRegex(folderNm);
|
||||||
NameValidator.containsWhitespaceRegex(folderNm) ){
|
|
||||||
isValid = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
File directory = new File(fullPath);
|
File directory = new File(fullPath);
|
||||||
File[] childFolders = directory.listFiles(File::isDirectory);
|
File[] childFolders = directory.listFiles(File::isDirectory);
|
||||||
@@ -82,27 +79,24 @@ public class MapSheetMngService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
FileTime time = null;
|
FileTime time = null;
|
||||||
|
String lastModified = "";
|
||||||
try {
|
try {
|
||||||
time = Files.getLastModifiedTime(path);
|
time = Files.getLastModifiedTime(path);
|
||||||
|
lastModified = dttmFormat.format(new Date(time.toMillis()));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
String lastModified = dttmFormat.format(new Date(time.toMillis()));
|
return new FolderDto(
|
||||||
|
folderNm,
|
||||||
FolderDto folderDto =
|
parentFolderNm,
|
||||||
new FolderDto(
|
parentPath,
|
||||||
folderNm,
|
fullPath,
|
||||||
parentFolderNm,
|
depth,
|
||||||
parentPath,
|
childCnt,
|
||||||
fullPath,
|
lastModified,
|
||||||
depth,
|
isValid
|
||||||
childCnt,
|
);
|
||||||
lastModified,
|
|
||||||
isValid
|
|
||||||
);
|
|
||||||
|
|
||||||
return folderDto;
|
|
||||||
})
|
})
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
@@ -122,9 +116,9 @@ public class MapSheetMngService {
|
|||||||
throw new RuntimeException(e);
|
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) {
|
public FilesDto getFilesAll(SrchFilesDto srchDto) {
|
||||||
@@ -161,12 +155,17 @@ public class MapSheetMngService {
|
|||||||
|
|
||||||
// 생성자를 통해 객체를 만들고 리스트에 추가
|
// 생성자를 통해 객체를 만들고 리스트에 추가
|
||||||
String fileName = file.getName();
|
String fileName = file.getName();
|
||||||
String filePath = file.getAbsolutePath();
|
String parentPath = file.getParent();
|
||||||
|
String fullPath = file.getAbsolutePath();
|
||||||
String ext = FilenameUtils.getExtension(fileName);
|
String ext = FilenameUtils.getExtension(fileName);
|
||||||
|
|
||||||
|
Path path = Paths.get(parentPath);
|
||||||
|
String parentFolderNm = path.getFileName().toString();
|
||||||
|
|
||||||
long fileSize = file.length();
|
long fileSize = file.length();
|
||||||
String lastModified = dttmFormat.format(new Date(file.lastModified()));
|
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;
|
fileTotCnt = fileTotCnt + 1;
|
||||||
fileTotSize = fileTotSize + fileSize;
|
fileTotSize = fileTotSize + fileSize;
|
||||||
@@ -181,6 +180,61 @@ public class MapSheetMngService {
|
|||||||
return filesDto;
|
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(
|
public Page<MapSheetMngDto.ErrorDataDto> findMapSheetErrorList(
|
||||||
MapSheetMngDto.@Valid searchReq searchReq) {
|
MapSheetMngDto.@Valid searchReq searchReq) {
|
||||||
return mapSheetMngCoreService.findMapSheetErrorList(searchReq);
|
return mapSheetMngCoreService.findMapSheetErrorList(searchReq);
|
||||||
|
|||||||
Reference in New Issue
Block a user