summaryrefslogtreecommitdiffstats
path: root/base/server/cmscore/src/com/netscape/cmscore/dbs
diff options
context:
space:
mode:
authorEndi S. Dewata <edewata@redhat.com>2014-03-17 11:40:42 -0400
committerEndi S. Dewata <edewata@redhat.com>2014-03-19 16:19:04 -0400
commitfbd1b96a35946b7ebf36afea3f3a2a50dcbf193f (patch)
treea8de6caa0be49b39321c546e02b35b6710299f1f /base/server/cmscore/src/com/netscape/cmscore/dbs
parent4c02156a7cc336afcb2cb46f77d98097eb83cda1 (diff)
downloadpki-fbd1b96a35946b7ebf36afea3f3a2a50dcbf193f.tar.gz
pki-fbd1b96a35946b7ebf36afea3f3a2a50dcbf193f.tar.xz
pki-fbd1b96a35946b7ebf36afea3f3a2a50dcbf193f.zip
Added search filter for TPS resources.
The TPS resources have been modified to accept a basic search filter for find operation. For resources based on LDAP database, the filtering is done using LDAP filter. For other resources, the filtering is done using string comparison. For now the filter is will only be matched against entry IDs. In the future the filter may be expanded to support other entry attributes. The CLI has been updated accordingly. The total attribute in DataCollection was changed from Integer into int because the total size of the collection cannot be null. The PKIException constructors have been consolidated into a single actual constructor. The other constructors have been modified to call the actual constructor with some default values. Ticket #847
Diffstat (limited to 'base/server/cmscore/src/com/netscape/cmscore/dbs')
-rw-r--r--base/server/cmscore/src/com/netscape/cmscore/dbs/Database.java15
-rw-r--r--base/server/cmscore/src/com/netscape/cmscore/dbs/LDAPDatabase.java11
2 files changed, 18 insertions, 8 deletions
diff --git a/base/server/cmscore/src/com/netscape/cmscore/dbs/Database.java b/base/server/cmscore/src/com/netscape/cmscore/dbs/Database.java
index 3df2d5919..f8c55204b 100644
--- a/base/server/cmscore/src/com/netscape/cmscore/dbs/Database.java
+++ b/base/server/cmscore/src/com/netscape/cmscore/dbs/Database.java
@@ -18,6 +18,7 @@
package com.netscape.cmscore.dbs;
+import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.Map;
@@ -43,8 +44,18 @@ public class Database<E> {
CMS.debug("Initializing " + name + " database");
}
- public Collection<E> getRecords() throws Exception {
- return records.values();
+ /**
+ * Find records matching filter
+ */
+ public Collection<E> findRecords(String filter) throws Exception {
+
+ Collection<E> results = new ArrayList<E>();
+ for (String id : records.keySet()) {
+ if (filter != null && !id.contains(filter)) continue;
+ results.add(records.get(id));
+ }
+
+ return results;
}
public E getRecord(String id) throws Exception {
diff --git a/base/server/cmscore/src/com/netscape/cmscore/dbs/LDAPDatabase.java b/base/server/cmscore/src/com/netscape/cmscore/dbs/LDAPDatabase.java
index f6ded787b..4c3ac8dfb 100644
--- a/base/server/cmscore/src/com/netscape/cmscore/dbs/LDAPDatabase.java
+++ b/base/server/cmscore/src/com/netscape/cmscore/dbs/LDAPDatabase.java
@@ -98,14 +98,14 @@ public abstract class LDAPDatabase<E extends IDBObj> extends Database<E> {
public abstract String createFilter(String filter);
@Override
- public Collection<E> getRecords() throws Exception {
- CMS.debug("LDAPDatabase: getRecords()");
+ public Collection<E> findRecords(String filter) throws Exception {
+ CMS.debug("LDAPDatabase: findRecords()");
try (IDBSSession session = dbSubsystem.createSession()) {
Collection<E> list = new ArrayList<E>();
-
- CMS.debug("LDAPDatabase: searching " + baseDN);
- IDBSearchResults results = session.search(baseDN, createFilter(null));
+ filter = createFilter(filter);
+ CMS.debug("LDAPDatabase: searching " + baseDN + " with filter " + filter);
+ IDBSearchResults results = session.search(baseDN, filter);
while (results.hasMoreElements()) {
@SuppressWarnings("unchecked")
@@ -167,5 +167,4 @@ public abstract class LDAPDatabase<E extends IDBObj> extends Database<E> {
session.delete(dn);
}
}
-
}