summaryrefslogtreecommitdiff
path: root/src/main/java/com/c2kernel/lookup/LDAPPropertyManager.java
diff options
context:
space:
mode:
authorAndrew Branson <andrew.branson@cern.ch>2013-12-12 14:13:36 +0100
committerAndrew Branson <andrew.branson@cern.ch>2013-12-12 14:13:36 +0100
commit428d828ca640d1348979f9982d1c0bc0a489a3b4 (patch)
treea40b0f8fa46942f5e9d4c805a4df724ee5a5aa6b /src/main/java/com/c2kernel/lookup/LDAPPropertyManager.java
parentd5d65f58e69424d898f88e8304a49f147d4036f6 (diff)
Properties preserve and respect the PropertyDescription 'isMutable'
property. This setting prevents the WriteProperty predefined step from changing the property value when isMutable is false. WriteProperty also requires the selected property to already exist - they should be created either during Item instantiation or using AddC2KObject. LDAPPropertyManager prepends the Property name in its entries with ! if they are non mutable. Various places around the kernel that create properties now set the mutable field. Fixes #150
Diffstat (limited to 'src/main/java/com/c2kernel/lookup/LDAPPropertyManager.java')
-rw-r--r--src/main/java/com/c2kernel/lookup/LDAPPropertyManager.java52
1 files changed, 36 insertions, 16 deletions
diff --git a/src/main/java/com/c2kernel/lookup/LDAPPropertyManager.java b/src/main/java/com/c2kernel/lookup/LDAPPropertyManager.java
index 57ed17d..fcf1ef8 100644
--- a/src/main/java/com/c2kernel/lookup/LDAPPropertyManager.java
+++ b/src/main/java/com/c2kernel/lookup/LDAPPropertyManager.java
@@ -51,7 +51,9 @@ public class LDAPPropertyManager {
LDAPAttribute props = entityEntry.getAttribute("cristalprop");
for (Enumeration<?> e = props.getStringValues(); e.hasMoreElements();) {
String thisProp = (String)e.nextElement();
- propbag.add(thisProp.substring(0, thisProp.indexOf(':')));
+ String thisName = thisProp.substring(0, thisProp.indexOf(':'));
+ if (thisName.startsWith("!") && thisName.length()>1) thisName = thisName.substring(1);
+ propbag.add(thisName);
}
String[] retArr = new String[props.size()];
@@ -61,12 +63,12 @@ public class LDAPPropertyManager {
/**
* @param thisEntity - EntityPath of the subject entity
* @param propName - the name of the property to retrieve
- * @return String the property value
+ * @return The Property object
* @throws ObjectNotFoundException
*/
- public String getPropertyValue(EntityPath thisEntity, String name) throws ObjectNotFoundException {
+ public Property getProperty(EntityPath thisEntity, String name) throws ObjectNotFoundException {
LDAPEntry entityEntry = LDAPLookupUtils.getEntry(ldap.getConnection(), thisEntity.getFullDN());
- return getPropertyAttr(entityEntry, name);
+ return getProperty(entityEntry, name);
}
/**
@@ -77,9 +79,13 @@ public class LDAPPropertyManager {
*/
public void deleteProperty(EntityPath thisEntity, String name) throws ObjectNotFoundException, ObjectCannotBeUpdated {
LDAPEntry entityEntry = LDAPLookupUtils.getEntry(ldap.getConnection(), thisEntity.getFullDN());
- String propVal = getPropertyAttr(entityEntry, name);
+ Property prop = getProperty(entityEntry, name);
Logger.msg(6, "LDAPLookupUtils.deleteProperty("+name+") - Deleting property");
- LDAPLookupUtils.removeAttributeValue(ldap.getConnection(), entityEntry, "cristalprop", name+":"+propVal);
+ LDAPLookupUtils.removeAttributeValue(ldap.getConnection(), entityEntry, "cristalprop", getPropertyAttrValue(prop));
+ }
+
+ private static String getPropertyAttrValue(Property prop) {
+ return (prop.isMutable()?"":"!")+prop.getName()+":"+prop.getValue();
}
/**
@@ -91,28 +97,42 @@ public class LDAPPropertyManager {
public void setProperty(EntityPath thisEntity, Property prop) throws ObjectNotFoundException, ObjectCannotBeUpdated {
LDAPEntry entityEntry = LDAPLookupUtils.getEntry(ldap.getConnection(), thisEntity.getFullDN());
try {
- String propVal = getPropertyAttr(entityEntry, prop.getName());
- Logger.msg(6, "LDAPLookupUtils.setProperty("+prop.getName()+") - Removing old value '"+propVal+"'");
- LDAPLookupUtils.removeAttributeValue(ldap.getConnection(), entityEntry, "cristalprop", prop.getName()+":"+propVal);
+ Property oldProp = getProperty(entityEntry, prop.getName());
+ Logger.msg(6, "LDAPLookupUtils.setProperty("+prop.getName()+") - Removing old value '"+oldProp.getValue()+"'");
+ LDAPLookupUtils.removeAttributeValue(ldap.getConnection(), entityEntry, "cristalprop", getPropertyAttrValue(oldProp));
} catch (ObjectNotFoundException ex) {
Logger.msg(6, "LDAPLookupUtils.setProperty("+prop.getName()+") - creating new property.");
}
Logger.msg(6, "LDAPLookupUtils.setProperty("+prop.getName()+") - setting to '"+prop.getValue()+"'");
- LDAPLookupUtils.addAttributeValue(ldap.getConnection(), entityEntry, "cristalprop", prop.getName()+":"+prop.getValue());
+ LDAPLookupUtils.addAttributeValue(ldap.getConnection(), entityEntry, "cristalprop", getPropertyAttrValue(prop));
}
- private static String getPropertyAttr(LDAPEntry myEntry, String propName) throws ObjectNotFoundException {
+ public static Property getProperty(LDAPEntry myEntry, String propName) throws ObjectNotFoundException {
// delete existing props
LDAPAttribute props = myEntry.getAttribute("cristalprop");
if (props == null)
throw new ObjectNotFoundException("Property "+propName+" does not exist", "");
String propPrefix = propName+":";
- for (Enumeration<?> e = props.getStringValues(); e.hasMoreElements();) {
- String val = (String)e.nextElement();
- if (val.toLowerCase().startsWith(propPrefix.toLowerCase()))
- return val.substring(propPrefix.length());
+ String roPropPrefix = "!"+propPrefix;
+ String val = null, name = null; boolean mutable = false;
+ for (Enumeration<?> e = props.getStringValues(); name==null && e.hasMoreElements();) {
+ String attrVal = (String)e.nextElement();
+ if (attrVal.toLowerCase().startsWith(propPrefix.toLowerCase())) {
+ name = attrVal.substring(0, propPrefix.length()-1);
+ val = attrVal.substring(propPrefix.length());
+ mutable = true; break;
+ }
+
+ if (attrVal.toLowerCase().startsWith(roPropPrefix.toLowerCase())) {
+ name = attrVal.substring(1, roPropPrefix.length()-1);
+ val = attrVal.substring(roPropPrefix.length());
+ mutable = false; break;
+ }
}
- throw new ObjectNotFoundException("Property "+propName+" does not exist", "");
+ if (name == null)
+ throw new ObjectNotFoundException("Property "+propName+" does not exist", "");
+ Logger.msg(6, "Loaded "+(mutable?"":"Non-")+"Mutable Property: "+name+"="+val);
+ return new Property(name, val, mutable);
}
}