Merge pull request #7654 from eugene7646/profiles_NPE_840_DEVELOP

NPE when cancelling profiles creation (8404)
This commit is contained in:
eugene7646 2022-08-11 11:42:07 -04:00 committed by GitHub
commit 4105a2097f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 39 additions and 8 deletions

View File

@ -202,13 +202,22 @@ public final class IngestProfiles {
* @param selectedProfile * @param selectedProfile
*/ */
synchronized static void deleteProfile(IngestProfile selectedProfile) { synchronized static void deleteProfile(IngestProfile selectedProfile) {
deleteProfile(selectedProfile.getName());
}
/**
* Deletes all of the files which are currently storing a profile.
*
* @param profile name
*/
synchronized static void deleteProfile(String profileName) {
try { try {
File rootSettingsFile = getRootSettingsFile(selectedProfile.getName()); File rootSettingsFile = getRootSettingsFile(profileName);
File settingsDirectory = getSettingsDirectory(selectedProfile.getName()); File settingsDirectory = getSettingsDirectory(profileName);
Files.deleteIfExists(rootSettingsFile.toPath()); Files.deleteIfExists(rootSettingsFile.toPath());
FileUtils.deleteDirectory(settingsDirectory); FileUtils.deleteDirectory(settingsDirectory);
} catch (IOException ex) { } catch (IOException ex) {
logger.log(Level.WARNING, "Error deleting directory for profile " + selectedProfile.getName(), ex); logger.log(Level.WARNING, "Error deleting directory for profile " + profileName, ex);
} }
} }

View File

@ -86,6 +86,14 @@ class ProfilePanel extends IngestModuleGlobalSettingsPanel {
return ingestSettingsPanel.getSettings(); return ingestSettingsPanel.getSettings();
} }
String getIngestProfileName() {
if (profile != null) {
return profile.getName();
} else {
return NEW_PROFILE_NAME;
}
}
/** /**
* This method is called from within the constructor to initialize the form. * This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always * WARNING: Do NOT modify this code. The content of this method is always

View File

@ -391,7 +391,7 @@ class ProfileSettingsPanel extends IngestModuleGlobalSettingsPanel implements Op
*/ */
private void doProfileDialog(IngestProfile selectedProfile) { private void doProfileDialog(IngestProfile selectedProfile) {
// Create a files set defintion panel. // Create a files set defintion panel.
final AdvancedConfigurationDialog dialog = new AdvancedConfigurationDialog(true); final AdvancedConfigurationDialog dialog = new AdvancedConfigurationDialog(true);
this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
//start wait cursor for ingest job settings construction //start wait cursor for ingest job settings construction
if (selectedProfile != null) { if (selectedProfile != null) {
@ -430,6 +430,15 @@ class ProfileSettingsPanel extends IngestModuleGlobalSettingsPanel implements Op
} }
panel.saveSettings(); panel.saveSettings();
load(); load();
} else if (option == JOptionPane.CANCEL_OPTION) {
if (selectedProfile == null) {
// for new profiles, if user canlessed a profile create/edit then delete the temp empty profile that was created.
// Otherwise it will remain in "config/ModuleSettings/IngestSettings" and then will get loaded
// next time we open ProfilePanel(), causing an NPE (JIRA-8404). This only needs to be done when creating
// a new ingest profile. If user cancelled editing of an existing profile, then we should not delete
// that profile.
IngestProfile.deleteProfile(panel.getIngestProfileName());
}
} }
} }
@ -479,7 +488,12 @@ class ProfileSettingsPanel extends IngestModuleGlobalSettingsPanel implements Op
for (FilesSet fSet : FilesSetsManager.getStandardFileIngestFilters()) { for (FilesSet fSet : FilesSetsManager.getStandardFileIngestFilters()) {
fileIngestFilters.put(fSet.getName(), fSet); fileIngestFilters.put(fSet.getName(), fSet);
} }
filterDescArea.setText(fileIngestFilters.get(selectedProfile.getFileIngestFilter()).getDescription()); String selectedFilter = selectedProfile.getFileIngestFilter();
if (selectedFilter == null) {
filterDescArea.setText(NbBundle.getMessage(ProfileSettingsPanel.class, "ProfileSettingsPanel.messages.filterLoadFailed"));
} else {
filterDescArea.setText(fileIngestFilters.get(selectedFilter).getDescription());
}
} catch (FilesSetsManager.FilesSetsManagerException ex) { } catch (FilesSetsManager.FilesSetsManagerException ex) {
filterDescArea.setText(NbBundle.getMessage(ProfileSettingsPanel.class, "ProfileSettingsPanel.messages.filterLoadFailed")); filterDescArea.setText(NbBundle.getMessage(ProfileSettingsPanel.class, "ProfileSettingsPanel.messages.filterLoadFailed"));
} }