summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Branson <andrew.branson@cern.ch>2014-09-30 12:28:42 +0200
committerAndrew Branson <andrew.branson@cern.ch>2014-09-30 12:28:42 +0200
commit8307f06a338b1f73f47e83b94aa64c2241e9baa7 (patch)
treee31851213922c3241bcc075d68a092ab12d50c76
parent25e0517ffc1db85e2f89318abbec9b5202bb43c0 (diff)
Initial properties can be supplied as a marshalled PropertyArrayList as
an optional additional parameter to CreateItem/AgentFromDescription. Each property supplied must be defined in the property description.
-rw-r--r--src/main/java/com/c2kernel/lifecycle/instance/predefined/agent/CreateAgentFromDescription.java7
-rw-r--r--src/main/java/com/c2kernel/lifecycle/instance/predefined/item/CreateItemFromDescription.java22
-rw-r--r--src/main/java/com/c2kernel/property/PropertyDescriptionList.java36
3 files changed, 51 insertions, 14 deletions
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/predefined/agent/CreateAgentFromDescription.java b/src/main/java/com/c2kernel/lifecycle/instance/predefined/agent/CreateAgentFromDescription.java
index 088bee1..780c82e 100644
--- a/src/main/java/com/c2kernel/lifecycle/instance/predefined/agent/CreateAgentFromDescription.java
+++ b/src/main/java/com/c2kernel/lifecycle/instance/predefined/agent/CreateAgentFromDescription.java
@@ -22,6 +22,7 @@ import com.c2kernel.lookup.AgentPath;
import com.c2kernel.lookup.ItemPath;
import com.c2kernel.lookup.RolePath;
import com.c2kernel.process.Gateway;
+import com.c2kernel.property.PropertyArrayList;
import com.c2kernel.utils.Logger;
/**************************************************************************
@@ -48,7 +49,9 @@ public class CreateAgentFromDescription extends CreateItemFromDescription
String[] input = getDataList(requestData);
String newName = input[0];
-
+ PropertyArrayList initProps =
+ input.length > 1?getInitProperties(input[1]):new PropertyArrayList();
+
Logger.msg(1, "CreateAgentFromDescription::request() - Starting.");
try {
@@ -87,7 +90,7 @@ public class CreateAgentFromDescription extends CreateItemFromDescription
newAgent.initialise(
agent.getSystemKey(),
- Gateway.getMarshaller().marshall(getNewProperties(itemPath, newName, agent)),
+ Gateway.getMarshaller().marshall(getNewProperties(itemPath, initProps, newName, agent)),
Gateway.getMarshaller().marshall(getNewWorkflow(itemPath)),
Gateway.getMarshaller().marshall(getNewCollections(itemPath))
);
diff --git a/src/main/java/com/c2kernel/lifecycle/instance/predefined/item/CreateItemFromDescription.java b/src/main/java/com/c2kernel/lifecycle/instance/predefined/item/CreateItemFromDescription.java
index eea3976..d9c65d5 100644
--- a/src/main/java/com/c2kernel/lifecycle/instance/predefined/item/CreateItemFromDescription.java
+++ b/src/main/java/com/c2kernel/lifecycle/instance/predefined/item/CreateItemFromDescription.java
@@ -11,8 +11,13 @@
package com.c2kernel.lifecycle.instance.predefined.item;
+import java.io.IOException;
import java.util.ArrayList;
+import org.exolab.castor.mapping.MappingException;
+import org.exolab.castor.xml.MarshalException;
+import org.exolab.castor.xml.ValidationException;
+
import com.c2kernel.collection.Collection;
import com.c2kernel.collection.CollectionArrayList;
import com.c2kernel.collection.CollectionDescription;
@@ -59,6 +64,8 @@ public class CreateItemFromDescription extends PredefinedStep
String[] input = getDataList(requestData);
String newName = input[0];
String domPath = input[1];
+ PropertyArrayList initProps =
+ input.length > 2?getInitProperties(input[2]):new PropertyArrayList();
Logger.msg(1, "CreateItemFromDescription - Starting.");
@@ -94,7 +101,7 @@ public class CreateItemFromDescription extends PredefinedStep
newItem.initialise(
agent.getSystemKey(),
- Gateway.getMarshaller().marshall(getNewProperties(itemPath, newName, agent)),
+ Gateway.getMarshaller().marshall(getNewProperties(itemPath, initProps, newName, agent)),
Gateway.getMarshaller().marshall(getNewWorkflow(itemPath)),
Gateway.getMarshaller().marshall(getNewCollections(itemPath))
);
@@ -111,10 +118,19 @@ public class CreateItemFromDescription extends PredefinedStep
}
- protected PropertyArrayList getNewProperties(ItemPath itemPath, String newName, AgentPath agent) throws ObjectNotFoundException {
+ protected PropertyArrayList getInitProperties(String input) throws InvalidDataException {
+ try {
+ return (PropertyArrayList)Gateway.getMarshaller().unmarshall(input);
+ } catch (Exception e) {
+ Logger.error(e);
+ throw new InvalidDataException("Initial property parameter was not a marshalled PropertyArrayList: "+input, "");
+ }
+ }
+
+ protected PropertyArrayList getNewProperties(ItemPath itemPath, PropertyArrayList initProps, String newName, AgentPath agent) throws ObjectNotFoundException, InvalidDataException {
// copy properties -- intend to create from propdesc
PropertyDescriptionList pdList = PropertyUtility.getPropertyDescriptionOutcome(itemPath);
- PropertyArrayList props = pdList.instanciate();
+ PropertyArrayList props = pdList.instantiate(initProps);
// set Name prop or create if not present
boolean foundName = false;
for (Property prop : props.list) {
diff --git a/src/main/java/com/c2kernel/property/PropertyDescriptionList.java b/src/main/java/com/c2kernel/property/PropertyDescriptionList.java
index ed93008..96344a0 100644
--- a/src/main/java/com/c2kernel/property/PropertyDescriptionList.java
+++ b/src/main/java/com/c2kernel/property/PropertyDescriptionList.java
@@ -10,7 +10,9 @@
package com.c2kernel.property;
import java.util.ArrayList;
+import java.util.HashMap;
+import com.c2kernel.common.InvalidDataException;
import com.c2kernel.utils.CastorArrayList;
public class PropertyDescriptionList extends CastorArrayList<PropertyDescription>
@@ -27,8 +29,7 @@ public class PropertyDescriptionList extends CastorArrayList<PropertyDescription
public String getClassProps() {
StringBuffer props = new StringBuffer();
- for (Object name : list) {
- PropertyDescription element = (PropertyDescription)name;
+ for (PropertyDescription element : list) {
if (element.getIsClassIdentifier()) {
if (props.length()>0)
props.append(",");
@@ -39,8 +40,7 @@ public class PropertyDescriptionList extends CastorArrayList<PropertyDescription
}
public boolean setDefaultValue(String name, String value) {
- for (Object name2 : list) {
- PropertyDescription element = (PropertyDescription)name2;
+ for (PropertyDescription element : list) {
if (element.getName().equals(name)) {
element.setDefaultValue(value);
return true;
@@ -49,16 +49,34 @@ public class PropertyDescriptionList extends CastorArrayList<PropertyDescription
return false;
}
- public PropertyArrayList instanciate() {
- PropertyArrayList props = new PropertyArrayList();
+ public boolean definesProperty(String name) {
+ for (PropertyDescription element : list) {
+ if (element.getName().equals(name))
+ return true;
+ }
+ return false;
+ }
+
+ public PropertyArrayList instantiate(PropertyArrayList initProps) throws InvalidDataException {
+ // check that supplied init properties exist in desc list
+ HashMap<String, String> validatedInitProps = new HashMap<String, String>();
+ for (Property initProp : initProps.list) {
+ if (!definesProperty(initProp.getName()))
+ throw new InvalidDataException("Property "+initProp.getName()+" has not been declared in the property descriptions", "");
+ else
+ validatedInitProps.put(initProp.getName(), initProp.getValue());
+ }
+
+ PropertyArrayList propInst = new PropertyArrayList();
for (int i = 0; i < list.size(); i++) {
PropertyDescription pd = list.get(i);
String propName = pd.getName();
String propVal = pd.getDefaultValue();
+ if (validatedInitProps.containsKey(propName))
+ propVal = validatedInitProps.get(propName);
boolean isMutable = pd.getIsMutable();
- props.list.add( new Property(propName, propVal, isMutable));
+ propInst.list.add( new Property(propName, propVal, isMutable));
}
- return props;
+ return propInst;
}
-
}