diff options
| author | Andrew Branson <andrew.branson@cern.ch> | 2013-07-29 12:16:32 +0200 |
|---|---|---|
| committer | Andrew Branson <andrew.branson@cern.ch> | 2013-07-29 12:16:32 +0200 |
| commit | a7e90e86fa912ccb438d74f7def87e1bded9b7c4 (patch) | |
| tree | f6253cf1c66a86580e61f32dd5e6309c4e178404 | |
| parent | 2f54a2ed3e37cbb6af7a14829fe3fb17502cb6ab (diff) | |
new lookup search method that uses a PropertyDescriptionList to find
instances of an item description. Closes #114
| -rw-r--r-- | src/main/java/com/c2kernel/lookup/LDAPLookup.java | 23 | ||||
| -rw-r--r-- | src/test/resources/searchPropDesc.js | 10 |
2 files changed, 33 insertions, 0 deletions
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()); +} |
