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