]> 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/Message.js
slc namespace en realized-flows
[gpl/argeo-slc.git] / server / org.argeo.slc.ria / src / 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.setBatchEntrySpecs([]);
25 this.setAttributes({});
26 },
27 properties : {
28 /**
29 * The unique id identifying the message
30 */
31 uuid : {
32 check : "String"
33 },
34 /**
35 * Execution status
36 */
37 status : {
38 check : "String",
39 init : "STARTED"
40 },
41 /**
42 * Execution type
43 */
44 type : {
45 check : "String",
46 init : "slcAnt"
47 },
48 /**
49 * Execution Host
50 */
51 host : {
52 check : "String",
53 init : "localhost"
54 },
55 /**
56 * Execution User
57 */
58 user : {
59 check : "String",
60 init : "user"
61 },
62 /**
63 * Date of the message. now() by default.
64 */
65 date : {
66 check : "String",
67 init : new Date().toString()
68 },
69 /**
70 * Additionnal attributes as map of key/values
71 */
72 attributes : {
73 check : "Map"
74 },
75 batchEntrySpecs : {
76 check : "Array"
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('<slc:realized-flows>');
111 for(var i=0;i<flows.length;i++){
112 builder.add(flows[i].toXml());
113 }
114 builder.add('</slc: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 });