]> git.argeo.org Git - gpl/argeo-slc.git/blob - org.argeo.slc.webapp/src/main/webapp/argeo-ria-lib/slc/class/org/argeo/slc/ria/execution/Message.js
Last XML updates
[gpl/argeo-slc.git] / org.argeo.slc.webapp / src / main / webapp / argeo-ria-lib / slc / class / org / argeo / slc / ria / execution / Message.js
1 /**
2 * A generic JMS slcExecution message encapsulator.
3 */
4 qx.Class.define("org.argeo.slc.ria.execution.Message", {
5 extend : qx.core.Object,
6 /**
7 * New instance
8 * @param uuid {String} The Uuid of the message. If none is passed, one is generated.
9 */
10 construct : function(uuid){
11 this.base(arguments);
12 if(uuid){
13 this.setUuid(uuid);
14 }else{
15 var s = [];
16 var itoh = '0123456789ABCDEF';
17 for (var i = 0; i <36; i++) s[i] = Math.floor(Math.random()*0x10);
18 s[14] = 4; // Set 4 high bits of time_high field to version
19 s[19] = (s[19] & 0x3) | 0x8; // Specify 2 high bits of clock sequence
20 for (var i = 0; i <36; i++) s[i] = itoh[s[i]];
21 s[8] = s[13] = s[18] = s[23] = '-';
22 this.setUuid(s.join('').toLowerCase());
23 }
24 this.setAttributes({});
25 },
26 properties : {
27 /**
28 * The unique id identifying the message
29 */
30 uuid : {
31 check : "String"
32 },
33 /**
34 * Execution status
35 */
36 status : {
37 check : "String",
38 init : "STARTED"
39 },
40 /**
41 * Execution type
42 */
43 type : {
44 check : "String",
45 init : "slcAnt"
46 },
47 /**
48 * Execution Host
49 */
50 host : {
51 check : "String",
52 init : "localhost"
53 },
54 /**
55 * Execution User
56 */
57 user : {
58 check : "String",
59 init : "user"
60 },
61 /**
62 * Date of the message. now() by default.
63 */
64 date : {
65 check : "String",
66 init : new Date().toString()
67 },
68 /**
69 * Additionnal attributes as map of key/values
70 */
71 attributes : {
72 check : "Map"
73 },
74 batchEntrySpecs : {
75 check : "Array",
76 init : []
77 }
78 },
79 members : {
80
81 /**
82 * Add a free attribute to the message
83 * @param attName {String} Name
84 * @param attValue {String} Value
85 */
86 addAttribute: function(attName, attValue){
87 var attr = this.getAttributes();
88 attr[attName] = attValue;
89 this.setAttributes(attr);
90 },
91
92 addBatchEntrySpec : function(entrySpec){
93 this.getBatchEntrySpecs().push(entrySpec);
94 },
95
96 /**
97 * Build the xml formatted message body to send
98 *
99 * @return {String} The message content as Xml
100 */
101 toXml : function (){
102 var builder = new qx.util.StringBuilder();
103 builder.add('<slc:slc-execution xmlns:slc="http://argeo.org/projects/slc/schemas" uuid="'+this.getUuid()+'">');
104 builder.add('<slc:status>'+this.getStatus()+'</slc:status>');
105 builder.add('<slc:type>'+this.getType()+'</slc:type>');
106 builder.add('<slc:host>'+this.getHost()+'</slc:host>');
107 builder.add('<slc:user>'+this.getUser()+'</slc:user>');
108 var flows = this.getBatchEntrySpecs();
109 if(flows.length){
110 builder.add('<realized-flows>');
111 for(var i=0;i<flows.length;i++){
112 builder.add(flows[i].toXml());
113 }
114 builder.add('</realized-flows>');
115 }
116 var attr = this.getAttributes();
117 if(qx.lang.Object.getLength(attr)){
118 builder.add('<slc:attributes>');
119 for(var key in attr){
120 builder.add('<slc:attribute name="'+key+'">'+attr[key]+'</slc:attribute>');
121 }
122 builder.add('</slc:attributes>');
123 }
124 builder.add('</slc:slc-execution>');
125 return builder.get();
126 },
127
128 /**
129 * Parse an XML answer and fill the object with it.
130 * @param slcExecXml {String} An slcExecMessage mapped in XML.
131 */
132 fromXml : function(slcExecXml){
133 var NSMap = {slc:"http://argeo.org/projects/slc/schemas"};
134 this.setStatus(org.argeo.ria.util.Element.getSingleNodeText(slcExecXml, "slc:status", NSMap));
135 this.setType(org.argeo.ria.util.Element.getSingleNodeText(slcExecXml, "slc:type", NSMap));
136 this.setHost(org.argeo.ria.util.Element.getSingleNodeText(slcExecXml, "slc:host", NSMap));
137 this.setUser(org.argeo.ria.util.Element.getSingleNodeText(slcExecXml, "slc:user", NSMap));
138 var attributes = org.argeo.ria.util.Element.selectNodes(slcExecXml, "slc:attribute", NSMap);
139 for(var i=0;i<attributes.length;i++){
140 this.addAttribute(attribute.getAttribute("name"), attribute.firstChild);
141 }
142 var stepsDates = org.argeo.ria.util.Element.selectNodes(slcExecXml, "slc:steps/slc:slc-execution-step/slc:begin", NSMap);
143 if(stepsDates.length){
144 this.setDate(org.argeo.ria.util.Element.getSingleNodeText(stepsDates[stepsDates.length-1], ".", NSMap));
145 }
146 }
147 }
148 });