From a7e90e86fa912ccb438d74f7def87e1bded9b7c4 Mon Sep 17 00:00:00 2001 From: Andrew Branson Date: Mon, 29 Jul 2013 12:16:32 +0200 Subject: new lookup search method that uses a PropertyDescriptionList to find instances of an item description. Closes #114 --- src/main/java/com/c2kernel/lookup/LDAPLookup.java | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'src/main/java/com/c2kernel/lookup') diff --git a/src/main/java/com/c2kernel/lookup/LDAPLookup.java b/src/main/java/com/c2kernel/lookup/LDAPLookup.java index 72a847d..996ca0e 100644 --- a/src/main/java/com/c2kernel/lookup/LDAPLookup.java +++ b/src/main/java/com/c2kernel/lookup/LDAPLookup.java @@ -15,6 +15,8 @@ import com.c2kernel.entity.agent.ActiveEntity; import com.c2kernel.entity.proxy.EntityProxyManager; import com.c2kernel.entity.proxy.ProxyMessage; import com.c2kernel.process.Gateway; +import com.c2kernel.property.PropertyDescription; +import com.c2kernel.property.PropertyDescriptionList; import com.c2kernel.utils.Logger; import com.c2kernel.utils.Resource; import com.novell.ldap.LDAPAttributeSet; @@ -337,6 +339,27 @@ public class LDAPLookup searchCons.setDereference(LDAPSearchConstraints.DEREF_SEARCHING); return search(start.getFullDN(),LDAPConnection.SCOPE_SUB,"cristalprop="+LDAPLookupUtils.escapeSearchFilter(val),searchCons); } + + public LDAPPathSet search(Path start, PropertyDescriptionList props) { + StringBuffer query = new StringBuffer(); + int propCount = 0; + for (PropertyDescription propDesc: props.list) { + if (propDesc.getIsClassIdentifier()) { + String thisProp = LDAPLookupUtils.escapeSearchFilter(propDesc.getName()+(":")+propDesc.getDefaultValue()); + query.append("(cristalprop=").append(thisProp).append(")"); + propCount++; + } + } + LDAPSearchConstraints searchCons = new LDAPSearchConstraints(); + searchCons.setBatchSize(0); + searchCons.setDereference(LDAPSearchConstraints.DEREF_SEARCHING); + if (propCount == 0) + return search(start.getFullDN(),LDAPConnection.SCOPE_SUB,"objectClass=cristalentity",searchCons); + else if (propCount == 1) + return search(start.getFullDN(),LDAPConnection.SCOPE_SUB,query.toString(),searchCons); + else + return search(start.getFullDN(),LDAPConnection.SCOPE_SUB,"(&"+query.toString()+")",searchCons); + } public LDAPPathSet searchType(Path start, Path type) { return null; -- cgit v1.2.3