Add pre-populated keyword search lists

This commit is contained in:
Dick Fickling 2012-02-23 17:40:17 -05:00
parent 3fc87577f5
commit 1956cf2982
2 changed files with 79 additions and 29 deletions

View File

@ -190,22 +190,38 @@ class KeywordSearchEditListPanel extends javax.swing.JPanel implements ListSelec
void initButtons() {
//initialize buttons
boolean listSet = (currentKeywordList != null);
List<String> locked = new ArrayList<String>();
if (ingestRunning) {
locked = KeywordSearchIngestService.getDefault().getKeywordLists();
// Certain buttons will be disabled if no list is set
boolean listSet = currentKeywordList != null;
// Certain buttons will be disabled if ingest is ongoing
boolean ingestOngoing = this.ingestRunning;
// Certain buttons will be disabled if ingest is ongoing on this list
boolean inIngest = false;
// Certain buttons will be disabled if the selected list is locked
boolean locked = false;
// Certain buttons will be disabled if no keywords are set
boolean noKeywords = getAllKeywords().isEmpty();
List<String> ingestLists = new ArrayList<String>();
if (ingestOngoing) {
ingestLists = KeywordSearchIngestService.getDefault().getKeywordLists();
}
boolean currentUnlocked = !locked.contains(currentKeywordList);
addWordButton.setEnabled(listSet && currentUnlocked);
addWordField.setEnabled(listSet && currentUnlocked);
chRegex.setEnabled(listSet && currentUnlocked);
useForIngestCheckbox.setEnabled(listSet && currentUnlocked);
inIngest = ingestLists.contains(currentKeywordList);
KeywordSearchListsXML loader = KeywordSearchListsXML.getCurrent();
KeywordSearchList currentList = loader.getList(currentKeywordList);
if(currentList != null){
locked = currentList.isLocked();
}
addWordButton.setEnabled(listSet && (!ingestOngoing || !inIngest) && !locked);
addWordField.setEnabled(listSet && (!ingestOngoing || !inIngest) && !locked);
chRegex.setEnabled(listSet && (!ingestOngoing || !inIngest) && !locked);
useForIngestCheckbox.setEnabled(listSet && (!ingestOngoing || !inIngest));
saveListButton.setEnabled(listSet);
exportButton.setEnabled(listSet);
deleteListButton.setEnabled(listSet && currentUnlocked);
deleteWordButton.setEnabled(listSet && currentUnlocked);
deleteListButton.setEnabled(listSet && (!ingestOngoing || !inIngest) && !locked);
deleteWordButton.setEnabled(listSet && (!ingestOngoing || !inIngest) && !locked);
if (getAllKeywords().isEmpty()) {
if (noKeywords) {
saveListButton.setEnabled(false);
exportButton.setEnabled(false);
deleteWordButton.setEnabled(false);
@ -613,7 +629,7 @@ class KeywordSearchEditListPanel extends javax.swing.JPanel implements ListSelec
KeywordSearchUtil.DIALOG_MESSAGE_TYPE.WARN);*/
boolean save = true;
if (save) {
loader.addList(currentKeywordList, newKeywords, newIngest);
loader.addList(currentKeywordList, newKeywords, newIngest, oldList.isLocked());
}
}
}

View File

@ -98,6 +98,30 @@ public class KeywordSearchListsXML {
dateFormatter = new SimpleDateFormat(DATE_FORMAT);
}
private void prepopulateLists() {
//phone number
List<Keyword> phones = new ArrayList<Keyword>();
phones.add(new Keyword("\\d\\d\\d[\\.-]\\d\\d\\d[\\.-]\\d\\d\\d\\d", false));
phones.add(new Keyword("\\d{8,10}", false));
phones.add(new Keyword("phone|fax", false));
//IP address
List<Keyword> ips = new ArrayList<Keyword>();
ips.add(new Keyword("(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])", false));
//email
List<Keyword> emails = new ArrayList<Keyword>();
emails.add(new Keyword("[e\\-]{0,2}mail", false));
emails.add(new Keyword("[A-Z0-9._%-]+@[A-Z0-9.-]+\\.[A-Z]{2,4}", false));
//URL
List<Keyword> urls = new ArrayList<Keyword>();
urls.add(new Keyword("ftp|sftp|ssh|http|https|www", false));
addList("Phone Numbers", phones, true, true);
addList("IP Addresses", ips, true, true);
addList("Email Addresses", emails, true, true);
addList("URLs", urls, true, true);
}
/**
* get instance for managing the current keyword list of the application
*/
@ -120,6 +144,7 @@ public class KeywordSearchListsXML {
boolean created = false;
theLists.clear();
prepopulateLists();
if (!this.listFileExists()) {
//create new if it doesn't exist
save();
@ -185,16 +210,16 @@ public class KeywordSearchListsXML {
* @param useForIngest should this list be used for ingest
* @return true if old list was replaced
*/
boolean addList(String name, List<Keyword> newList, boolean useForIngest) {
boolean addList(String name, List<Keyword> newList, boolean useForIngest, boolean locked) {
boolean replaced = false;
KeywordSearchList curList = getList(name);
final Date now = new Date();
if (curList == null) {
theLists.put(name, new KeywordSearchList(name, now, now, useForIngest, newList));
theLists.put(name, new KeywordSearchList(name, now, now, useForIngest, newList, locked));
save();
changeSupport.firePropertyChange(ListsEvt.LIST_ADDED.toString(), null, name);
} else {
theLists.put(name, new KeywordSearchList(name, curList.getDateCreated(), now, useForIngest, newList));
theLists.put(name, new KeywordSearchList(name, curList.getDateCreated(), now, useForIngest, newList, locked));
save();
replaced = true;
changeSupport.firePropertyChange(ListsEvt.LIST_UPDATED.toString(), null, name);
@ -203,22 +228,17 @@ public class KeywordSearchListsXML {
return replaced;
}
boolean addList(String name, List<Keyword> newList, boolean useForIngest) {
KeywordSearchList curList = getList(name);
if (curList == null) {
return addList(name, newList, false, false);
} else {
return addList(name, newList, curList.getUseForIngest(), false);
}
}
boolean addList(String name, List<Keyword> newList) {
boolean replaced = false;
KeywordSearchList curList = getList(name);
final Date now = new Date();
if (curList == null) {
theLists.put(name, new KeywordSearchList(name, now, now, false, newList));
save();
changeSupport.firePropertyChange(ListsEvt.LIST_ADDED.toString(), null, name);
} else {
theLists.put(name, new KeywordSearchList(name, curList.getDateCreated(), now, curList.getUseForIngest(), newList));
save();
replaced = true;
changeSupport.firePropertyChange(ListsEvt.LIST_UPDATED.toString(), null, name);
}
return replaced;
return addList(name, newList, false);
}
@ -284,6 +304,9 @@ public class KeywordSearchListsXML {
doc.appendChild(rootEl);
for (String listName : theLists.keySet()) {
if(listName.equals("IP Addresses") || listName.equals("Email Addresses") ||
listName.equals("Phone Numbers") || listName.equals("URLs"))
break;
KeywordSearchList list = theLists.get(listName);
String created = dateFormatter.format(list.getDateCreated());
String modified = dateFormatter.format(list.getDateModified());
@ -438,15 +461,22 @@ class KeywordSearchList {
private Date modified;
private Boolean useForIngest;
private List<Keyword> keywords;
private Boolean locked;
KeywordSearchList(String name, Date created, Date modified, Boolean useForIngest, List<Keyword> keywords) {
KeywordSearchList(String name, Date created, Date modified, Boolean useForIngest, List<Keyword> keywords, boolean locked) {
this.name = name;
this.created = created;
this.modified = modified;
this.useForIngest = useForIngest;
this.keywords = keywords;
this.locked = locked;
}
KeywordSearchList(String name, Date created, Date modified, Boolean useForIngest, List<Keyword> keywords) {
this(name, created, modified, useForIngest, keywords, false);
}
@Override
public boolean equals(Object obj) {
if (obj == null) {
@ -491,4 +521,8 @@ class KeywordSearchList {
List<Keyword> getKeywords() {
return keywords;
}
Boolean isLocked() {
return locked;
}
}