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() { void initButtons() {
//initialize buttons //initialize buttons
boolean listSet = (currentKeywordList != null); // Certain buttons will be disabled if no list is set
List<String> locked = new ArrayList<String>(); boolean listSet = currentKeywordList != null;
if (ingestRunning) { // Certain buttons will be disabled if ingest is ongoing
locked = KeywordSearchIngestService.getDefault().getKeywordLists(); 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); inIngest = ingestLists.contains(currentKeywordList);
addWordButton.setEnabled(listSet && currentUnlocked);
addWordField.setEnabled(listSet && currentUnlocked); KeywordSearchListsXML loader = KeywordSearchListsXML.getCurrent();
chRegex.setEnabled(listSet && currentUnlocked); KeywordSearchList currentList = loader.getList(currentKeywordList);
useForIngestCheckbox.setEnabled(listSet && currentUnlocked); 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); saveListButton.setEnabled(listSet);
exportButton.setEnabled(listSet); exportButton.setEnabled(listSet);
deleteListButton.setEnabled(listSet && currentUnlocked); deleteListButton.setEnabled(listSet && (!ingestOngoing || !inIngest) && !locked);
deleteWordButton.setEnabled(listSet && currentUnlocked); deleteWordButton.setEnabled(listSet && (!ingestOngoing || !inIngest) && !locked);
if (getAllKeywords().isEmpty()) { if (noKeywords) {
saveListButton.setEnabled(false); saveListButton.setEnabled(false);
exportButton.setEnabled(false); exportButton.setEnabled(false);
deleteWordButton.setEnabled(false); deleteWordButton.setEnabled(false);
@ -613,7 +629,7 @@ class KeywordSearchEditListPanel extends javax.swing.JPanel implements ListSelec
KeywordSearchUtil.DIALOG_MESSAGE_TYPE.WARN);*/ KeywordSearchUtil.DIALOG_MESSAGE_TYPE.WARN);*/
boolean save = true; boolean save = true;
if (save) { 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); 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 * get instance for managing the current keyword list of the application
*/ */
@ -120,6 +144,7 @@ public class KeywordSearchListsXML {
boolean created = false; boolean created = false;
theLists.clear(); theLists.clear();
prepopulateLists();
if (!this.listFileExists()) { if (!this.listFileExists()) {
//create new if it doesn't exist //create new if it doesn't exist
save(); save();
@ -185,16 +210,16 @@ public class KeywordSearchListsXML {
* @param useForIngest should this list be used for ingest * @param useForIngest should this list be used for ingest
* @return true if old list was replaced * @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; boolean replaced = false;
KeywordSearchList curList = getList(name); KeywordSearchList curList = getList(name);
final Date now = new Date(); final Date now = new Date();
if (curList == null) { 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(); save();
changeSupport.firePropertyChange(ListsEvt.LIST_ADDED.toString(), null, name); changeSupport.firePropertyChange(ListsEvt.LIST_ADDED.toString(), null, name);
} else { } 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(); save();
replaced = true; replaced = true;
changeSupport.firePropertyChange(ListsEvt.LIST_UPDATED.toString(), null, name); changeSupport.firePropertyChange(ListsEvt.LIST_UPDATED.toString(), null, name);
@ -203,22 +228,17 @@ public class KeywordSearchListsXML {
return replaced; 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 addList(String name, List<Keyword> newList) {
boolean replaced = false; return addList(name, newList, 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;
} }
@ -284,6 +304,9 @@ public class KeywordSearchListsXML {
doc.appendChild(rootEl); doc.appendChild(rootEl);
for (String listName : theLists.keySet()) { 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); KeywordSearchList list = theLists.get(listName);
String created = dateFormatter.format(list.getDateCreated()); String created = dateFormatter.format(list.getDateCreated());
String modified = dateFormatter.format(list.getDateModified()); String modified = dateFormatter.format(list.getDateModified());
@ -438,15 +461,22 @@ class KeywordSearchList {
private Date modified; private Date modified;
private Boolean useForIngest; private Boolean useForIngest;
private List<Keyword> keywords; 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.name = name;
this.created = created; this.created = created;
this.modified = modified; this.modified = modified;
this.useForIngest = useForIngest; this.useForIngest = useForIngest;
this.keywords = keywords; 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 @Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
if (obj == null) { if (obj == null) {
@ -491,4 +521,8 @@ class KeywordSearchList {
List<Keyword> getKeywords() { List<Keyword> getKeywords() {
return keywords; return keywords;
} }
Boolean isLocked() {
return locked;
}
} }