]> git.argeo.org Git - gpl/argeo-slc.git/blob - server/org.argeo.slc.ria/src/argeo-ria-lib/slc/class/org/argeo/slc/ria/SlcApi.js
Forgotten log
[gpl/argeo-slc.git] / server / org.argeo.slc.ria / src / argeo-ria-lib / slc / class / org / argeo / slc / ria / SlcApi.js
1 /**
2 * SLC API Client implementation :
3 * This class encapsulate the various SLC services available. It just creates the Request object
4 * and return them, it does not execute them.
5 * Available services are :
6 * + loadResult / removeResult / addResult
7 * + listCollection / listResults
8 * When using it, be sure the static constant DEFAULT_CONTEXT is pointing to the right URL.
9 */
10 qx.Class.define("org.argeo.slc.ria.SlcApi",
11 {
12 extend : qx.core.Object,
13
14 statics : {
15 DEFAULT_CONTEXT : "/org.argeo.slc.webapp",
16
17 REMOVE_RESULT_FROM_COLL_SERVICE : "removeResultFromCollection.service",
18 ADD_RESULT_TO_COLL_SERVICE : "addResultToCollection.service",
19 LIST_COLLECTIONS_SERVICE : "listCollectionRefs.service",
20 COPY_COLLECTION_TO_COLL_SERVICE : "copyCollectionToCollection.service",
21 LIST_RESULTS_SERVICE : "listResultAttributes.service",
22 GET_RESULT_SERVICE : "getResult.service",
23 LIST_SLCEXEC_SERVICE : "listSlcExecutions.service",
24 NEW_SLCEXEC_SERVICE : "newSlcExecution.service",
25
26 LIST_AGENTS_SERVICE : "listAgents.service",
27 LIST_MODULES_SERVICE : "listModulesDescriptors.service",
28 GET_EXECUTION_DESC_SERVICE : "getExecutionDescriptor.service",
29 RELOAD_BUNDLE_SERVICE : "reloadBundle.service",
30 AMQ_SERVICE : "amq",
31
32 /**
33 * Standard Request getter
34 * @param serviceName {String} The name of the service to call (without base context)
35 * @param fireReloadEventType {String} Whether query should trigger a ReloadEvent
36 * @param iLoadStatusables {org.argeo.ria.components.ILoadStatusables[]} Gui parts to update
37 * @return {qx.io.remote.Request}
38 */
39 getServiceRequest:function(serviceName, fireReloadEventType, iLoadStatusables){
40 var serviceManager = org.argeo.ria.remote.RequestManager.getInstance();
41 return serviceManager.getRequest(
42 org.argeo.slc.ria.SlcApi.DEFAULT_CONTEXT+"/"+serviceName,
43 "GET",
44 "application/xml",
45 fireReloadEventType,
46 iLoadStatusables
47 );
48 },
49
50 /**
51 * Remove a result from a collection
52 * @param collectionId {String} Id of the destination collection
53 * @param resultId {String} Id of the test result to remove
54 * @param fireReloadEventType {String} Whether query should trigger a ReloadEvent
55 * @param iLoadStatusables {org.argeo.ria.components.ILoadStatusables[]} Gui parts to update
56 * @return {qx.io.remote.Request}
57 */
58 getRemoveResultService : function(collectionId, resultId, fireReloadEventType, iLoadStatusables){
59 var request = org.argeo.slc.ria.SlcApi.getServiceRequest(
60 org.argeo.slc.ria.SlcApi.REMOVE_RESULT_FROM_COLL_SERVICE,
61 fireReloadEventType,
62 iLoadStatusables
63 );
64 request.setParameter("collectionId", collectionId);
65 request.setParameter("resultUuid", resultId);
66 return request;
67 },
68
69 /**
70 * Remove a set of results from a collection. Either filtered by a given pattern, or the whole collection.
71 * @param collectionId {String} The id of the collection
72 * @param patternAttribute {String} An optional attribute name on which to filter
73 * @param patternValue {String} The pattern to use for filtering a subset of result
74 * @param fireReloadEventType {String} Whether query should trigger a ReloadEvent
75 * @param iLoadStatusables {org.argeo.ria.components.ILoadStatusables[]} Gui parts to update
76 * @return {qx.io.remote.Request} The Request object
77 */
78 getRemoveFromCollectionService : function(collectionId, patternAttribute, patternValue, fireReloadEventType, iLoadStatusables){
79 var request = org.argeo.slc.ria.SlcApi.getServiceRequest(
80 org.argeo.slc.ria.SlcApi.REMOVE_RESULT_FROM_COLL_SERVICE,
81 fireReloadEventType,
82 iLoadStatusables
83 );
84 request.setParameter("collectionId", collectionId);
85 if(patternAttribute && patternValue){
86 request.setParameter("attrName", patternAttribute);
87 request.setParameter("attrPattern", patternValue);
88 }
89 return request;
90 },
91
92 /**
93 * Add a result to a given collection
94 * @param collectionId {String} Id of the destination collection
95 * @param resultId {String} Id of the test result to add
96 * @param fireReloadEventType {String} Whether query should trigger a ReloadEvent
97 * @param iLoadStatusables {org.argeo.ria.components.ILoadStatusables[]} Gui parts to update
98 * @return {qx.io.remote.Request}
99 */
100 getAddResultService : function(collectionId, resultId, fireReloadEventType, iLoadStatusables){
101 var request = org.argeo.slc.ria.SlcApi.getServiceRequest(
102 org.argeo.slc.ria.SlcApi.ADD_RESULT_TO_COLL_SERVICE,
103 fireReloadEventType,
104 iLoadStatusables
105 );
106 request.setParameter("collectionId", collectionId);
107 request.setParameter("resultUuid", resultId);
108 return request;
109 },
110
111 /**
112 * List current collections
113 * @param fireReloadEventType {String} Whether query should trigger a ReloadEvent
114 * @param iLoadStatusables {org.argeo.ria.components.ILoadStatusables[]} Gui parts to update
115 * @return {qx.io.remote.Request}
116 */
117 getListCollectionsService : function(fireReloadEventType, iLoadStatusables){
118 return org.argeo.slc.ria.SlcApi.getServiceRequest(
119 org.argeo.slc.ria.SlcApi.LIST_COLLECTIONS_SERVICE,
120 fireReloadEventType,
121 iLoadStatusables
122 );
123 },
124
125 /**
126 * Copy a whole collection or a subset of it to another collection. If a new id is provided for the target, it will be created.
127 * @param sourceCollectionId {String} The current collection from which to copy
128 * @param targetCollectionId {String} The target collection. If unknown, it will be created.
129 * @param patternAttribute {String} An optional attribute on which a filter can be applied to create a subset.
130 * @param patternValue {String} The associated pattern to filter on the atttribute's value.
131 * @param fireReloadEventType {String} Whether query should trigger a ReloadEvent
132 * @param iLoadStatusables {org.argeo.ria.components.ILoadStatusables[]} Gui parts to update
133 * @return {qx.io.remote.Request} The request object
134 */
135 getCopyCollectionService : function(sourceCollectionId, targetCollectionId, patternAttribute, patternValue, fireReloadEventType, iLoadStatusables){
136 var request = org.argeo.slc.ria.SlcApi.getServiceRequest(
137 org.argeo.slc.ria.SlcApi.COPY_COLLECTION_TO_COLL_SERVICE,
138 fireReloadEventType,
139 iLoadStatusables
140 );
141 request.setParameter("sourceCollectionId", sourceCollectionId);
142 request.setParameter("targetCollectionId", targetCollectionId);
143 if(patternAttribute && patternValue){
144 request.setParameter("attrName", patternAttribute);
145 request.setParameter("attrPattern", patternValue);
146 }
147 return request;
148 },
149
150 /**
151 * List all results or results of a given collection
152 * @param collectionId {String} Id of the collection to load
153 * @param fireReloadEventType {String} Whether query should trigger a ReloadEvent
154 * @param iLoadStatusables {org.argeo.ria.components.ILoadStatusables[]} Gui parts to update
155 * @return {qx.io.remote.Request}
156 */
157 getListResultsService : function(collectionId, fireReloadEventType, iLoadStatusables){
158 var request = org.argeo.slc.ria.SlcApi.getServiceRequest(
159 org.argeo.slc.ria.SlcApi.LIST_RESULTS_SERVICE,
160 fireReloadEventType,
161 iLoadStatusables
162 );
163 if(collectionId){
164 request.setParameter("id", collectionId);
165 }
166 return request;
167 },
168
169 /**
170 * Load a result test
171 * @param resultId {String} Id of the test result to load
172 * @param fireReloadEventType {String} Whether query should trigger a ReloadEvent
173 * @param iLoadStatusables {org.argeo.ria.components.ILoadStatusables[]} Gui parts to update
174 * @return {qx.io.remote.Request}
175 */
176 getLoadResultService : function(resultId, fireReloadEventType, iLoadStatusables){
177 var request = org.argeo.slc.ria.SlcApi.getServiceRequest(
178 org.argeo.slc.ria.SlcApi.GET_RESULT_SERVICE,
179 fireReloadEventType,
180 iLoadStatusables
181 );
182 request.setParameter("uuid", resultId);
183 return request;
184 },
185
186 /**
187 * List currently registered SlcExecutions.
188 * @param fireReloadEventType {String} Event type to trigger (optionnal)
189 * @param iLoadStatusables {org.argeo.ria.components.ILoadStatusables[]} Gui parts to update
190 * @return {qx.io.remote.Request}
191 */
192 getListSlcExecutionsService:function(fireReloadEventType, iLoadStatusables){
193 return org.argeo.slc.ria.SlcApi.getServiceRequest(
194 org.argeo.slc.ria.SlcApi.LIST_SLCEXEC_SERVICE,
195 fireReloadEventType,
196 iLoadStatusables
197 );
198 },
199
200
201 /**
202 * New SlcExecution
203 * @param agentId {String} Agent id target
204 * @param xmlDescription {String} XML of the Slc Execution
205 * @param fireReloadEventType {String} Event type to trigger (optionnal)
206 * @param iLoadStatusables {org.argeo.ria.components.ILoadStatusables[]} Gui parts to update
207 * @return {qx.io.remote.Request}
208 */
209 getNewSlcExecutionService:function(agentId, xmlDescription, fireReloadEventType, iLoadStatusables){
210 var req = org.argeo.slc.ria.SlcApi.getServiceRequest(
211 org.argeo.slc.ria.SlcApi.NEW_SLCEXEC_SERVICE + "?slc_agentId="+agentId,
212 fireReloadEventType,
213 iLoadStatusables
214 );
215 req.setMethod("POST");
216 //req.setRequestHeader("Content-Type", "text/xml");
217 req.setData("body=" + encodeURIComponent(xmlDescription));
218 return req;
219 },
220
221
222 /**
223 * List currently available agents queues.
224 * @param fireReloadEventType {String} Event type to trigger (optionnal)
225 * @param iLoadStatusables {org.argeo.ria.components.ILoadStatusables[]} Gui parts to update
226 * @return {qx.io.remote.Request}
227 */
228 getListAgentsService:function(fireReloadEventType, iLoadStatusables){
229 return org.argeo.slc.ria.SlcApi.getServiceRequest(
230 org.argeo.slc.ria.SlcApi.LIST_AGENTS_SERVICE,
231 fireReloadEventType,
232 iLoadStatusables
233 );
234 },
235
236 /**
237 * Load the module descriptors
238 * @param fireReloadEventType {String} Event type to trigger (optionnal)
239 * @param iLoadStatusables {org.argeo.ria.components.ILoadStatusables[]} Gui parts to update
240 * @return {qx.io.remote.Request}
241 */
242 getListModulesService : function(agentId, fireReloadEventType, iLoadStatusables){
243 var req = org.argeo.slc.ria.SlcApi.getServiceRequest(
244 org.argeo.slc.ria.SlcApi.LIST_MODULES_SERVICE,
245 fireReloadEventType,
246 iLoadStatusables
247 );
248 req.setParameter("agentId", agentId);
249 return req;
250 },
251
252 /**
253 * Get an execution module descriptor by its name and version
254 * @param moduleName {String} The name of the module to get
255 * @param moduleVersion {String} Its version, passed directly as a string
256 * @param fireReloadEventType {String} Event type to trigger (optionnal)
257 * @param iLoadStatusables {org.argeo.ria.components.ILoadStatusables[]} Gui parts to update
258 * @return {qx.io.remote.Request}
259 */
260 getLoadExecutionDescriptorService : function(agentId,moduleName, moduleVersion, fireReloadEventType, iLoadStatusables){
261 var req = org.argeo.slc.ria.SlcApi.getServiceRequest(
262 org.argeo.slc.ria.SlcApi.GET_EXECUTION_DESC_SERVICE,
263 fireReloadEventType,
264 iLoadStatusables
265 );
266 req.setParameter("agentId", agentId);
267 req.setParameter("moduleName", moduleName);
268 req.setParameter("version", moduleVersion);
269 return req;
270 },
271
272 /**
273 * Fire the reload of an OSGI bundle.
274 * @param fireReloadEventType {String} Event type to trigger (optionnal)
275 * @param iLoadStatusables {org.argeo.ria.components.ILoadStatusables[]} Gui parts to update
276 * @return {qx.io.remote.Request}
277 */
278 getReloadBundleService : function(bundleName, bundleVersion, fireReloadEventType, iLoadStatusables){
279 var req = org.argeo.slc.ria.SlcApi.getServiceRequest(
280 org.argeo.slc.ria.SlcApi.RELOAD_BUNDLE_SERVICE,
281 fireReloadEventType,
282 iLoadStatusables
283 );
284 req.setParameter("bundleName", bundleName);
285 req.setParameter("bundleVersion", bundleVersion);
286 return req;
287 },
288
289
290
291 /**
292 * Send a JMS message to the AMQ_CONTEXT
293 * @param destination {String} The destination queue, in the form "topic://destination"
294 * @param message {org.argeo.slc.ria.SlcExecutionMessage} The message object
295 * @param iLoadStatusables {org.argeo.ria.components.ILoadStatusables[]} Gui parts to update
296 */
297 getSendAmqMessageRequest : function(destination, message, iLoadStatusables){
298 var serviceManager = org.argeo.ria.remote.RequestManager.getInstance();
299 var request = serviceManager.getRequest(
300 org.argeo.slc.ria.SlcApi.DEFAULT_CONTEXT+"/"+org.argeo.slc.ria.SlcApi.AMQ_SERVICE,
301 "POST",
302 "text/plain",
303 null,
304 iLoadStatusables
305 );
306 request.setParameter("destination", destination);
307 request.setParameter("message", message.toXml());
308 request.setParameter("type", "send");
309 return request;
310 }
311
312 }
313 });