]> 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
Auto-open logger (with associated preference), add re-open button in logger toolbar...
[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 LIST_RESULTS_LONG_SERVICE : "listResults.service",
23 GET_RESULT_SERVICE : "getResult.service",
24 GET_ATTACHEMENT_SERVICE : "getAttachment.service",
25 LIST_SLCEXEC_SERVICE : "listSlcExecutions.service",
26 NEW_SLCEXEC_SERVICE : "newSlcExecution.service",
27
28 LIST_AGENTS_SERVICE : "listAgents.service",
29 LIST_MODULES_SERVICE : "listModulesDescriptors.service",
30 GET_EXECUTION_DESC_SERVICE : "getExecutionDescriptor.service",
31 GET_SLC_EXECUTION_SERVICE : "getSlcExecution.service",
32 TAIL_SLCEXEC_STEP_COUNT : "tailSlcExecutionStepsCount.service",
33 TAIL_SLCEXEC_STEP_OFFSET : "tailSlcExecutionStepsOffset.service",
34 DOWNLOAD_SLCEXEC_STEPS : "downloadSlcExecution.service",
35
36 RELOAD_BUNDLE_SERVICE : "reloadBundle.service",
37 AMQ_SERVICE : "amq",
38
39 LIST_MODULAR_DISTRIB_SERVICE : "listModularDistributions.service",
40 INSTALL_MODULE_SERVICE : "installModule.service",
41 UNINSTALL_MODULE_SERVICE : "uninstallModule.service",
42
43 /**
44 * Standard Request getter
45 * @param serviceName {String} The name of the service to call (without base context)
46 * @param fireReloadEventType {String} Whether query should trigger a ReloadEvent
47 * @param iLoadStatusables {org.argeo.ria.components.ILoadStatusables[]} Gui parts to update
48 * @return {qx.io.remote.Request}
49 */
50 getServiceRequest:function(serviceName, fireReloadEventType, iLoadStatusables){
51 var serviceManager = org.argeo.ria.remote.RequestManager.getInstance();
52 return serviceManager.getRequest(
53 org.argeo.slc.ria.SlcApi.DEFAULT_CONTEXT+"/"+serviceName,
54 "GET",
55 "application/xml",
56 fireReloadEventType,
57 iLoadStatusables
58 );
59 },
60
61 /**
62 * Remove a result from a collection
63 * @param collectionId {String} Id of the destination collection
64 * @param resultId {String} Id of the test result to remove
65 * @param fireReloadEventType {String} Whether query should trigger a ReloadEvent
66 * @param iLoadStatusables {org.argeo.ria.components.ILoadStatusables[]} Gui parts to update
67 * @return {qx.io.remote.Request}
68 */
69 getRemoveResultService : function(collectionId, resultId, fireReloadEventType, iLoadStatusables){
70 var request = org.argeo.slc.ria.SlcApi.getServiceRequest(
71 org.argeo.slc.ria.SlcApi.REMOVE_RESULT_FROM_COLL_SERVICE,
72 fireReloadEventType,
73 iLoadStatusables
74 );
75 request.setParameter("collectionId", collectionId);
76 request.setParameter("resultUuid", resultId);
77 return request;
78 },
79
80 /**
81 * Remove a set of results from a collection. Either filtered by a given pattern, or the whole collection.
82 * @param collectionId {String} The id of the collection
83 * @param patternAttribute {String} An optional attribute name on which to filter
84 * @param patternValue {String} The pattern to use for filtering a subset of result
85 * @param fireReloadEventType {String} Whether query should trigger a ReloadEvent
86 * @param iLoadStatusables {org.argeo.ria.components.ILoadStatusables[]} Gui parts to update
87 * @return {qx.io.remote.Request} The Request object
88 */
89 getRemoveFromCollectionService : function(collectionId, patternAttribute, patternValue, fireReloadEventType, iLoadStatusables){
90 var request = org.argeo.slc.ria.SlcApi.getServiceRequest(
91 org.argeo.slc.ria.SlcApi.REMOVE_RESULT_FROM_COLL_SERVICE,
92 fireReloadEventType,
93 iLoadStatusables
94 );
95 request.setParameter("collectionId", collectionId);
96 if(patternAttribute && patternValue){
97 request.setParameter("attrName", patternAttribute);
98 request.setParameter("attrPattern", patternValue);
99 }
100 return request;
101 },
102
103 /**
104 * Add a result to a given collection
105 * @param collectionId {String} Id of the destination collection
106 * @param resultId {String} Id of the test result to add
107 * @param fireReloadEventType {String} Whether query should trigger a ReloadEvent
108 * @param iLoadStatusables {org.argeo.ria.components.ILoadStatusables[]} Gui parts to update
109 * @return {qx.io.remote.Request}
110 */
111 getAddResultService : function(collectionId, resultId, fireReloadEventType, iLoadStatusables){
112 var request = org.argeo.slc.ria.SlcApi.getServiceRequest(
113 org.argeo.slc.ria.SlcApi.ADD_RESULT_TO_COLL_SERVICE,
114 fireReloadEventType,
115 iLoadStatusables
116 );
117 request.setParameter("collectionId", collectionId);
118 request.setParameter("resultUuid", resultId);
119 return request;
120 },
121
122 /**
123 * List current collections
124 * @param fireReloadEventType {String} Whether query should trigger a ReloadEvent
125 * @param iLoadStatusables {org.argeo.ria.components.ILoadStatusables[]} Gui parts to update
126 * @return {qx.io.remote.Request}
127 */
128 getListCollectionsService : function(fireReloadEventType, iLoadStatusables){
129 return org.argeo.slc.ria.SlcApi.getServiceRequest(
130 org.argeo.slc.ria.SlcApi.LIST_COLLECTIONS_SERVICE,
131 fireReloadEventType,
132 iLoadStatusables
133 );
134 },
135
136 /**
137 * 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.
138 * @param sourceCollectionId {String} The current collection from which to copy
139 * @param targetCollectionId {String} The target collection. If unknown, it will be created.
140 * @param patternAttribute {String} An optional attribute on which a filter can be applied to create a subset.
141 * @param patternValue {String} The associated pattern to filter on the atttribute's value.
142 * @param fireReloadEventType {String} Whether query should trigger a ReloadEvent
143 * @param iLoadStatusables {org.argeo.ria.components.ILoadStatusables[]} Gui parts to update
144 * @return {qx.io.remote.Request} The request object
145 */
146 getCopyCollectionService : function(sourceCollectionId, targetCollectionId, patternAttribute, patternValue, fireReloadEventType, iLoadStatusables){
147 var request = org.argeo.slc.ria.SlcApi.getServiceRequest(
148 org.argeo.slc.ria.SlcApi.COPY_COLLECTION_TO_COLL_SERVICE,
149 fireReloadEventType,
150 iLoadStatusables
151 );
152 request.setParameter("sourceCollectionId", sourceCollectionId);
153 request.setParameter("targetCollectionId", targetCollectionId);
154 if(patternAttribute && patternValue){
155 request.setParameter("attrName", patternAttribute);
156 request.setParameter("attrPattern", patternValue);
157 }
158 return request;
159 },
160
161 /**
162 * List all results or results of a given collection with all details
163 * @param collectionId {String} Id of the collection to load
164 * @param fireReloadEventType {String} Whether query should trigger a ReloadEvent
165 * @param iLoadStatusables {org.argeo.ria.components.ILoadStatusables[]} Gui parts to update
166 * @return {qx.io.remote.Request}
167 */
168 getListResultsLongService : function(collectionId, fireReloadEventType, iLoadStatusables){
169 var request = org.argeo.slc.ria.SlcApi.getServiceRequest(
170 org.argeo.slc.ria.SlcApi.LIST_RESULTS_LONG_SERVICE,
171 fireReloadEventType,
172 iLoadStatusables
173 );
174 if(collectionId){
175 request.setParameter("id", collectionId);
176 }
177 return request;
178 },
179
180 /**
181 * List all results or results of a given collection
182 * @param collectionId {String} Id of the collection to load
183 * @param fireReloadEventType {String} Whether query should trigger a ReloadEvent
184 * @param iLoadStatusables {org.argeo.ria.components.ILoadStatusables[]} Gui parts to update
185 * @return {qx.io.remote.Request}
186 */
187 getListResultsService : function(collectionId, fireReloadEventType, iLoadStatusables){
188 var request = org.argeo.slc.ria.SlcApi.getServiceRequest(
189 org.argeo.slc.ria.SlcApi.LIST_RESULTS_SERVICE,
190 fireReloadEventType,
191 iLoadStatusables
192 );
193 if(collectionId){
194 request.setParameter("id", collectionId);
195 }
196 return request;
197 },
198
199 /**
200 * Load a result test
201 * @param resultId {String} Id of the test result to load
202 * @param fireReloadEventType {String} Whether query should trigger a ReloadEvent
203 * @param iLoadStatusables {org.argeo.ria.components.ILoadStatusables[]} Gui parts to update
204 * @return {qx.io.remote.Request}
205 */
206 getLoadResultService : function(resultId, fireReloadEventType, iLoadStatusables){
207 var request = org.argeo.slc.ria.SlcApi.getServiceRequest(
208 org.argeo.slc.ria.SlcApi.GET_RESULT_SERVICE,
209 fireReloadEventType,
210 iLoadStatusables
211 );
212 request.setParameter("uuid", resultId);
213 return request;
214 },
215
216 buildGetAttachmentUrl : function(attachmentId, contentType, name){
217 return org.argeo.slc.ria.SlcApi.DEFAULT_CONTEXT + "/" + org.argeo.slc.ria.SlcApi.GET_ATTACHEMENT_SERVICE
218 + "?uuid=" + attachmentId + "&contentType=" + contentType + "&name=" + name;
219 },
220
221 /**
222 * List currently registered SlcExecutions.
223 * @param fireReloadEventType {String} Event type to trigger (optionnal)
224 * @param iLoadStatusables {org.argeo.ria.components.ILoadStatusables[]} Gui parts to update
225 * @return {qx.io.remote.Request}
226 */
227 getListSlcExecutionsService:function(fireReloadEventType, iLoadStatusables){
228 return org.argeo.slc.ria.SlcApi.getServiceRequest(
229 org.argeo.slc.ria.SlcApi.LIST_SLCEXEC_SERVICE,
230 fireReloadEventType,
231 iLoadStatusables
232 );
233 },
234
235 /**
236 * List currently registered SlcExecutions.
237 * @param fireReloadEventType {String} Event type to trigger (optionnal)
238 * @param iLoadStatusables {org.argeo.ria.components.ILoadStatusables[]} Gui parts to update
239 * @return {qx.io.remote.Request}
240 */
241 getListModularDistributionsService:function(fireReloadEventType, iLoadStatusables){
242 return org.argeo.slc.ria.SlcApi.getServiceRequest(
243 org.argeo.slc.ria.SlcApi.LIST_MODULAR_DISTRIB_SERVICE,
244 fireReloadEventType,
245 iLoadStatusables
246 );
247 },
248
249 getInstallModuleService : function(){
250 return org.argeo.slc.ria.SlcApi.DEFAULT_CONTEXT +"/"+ org.argeo.slc.ria.SlcApi.INSTALL_MODULE_SERVICE;
251 },
252
253 /**
254 * Load a result test
255 * @param resultId {String} Id of the test result to load
256 * @param fireReloadEventType {String} Whether query should trigger a ReloadEvent
257 * @param iLoadStatusables {org.argeo.ria.components.ILoadStatusables[]} Gui parts to update
258 * @return {qx.io.remote.Request}
259 */
260 getUninstallModuleService : function(moduleName, moduleVersion, fireReloadEventType, iLoadStatusables){
261 var request = org.argeo.slc.ria.SlcApi.getServiceRequest(
262 org.argeo.slc.ria.SlcApi.UNINSTALL_MODULE_SERVICE,
263 fireReloadEventType,
264 iLoadStatusables
265 );
266 request.setParameter("name", moduleName);
267 request.setParameter("version", moduleVersion);
268 return request;
269 },
270
271
272
273 /**
274 * New SlcExecution
275 * @param agentId {String} Agent id target
276 * @param xmlDescription {String} XML of the Slc Execution
277 * @param fireReloadEventType {String} Event type to trigger (optionnal)
278 * @param iLoadStatusables {org.argeo.ria.components.ILoadStatusables[]} Gui parts to update
279 * @return {qx.io.remote.Request}
280 */
281 getNewSlcExecutionService:function(agentId, xmlDescription, fireReloadEventType, iLoadStatusables){
282 var req = org.argeo.slc.ria.SlcApi.getServiceRequest(
283 org.argeo.slc.ria.SlcApi.NEW_SLCEXEC_SERVICE + "?slc_agentId="+agentId,
284 fireReloadEventType,
285 iLoadStatusables
286 );
287 req.setMethod("POST");
288 //req.setRequestHeader("Content-Type", "text/xml");
289 req.setData("body=" + encodeURIComponent(xmlDescription));
290 return req;
291 },
292
293 getSlcExecutionService :function(executionMessageId, fireReloadEventType, iLoadStatusables){
294 var request = org.argeo.slc.ria.SlcApi.getServiceRequest(
295 org.argeo.slc.ria.SlcApi.GET_SLC_EXECUTION_SERVICE,
296 fireReloadEventType,
297 iLoadStatusables
298 );
299 request.setParameter("uuid", executionMessageId);
300 return request;
301 },
302
303 getTailSlcExecutionStepService : function(executionUuid, stepCount, offset, fireReloadEventType, iLoadStatusables){
304 var request = org.argeo.slc.ria.SlcApi.getServiceRequest(
305 (offset?org.argeo.slc.ria.SlcApi.TAIL_SLCEXEC_STEP_OFFSET:org.argeo.slc.ria.SlcApi.TAIL_SLCEXEC_STEP_COUNT),
306 fireReloadEventType,
307 iLoadStatusables
308 );
309 request.setParameter("uuid", executionUuid);
310 if(offset){
311 request.setParameter("stepOffsetUuid", offset);
312 }else{
313 request.setParameter("stepCount", stepCount);
314 }
315 return request;
316 },
317
318 /**
319 * List currently available agents queues.
320 * @param fireReloadEventType {String} Event type to trigger (optionnal)
321 * @param iLoadStatusables {org.argeo.ria.components.ILoadStatusables[]} Gui parts to update
322 * @return {qx.io.remote.Request}
323 */
324 getListAgentsService:function(fireReloadEventType, iLoadStatusables){
325 return org.argeo.slc.ria.SlcApi.getServiceRequest(
326 org.argeo.slc.ria.SlcApi.LIST_AGENTS_SERVICE,
327 fireReloadEventType,
328 iLoadStatusables
329 );
330 },
331
332 /**
333 * Load the module descriptors
334 * @param fireReloadEventType {String} Event type to trigger (optionnal)
335 * @param iLoadStatusables {org.argeo.ria.components.ILoadStatusables[]} Gui parts to update
336 * @return {qx.io.remote.Request}
337 */
338 getListModulesService : function(agentId, fireReloadEventType, iLoadStatusables){
339 var req = org.argeo.slc.ria.SlcApi.getServiceRequest(
340 org.argeo.slc.ria.SlcApi.LIST_MODULES_SERVICE,
341 fireReloadEventType,
342 iLoadStatusables
343 );
344 req.setParameter("agentId", agentId);
345 return req;
346 },
347
348 /**
349 * Get an execution module descriptor by its name and version
350 * @param moduleName {String} The name of the module to get
351 * @param moduleVersion {String} Its version, passed directly as a string
352 * @param fireReloadEventType {String} Event type to trigger (optionnal)
353 * @param iLoadStatusables {org.argeo.ria.components.ILoadStatusables[]} Gui parts to update
354 * @return {qx.io.remote.Request}
355 */
356 getLoadExecutionDescriptorService : function(agentId,moduleName, moduleVersion, fireReloadEventType, iLoadStatusables){
357 var req = org.argeo.slc.ria.SlcApi.getServiceRequest(
358 org.argeo.slc.ria.SlcApi.GET_EXECUTION_DESC_SERVICE,
359 fireReloadEventType,
360 iLoadStatusables
361 );
362 req.setParameter("agentId", agentId);
363 req.setParameter("moduleName", moduleName);
364 req.setParameter("version", moduleVersion);
365 return req;
366 },
367
368 /**
369 * Fire the reload of an OSGI bundle.
370 * @param fireReloadEventType {String} Event type to trigger (optionnal)
371 * @param iLoadStatusables {org.argeo.ria.components.ILoadStatusables[]} Gui parts to update
372 * @return {qx.io.remote.Request}
373 */
374 getReloadBundleService : function(bundleName, bundleVersion, fireReloadEventType, iLoadStatusables){
375 var req = org.argeo.slc.ria.SlcApi.getServiceRequest(
376 org.argeo.slc.ria.SlcApi.RELOAD_BUNDLE_SERVICE,
377 fireReloadEventType,
378 iLoadStatusables
379 );
380 req.setParameter("bundleName", bundleName);
381 req.setParameter("bundleVersion", bundleVersion);
382 return req;
383 },
384
385
386
387 /**
388 * Send a JMS message to the AMQ_CONTEXT
389 * @param destination {String} The destination queue, in the form "topic://destination"
390 * @param message {org.argeo.slc.ria.SlcExecutionMessage} The message object
391 * @param iLoadStatusables {org.argeo.ria.components.ILoadStatusables[]} Gui parts to update
392 */
393 getSendAmqMessageRequest : function(destination, message, iLoadStatusables){
394 var serviceManager = org.argeo.ria.remote.RequestManager.getInstance();
395 var request = serviceManager.getRequest(
396 org.argeo.slc.ria.SlcApi.DEFAULT_CONTEXT+"/"+org.argeo.slc.ria.SlcApi.AMQ_SERVICE,
397 "POST",
398 "text/plain",
399 null,
400 iLoadStatusables
401 );
402 request.setParameter("destination", destination);
403 request.setParameter("message", message.toXml());
404 request.setParameter("type", "send");
405 return request;
406 }
407
408 }
409 });