/**
* Data model for an entry of the Batch list : original Spec, flow and module, and currently computed value.
*/
qx.Class.define("org.argeo.slc.ria.execution.BatchEntrySpec", {
extend : org.argeo.slc.ria.execution.Spec,
properties : {
/**
* Reference module
*/
module :{},
/**
* Reference flow
*/
flow : {},
/**
* Original Spec (values shall stay untouched).
*/
originalSpec : {}
},
/**
* Instance of BatchEntrySpec
* @param module {org.argeo.slc.ria.execution.Module} Reference module
* @param flow {org.argeo.slc.ria.execution.Flow} Reference flow
*/
construct : function(module, flow, xmlElement){
this.base(arguments);
if(xmlElement){
this.fromXml(xmlElement);
}else{
this.setModule(module);
this.setFlow(flow);
this.setOriginalSpec(flow.getExecutionSpec());
this.setName(flow.getExecutionSpec().getName());
}
this.fetchInstanceValues();
},
members : {
/**
* Create a label to display in the batch list.
* @return {String} The label
*/
getLabel : function(){
var label = this.getModule().getName();
label += "/" + this.getModule().getVersion();
label += "/" + this.getFlow().getName();
return label;
},
toXml : function(){
var valuesXml = '';
var values = this.getValues();
for(var key in values){
if(values[key].getValue() == null && !values[key].isFrozen() && !values[key].isHidden()){
throw new Error("Cannot send empty values! (Parameter "+key+")");
}
valuesXml += values[key].toValueXml();
}
var execFlowDescXML = '';
if(this.getFlow().getDescription()!=""){
execFlowDescXML += ''+this.getFlow().getDescription()+'';
}
execFlowDescXML += ''+valuesXml+'';
var execSpecDescXML = this.getOriginalSpec().toXml();
var moduleData = this.getModule().moduleDataToXml();
return ''+moduleData + execFlowDescXML + execSpecDescXML +'';
},
fromXml : function(xmlElement){
var parser = org.argeo.ria.util.Element;
var simpleModule = new org.argeo.slc.ria.execution.Module();
simpleModule.setName(parser.getSingleNodeText(xmlElement, "slc:module-name"));
simpleModule.setVersion(parser.getSingleNodeText(xmlElement, "slc:module-version"));
this.setModule(simpleModule);
var spec = new org.argeo.slc.ria.execution.Spec();
var flow = new org.argeo.slc.ria.execution.Flow();
spec.setXmlNode(parser.selectSingleNode(xmlElement, "slc:default-execution-spec"));
flow.setXmlNode(parser.selectSingleNode(xmlElement, "slc:execution-flow-descriptor"));
flow.setExecutionSpec(spec);
this.setOriginalSpec(spec);
this.setFlow(flow);
this.setName(spec.getName());
},
/**
* Fetch the Spec Values with the Flow Values to make the current instance value
*/
fetchInstanceValues : function(){
var specValues = this.getOriginalSpec().getValues();
var flow = this.getFlow();
var instanceValues = {};
for(var key in specValues){
var flowValue = flow.getValue(
key,
specValues[key].getSpecType(),
specValues[key].getSpecSubType()
);
var instValue = specValues[key].clone();
if(flowValue){
instValue.setValue(flowValue);
}
instanceValues[key] = instValue;
}
this.setValues(instanceValues);
}
}
});