]> git.argeo.org Git - gpl/argeo-slc.git/blob - server/org.argeo.slc.ria/src/argeo-ria-lib/slc/class/org/argeo/slc/ria/execution/BatchEntrySpec.js
Rename
[gpl/argeo-slc.git] / server / org.argeo.slc.ria / src / argeo-ria-lib / slc / class / org / argeo / slc / ria / execution / BatchEntrySpec.js
1 /**
2 * Data model for an entry of the Batch list : original Spec, flow and module, and currently computed value.
3 */
4 qx.Class.define("org.argeo.slc.ria.execution.BatchEntrySpec", {
5 extend : org.argeo.slc.ria.execution.Spec,
6
7 properties : {
8 /**
9 * Reference module
10 */
11 module :{},
12 /**
13 * Reference flow
14 */
15 flow : {},
16 /**
17 * Original Spec (values shall stay untouched).
18 */
19 originalSpec : {}
20 },
21
22 /**
23 * Instance of BatchEntrySpec
24 * @param module {org.argeo.slc.ria.execution.Module} Reference module
25 * @param flow {org.argeo.slc.ria.execution.Flow} Reference flow
26 */
27 construct : function(module, flow){
28 this.base(arguments);
29 this.setModule(module);
30 this.setFlow(flow);
31 this.setOriginalSpec(flow.getExecutionSpec());
32 this.setName(flow.getExecutionSpec().getName());
33 this.fetchInstanceValues();
34 },
35
36 members : {
37 /**
38 * Create a label to display in the batch list.
39 * @return {String} The label
40 */
41 getLabel : function(){
42 var label = this.getModule().getName();
43 label += "/" + this.getModule().getVersion();
44 label += "/" + this.getFlow().getName();
45 return label;
46 },
47
48 toXml : function(){
49 var valuesXml = '';
50 var values = this.getValues();
51 for(var key in values){
52 if(values[key].getValue() == null && !values[key].isFrozen() && !values[key].isHidden()){
53 throw new Error("Cannot send empty values! (Parameter "+key+")");
54 }
55 valuesXml += values[key].toValueXml();
56 }
57 var execFlowDescXML = '<slc:execution-flow-descriptor name="'+this.getFlow().getName()+'" executionSpec="'+this.getName()+'">';
58 if(this.getFlow().getDescription()!=""){
59 execFlowDescXML += '<slc:description>'+this.getFlow().getDescription()+'</slc:description>';
60 }
61 execFlowDescXML += '<slc:values>'+valuesXml+'</slc:values></slc:execution-flow-descriptor>';
62
63 var execSpecDescXML = this.getOriginalSpec().toXml();
64
65 var moduleData = this.getModule().moduleDataToXml();
66
67 return '<slc:realized-flow>'+moduleData + execFlowDescXML + execSpecDescXML +'</slc:realized-flow>';
68
69 },
70
71 /**
72 * Fetch the Spec Values with the Flow Values to make the current instance value
73 */
74 fetchInstanceValues : function(){
75 var specValues = this.getOriginalSpec().getValues();
76 var flow = this.getFlow();
77 var instanceValues = {};
78 for(var key in specValues){
79 var flowValue = flow.getValue(
80 key,
81 specValues[key].getSpecType(),
82 specValues[key].getSpecSubType()
83 );
84 var instValue = specValues[key].clone();
85 if(flowValue){
86 instValue.setValue(flowValue);
87 }
88 instanceValues[key] = instValue;
89 }
90 this.setValues(instanceValues);
91 }
92 }
93 });