comparison WebServiceExtensionsV1.1/WebServiceToolWorkflow_REST_SOAP/generateClient1.py~ @ 0:049760c677de default tip

Galaxy WSExtensions added successfully
author uga-galaxy-group
date Tue, 05 Jul 2011 19:34:18 -0400
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:049760c677de
1 '''
2 @author Chaitanya Guttula, Sumedha Ganjoo
3 @see LICENSE (MIT style license file).
4 '''
5
6 import warnings
7
8 with warnings.catch_warnings():
9 warnings.simplefilter("ignore")
10 import platform
11
12 from jpype._jpackage import JPackage
13 from jpype import *
14 import os.path
15 import sys
16 import string
17 from edit_tool_conf1 import *
18 from clientGenerator.msHandler import *
19 from clientGenerator.creatorEngineComplex import *
20 from clientGenerator.wsdl2path import *
21 from clientGenerator.paramConverter import *
22
23 __author__=""
24
25 #generates client for a web service to be used as standalone
26 class ClientGenerator1(object):
27
28 def __init__(self,webservice,operation,outputfile,servicetype):#,url):
29 with warnings.catch_warnings():
30 warnings.simplefilter("ignore")
31 self.webservice = webservice
32 self.operation = operation
33 self.inputs = outputfile
34 self.outputfile = outputfile
35 #self.url = url
36
37 self.servicetype = servicetype
38 self.galaxyhome=os.environ.get('GALAXY_HOME')
39 self.clientfile = ''
40 if self.servicetype == 'SOAP':
41 wLoad=wsdlLoader()
42 sys.path.append(self.galaxyhome+'/tools/WebServiceToolWorkflow_REST_SOAP/clientGenerator')
43 os.chdir(self.galaxyhome+'/tools/WebServiceToolWorkflow_REST_SOAP/clientGenerator')
44
45 a = str(self.webservice).split('/')
46 wsdlnamelist = a[len(a)-1].split(".")
47 if len(wsdlnamelist)==1:
48 wsdlnamelist=a[len(a)-1].split('?')
49 print wsdlnamelist
50
51 foldername=wsdlnamelist[0]
52
53 path =self.galaxyhome+'/tools/WebServiceToolWorkflow_REST_SOAP/clientGenerator/'+foldername
54
55 #creates the client stubs
56 self.clientfile = wLoad.wsdlUrl2path(str(self.webservice),foldername)
57
58 print 'Client file : ',self.clientfile
59 self.paramelement = None
60
61
62
63 ''' Replaces space (' ') with '**' in the given string '''
64 def formatString(self,string):
65 l = string.split(' ')
66 return '**'.join(l)
67
68 def isRequired(self,param):
69 #j=0
70 #for param in inputl:
71 cc = ClientCreator()
72 self.msinstance = cc.opname2inputClassOb(self.operation,self.clientfile)
73 test = MessageHandler()
74 required = False
75 if (param.find('|$|')>-1):
76 plist = param.split('|')
77 #root = test.getParameter(self.msinstance(),plist[0])
78 k = 0
79 iparam = ''
80 for p in plist:
81 if(k<len(plist)-3):
82 if(k==0):
83 iparam = iparam+(p)
84 else:
85 iparam = iparam+'|'+p
86 k=k+1
87 paramelement = test.getParameter(self.msinstance(),iparam)
88 else:
89 paramelement = test.getParameter(self.msinstance(),param)
90 self.paramelement = paramelement
91 if (param.find('|')>-1):
92 plist = param.split('|')
93 root = test.getParameter(self.msinstance(),plist[0])
94 if not getattr(root,'nillable') and not getattr(paramelement,'nillable'):
95 required = True
96 return True
97 elif getattr(root,'nillable') or (not getattr(root,'nillable') and getattr(paramelement,'nillable')):
98 required = False
99 return False
100 else:
101 if not getattr(paramelement,'nillable'):
102 required = True
103 return True
104 elif getattr(paramelement,'nillable'):
105 required = False
106 return False
107 return required
108
109
110 #replace '**' with ' '
111 def formatString(self,string):
112 l = string.split(' ')
113 return '**'.join(l)
114
115 '''
116 Checks if the tool(operation) is already addded to Galaxy. It opens the tool_conf.xml file and loops through the "Web Service Workflow Tools" sections
117 Then opens each and every tool (xml file) and looks for the description tag for the "Web Service" and "Client for Method" values and then checks
118 if it same as the opearation and web service. As the code is dependent on description of the toool xml fie, any change in the description
119 of the tool xml file can impact this function.
120 '''
121 def isToolPresent(self):
122
123 f = open(self.galaxyhome+'/tool_conf.xml','r')
124 line = f.readline()
125 linestripped = line.lstrip()
126 linestripped = linestripped.rstrip()
127
128 while linestripped != '<section name="Select Web Service Tool" id="WebServices">':
129 line = f.readline()
130 linestripped = line.lstrip()
131 linestripped = linestripped.rstrip()
132
133 line = f.readline()
134 linestripped = line.lstrip()
135 linestripped = linestripped.rstrip()
136
137 while linestripped != '</section>':
138 if linestripped.find('<') >-1:
139 toolparts = linestripped.split('"')
140 print '\ntoolparts are : ',toolparts
141 f1 = open(self.galaxyhome+'/tools/'+toolparts[-2],'r')
142 line1 = f1.readline()
143 while not line1.find('<description>') >-1:
144 line1 = f1.readline()
145
146 linestripped1 = line1.lstrip()
147 linestripped1 = linestripped1.rstrip()
148 descriptionparts=linestripped1.split(' ')
149 print '\nOperation : ',descriptionparts
150 service = ''
151 if(self.servicetype == 'SOAP'):
152 service = self.clientfile
153 elif self.servicetype == 'REST':
154 service = self.webservice
155 if(descriptionparts[5]==self.operation and descriptionparts[10] == service):
156 f.close()
157 f1.close()
158 return True
159 f1.close()
160 line = f.readline()
161 linestripped = line.lstrip()
162 linestripped = linestripped.rstrip()
163
164 f.close()
165 return False
166
167
168 '''
169 Creates a client file2 (xml file) for the given opertion in the SOAP web service
170 This operation is invokes standalone and is cannot be used in workflows
171 Then invokes another operation which adds this client file (tool) to the toolconfig.xml
172 under 'Web Service Tools'
173
174 '''
175
176 def wsdlClient(self):
177 with warnings.catch_warnings():
178 warnings.simplefilter("ignore")
179 wLoad=wsdlLoader()
180 galaxyhome=os.environ.get('GALAXY_HOME')
181 sys.path.append(galaxyhome+'/tools/WebServiceToolWorkflow_REST_SOAP/clientGenerator')
182 os.chdir(galaxyhome+'/tools/WebServiceToolWorkflow_REST_SOAP/clientGenerator')
183
184 a= str(self.webservice).split('/')
185 wsdlnamelist = a[len(a)-1].split(".")
186 if len(wsdlnamelist)==1:
187 wsdlnamelist=a[len(a)-1].split('?')
188 print wsdlnamelist
189
190 foldername=wsdlnamelist[0]
191
192 path =galaxyhome+'/tools/WebServiceToolWorkflow_REST_SOAP/clientGenerator/'+foldername
193
194 #creates the client stubs
195 clientfile=wLoad.wsdlUrl2path(str(self.webservice),foldername)
196
197 webservice = clientfile#sys.argv[4]
198 #operation = sys.argv[3]
199 outputfile=open(self.outputfile,'w')
200 test = ClientCreator()
201 inputs= test.opname2inputs(self.operation,webservice)
202 inputl = nested2flatDict(inputs)
203 inputlist = inputl.keys()
204 #noOfInputs=inputlist.count()
205 count =0
206 if (len(inputs)==0):
207 inputs={' ':' '}
208 #inputlist=inputs.keys()
209 for i in inputlist:
210 if count==0:
211 outputfile.write(i+'\t'+webservice+'\t'+self.operation+'\n')
212 else:
213 outputfile.write(i+'\n')
214 count=count+1
215
216
217 cc = ClientCreator()
218 self.msinstance = cc.opname2inputClassOb(self.operation,webservice)
219
220 ##generate client's xml
221 galaxyhome=os.environ.get('GALAXY_HOME')
222
223 #./clients/ClientCount.xml keeps the count of the clients/tools currently registered in Galaxy for Web service invocation.
224 #read the count and increment it.
225
226 clientCountFile=open(galaxyhome+'/tools/WebServiceToolWorkflow_REST_SOAP/clients/ClientCount.xml','r')
227 clientCountFile.readline()
228 clientCountStr = clientCountFile.readline()
229 clientCount=string.atoi(clientCountStr)
230 clientCount=clientCount+1
231 clientCountFile.close()
232
233 clientCountFile=open(galaxyhome+'/tools/WebServiceToolWorkflow_REST_SOAP/clients/ClientCount.xml','w')
234 clientCountFile.write('<count> \n')
235 clientCountFile.write(str(clientCount)+'\n')
236 clientCountFile.write('</count> \n')
237 clientCountFile.close()
238
239 clientName = 'WebServiceclient_'+ str(clientCount)
240
241 clientXml=open(galaxyhome+'/tools/WebServiceToolWorkflow_REST_SOAP/clients/'+clientName+'.xml','w')
242 clientXml.seek(0,0)
243
244 clientXml.write('<tool id="' + clientName+'" name="'+foldername+'.' + self.operation +'">\n')
245 clientXml.write(' <description> Client for operation : '+self.operation+' , Web service : '+webservice+' </description>\n')
246
247 #Only Required parameters
248 clientXml.write(' <command interpreter="python">\n #if $cond_source.optional_param_source=="no" #client_1.py'+' $output $servicetype ' +webservice+' '+self.operation)
249
250 #clientXml.write(' <command interpreter="python">\n client_1.py \n' +' $output \n ' +self.webservice+' \n '+self.operation+'\n')
251 ##write such that the parameters passed to client1.py(change name to clientName.py) are dependent on a for loop
252 test = MessageHandler()
253 j=0
254 for param in inputl:
255 if self.isRequired(param):
256 clientXml.write(' "'+param+'"')
257 clientXml.write(' $param'+str(j))
258 j=j+1
259
260
261 #Both Required and optional paramters
262 clientXml.write(' #else #client_1.py'+' $output $servicetype ' +webservice+' '+self.operation+'\n')
263
264 '''
265 Required parameters - If the parameter is complex type (tree structure) then the the parameter is required
266 only if both the root node and the leaf node are required (i.e. both root and leaf have attribute nillable as false)
267 '''
268
269 j=0
270 for param in inputl:
271 if self.isRequired(param):
272 clientXml.write(' "'+param+'"')
273 clientXml.write(' $param'+str(j))
274 j=j+1
275
276
277 '''
278 Optional parameters - If the parameter is complex type (tree structure) then the the paramter is optional
279 if its root element is optional (i.e. root has attribute nillable as true) even if the leaf node (element)
280 is required (i.e. leaf element has attribute nillable as false)
281 '''
282 for param in inputl:
283 if not self.isRequired(param):
284 clientXml.write(' "'+param+'"')
285 clientXml.write(' $param'+str(j))
286 j=j+1
287
288
289 #params for array type
290 # for param in self.inputs:
291 # paramelement = test.getParameter(self.msinstance(),param)
292 # if getattr(paramelement,'nillable')==True:
293 # if string.find(param,"|0|")>-1:
294 # ele = string(param,"|0|")
295 # for param in self.inputs:
296
297
298 # clientXml.write(' "'+param+'"')
299 # clientXml.write(' $cond_source.param' + str(j))
300 # j=j+1
301
302 clientXml.write(' #end if \n</command>\n')
303
304
305 # for param in self.inputs:
306 # paramelement = test.getParameter(self.msinstance(),param)
307 # if getattr(paramelement,'nillable')==False or getattr(paramelement,'minOccurs')==1:
308 # clientXml.write(' "'+param+'"\n')
309 # clientXml.write(' $param'+str(j)+'\n')
310 # j=j+1
311
312
313 #clientXml.write('</command>\n')
314
315 #start writing inputs
316 ##write inputs depending on required or not. if not required den dont display
317 ##if required- den check default value, and if options exist.Depending on that
318 ##decide the type of parameter and options
319 ##The input servicetype tells what type of webservice it is wether SOAP or REST - Useful during invocation of the web servcie
320 clientXml.write(' <inputs>\n')
321 clientXml.write(' <param name="servicetype" type="hidden" value="SOAP" />\n')
322
323
324 j=0
325 for param in inputl:
326 if self.isRequired(param):
327 pName = getattr(self.paramelement,'pname')
328 clientXml.write('<param format="text" size = "150" name = "param'+str(j)+'" ')
329 clientXml.write('type="text" label="Enter '+pName+'" help="see tip below" />\n')
330 j=j+1
331
332 clientXml.write('\n <conditional name="cond_source"> \n <param name="optional_param_source" type="select" label="Show Optional Parameters">\n <option value="no" selected="true">no</option> \n <option value="yes">yes</option> \n </param>\n')
333 clientXml.write('<when value="no"> \n </when>')
334 clientXml.write('<when value="yes"> \n')
335
336 for param in inputl:
337 if not self.isRequired(param):
338 pName = getattr(self.paramelement,'pname')
339 clientXml.write('<param format="text" size = "150" name = "param'+str(j)+'" ')
340 clientXml.write('type="text" label="Enter '+pName+'" help="see tip below" />\n')
341 j=j+1
342
343
344 clientXml.write('</when>\n</conditional>')
345
346 # j=0
347 # for param in self.inputs:
348 # paramelement = test.getParameter(self.msinstance(),param)
349 # if not getattr(paramelement,'nillable'):
350 # pName = getattr(paramelement,'pname')#param.getName()
351 # clientXml.write('<param format="text" size = "150" name = "param'+str(j)+'" ')
352 # clientXml.write('type="text" label="'+pName+'" help="see tip below" />\n')
353 # j=j+1
354
355 clientXml.write('</inputs>\n <outputs>\n <data format="tabular" name="output" />\n </outputs>\n')
356
357 clientXml.write(' <help>\n')
358 paramtype = None
359 for param in inputl:
360 if self.isRequired(param):
361 if isinstance(self.paramelement,ZSI.TC.String):
362 paramtype = 'String'
363 elif isinstance(self.paramelement,ZSI.TCnumbers.FPfloat):
364 paramtype = 'Floating point'
365 elif isinstance(self.paramelement,ZSI.TC.Boolean):
366 paramtype = 'Boolean'
367 elif isinstance(self.paramelement,ZSI.TCnumbers.Iint):
368 paramtype = 'Integer'
369 clientXml.write('\n.. class:: infomark\n\n**TIP:** About '+ getattr(self.paramelement,'pname') +': type is ' + paramtype + '\n')
370
371
372
373
374 clientXml.write(' </help>\n</tool>')
375
376 # clientXml.write(' <help>\n')
377
378 # j=0
379 # for param in params:
380 # clientXml.write('\n.. class:: infomark\n\n**TIP:** '+ param +' type is ' + paramTypes[j] +'\n')
381
382 # clientXml.write(' </help>\n</tool>')
383 # clientXml.write('</tool>')
384 clientXml.close()
385 editor = editToolConfig1()
386 editor.addTool(clientName)
387
388 ##later add help feature
389
390
391 def wadlClient(self):
392 ##parse wadl
393 pkg=JPackage('lsdis')
394 urlToPass=java.net.URL(self.webservice)
395 wadlUrl = self.webservice
396
397 webserviceId = ''#self.operation
398 resUrl = self.operation
399
400 urls = []
401 methods = []
402 params = []
403 docs = []
404
405 WADLParserDriver=pkg.WADLParserDriver
406 wPD=WADLParserDriver()
407 wPD.parse(urlToPass)
408 urls = wPD.getUrl()
409 methods = wPD.getCompleteMethodList()
410
411 #write into the output file information about the method and Web service to be invoked.
412 f=open(self.outputfile,'w')
413 f.write(self.webservice)
414 f.write('\n'+ resUrl)
415
416 a= str(self.webservice).split('/')
417 wadlnamelist = a[len(a)-1].split(".")
418 if len(wadlnamelist)==1:
419 wadlnamelist=a[len(a)-1].split('?')
420 print wadlnamelist
421
422 wadlname=wadlnamelist[0]
423
424
425 #get parameters for the selected method of the Web service
426 i=0
427 for method in methods:
428 x = str(method.getId())
429 y = str(urls.get(i))
430 webserviceId = x
431 #if x==webserviceId:
432 if y == resUrl :
433 params = method.getRequest().getParams()
434 break
435 i=i+1
436
437 f.write('\n'+webserviceId)
438 galaxyhome=os.environ.get('GALAXY_HOME')
439
440 methodname = resUrl.split('/')
441
442 #./clients/ClientCount.xml keeps the count of the clients/tools currently registered in Galaxy for Web service invocation.
443 #read the count and increment it.
444 clientCountFile=open(galaxyhome+'/tools/WebServiceToolWorkflow_REST_SOAP/clients/ClientCount.xml','r')
445 clientCountFile.readline()
446 clientCountStr = clientCountFile.readline()
447 clientCount=string.atoi(clientCountStr)
448 clientCount=clientCount+1
449 clientCountFile.close()
450
451 clientCountFile=open(galaxyhome+'/tools/WebServiceToolWorkflow_REST_SOAP/clients/ClientCount.xml','w')
452
453 clientCountFile.write('<count> \n')
454 clientCountFile.write(str(clientCount)+'\n')
455 clientCountFile.write('</count> \n')
456
457 #include the count in the tool's name and id to uniquely identify it.
458 clientName = 'WebServiceclient_'+ str(clientCount)
459
460 #create a new xml file under ./clients/
461 clientXml=open(galaxyhome+'/tools/WebServiceToolWorkflow_REST_SOAP/clients/'+clientName+'.xml','w')
462 clientXml.seek(0,0)
463
464 #write the tool id, name and description
465 clientXml.write('<tool id="' + clientName+'1" name="'+wadlname+'.' + methodname[-1] +' ">\n')
466 clientXml.write(' <description> Client for method : '+self.operation+' , Web service : '+self.webservice+' </description>\n')
467
468 #the one-time invocation tool/client for a REST Web service invokes ./clients/client_1.py to invoke the Web service
469 #write the command tag to specify the arguments passed to this client_1.py
470 clientXml.write(' <command interpreter="python">\n #if $cond_source.optional_param_source=="no" #client_1.py'+' $output $servicetype ' +resUrl)
471
472 j=0
473
474 for param in params:
475 if param.isRequired():
476 clientXml.write(' '+self.formatString(param.getName()))
477 clientXml.write(' $param' + str(j))
478 j=j+1
479 clientXml.write(' #else #client_1.py'+' $output $servicetype ' +resUrl)
480 j=0
481 for param in params:
482 if param.isRequired():
483 clientXml.write(' '+self.formatString(param.getName()))
484 clientXml.write(' $param' + str(j))
485 j=j+1
486
487 for param in params:
488 if not param.isRequired():
489 clientXml.write(' '+self.formatString(param.getName()))
490 clientXml.write(' $cond_source.param' + str(j))
491 j=j+1
492 clientXml.write(' #end if \n</command>\n')
493
494 #start writing inputs
495 ##write inputs depending on required or not. if not required den dont display
496 ##if required- den check default value, and if options exist.Depending on that
497 ##decide the type of parameter and options
498 ##The input servicetype tells what type of webservice it is wether SOAP or REST - Useful during invocation of the web servcie
499 clientXml.write(' <inputs>\n')
500 clientXml.write(' <param name="servicetype" type="hidden" value="REST" />')
501
502 #create a param for each required parameter described in the WADL. Check if defaults and options are specified in the WADL
503 j=0
504 for param in params:
505 if param.isRequired():
506 pName = param.getName()
507 for doc in param.getDocs():
508 if doc.getTitle()=="prompt" or doc.getTitle()=="Prompt" or doc.getTitle()=="PROMPT":
509 pName = doc.getInnerText()
510 if param.getOptions().size()==0:
511 clientXml.write('<param format="text" size = "150" name = "param'+str(j)+'" ')
512 if not param.getDefault1() == None:
513 clientXml.write('value="'+param.getDefault1()+'" ')
514 clientXml.write('type="text" label="Enter '+pName+'" help="see tip below" />\n')
515 j=j+1
516 else:
517 clientXml.write('<param name="param'+str(j)+'" type="select" label="Select '+pName+'" help="see tip below">\n' )
518 for option in param.getOptions():
519 clientXml.write(' <option value="'+self.formatString(option.getName())+'" ')
520 if option.getName() == param.getDefault1():
521 clientXml.write('selected="true"')
522 clientXml.write('>'+option.getName()+'</option>\n ')
523 clientXml.write(' </param> \n')
524 j=j+1
525
526 #create a conditional param for each optional parameter described in the WADL.
527 clientXml.write('\n <conditional name="cond_source"> \n <param name="optional_param_source" type="select" label="Show Optional Parameters">\n <option value="no" selected="true">no</option> \n <option value="yes">yes</option> \n </param>\n')
528 clientXml.write('<when value="no"> \n </when>')
529 clientXml.write('<when value="yes"> \n')
530 for param in params:
531 if not param.isRequired():
532 pName = param.getName()
533 for doc in param.getDocs():
534 if doc.getTitle()=="prompt" or doc.getTitle()=="Prompt" or doc.getTitle()=="PROMPT":
535 pName = doc.getInnerText()
536 if param.getOptions().size()==0:
537 clientXml.write('<param format="text" size = "150" name = "param'+str(j)+'" ')
538 if not param.getDefault1() == None:
539 clientXml.write('value="'+param.getDefault1()+'" ')
540 clientXml.write('type="text" label="Enter '+pName+'" help="see tip below" />\n')
541 j=j+1
542 else:
543 clientXml.write('<param name="param'+str(j)+'" type="select" label="Select '+pName+'" help="see tip below">\n' )
544 for option in param.getOptions():
545 clientXml.write(' <option value="'+self.formatString(option.getName())+'" ')
546 if option.getName() == param.getDefault1():
547 clientXml.write('selected="true"')
548 clientXml.write('>'+option.getName()+'</option>\n ')
549 clientXml.write(' </param> \n')
550 j=j+1
551
552
553 clientXml.write('</when>\n</conditional>')
554 clientXml.write('</inputs>\n <outputs>\n <data format="tabular" name="output" />\n </outputs>\n')
555
556 #write information about each parameter in the help section
557 clientXml.write(' <help>\n')
558
559 clientXml.write('Replace white space with ** in all parameter values\n')
560
561 for param in params:
562 if param.isRequired():
563 pName = param.getName()
564 for doc in param.getDocs():
565 if doc.getTitle()=="prompt" or doc.getTitle()=="Prompt" or doc.getTitle()=="PROMPT":
566 pName = doc.getInnerText()
567 clientXml.write('\n.. class:: infomark\n\n**TIP:** '+ pName +' type is ' + param.getType()+'\n')
568
569 clientXml.write(' </help>\n</tool>')
570
571
572 #adds the newly created tool to tool_conf.xml in Galaxy under the 'Web Service Tools' section.
573 editor = editToolConfig1()
574 editor.addTool(clientName)
575
576 ##later add help feature
577
578
579 def sawadlClient(self):
580 ##parse sawadl
581 javahome = os.environ.get('JAVA_HOME')
582 galaxyhome=os.environ.get('GALAXY_HOME')
583 classpath= galaxyhome + '/tools/WebServiceToolWorkflow_REST_SOAP/lib/SAWADLParser/bin'
584 jarpath = galaxyhome + '/tools/WebServiceToolWorkflow_REST_SOAP/lib/'
585 machine = platform.machine()
586
587 #if machine == 'x86_64' :
588 # print 'a'
589 # startJVM("%s/jre/lib/amd64/server/libjvm.so" % javahome,"-ea", "-Djava.class.path=%s" % classpath,"-Djava.ext.dirs=%s" % jarpath)
590 #elif machine == 'i686' :
591 # print 'b'
592 # startJVM("%s/jre/lib/i386/server/libjvm.so" % javahome,"-ea", "-Djava.class.path=%s" % classpath,"-Djava.ext.dirs=%s" % jarpath)
593 #elif machine == 'sun4u' :
594 # startJVM("%s/jre/lib/sparc/server/libjvm.so" % javahome,"-ea", "-Djava.class.path=%s" % classpath,"-Djava.ext.dirs=%s" % jarpath)
595 #else :
596 # print 'c'
597 # System.exit("Could not identify machine, please specify path to libjvm.so")
598
599
600 pkg=JPackage('edu.uga.cs.lsdis.meteors.wadls')
601 pkgModel =JPackage('org.semanticweb.owlapi.model')
602 pkgApiBinding =JPackage('org.semanticweb.owlapi.apibinding')
603 pkgVocab = JPackage('org.semanticweb.owlapi.vocab')
604
605 DOCUMENT_IRI = "http://cs.uga.edu/~ganjoo/galaxy/EDAM.owl"
606
607 sawadlUrl = self.webservice
608
609 webserviceId = ''#self.methodName
610 resUrl = self.operation
611
612 urls = []
613 methods = []
614 params = []
615 annotationSet = []
616
617 SAWADLParserDriver=pkg.SAWADLParserDriver
618 sawPD=SAWADLParserDriver()
619 sawPD.parse(sawadlUrl)
620 urls = sawPD.getUrl()
621 methods = sawPD.getCompleteMethodList()
622
623 IRI = pkgModel.IRI
624 OWLRDFVocabulary = pkgVocab.OWLRDFVocabulary
625 OWLManager = pkgApiBinding.OWLManager
626 OWLLiteral = pkgModel.OWLLiteral
627 owlOntManager = OWLManager.createOWLOntologyManager()
628 ontology = owlOntManager.loadOntologyFromOntologyDocument(IRI.create(DOCUMENT_IRI))
629 dataFactory = owlOntManager.getOWLDataFactory()
630 propertyComment = dataFactory.getOWLAnnotationProperty(OWLRDFVocabulary.RDFS_COMMENT.getIRI())
631
632 f=open(self.outputfile,'w')
633 f.write(sawadlUrl)
634 f.write(resUrl+'\t')
635
636
637 i=0
638 for method in methods:
639 x = str(method.getName())
640 y = str(urls.get(i))
641 #if x == webserviceId :
642 webserviceId = x
643 if y == resUrl :
644 params = method.getRequest().getParamList()
645 break
646 i=i+1
647
648 f.write(webserviceId)
649
650
651 ##generate client's xml
652 galaxyhome=os.environ.get('GALAXY_HOME')
653
654 #./clients/ClientCount.xml keeps the count of the clients/tools currently registered in Galaxy for Web service invocation.
655 #read the count and increment it.
656
657 clientCountFile=open(galaxyhome+'/tools/WebServiceToolWorkflow_REST_SOAP/clients/ClientCount.xml','r')
658 clientCountFile.readline()
659 clientCountStr = clientCountFile.readline()
660 clientCount=string.atoi(clientCountStr)
661 clientCount=clientCount+1
662 clientCountFile.close()
663
664 clientCountFile=open(galaxyhome+'/tools/WebServiceToolWorkflow_REST_SOAP/clients/ClientCount.xml','w')
665 clientCountFile.write('<count> \n')
666 clientCountFile.write(str(clientCount)+'\n')
667 clientCountFile.write('</count> \n')
668
669 clientName = 'WebServiceclient_'+ str(clientCount)
670
671 clientXml=open(galaxyhome+'/tools/WebServiceToolWorkflow_REST_SOAP/clients/'+clientName+'.xml','w')
672 clientXml.seek(0,0)
673
674 clientXml.write('<tool id="' + clientName+'1" name="' + webserviceId +'">\n')
675 clientXml.write(' <description> Client for method: '+webserviceId+' , Web service: '+self.webservice+' </description>\n')
676
677
678 clientXml.write(' <command interpreter="python">\n #if $cond_source.optional_param_source=="no" #client_1.py'+' $output $servicetype ' +resUrl)
679 ##write such that the parameters passed to client1.py(change name to clientName.py) are dependent on a for loop
680
681
682 j=0
683 for param in params:
684 if param.getRequired()=='true' or param.getRequired()=='True' or param.getRequired()=='TRUE':
685 clientXml.write(' '+self.formatString(param.getName())+'\n')
686 clientXml.write(' $param' + str(j)+'\n')
687 j=j+1
688
689 clientXml.write(' #else #client_1.py'+' $output $servicetype ' +resUrl)
690 j=0
691 for param in params:
692 if param.getRequired()=='true' or param.getRequired()=='True' or param.getRequired()=='TRUE':
693 clientXml.write(' '+self.formatString(param.getName()))
694 clientXml.write(' $param' + str(j))
695 j=j+1
696
697 for param in params:
698 if not param.getRequired()=='true' and not param.getRequired()=='True' and not param.getRequired()=='TRUE':
699 clientXml.write(' '+self.formatString(param.getName()))
700 clientXml.write(' $cond_source.param' + str(j))
701 j=j+1
702
703 clientXml.write('#end if \n </command>\n')
704
705 #start writing inputs
706 ##write inputs depending on required or not. if not required den dont display
707 ##if required- den check default value, and if options exist.Depending on that
708 ##decide the type of parameter and options
709 ##The input param servicetype tells what type of webservice it is wether SOAP or REST - Useful during invocation of the web servcie
710 clientXml.write(' <inputs>\n')
711 cleintXml.write(' <param name="servicetype" type="hidden" value="REST"/>')
712
713 j=0
714 for param in params:
715 if param.getRequired()=='true' or param.getRequired()=='True' or param.getRequired()=='TRUE':
716 f.write('\n '+ param.getName() + ' options: '+str(param.getOptionvalue().size()))
717 if param.getOptionvalue().size()==0:
718 clientXml.write('<param format="text" size = "150" name = "param'+str(j)+'" ')
719 if not param.getDefault1() == None:
720 clientXml.write('value="'+param.getDefault1()+'" ')
721 clientXml.write('type="text" label="Enter '+param.getName()+'" help="see tip below" />\n')
722 j=j+1
723 else:
724 clientXml.write('<param name="param'+str(j)+'" type="select" label="Select '+param.getName()+'" help="see tip below">\n' )
725 for option in param.getOptionvalue():
726 clientXml.write(' <option value="'+self.formatString(option)+'" ')
727 if option == param.getDefault1():
728 clientXml.write('selected="true"')
729 clientXml.write('>'+option+'</option>\n ')
730 clientXml.write(' </param> \n')
731 j=j+1
732
733
734 clientXml.write('\n <conditional name="cond_source"> \n <param name="optional_param_source" type="select" label="Display Optional Parameters">\n <option value="no" selected="true">no</option> \n <option value="yes">yes</option> \n </param>\n')
735 clientXml.write('<when value="no"> \n </when>')
736 clientXml.write('<when value="yes"> \n')
737
738 for param in params:
739 if not param.getRequired()=='true' and not param.getRequired()=='True' and not param.getRequired()=='TRUE':
740 f.write('\n '+ param.getName() + ' options: '+str(param.getOptionvalue().size()))
741 if param.getOptionvalue().size()==0:
742 clientXml.write('<param format="text" size = "150" name = "param'+str(j)+'" ')
743 if not param.getDefault1() == None:
744 clientXml.write('value="'+param.getDefault1()+'" ')
745 clientXml.write('type="text" label="Enter '+param.getName()+'" help="see tip below" />\n')
746 j=j+1
747 else:
748 clientXml.write('<param name="param'+str(j)+'" type="select" label="Select '+param.getName()+'" help="see tip below">\n' )
749 for option in param.getOptionvalue():
750 clientXml.write(' <option value="'+self.formatString(option)+'" ')
751 if option == param.getDefault1():
752 clientXml.write('selected="true"')
753 clientXml.write('>'+option+'</option>\n ')
754 clientXml.write(' </param> \n')
755 j=j+1
756
757 clientXml.write('</when>\n</conditional>\n')
758
759 clientXml.write('</inputs>\n <outputs>\n <data format="tabular" name="output" />\n </outputs>\n')
760
761 clientXml.write(' <help>\n')
762 for param in params:
763 if param.getRequired()=='true' or param.getRequired()=='True' or param.getRequired()=='TRUE':
764 clientXml.write('\n.. class:: infomark\n\n**TIP:** About '+ param.getName() +': type is ' + param.getType())
765
766 modelRef = sawPD.getCompleteModelReference(param)
767 if not modelRef is None:
768 paramClass = dataFactory.getOWLClass(IRI.create(modelRef));
769 annotationSet = paramClass.getAnnotations(ontology,propertyComment)
770 for annotation in annotationSet:
771 if isinstance(annotation.getValue(),OWLLiteral):
772 val = annotation.getValue()
773 if val.isOWLStringLiteral() and not val.isOWLTypedLiteral():
774 print 'val.getLiteral()=' + val.getLiteral()
775 clientXml.write(', description from ontology is "' + val.getLiteral()+'"')
776 break
777 clientXml.write('\n')
778 clientXml.write(' </help>\n</tool>')
779 editor = editToolConfig1()
780 editor.addTool(clientName)
781
782 ##later add help feature
783
784 def wsdlRESTClient(self):
785 ##parse wadl
786 javahome = os.environ.get('JAVA_HOME')
787 galaxyhome=os.environ.get('GALAXY_HOME')
788 classpath= galaxyhome + '/tools/WebServiceToolWorkflow_REST_SOAP/WodenWSDLParser/bin'
789 jarpath = galaxyhome + '/tools/WebServiceToolWorkflow_REST_SOAP/WodenWSDLParser/lib/'
790 machine = platform.machine()
791
792 if machine == 'x86_64' :
793 print 'a'
794 startJVM("%s/jre/lib/amd64/server/libjvm.so" % javahome,"-ea", "-Djava.class.path=%s" % classpath,"-Djava.ext.dirs=%s" % jarpath)
795 elif machine == 'i686' :
796 print 'b'
797 startJVM("%s/jre/lib/i386/server/libjvm.so" % javahome,"-ea", "-Djava.class.path=%s" % classpath,"-Djava.ext.dirs=%s" % jarpath)
798 elif machine == 'sun4u' :
799 startJVM("%s/jre/lib/sparc/server/libjvm.so" % javahome,"-ea", "-Djava.class.path=%s" % classpath,"-Djava.ext.dirs=%s" % jarpath)
800 else :
801 print 'c'
802 System.exit("Could not identify machine, please specify path to libjvm.so")
803
804
805 pkg=JPackage('lsdis')
806 wsdlUrl = self.webserviceId
807
808 webserviceId = ''#self.methodName
809 resUrl = self.resourceName
810
811 urls = []
812 methods = []
813 params = []
814 paramTypes = []
815
816 WSDLParserDriver =pkg.WSDLParserDriver
817 wPD=WSDLParserDriver()
818 wPD.parse(wsdlUrl)
819 methods = wPD.getCompleteMethodList()
820 urls = wPD.getUrl()
821
822 f=open(self.Ofile,'w')
823 f.write(wsdlUrl)
824 f.write('\n'+ resUrl)
825 f.write('\n'+webserviceId)
826
827
828 i=0
829 for method in methods:
830 x = str(method.getName().getLocalPart())
831 y = str(url.get(i))
832 webserviceId = x
833 if y == resUrl :
834 wPD.getParameters(x)
835 f.write('method matched')
836 paramTypes = wPD.getParamTypeList()
837 params = wPD.getParamList()
838 break
839 i=i+1
840
841
842
843
844 ##generate client's xml
845 galaxyhome=os.environ.get('GALAXY_HOME')
846
847 clientCountFile=open(galaxyhome+'/tools/WebServiceTool/clients/ClientCount.xml','r')
848 clientCountFile.readline()
849 clientCountStr = clientCountFile.readline()
850 clientCount=string.atoi(clientCountStr)
851 clientCount=clientCount+1
852 clientCountFile.close()
853
854 clientCountFile=open(galaxyhome+'/tools/WebServiceTool/clients/ClientCount.xml','w')
855 clientCountFile.write('<count> \n')
856 clientCountFile.write(str(clientCount)+'\n')
857 clientCountFile.write('</count> \n')
858
859
860
861
862 clientName = 'WebServiceclient_'+ str(clientCount)
863
864 clientXml=open(galaxyhome+'/tools/WebServiceTool/clients/'+clientName+'.xml','w')
865 clientXml.seek(0,0)
866
867 clientXml.write('<tool id="' + clientName+'" name="' + webserviceId +'">\n')
868 clientXml.write(' <description> Client for method: '+webserviceId+' , Web service: '+self.webservice+' </description>\n')
869
870
871 clientXml.write(' <command interpreter="python">\n client_1.py \n'+' $output \n $servicetype\n ' +resUrl+'\n')
872 ##write such that the parameters passed to client1.py(change name to clientName.py) are dependent on a for loop
873
874 j=0
875 for param in params:
876 clientXml.write(' '+self.formatString(param)+'\n')
877 clientXml.write(' $param' + str(j)+'\n')
878 j=j+1
879 clientXml.write('</command>\n')
880
881 ##write inputs depending on required or not. if not required den dont display
882 ##if required- den check default value, and if options exist.Depending on that
883 ##decide the type of parameter and options
884 clientXml.write(' <inputs>\n')
885 cleintXml.write(' <param name="servicetype" type="hidden" value="REST"/>')
886
887 j=0
888 for param in params:
889 clientXml.write('<param format="text" size = "150" name = "param'+str(j)+'" ')
890 clientXml.write('type="text" label="'+param+'" help="see tip below" />\n')
891 j=j+1
892
893
894
895 clientXml.write('</inputs>\n <outputs>\n <data format="tabular" name="output" />\n </outputs>\n')
896
897 clientXml.write(' <help>\n')
898
899 clientXml.write('** Replace white with ** in all parameter values **\n')
900
901 j=0
902 for param in params:
903 clientXml.write('\n.. class:: infomark\n\n**TIP:** '+ param +' type is ' + paramTypes[j] +'\n')
904
905 clientXml.write(' </help>\n</tool>')
906 editor = editToolConfig()
907 editor.addTool(clientName)
908
909 ##later add help feature
910
911
912 # Addedfor testing purpose
913
914 if __name__ == "__main__":
915
916 test = ClientGenerator1('http://www.cs.uga.edu/~guttula/wublast.wsdl','run',None,'SOAP')
917 present = test.isToolPresent()
918 required = test.isRequired('_parameters|_sequence')
919 print 'required : ',required