Skip to content

Commit bebb98e

Browse files
committed
MDs that does not exists wont be shown to the enduser
Also change utils -> util
1 parent aee252b commit bebb98e

23 files changed

Lines changed: 174 additions & 103 deletions

src/main/java/org/pwss/FileIntegrityScannerFrontend.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import org.pwss.navigation.NavigationEvents;
1717
import org.pwss.navigation.NavigationHandler;
1818
import org.pwss.navigation.Screen;
19-
import org.pwss.utils.OSUtils;
19+
import org.pwss.util.OSUtil;
2020
import org.pwss.view.screen.splash_screen.FileIntegrityScannerSplashScreen;
2121
import org.slf4j.LoggerFactory;
2222

@@ -40,7 +40,7 @@ class FileIntegrityScannerFrontend {
4040
final static void StartApplication() throws FailedToLaunchAppException {
4141
final org.slf4j.Logger log = LoggerFactory.getLogger(FileIntegrityScannerFrontend.class);
4242
log.debug("Starting File-Integrity Scanner Frontend Application");
43-
log.debug("OS Name: {}", OSUtils.getOSName());
43+
log.debug("OS Name: {}", OSUtil.getOSName());
4444
try {
4545
if (AppConfig.USE_SPLASH_SCREEN) {
4646
FileIntegrityScannerSplashScreen.showSplash();

src/main/java/org/pwss/controller/HomeController.java

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,14 @@
5959
import org.pwss.service.NoteService;
6060
import org.pwss.service.ScanService;
6161
import org.pwss.service.ScanSummaryService;
62-
import org.pwss.utils.AppTheme;
63-
import org.pwss.utils.ConversionUtils;
64-
import org.pwss.utils.ErrorUtils;
65-
import org.pwss.utils.LiveFeedUtils;
66-
import org.pwss.utils.MonitoredDirectoryUtils;
67-
import org.pwss.utils.OSUtils;
68-
import org.pwss.utils.ReportUtils;
69-
import org.pwss.utils.StringConstants;
62+
import org.pwss.util.AppTheme;
63+
import org.pwss.util.ConversionUtil;
64+
import org.pwss.util.ErrorUtil;
65+
import org.pwss.util.LiveFeedUtil;
66+
import org.pwss.util.MonitoredDirectoryUtil;
67+
import org.pwss.util.OSUtil;
68+
import org.pwss.util.ReportUtil;
69+
import org.pwss.util.StringConstants;
7070
import org.pwss.view.popup_menu.MonitoredDirectoryPopupFactory;
7171
import org.pwss.view.popup_menu.listener.MonitoredDirectoryPopupListenerImpl;
7272
import org.pwss.view.screen.HomeScreen;
@@ -76,7 +76,6 @@
7676
import static org.pwss.app_settings.AppConfig.MAX_HASH_EXTRACTION_FILE_SIZE;
7777
import static org.pwss.app_settings.AppConfig.USE_SPLASH_SCREEN;
7878

79-
// TODO: NEEDS REFACTORING - VERY LARGE CLASS
8079
public final class HomeController extends BaseController<HomeScreen> {
8180

8281
/**
@@ -250,7 +249,8 @@ void fetchDataAndRefreshView() {
250249
try {
251250
// Fetch all monitored directories for display in the monitored directories
252251
// table
253-
allMonitoredDirectories = monitoredDirectoryService.getAllDirectories();
252+
allMonitoredDirectories = MonitoredDirectoryUtil
253+
.filterMonitoredDirectoriesOnConfirmedPath(monitoredDirectoryService.getAllDirectories());
254254

255255
// Only fetch diffs if there are active monitored directories present
256256
final long activeDirCount = allMonitoredDirectories.stream().filter(MonitoredDirectory::isActive).count();
@@ -371,7 +371,7 @@ public void mouseClicked(MouseEvent e) {
371371
DiffTableModel model = (DiffTableModel) screen.getDiffTable().getModel();
372372
Optional<Diff> diff = model.getDiffAt(modelRow);
373373

374-
diff.ifPresent(d -> screen.getDiffDetails().setText(ReportUtils.formatDiff(d)));
374+
diff.ifPresent(d -> screen.getDiffDetails().setText(ReportUtil.formatDiff(d)));
375375
} else {
376376
screen.getDiffDetails().setText("");
377377
}
@@ -395,7 +395,7 @@ public void mouseClicked(MouseEvent e) {
395395
int selectedRow = screen.getFileScanSummaryTable().getSelectedRow();
396396
if (selectedRow >= 0 && selectedRow < fileSummaries.size()) {
397397
ScanSummary selectedSummary = fileSummaries.get(selectedRow);
398-
screen.getScanSummaryDetails().setText(ReportUtils.formatSummary(selectedSummary));
398+
screen.getScanSummaryDetails().setText(ReportUtil.formatSummary(selectedSummary));
399399
} else {
400400
screen.getScanSummaryDetails().setText("");
401401
}
@@ -426,12 +426,12 @@ public void mouseClicked(MouseEvent e) {
426426
screen.getMaxHashExtractionFileSizeSlider().addChangeListener(l -> {
427427
long valueMegabytes = screen.getMaxHashExtractionFileSizeSlider().getValue();
428428
log.debug("Setting max hash extraction file size to {} MB", valueMegabytes);
429-
long valueBytes = ConversionUtils.megabytesToBytes(valueMegabytes);
429+
long valueBytes = ConversionUtil.megabytesToBytes(valueMegabytes);
430430

431431
// Set App config value to size in bytes
432432
if (AppConfig.setMaxHashExtractionFileSize(valueBytes)) {
433433
screen.getMaxHashExtractionFileSizeValueLabel().setText(valueMegabytes + " MB");
434-
maxFileSizeForHashExtraction = ConversionUtils.megabytesToBytes(valueMegabytes);
434+
maxFileSizeForHashExtraction = ConversionUtil.megabytesToBytes(valueMegabytes);
435435
} else {
436436
log.error("Failed to update max hash extraction file size in app config.");
437437
}
@@ -452,7 +452,7 @@ public void mouseClicked(MouseEvent e) {
452452
// If unchecked set the size to the current slider value
453453
long sliderValueMegabytes = screen.getMaxHashExtractionFileSizeSlider().getValue();
454454
log.debug("Setting max hash extraction file size to {} MB", sliderValueMegabytes);
455-
long sliderValueBytes = ConversionUtils.megabytesToBytes(sliderValueMegabytes);
455+
long sliderValueBytes = ConversionUtil.megabytesToBytes(sliderValueMegabytes);
456456
if (AppConfig.setMaxHashExtractionFileSize(sliderValueBytes)) {
457457
maxFileSizeForHashExtraction = sliderValueBytes;
458458
screen.getMaxHashExtractionFileSizeValueLabel().setText(sliderValueMegabytes + " MB");
@@ -469,7 +469,7 @@ protected void refreshView() {
469469
// Update UI components based on the current state
470470
screen.getScanButton().setText(scanRunning ? StringConstants.SCAN_STOP : StringConstants.SCAN_FULL);
471471

472-
String notifications = MonitoredDirectoryUtils
472+
String notifications = MonitoredDirectoryUtil
473473
.getMonitoredDirectoryNotificationMessage(allMonitoredDirectories);
474474
boolean hasNotifications = !notifications.isEmpty();
475475

@@ -515,7 +515,7 @@ public Component getListCellRendererComponent(JList<?> list, Object value, int i
515515
if (!dir.baselineEstablished()) {
516516
setForeground(Color.YELLOW);
517517
setToolTipText(StringConstants.TOOLTIP_BASELINE_NOT_ESTABLISHED);
518-
} else if (MonitoredDirectoryUtils.isScanOlderThanAWeek(dir)) {
518+
} else if (MonitoredDirectoryUtil.isScanOlderThanAWeek(dir)) {
519519
setForeground(Color.ORANGE);
520520
setToolTipText(StringConstants.TOOLTIP_OLD_SCAN);
521521
} else {
@@ -543,7 +543,7 @@ public Component getListCellRendererComponent(JList<?> list, Object value, int i
543543
diff.ifPresent(d -> {
544544
int choice = screen.showOptionDialog(
545545
JOptionPane.WARNING_MESSAGE,
546-
OSUtils.getQuarantineWarningMessage(),
546+
OSUtil.getQuarantineWarningMessage(),
547547
new String[] { StringConstants.GENERIC_YES, StringConstants.GENERIC_NO },
548548
StringConstants.GENERIC_NO);
549549
if (choice == 0) {
@@ -607,7 +607,7 @@ public Component getListCellRendererComponent(JList<?> list, Object value, int i
607607
screen.getMaxHashExtractionFileSizeSlider().setEnabled(true);
608608

609609
final int maxSliderValueMegabytes = Math
610-
.toIntExact(ConversionUtils.bytesToMegabytes(maxFileSizeForHashExtraction));
610+
.toIntExact(ConversionUtil.bytesToMegabytes(maxFileSizeForHashExtraction));
611611
screen.getMaxHashExtractionFileSizeSlider().setValue(maxSliderValueMegabytes);
612612
screen.getMaxHashExtractionFileSizeValueLabel().setText(maxSliderValueMegabytes + " MB");
613613
} else {
@@ -691,7 +691,7 @@ public void performStartScan(boolean singleDirectory) {
691691
log.debug(StringConstants.SCAN_START_ERROR, e);
692692
log.error(StringConstants.SCAN_START_ERROR + " {}", e.getMessage());
693693
SwingUtilities.invokeLater(() -> screen
694-
.showError(ErrorUtils.formatErrorMessage(StringConstants.SCAN_START_ERROR, e.getMessage())));
694+
.showError(ErrorUtil.formatErrorMessage(StringConstants.SCAN_START_ERROR, e.getMessage())));
695695
}
696696
}
697697

@@ -830,12 +830,12 @@ private void startPollingScanLiveFeed(boolean singleDirectory, List<MonitoredDir
830830
LiveFeedResponse liveFeed = scanService.getLiveFeed();
831831

832832
String currentLiveFeedText = screen.getLiveFeedText().getText();
833-
String newEntry = LiveFeedUtils.formatLiveFeedEntry(liveFeed.livefeed());
833+
String newEntry = LiveFeedUtil.formatLiveFeedEntry(liveFeed.livefeed());
834834
String updatedLiveFeedText = currentLiveFeedText + newEntry;
835835
screen.getLiveFeedText().setText(updatedLiveFeedText);
836836

837837
// Update the total difference count based on new warnings
838-
totalDiffCount.addAndGet(LiveFeedUtils.countWarnings(liveFeed.livefeed()));
838+
totalDiffCount.addAndGet(LiveFeedUtil.countWarnings(liveFeed.livefeed()));
839839
screen.getLiveFeedDiffCount().setText(StringConstants.SCAN_DIFFS_PREFIX + totalDiffCount);
840840

841841
// Update scanRunning state and refresh the UI if necessary
@@ -849,7 +849,7 @@ private void startPollingScanLiveFeed(boolean singleDirectory, List<MonitoredDir
849849

850850
liveFeed = scanService.getLiveFeed();
851851

852-
totalDiffCount.getAndAdd(LiveFeedUtils.countWarnings(liveFeed.livefeed()));
852+
totalDiffCount.getAndAdd(LiveFeedUtil.countWarnings(liveFeed.livefeed()));
853853
screen.getLiveFeedDiffCount().setText(StringConstants.SCAN_DIFFS_PREFIX + totalDiffCount);
854854

855855
onFinishScan(true, singleDirectory);

src/main/java/org/pwss/controller/LoginController.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
import org.pwss.navigation.NavigationEvents;
1212
import org.pwss.navigation.Screen;
1313
import org.pwss.service.AuthService;
14-
import org.pwss.utils.LoginUtils;
15-
import org.pwss.utils.StringConstants;
14+
import org.pwss.util.LoginUtil;
15+
import org.pwss.util.StringConstants;
1616
import org.pwss.view.screen.LoginScreen;
1717
import org.slf4j.LoggerFactory;
1818

@@ -180,10 +180,10 @@ private boolean validateInput() {
180180
String confirmPassword = screen.getConfirmPassword();
181181
String licenseKey = licenseKeySet ? LICENSE_KEY : screen.getLicenseKey();
182182

183-
LoginUtils.LoginValidationResult result = LoginUtils.validateInput(username, password, confirmPassword,
183+
LoginUtil.LoginValidationResult result = LoginUtil.validateInput(username, password, confirmPassword,
184184
licenseKey, createUserMode);
185185
if (!result.isValid()) {
186-
screen.showError(LoginUtils.formatErrors(result.errors()));
186+
screen.showError(LoginUtil.formatErrors(result.errors()));
187187
}
188188

189189
return result.isValid();

src/main/java/org/pwss/controller/NewDirectoryController.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
import org.pwss.navigation.NavigationEvents;
66
import org.pwss.navigation.Screen;
77
import org.pwss.service.MonitoredDirectoryService;
8-
import org.pwss.utils.OSUtils;
9-
import org.pwss.utils.StringConstants;
8+
import org.pwss.util.OSUtil;
9+
import org.pwss.util.StringConstants;
1010
import org.pwss.view.screen.NewDirectoryScreen;
1111

1212
/**
@@ -55,7 +55,7 @@ void refreshView() {
5555
screen.getCreateButton().setEnabled(selectedPath != null && !selectedPath.isEmpty());
5656

5757
// Additional check for Unix-based systems to disable creation for /dev and /proc paths
58-
if (OSUtils.isUnix() && selectedPath != null) {
58+
if (OSUtil.isUnix() && selectedPath != null) {
5959
if (selectedPath.startsWith("/dev") || selectedPath.startsWith("/proc")) {
6060
screen.getCreateButton().setEnabled(false);
6161
screen.showError("Cannot monitor directories under /dev or /proc on Unix-based systems.");

src/main/java/org/pwss/controller/ScanDetailsController.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
import org.pwss.service.FileService;
1616
import org.pwss.service.ScanService;
1717
import org.pwss.service.ScanSummaryService;
18-
import org.pwss.utils.OSUtils;
19-
import org.pwss.utils.ReportUtils;
20-
import org.pwss.utils.StringConstants;
18+
import org.pwss.util.OSUtil;
19+
import org.pwss.util.ReportUtil;
20+
import org.pwss.util.StringConstants;
2121
import org.pwss.view.screen.ScanDetailsScreen;
2222
import org.slf4j.LoggerFactory;
2323

@@ -114,7 +114,7 @@ void initListeners() {
114114
int selectedRow = screen.getScanSummaryTable().getSelectedRow();
115115
if (selectedRow >= 0 && selectedRow < scanSummaries.size()) {
116116
ScanSummary selectedSummary = scanSummaries.get(selectedRow);
117-
screen.getScanSummaryDetails().setText(ReportUtils.formatSummary(selectedSummary));
117+
screen.getScanSummaryDetails().setText(ReportUtil.formatSummary(selectedSummary));
118118
} else {
119119
screen.getScanSummaryDetails().setText("");
120120
screen.getDiffDetails().setText("");
@@ -125,7 +125,7 @@ void initListeners() {
125125
int selectedRow = screen.getDiffTable().getSelectedRow();
126126
if (selectedRow >= 0 && selectedRow < diffs.size()) {
127127
Diff selectedDiff = diffs.get(selectedRow);
128-
screen.getDiffDetails().setText(ReportUtils.formatDiff(selectedDiff));
128+
screen.getDiffDetails().setText(ReportUtil.formatDiff(selectedDiff));
129129
} else {
130130
screen.getDiffDetails().setText("");
131131
}
@@ -158,7 +158,7 @@ public void onCellButtonClicked(int row, int column) {
158158
diff.ifPresent(d -> {
159159
int choice = screen.showOptionDialog(
160160
JOptionPane.WARNING_MESSAGE,
161-
OSUtils.getQuarantineWarningMessage(),
161+
OSUtil.getQuarantineWarningMessage(),
162162
new String[] { StringConstants.GENERIC_YES, StringConstants.GENERIC_NO },
163163
StringConstants.GENERIC_NO);
164164
if (choice == 0) {

src/main/java/org/pwss/model/entity/MonitoredDirectory.java

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,51 @@
33
import java.util.Date;
44

55

6-
public record MonitoredDirectory(long id, String path, boolean isActive, Time addedAt, Date lastScanned, Notes notes,
7-
boolean baselineEstablished, boolean includeSubdirectories) {
8-
}
6+
/**
7+
* A record class representing a monitored directory.
8+
* This class stores information about directories that are being monitored,
9+
* including their ID, path, active status, timestamps, and other relevant details.
10+
*/
11+
public record MonitoredDirectory(
12+
/**
13+
* The unique identifier for this monitored directory.
14+
*/
15+
long id,
16+
17+
/**
18+
* The file system path of the monitored directory.
19+
*/
20+
String path,
21+
22+
/**
23+
* A flag indicating whether the directory is currently active (being monitored).
24+
*/
25+
boolean isActive,
26+
27+
/**
28+
* The time when this directory was added to monitoring.
29+
*/
30+
Time addedAt,
31+
32+
/**
33+
* The date and time when this directory was last scanned.
34+
*/
35+
Date lastScanned,
36+
37+
/**
38+
* Additional notes or comments about this monitored directory.
39+
*/
40+
Notes notes,
41+
42+
/**
43+
* A flag indicating whether a baseline has been established for this directory.
44+
* This might be used to determine if the initial state of the directory has been recorded.
45+
*/
46+
boolean baselineEstablished,
47+
48+
/**
49+
* A flag indicating whether subdirectories should also be monitored
50+
* when monitoring this directory.
51+
*/
52+
boolean includeSubdirectories) {
53+
}

src/main/java/org/pwss/model/table/MonitoredDirectoryTableModel.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
11
package org.pwss.model.table;
22

33
import java.util.Date;
4+
45
import java.util.List;
56
import java.util.Optional;
67
import javax.swing.table.AbstractTableModel;
78
import org.pwss.model.entity.MonitoredDirectory;
9+
import org.pwss.util.MonitoredDirectoryUtil;
810

911
public class MonitoredDirectoryTableModel extends AbstractTableModel {
1012
private final List<MonitoredDirectory> directories;
1113
private final String[] columnNames = {
12-
"\uD83D\uDCC1 Path", "\uD83D\uDCDD Note", "\uD83D\uDD59 Last Scanned", "\u2693 Baseline Established", "\uD83D\uDCC2 Include Subdirectories", "\uD83D\uDD0C Active"
14+
"\uD83D\uDCC1 Path", "\uD83D\uDCDD Note", "\uD83D\uDD59 Last Scanned", "\u2693 Baseline Established",
15+
"\uD83D\uDCC2 Include Subdirectories", "\uD83D\uDD0C Active"
1316
};
1417

1518
public MonitoredDirectoryTableModel(List<MonitoredDirectory> directories) {
16-
this.directories = directories;
19+
this.directories = MonitoredDirectoryUtil.filterMonitoredDirectoriesOnConfirmedPath(directories);
1720
}
1821

1922
@Override
@@ -58,8 +61,9 @@ public Object getValueAt(int rowIndex, int columnIndex) {
5861
* Get the MonitoredDirectory object at the specified row index.
5962
*
6063
* @param rowIndex the index of the row in the table.
61-
* @return an Optional containing the MonitoredDirectory object at the specified row index,
62-
* or an empty Optional if the index is out of bounds.
64+
* @return an Optional containing the MonitoredDirectory object at the specified
65+
* row index,
66+
* or an empty Optional if the index is out of bounds.
6367
*/
6468
public Optional<MonitoredDirectory> getDirectoryAt(int rowIndex) {
6569
if (rowIndex >= 0 && rowIndex < directories.size()) {
@@ -68,4 +72,3 @@ public Optional<MonitoredDirectory> getDirectoryAt(int rowIndex) {
6872
return Optional.empty();
6973
}
7074
}
71-

src/main/java/org/pwss/model/table/QuarantineTableModel.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import java.util.Optional;
55
import javax.swing.table.AbstractTableModel;
66
import org.pwss.model.entity.QuarantineMetadata;
7-
import org.pwss.utils.OSUtils;
7+
import org.pwss.util.OSUtil;
88

99
/**
1010
* Table model for displaying quarantine metadata in a table.
@@ -41,7 +41,7 @@ public Object getValueAt(int rowIndex, int columnIndex) {
4141
QuarantineMetadata metadata = data.get(rowIndex);
4242
return switch (columnIndex) {
4343
case 0 -> metadata.fileId();
44-
case 1 -> OSUtils.formatQuarantinePath(metadata.keyName());
44+
case 1 -> OSUtil.formatQuarantinePath(metadata.keyName());
4545
case 2 -> "\uD83D\uDCE4";
4646
default -> null;
4747
};

src/main/java/org/pwss/utils/AppTheme.java renamed to src/main/java/org/pwss/util/AppTheme.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package org.pwss.utils;
1+
package org.pwss.util;
22

33
/**
44
* Enum representing different application themes.

src/main/java/org/pwss/utils/ConversionUtils.java renamed to src/main/java/org/pwss/util/ConversionUtil.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package org.pwss.utils;
1+
package org.pwss.util;
22

33
/**
44
* Utility class providing methods to convert between different units of data
@@ -13,7 +13,7 @@
1313
* comprehension or processing.
1414
* </p>
1515
*/
16-
public class ConversionUtils {
16+
public class ConversionUtil {
1717
private static final long MEGABYTE = 1024L * 1024L;
1818
private static final long GIGABYTE = MEGABYTE * 1024L;
1919

0 commit comments

Comments
 (0)