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 +++++++++++++++++++++++ src/test/resources/searchPropDesc.js | 10 ++++++++++ 2 files changed, 33 insertions(+) create mode 100644 src/test/resources/searchPropDesc.js 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; diff --git a/src/test/resources/searchPropDesc.js b/src/test/resources/searchPropDesc.js new file mode 100644 index 0000000..8bb7d17 --- /dev/null +++ b/src/test/resources/searchPropDesc.js @@ -0,0 +1,10 @@ +importClass(com.c2kernel.lookup.DomainPath); +importClass(com.c2kernel.process.Gateway); +importClass(com.c2kernel.utils.Logger); + +function searchType(factoryname) { + var desc = proxy.getProxy(new DomainPath("/desc/dev/"+factoryname)); + var propDesc = desc.getViewpoint("PropertyDescription", "last").getOutcome().getData(); + var results = lookup.search(new DomainPath("/"), Gateway.getMarshaller().unmarshall(propDesc)); + while(results.hasMoreElements()) Logger.msg(proxy.getProxy(results.nextElement()).getName()); +} -- cgit v1.2.3