Skip to content

Commit

Permalink
changed attribute type
Browse files Browse the repository at this point in the history
  • Loading branch information
Bot-Dev-RPA committed Feb 27, 2024
1 parent cf8fd3d commit ae636ea
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 14 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ configure(allprojects) {
testNgVersion = '7.9.0'
loggerVersion = '2.20.0'
jnaVersion = '5.3.1'
version '3.0.2'
version '3.0.3'
}
group "$groupName"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class DeleteFilesFolders {

@Execute
public void action(
@Idx(index = "1", type = AttributeType.TEXT)
@Idx(index = "1", type = AttributeType.FILE)
@Pkg(label = "Enter base folder path", description = "Files/Folders will be scanned within this folder " +
"for deletion")
@NotEmpty
Expand Down Expand Up @@ -179,7 +179,13 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) {
}
}
directoriesToDelete.removeAll(directoriesToSkipDeletion);
deleteFileDirectories(filesToDelete, directoriesToDelete, unableToDeleteBehavior);
if (selectMethod.equalsIgnoreCase(PROCESS_ALL_TYPES)) {
delete(filesToDelete, unableToDeleteBehavior);
delete(directoriesToDelete, unableToDeleteBehavior);
} else if (selectMethod.equalsIgnoreCase(PROCESS_ONLY_FILE_TYPE)) {
delete(filesToDelete, unableToDeleteBehavior);
}

} catch (IOException e) {
if (unableToDeleteBehavior.equalsIgnoreCase(ERROR_THROW)) {
throw new BotCommandException(e.getMessage());
Expand Down Expand Up @@ -230,8 +236,8 @@ private boolean shouldSkipFile(Path path, String filePattern) {
return Files.isRegularFile(path) && Pattern.matches(filePattern, path.toFile().getAbsolutePath());
}

private static void deleteFileDirectories(Set<Path> filesToDelete, Set<Path> directoriesToDelete,
String unableToDeleteBehavior) {
private static void delete(Set<Path> filesToDelete,
String unableToDeleteBehavior) {
for (Path filePath : filesToDelete) {
try {
FileUtils.forceDelete(filePath.toFile());
Expand All @@ -241,15 +247,6 @@ private static void deleteFileDirectories(Set<Path> filesToDelete, Set<Path> dir
}
}
}
for (Path dirPath : directoriesToDelete) {
try {
FileUtils.forceDelete(dirPath.toFile());
} catch (IOException e) {
if (unableToDeleteBehavior.equalsIgnoreCase(ERROR_THROW)) {
throw new BotCommandException(e.getMessage());
}
}
}
}

}
27 changes: 27 additions & 0 deletions src/test/java/device/DeleteFilesFoldersTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public void testDeleteFilesAndDirectories() {
Collection<File> filesAndDirs = FileUtils.listFilesAndDirs(testDirectory,
TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE);
filesAndDirs.remove(testDirectory);
System.out.println(filesAndDirs);
Assert.assertEquals(filesAndDirs.size(), 0, "Test directory should be " +
"empty after deletion");
}
Expand All @@ -95,6 +96,7 @@ public void testNotDeleteFilesAndDirectories() {
Collection<File> filesAndDirs = FileUtils.listFilesAndDirs(testDirectory,
TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE);
filesAndDirs.remove(testDirectory);
System.out.println(filesAndDirs);
Assert.assertEquals(filesAndDirs.size(), 3, "Test directory should be " +
"intact as threshold does not match");
}
Expand All @@ -117,6 +119,7 @@ public void testSkipDirectoryDeletion() {
Collection<File> filesAndDirs = FileUtils.listFilesAndDirs(testDirectory,
TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE);
filesAndDirs.remove(testDirectory);
System.out.println(filesAndDirs);
Assert.assertEquals(filesAndDirs.size(), 2, "Test directory must contain skipped directory and its children");
}

Expand All @@ -138,9 +141,32 @@ public void testSkipFileDeletion() {
Collection<File> filesAndDirs = FileUtils.listFilesAndDirs(testDirectory,
TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE);
filesAndDirs.remove(testDirectory);
System.out.println(filesAndDirs);
Assert.assertEquals(filesAndDirs.size(), 3, "Test directory must contain directory and its skipped children");
}

@Test
public void testSkipFileTypeDeletion() {
Boolean recursive = Boolean.TRUE;
Number thresholdNumber = 0;//all files and folders will match
Boolean skipFolders = false;
String skipFolderPathPattern = "";
Boolean skipFiles = false;
String skipFilePathPattern = "";

deleteFilesFolders.action(TEST_DIRECTORY_PATH, PROCESS_ONLY_FILE_TYPE, recursive, thresholdNumber,
THRESHOLD_UNIT_DAY, THRESHOLD_CRITERIA_CREATION,
skipFolders, skipFolderPathPattern, skipFiles, skipFilePathPattern, ERROR_IGNORE);

File testDirectory = new File(TEST_DIRECTORY_PATH);
Assert.assertTrue(testDirectory.exists());
Collection<File> filesAndDirs = FileUtils.listFilesAndDirs(testDirectory,
TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE);
filesAndDirs.remove(testDirectory);
System.out.println(filesAndDirs);
Assert.assertEquals(filesAndDirs.size(), 1, "Only directory should be present");
}

@Test
public void testSkipFileDeletionSingleFolder() {
Boolean recursive = Boolean.TRUE;
Expand All @@ -159,6 +185,7 @@ public void testSkipFileDeletionSingleFolder() {
Collection<File> filesAndDirs = FileUtils.listFilesAndDirs(testDirectory,
TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE);
filesAndDirs.remove(testDirectory);
System.out.println(filesAndDirs);
Assert.assertEquals(filesAndDirs.size(), 2, "Test directory must contain directory and its skipped children");
}
}

0 comments on commit ae636ea

Please sign in to comment.