summaryrefslogtreecommitdiff
path: root/src/main/java/com/c2kernel/lookup/LegacyLDAPPropertyManager.java
diff options
context:
space:
mode:
authorAndrew Branson <andrew.branson@cern.ch>2012-05-30 08:37:45 +0200
committerAndrew Branson <andrew.branson@cern.ch>2012-05-30 08:37:45 +0200
commitb086f57f56bf0eb9dab9cf321a0f69aaaae84347 (patch)
tree8e6e26e8b7eed6abad7a17b093bdbb55c5e6b1ba /src/main/java/com/c2kernel/lookup/LegacyLDAPPropertyManager.java
parent22088ae8d2d5ff390518dbe1c4372325ffb3a647 (diff)
Initial Maven Conversion
Diffstat (limited to 'src/main/java/com/c2kernel/lookup/LegacyLDAPPropertyManager.java')
-rw-r--r--src/main/java/com/c2kernel/lookup/LegacyLDAPPropertyManager.java75
1 files changed, 75 insertions, 0 deletions
diff --git a/src/main/java/com/c2kernel/lookup/LegacyLDAPPropertyManager.java b/src/main/java/com/c2kernel/lookup/LegacyLDAPPropertyManager.java
new file mode 100644
index 0000000..638c694
--- /dev/null
+++ b/src/main/java/com/c2kernel/lookup/LegacyLDAPPropertyManager.java
@@ -0,0 +1,75 @@
+package com.c2kernel.lookup;
+
+import com.c2kernel.common.ObjectCannotBeUpdated;
+import com.c2kernel.common.ObjectNotFoundException;
+import com.c2kernel.property.Property;
+import com.c2kernel.utils.Logger;
+import com.novell.ldap.LDAPAttribute;
+import com.novell.ldap.LDAPAttributeSet;
+import com.novell.ldap.LDAPDN;
+import com.novell.ldap.LDAPEntry;
+import com.novell.ldap.LDAPException;
+
+public class LegacyLDAPPropertyManager extends LDAPPropertyManager {
+
+ public LegacyLDAPPropertyManager(LDAPLookup ldap) {
+ super(ldap);
+ }
+
+ @Override
+ public void deleteProperty(EntityPath thisEntity, String name) throws ObjectNotFoundException, ObjectCannotBeUpdated {
+ try {
+ LDAPLookupUtils.delete(ldap.getConnection(), "cn="+name+","+thisEntity.getFullDN());
+ } catch (LDAPException ex) {
+ Logger.error("Error deleting prop "+name+" from "+thisEntity.getSysKey());
+ Logger.error(ex);
+ }
+ }
+
+ @Override
+ public String[] getPropertyNames(EntityPath thisEntity) throws ObjectNotFoundException {
+ String props[]= LDAPLookupUtils.getChildrenDNs(ldap.getConnection(), thisEntity.getFullDN(), "objectclass=cristalproperty");
+ String names[] = new String[props.length];
+ for (int i=0; i<props.length;i++)
+ names[i] = new String(LDAPDN.explodeDN(props[i],true)[0]);
+ return names;
+ }
+
+ @Override
+ public String getPropertyValue(EntityPath thisEntity, String name) throws ObjectNotFoundException {
+ LDAPEntry anEntry = LDAPLookupUtils.getEntry(ldap.getConnection(),"cn="+name+","+thisEntity.getFullDN());
+ if (anEntry==null)
+ throw new ObjectNotFoundException("LDAPLookup: Property "+name+" not found in "+thisEntity.getSysKey(), "");
+ return LDAPLookupUtils.getFirstAttributeValue(anEntry,"propval");
+ }
+
+ @Override
+ public boolean hasProperties(EntityPath thisEntity) throws ObjectNotFoundException {
+ return LDAPLookupUtils.hasChildren(ldap.getConnection(), thisEntity.getFullDN(), "objectclass=cristalproperty" );
+ }
+
+ @Override
+ public void setProperty(EntityPath thisEntity, Property prop) throws ObjectNotFoundException, ObjectCannotBeUpdated {
+ try {
+ LDAPEntry anEntry = LDAPLookupUtils.getEntry(ldap.getConnection(),"cn="+prop.getName()+","+thisEntity.getFullDN());
+ String currentVal = LDAPLookupUtils.getFirstAttributeValue(anEntry,"propval");
+ if (currentVal == null || !currentVal.equals(prop.getValue()) )
+ //change the propvalue if the prop.getValue() is not the same value in LDAP
+ LDAPLookupUtils.setAttributeValue(ldap.getConnection(), anEntry,"propval",prop.getValue());
+
+ } catch (ObjectNotFoundException ex) {
+ LDAPAttributeSet attrSet = new LDAPAttributeSet();
+ attrSet.add(new LDAPAttribute("objectclass","cristalproperty"));
+ attrSet.add(new LDAPAttribute("cn",prop.getName()));
+ if (prop.getValue()!=null && prop.getValue().length()!=0)
+ attrSet.add(new LDAPAttribute("propval",prop.getValue()));
+ LDAPEntry newEntry = new LDAPEntry("cn="+prop.getName()+","+thisEntity.getFullDN(),attrSet);
+ try {
+ LDAPLookupUtils.addEntry(ldap.getConnection(),newEntry);
+ } catch (Exception e) {
+ Logger.error(e);
+ throw new ObjectCannotBeUpdated(e.getMessage(), "");
+ }
+ }
+ }
+}