From 5c55fdeec103cd854d41333f987e6709ef022467 Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Wed, 6 Aug 2008 18:38:32 +0000 Subject: Client: Tweaked the way filter invalidation works Previously, an item has to match all filters, which would mean that having equals and inequals in the same subscription would mess things up. Now, to pass filter invalidation, an item has to match at least one equal (if there are any equals) and all inequals (if there are any inequals). --- .../fourisland/instadisc/Item/WellFormedItem.java | 56 +++++++++++++++++----- .../fourisland/instadisc/ManageFiltersForm.form | 3 -- .../fourisland/instadisc/ManageFiltersForm.java | 3 ++ 3 files changed, 46 insertions(+), 16 deletions(-) diff --git a/client/trunk/src/com/fourisland/instadisc/Item/WellFormedItem.java b/client/trunk/src/com/fourisland/instadisc/Item/WellFormedItem.java index 9b54f96..91d95aa 100644 --- a/client/trunk/src/com/fourisland/instadisc/Item/WellFormedItem.java +++ b/client/trunk/src/com/fourisland/instadisc/Item/WellFormedItem.java @@ -40,22 +40,54 @@ public class WellFormedItem { return good; } + private boolean checkForEqualFilters() { + boolean good = true; + + Filter[] filters = Wrapper.getAllFilter(); + int i = 0; + for (i = 0; i < filters.length; i++) { + if (filters[i].getSubscription().equals(aThis.headerMap.get("Subscription"))) { + if (filters[i].getEqual()) { + good = (good ? aThis.headerMap.get(filters[i].getField()).contains(filters[i].getTest()) : false); + } + } + } + + return good; + } + private boolean checkForFilterInvalidation() { boolean good = true; - + good = (good ? checkForEqualFilters() : false); + good = (good ? checkForInequalFilters() : false); + + if (!good) { + XmlRpc xmlrpc = new XmlRpc("deleteItem"); + xmlrpc.addParam(Integer.decode(aThis.headerMap.get("ID"))); + xmlrpc.execute(); + } + + return good; + } + + private boolean checkForInequalFilters() { + boolean good = true; + boolean start = false; + Filter[] filters = Wrapper.getAllFilter(); int i = 0; for (i = 0; i < filters.length; i++) { if (filters[i].getSubscription().equals(aThis.headerMap.get("Subscription"))) { - if (filters[i].getEqual()) - { - good = (good ? (!aThis.headerMap.get(filters[i].getField()).equals(filters[i].getTest())) : false); - } else { - good = (good ? (aThis.headerMap.get(filters[i].getField()).equals(filters[i].getTest())) : false); + if (!filters[i].getEqual()) { + if (!start) { + good = false; + start = true; + } + good = (good ? true : !aThis.headerMap.get(filters[i].getField()).contains(filters[i].getTest())); } } } - + return good; } @@ -107,9 +139,8 @@ public class WellFormedItem { private boolean checkForRequiredHeader(String string) { return checkForRequiredHeader(aThis.headerMap, string); } - - public static boolean checkForRequiredHeader(HashMap headerMap, String string) - { + + public static boolean checkForRequiredHeader(HashMap headerMap, String string) { return headerMap.containsKey(string); } @@ -117,7 +148,7 @@ public class WellFormedItem { try { URL url = new URL(aThis.headerMap.get("URL")); URI subUrl = new URI(aThis.headerMap.get("Subscription")); - + return url.getHost().equals(subUrl.getHost()); } catch (URISyntaxException ex) { Logger.getLogger(WellFormedItem.class.getName()).log(Level.SEVERE, null, ex); @@ -130,8 +161,7 @@ public class WellFormedItem { private boolean checkForSubscription() { boolean good = Wrapper.existsSubscription(aThis.headerMap.get("Subscription")); - if (!good) - { + if (!good) { SubscriptionFile.deleteSubscription(Wrapper.getSubscription(aThis.headerMap.get("Subscription")), false); } return good; diff --git a/client/trunk/src/com/fourisland/instadisc/ManageFiltersForm.form b/client/trunk/src/com/fourisland/instadisc/ManageFiltersForm.form index 3f1e603..fcf64df 100644 --- a/client/trunk/src/com/fourisland/instadisc/ManageFiltersForm.form +++ b/client/trunk/src/com/fourisland/instadisc/ManageFiltersForm.form @@ -88,9 +88,6 @@ - - - diff --git a/client/trunk/src/com/fourisland/instadisc/ManageFiltersForm.java b/client/trunk/src/com/fourisland/instadisc/ManageFiltersForm.java index cd4426e..620665d 100644 --- a/client/trunk/src/com/fourisland/instadisc/ManageFiltersForm.java +++ b/client/trunk/src/com/fourisland/instadisc/ManageFiltersForm.java @@ -162,6 +162,7 @@ public class ManageFiltersForm extends javax.swing.JDialog { }// //GEN-END:initComponents private void jList1ValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_jList1ValueChanged refreshFilterPane(); + jList2.setSelectedIndex(0); }//GEN-LAST:event_jList1ValueChanged private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed @@ -173,9 +174,11 @@ public class ManageFiltersForm extends javax.swing.JDialog { try { if (filter.getID() == -65536) { jButton1.setText("Add"); + jButton1.setEnabled(true); jButton2.setEnabled(false); } else { jButton1.setText("Edit"); + jButton1.setEnabled(true); jButton2.setEnabled(true); } } catch (Exception ex) { -- cgit 1.4.1