diff options
| author | Andrew Branson <andrew.branson@cern.ch> | 2013-12-12 14:13:36 +0100 |
|---|---|---|
| committer | Andrew Branson <andrew.branson@cern.ch> | 2013-12-12 14:13:36 +0100 |
| commit | 428d828ca640d1348979f9982d1c0bc0a489a3b4 (patch) | |
| tree | a40b0f8fa46942f5e9d4c805a4df724ee5a5aa6b /src/main/java/com/c2kernel/lifecycle/instance/predefined/WriteProperty.java | |
| parent | d5d65f58e69424d898f88e8304a49f147d4036f6 (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/lifecycle/instance/predefined/WriteProperty.java')
| -rw-r--r-- | src/main/java/com/c2kernel/lifecycle/instance/predefined/WriteProperty.java | 41 |
1 files changed, 25 insertions, 16 deletions
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/predefined/WriteProperty.java b/src/main/java/com/c2kernel/lifecycle/instance/predefined/WriteProperty.java index 1eef4f5..abb0e95 100644 --- a/src/main/java/com/c2kernel/lifecycle/instance/predefined/WriteProperty.java +++ b/src/main/java/com/c2kernel/lifecycle/instance/predefined/WriteProperty.java @@ -12,7 +12,10 @@ package com.c2kernel.lifecycle.instance.predefined;
import com.c2kernel.common.InvalidDataException;
+import com.c2kernel.common.ObjectNotFoundException;
import com.c2kernel.lookup.AgentPath;
+import com.c2kernel.persistency.ClusterStorage;
+import com.c2kernel.persistency.ClusterStorageException;
import com.c2kernel.process.Gateway;
import com.c2kernel.property.Property;
import com.c2kernel.utils.Logger;
@@ -38,24 +41,30 @@ public class WriteProperty extends PredefinedStep int transitionID, String requestData) throws InvalidDataException {
Logger.msg(1, "WriteProperty::request() - Starting.");
-
String[] params = getDataList(requestData);
+
if (params.length != 2)
- throw new InvalidDataException("WriteProperty::request() - need 2 params - name and value", "");
- try
- {
-
- Logger.msg(5, "WriteProperty::request() - name:" + params[0] +" val:"+params[1]);
-
- Property newProp = new Property(params[0], params[1]);
- Gateway.getStorage().put(itemSysKey, newProp, null );
- }
- catch( Exception ex )
- {
- Logger.error("WriteProperty::request() - during unmarshall.");
- Logger.error(ex);
- throw new InvalidDataException(ex.toString(), "");
- }
+ throw new InvalidDataException("WriteProperty usage: [ name, value ]", "");
+
+ Logger.msg(5, "WriteProperty::request() - name:" + params[0] +" val:"+params[1]);
+
+ String name = params[0];
+ String newValue = params[1];
+
+ Property prop;
+
+ try {
+ prop = (Property)Gateway.getStorage().get(itemSysKey, ClusterStorage.PROPERTY+"/"+name, null);
+ if (!prop.isMutable() && !newValue.equals(prop.getValue()))
+ throw new InvalidDataException("Property '"+name+"' is not mutable.", "");
+ prop.setValue(newValue);
+ Gateway.getStorage().put(itemSysKey, prop, null);
+ } catch (ObjectNotFoundException e) {
+ throw new InvalidDataException("WriteProperty: Property '"+name+"' not found.", "");
+ } catch (ClusterStorageException e) {
+ Logger.error(e);
+ throw new InvalidDataException("Storage error. See logs.", "");
+ }
Logger.msg(1, "WriteProperty::request() - DONE.");
return requestData;
|
