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