RAPP Platform  v0.6.0
RAPP Platform is a collection of ROS nodes and back-end processes that aim to deliver ready-to-use generic services to robots
 All Classes Namespaces Files Functions Variables Macros
mysql_wrapper_old.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 #Copyright 2015 RAPP
4 
5 #Licensed under the Apache License, Version 2.0 (the "License");
6 #you may not use this file except in compliance with the License.
7 #You may obtain a copy of the License at
8 
9  #http://www.apache.org/licenses/LICENSE-2.0
10 
11 #Unless required by applicable law or agreed to in writing, software
12 #distributed under the License is distributed on an "AS IS" BASIS,
13 #WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 #See the License for the specific language governing permissions and
15 #limitations under the License.
16 
17 # Author: Athanassios Kintsakis
18 # contact: akintsakis@issel.ee.auth.gr
19 
20 import rospy
21 import MySQLdb as mdb
22 import sys
23 
24 from rapp_platform_ros_communications.srv import (
25  fetchDataSrv,
26  fetchDataSrvResponse,
27  writeDataSrv,
28  writeDataSrvResponse,
29  deleteDataSrv,
30  deleteDataSrvResponse,
31  updateDataSrv,
32  updateDataSrvResponse,
33  whatRappsCanRunSrv,
34  whatRappsCanRunSrvResponse,
35  authTokenByServiceSrv,
36  authTokenByServiceSrvResponse,
37  )
38 
39 from rapp_platform_ros_communications.msg import (
40  StringArrayMsg
41  )
42 
43 from std_msgs.msg import (
44  String
45  )
46 
47 ## @class MySQLdbWrapper
48 # @brief The mysql wrapper ros node
50 
51  ## @brief Default contructor
52  #
53  # Declares the callbacks of the node's services
54  def __init__(self):
55  #tblUser services launch
56  self.serv_topic = rospy.get_param("rapp_mysql_wrapper_user_fetch_data_topic")
57  if(not self.serv_topic):
58  rospy.logerror("rapp_mysql_wrapper_user_fetch_data_topic")
59  self.serv=rospy.Service(self.serv_topic, fetchDataSrv, self.tblUserFetchDataHandler)
60  self.serv_topic = rospy.get_param("rapp_mysql_wrapper_user_write_data_topic")
61  if(not self.serv_topic):
62  rospy.logerror("rapp_mysql_wrapper_user_write_data_topic")
63  self.serv=rospy.Service(self.serv_topic, writeDataSrv, self.tblUserWriteDataHandler)
64  self.serv_topic = rospy.get_param("rapp_mysql_wrapper_user_delete_data_topic")
65  if(not self.serv_topic):
66  rospy.logerror("rapp_mysql_wrapper_user_delete_data_topic")
67  self.serv=rospy.Service(self.serv_topic, deleteDataSrv, self.tblUserDeleteDataHandler)
68  self.serv_topic = rospy.get_param("rapp_mysql_wrapper_user_update_data_topic")
69  if(not self.serv_topic):
70  rospy.logerror("rapp_mysql_wrapper_user_update_data_topic")
71  self.serv=rospy.Service(self.serv_topic, updateDataSrv, self.tblUserUpdateDataHandler)
72  #tblModel services launch
73  self.serv_topic = rospy.get_param("rapp_mysql_wrapper_model_fetch_data_topic")
74  if(not self.serv_topic):
75  rospy.logerror("rapp_mysql_wrapper_model_fetch_data_topic")
76  self.serv=rospy.Service(self.serv_topic, fetchDataSrv, self.tblModelFetchDataHandler)
77  self.serv_topic = rospy.get_param("rapp_mysql_wrapper_model_write_data_topic")
78  if(not self.serv_topic):
79  rospy.logerror("rapp_mysql_wrapper_model_write_data_topic")
80  self.serv=rospy.Service(self.serv_topic, writeDataSrv, self.tblModelWriteDataHandler)
81  self.serv_topic = rospy.get_param("rapp_mysql_wrapper_model_delete_data_topic")
82  if(not self.serv_topic):
83  rospy.logerror("rapp_mysql_wrapper_model_delete_data_topic")
84  self.serv=rospy.Service(self.serv_topic, deleteDataSrv, self.tblModelDeleteDataHandler)
85  self.serv_topic = rospy.get_param("rapp_mysql_wrapper_model_update_data_topic")
86  if(not self.serv_topic):
87  rospy.logerror("rapp_mysql_wrapper_model_update_data_topic")
88  self.serv=rospy.Service(self.serv_topic, updateDataSrv, self.tblModelUpdateDataHandler)
89  #tblRapp services launch
90  self.serv_topic = rospy.get_param("rapp_mysql_wrapper_rapp_fetch_data_topic")
91  if(not self.serv_topic):
92  rospy.logerror("rapp_mysql_wrapper_rapp_fetch_data_topic")
93  self.serv=rospy.Service(self.serv_topic, fetchDataSrv, self.tblRappFetchDataHandler)
94  self.serv_topic = rospy.get_param("rapp_mysql_wrapper_rapp_write_data_topic")
95  if(not self.serv_topic):
96  rospy.logerror("rapp_mysql_wrapper_rapp_write_data_topic")
97  self.serv=rospy.Service(self.serv_topic, writeDataSrv, self.tblRappWriteDataHandler)
98  self.serv_topic = rospy.get_param("rapp_mysql_wrapper_rapp_delete_data_topic")
99  if(not self.serv_topic):
100  rospy.logerror("rapp_mysql_wrapper_rapp_delete_data_topic")
101  self.serv=rospy.Service(self.serv_topic, deleteDataSrv, self.tblRappDeleteDataHandler)
102  self.serv_topic = rospy.get_param("rapp_mysql_wrapper_rapp_update_data_topic")
103  if(not self.serv_topic):
104  rospy.logerror("rapp_mysql_wrapper_rapp_update_data_topic")
105  self.serv=rospy.Service(self.serv_topic, updateDataSrv, self.tblRappUpdateDataHandler)
106  #tblRobot services launch
107  self.serv_topic = rospy.get_param("rapp_mysql_wrapper_robot_fetch_data_topic")
108  if(not self.serv_topic):
109  rospy.logerror("rapp_mysql_wrapper_robot_fetch_data_topic")
110  self.serv=rospy.Service(self.serv_topic, fetchDataSrv, self.tblRobotFetchDataHandler)
111  self.serv_topic = rospy.get_param("rapp_mysql_wrapper_robot_write_data_topic")
112  if(not self.serv_topic):
113  rospy.logerror("rapp_mysql_wrapper_robot_write_data_topic")
114  self.serv=rospy.Service(self.serv_topic, writeDataSrv, self.tblRobotWriteDataHandler)
115  self.serv_topic = rospy.get_param("rapp_mysql_wrapper_robot_delete_data_topic")
116  if(not self.serv_topic):
117  rospy.logerror("rapp_mysql_wrapper_robot_delete_data_topic")
118  self.serv=rospy.Service(self.serv_topic, deleteDataSrv, self.tblRobotDeleteDataHandler)
119  self.serv_topic = rospy.get_param("rapp_mysql_wrapper_robot_update_data_topic")
120  if(not self.serv_topic):
121  rospy.logerror("rapp_mysql_wrapper_robot_update_data_topic")
122  self.serv=rospy.Service(self.serv_topic, updateDataSrv, self.tblRobotUpdateDataHandler)
123  #tblAppsRobots services launch
124  self.serv_topic = rospy.get_param("rapp_mysql_wrapper_apps_robots_fetch_data_topic")
125  if(not self.serv_topic):
126  rospy.logerror("rapp_mysql_wrapper_apps_robots_fetch_data_topic")
127  self.serv=rospy.Service(self.serv_topic, fetchDataSrv, self.tblAppsRobotsFetchDataHandler)
128  self.serv_topic = rospy.get_param("rapp_mysql_wrapper_apps_robots_write_data_topic")
129  if(not self.serv_topic):
130  rospy.logerror("rapp_mysql_wrapper_apps_robots_write_data_topic")
131  self.serv=rospy.Service(self.serv_topic, writeDataSrv, self.tblAppsRobotsWriteDataHandler)
132  self.serv_topic = rospy.get_param("rapp_mysql_wrapper_apps_robots_delete_data_topic")
133  if(not self.serv_topic):
134  rospy.logerror("rapp_mysql_wrapper_apps_robots_delete_data_topic")
135  self.serv=rospy.Service(self.serv_topic, deleteDataSrv, self.tblAppsRobotsDeleteDataHandler)
136  self.serv_topic = rospy.get_param("rapp_mysql_wrapper_apps_robots_update_data_topic")
137  if(not self.serv_topic):
138  rospy.logerror("rapp_mysql_wrapper_apps_robots_update_data_topic")
139  self.serv=rospy.Service(self.serv_topic, updateDataSrv, self.tblAppsRobotsUpdateDataHandler)
140  #tblUsersOntologyInstances services launch
141  self.serv_topic = rospy.get_param("rapp_mysql_wrapper_users_ontology_instances_fetch_data_topic")
142  if(not self.serv_topic):
143  rospy.logerror("rapp_mysql_wrapper_users_ontology_instances_fetch_data_topic")
144  self.serv=rospy.Service(self.serv_topic, fetchDataSrv, self.tblUsersOntologyInstancesFetchDataHandler)
145  self.serv_topic = rospy.get_param("rapp_mysql_wrapper_users_ontology_instances_write_data_topic")
146  if(not self.serv_topic):
147  rospy.logerror("rapp_mysql_wrapper_users_ontology_instances_write_data_topic")
148  self.serv=rospy.Service(self.serv_topic, writeDataSrv, self.tblUsersOntologyInstancesWriteDataHandler)
149  self.serv_topic = rospy.get_param("rapp_mysql_wrapper_users_ontology_instances_delete_data_topic")
150  if(not self.serv_topic):
151  rospy.logerror("rapp_mysql_wrapper_users_ontology_instances_delete_data_topic")
152  self.serv=rospy.Service(self.serv_topic, deleteDataSrv, self.tblUsersOntologyInstancesDeleteDataHandler)
153  self.serv_topic = rospy.get_param("rapp_mysql_wrapper_users_ontology_instances_update_data_topic")
154  if(not self.serv_topic):
155  rospy.logerror("rapp_mysql_wrapper_users_ontology_instances_update_data_topic")
156  self.serv=rospy.Service(self.serv_topic, updateDataSrv, self.tblUsersOntologyInstancesUpdateDataHandler)
157  #viewUsersRobotsApps services launch
158  self.serv_topic = rospy.get_param("rapp_mysql_wrapper_view_users_robots_apps_topic")
159  if(not self.serv_topic):
160  rospy.logerror("rapp_mysql_wrapper_view_users_robots_apps_topic")
161  self.serv=rospy.Service(self.serv_topic, fetchDataSrv, self.viewUsersRobotsAppsFetchDataHandler)
162 
163  self.serv_topic = rospy.get_param("rapp_mysql_wrapper_what_rapps_can_run_topic")
164  if(not self.serv_topic):
165  rospy.logerror("rapp_mysql_wrapper_what_rapps_can_run Not found error")
166  self.serv=rospy.Service(self.serv_topic, whatRappsCanRunSrv, self.whatRappsCanRunDataHandler)
167 
168  self.serv_topic = rospy.get_param("rapp_mysql_wrapper_auth_token_by_service_topic")
169  if(not self.serv_topic):
170  rospy.logerror("rapp_mysql_wrapper_auth_token_by_service_topic Not found error")
171  self.serv=rospy.Service(self.serv_topic, authTokenByServiceSrv, self.authTokenByServiceDataHandler)
172 
173 
174  #cloud agent tables
175  #cloud_agent services launch
176  self.serv_topic = rospy.get_param("rapp_mysql_wrapper_cloud_agent_fetch_data_topic")
177  if(not self.serv_topic):
178  rospy.logerror("rapp_mysql_wrapper_cloud_agent_fetch_data_topic")
179  self.serv=rospy.Service(self.serv_topic, fetchDataSrv, self.tblCloudAgentFetchDataHandler)
180  self.serv_topic = rospy.get_param("rapp_mysql_wrapper_cloud_agent_write_data_topic")
181  if(not self.serv_topic):
182  rospy.logerror("rapp_mysql_wrapper_cloud_agent_write_data_topic")
183  self.serv=rospy.Service(self.serv_topic, writeDataSrv, self.tblCloudAgentWriteDataHandler)
184  self.serv_topic = rospy.get_param("rapp_mysql_wrapper_cloud_agent_delete_data_topic")
185  if(not self.serv_topic):
186  rospy.logerror("rapp_mysql_wrapper_cloud_agent_delete_data_topic")
187  self.serv=rospy.Service(self.serv_topic, deleteDataSrv, self.tblCloudAgentDeleteDataHandler)
188  self.serv_topic = rospy.get_param("rapp_mysql_wrapper_cloud_agent_update_data_topic")
189  if(not self.serv_topic):
190  rospy.logerror("rapp_mysql_wrapper_cloud_agent_update_data_topic")
191  self.serv=rospy.Service(self.serv_topic, updateDataSrv, self.tblCloudAgentUpdateDataHandler)
192 
193  #cloud_agent_service services launch
194  self.serv_topic = rospy.get_param("rapp_mysql_wrapper_cloud_agent_service_fetch_data_topic")
195  if(not self.serv_topic):
196  rospy.logerror("rapp_mysql_wrapper_cloud_agent_service_fetch_data_topic")
197  self.serv=rospy.Service(self.serv_topic, fetchDataSrv, self.tblCloudAgentServiceFetchDataHandler)
198  self.serv_topic = rospy.get_param("rapp_mysql_wrapper_cloud_agent_service_write_data_topic")
199  if(not self.serv_topic):
200  rospy.logerror("rapp_mysql_wrapper_cloud_agent_service_write_data_topic")
201  self.serv=rospy.Service(self.serv_topic, writeDataSrv, self.tblCloudAgentServiceWriteDataHandler)
202  self.serv_topic = rospy.get_param("rapp_mysql_wrapper_cloud_agent_service_delete_data_topic")
203  if(not self.serv_topic):
204  rospy.logerror("rapp_mysql_wrapper_cloud_agent_service_delete_data_topic")
205  self.serv=rospy.Service(self.serv_topic, deleteDataSrv, self.tblCloudAgentServiceDeleteDataHandler)
206  self.serv_topic = rospy.get_param("rapp_mysql_wrapper_cloud_agent_service_update_data_topic")
207  if(not self.serv_topic):
208  rospy.logerror("rapp_mysql_wrapper_cloud_agent_service_update_data_topic")
209  self.serv=rospy.Service(self.serv_topic, updateDataSrv, self.tblCloudAgentServiceUpdateDataHandler)
210 
211  #cloud_agent_service_arguments_ services launch
212  self.serv_topic = rospy.get_param("rapp_mysql_wrapper_cloud_agent_service_arguments_fetch_data_topic")
213  if(not self.serv_topic):
214  rospy.logerror("rapp_mysql_wrapper_cloud_agent_service_arguments_fetch_data_topic")
215  self.serv=rospy.Service(self.serv_topic, fetchDataSrv, self.tblCloudAgentServiceArgumentsFetchDataHandler)
216  self.serv_topic = rospy.get_param("rapp_mysql_wrapper_cloud_agent_service_arguments_write_data_topic")
217  if(not self.serv_topic):
218  rospy.logerror("rapp_mysql_wrapper_cloud_agent_service_arguments_write_data_topic")
219  self.serv=rospy.Service(self.serv_topic, writeDataSrv, self.tblCloudAgentServiceArgumentsWriteDataHandler)
220  self.serv_topic = rospy.get_param("rapp_mysql_wrapper_cloud_agent_service_arguments_delete_data_topic")
221  if(not self.serv_topic):
222  rospy.logerror("rapp_mysql_wrapper_cloud_agent_service_arguments_delete_data_topic")
223  self.serv=rospy.Service(self.serv_topic, deleteDataSrv, self.tblCloudAgentServiceArgumentsDeleteDataHandler)
224  self.serv_topic = rospy.get_param("rapp_mysql_wrapper_cloud_agent_service_arguments_update_data_topic")
225  if(not self.serv_topic):
226  rospy.logerror("rapp_mysql_wrapper_cloud_agent_service_arguments_update_data_topic")
227  self.serv=rospy.Service(self.serv_topic, updateDataSrv, self.tblCloudAgentServiceArgumentsUpdateDataHandler)
228 
229  ## @brief Implements the general write data to table function
230  # @param req [rapp_platform_ros_communications::writeDataSrvRequest::Request&] The ROS service request
231  # @param tblName [string] the table name
232  # @param res [rapp_platform_ros_communications::writeDataResponse::Response&] The ROS service response
233  def writeData(self,req,tblName):
234  try:
235  print tblName
236  res = writeDataSrvResponse()
237  db_username,db_password=self.getLogin()
238  con = mdb.connect('localhost', db_username, db_password, 'RappStore');
239  cur = con.cursor()
240  returncols=self.constructCommaColumns(req.req_cols)
241  if (len(returncols)>1):
242  returncols="("+returncols+")"
243  print returncols
244  values=""
245  for i in range(len(req.req_data)):
246  if (i==0):
247  values=values+"("+self.constructCommaColumns(req.req_data[i].s)+")"
248  else:
249  values=values+",("+self.constructCommaColumns(req.req_data[i].s)+")"
250 
251  query="Insert into "+tblName+" "+ returncols+" values "+values
252  cur.execute("LOCK TABLES "+tblName+" WRITE")
253  cur.execute(query)
254  cur.execute("UNLOCK TABLES")
255  con.close()
256  res.success.data=True
257  res.trace.append("Success")
258  except mdb.Error, e:
259  res.trace.append(("Database Error %d: %s" % (e.args[0],e.args[1])))
260  res.success.data=False
261  res.error="Error %d: %s" % (e.args[0],e.args[1])
262  except IndexError, e:
263  res.trace.append("IndexError: " +str(e))
264  res.success.data=False
265  res.error="IndexError: " +str(e)
266  except IOError, e:
267  res.success.data=False
268  res.trace.append("IOError: " +str(e))
269  res.error="IOError: " +str(e)
270  return res
271 
272  ## @brief Implements the general delete data from table function
273  # @param req [rapp_platform_ros_communications::deleteDataSrvRequest::Request&] The ROS service request
274  # @param tblName [string] the table name
275  # @param res [rapp_platform_ros_communications::deleteDataSrvResponse::Response&] The ROS service response
276  def deleteData(self,req,tblName):
277  try:
278  res = deleteDataSrvResponse()
279  db_username,db_password=self.getLogin()
280  con = mdb.connect('localhost', db_username, db_password, 'RappStore');
281  cur = con.cursor()
282  where=self.constructAndQuery(req.where_data)
283  query="Delete from "+tblName+where
284  cur.execute("LOCK TABLES "+tblName+" WRITE")
285  cur.execute(query)
286  cur.execute("UNLOCK TABLES")
287  con.close()
288  res.success.data=True
289  res.trace.append("Success")
290  except mdb.Error, e:
291  res.trace.append(("Database Error %d: %s" % (e.args[0],e.args[1])))
292  res.success.data=False
293  res.error="Error %d: %s" % (e.args[0],e.args[1])
294  except IndexError, e:
295  res.trace.append("IndexError: " +str(e))
296  res.success.data=False
297  res.error="IndexError: " +str(e)
298  except IOError, e:
299  res.success.data=False
300  res.trace.append("IOError: " +str(e))
301  res.error="IOError: " +str(e)
302  return res
303 
304  ## @brief Implements the general update data from table function
305  # @param req [rapp_platform_ros_communications::updateDataSrvRequest::Request&] The ROS service request
306  # @param tblName [string] the table name
307  # @param res [rapp_platform_ros_communications::updateDataSrvResponse::Response&] The ROS service response
308  def updateData(self,req,tblName):
309  try:
310  res = updateDataSrvResponse()
311  db_username,db_password=self.getLogin()
312  con = mdb.connect('localhost', db_username, db_password, 'RappStore');
313  cur = con.cursor()
314  returncols=self.constructCommaColumns(req.set_cols)
315  where=self.constructAndQuery(req.where_data)
316  query="Update "+tblName+" SET "+returncols+where
317  print query
318  cur.execute("LOCK TABLES "+tblName+" WRITE")
319  cur.execute(query)
320  cur.execute("UNLOCK TABLES")
321  con.close()
322  res.success.data=True
323  res.trace.append("Success")
324  except mdb.Error, e:
325  res.trace.append(("Database Error %d: %s" % (e.args[0],e.args[1])))
326  res.success.data=False
327  res.error="Error %d: %s" % (e.args[0],e.args[1])
328  except IndexError, e:
329  res.trace.append("IndexError: " +str(e))
330  res.success.data=False
331  res.error="IndexError: " +str(e)
332  except IOError, e:
333  res.success.data=False
334  res.trace.append("IOError: " +str(e))
335  res.error="IOError: " +str(e)
336  return res
337 
338  ## @brief Implements the general fetch data from table function
339  # @param req [rapp_platform_ros_communications::fetchDataSrvRequest::Request&] The ROS service request
340  # @param tblName [string] the table name
341  # @param res [rapp_platform_ros_communications::fetchDataSrvResponse::Response&] The ROS service response
342  def fetchData(self,req,tblName):
343  try:
344  res = fetchDataSrvResponse()
345  db_username,db_password=self.getLogin()
346  con = mdb.connect('localhost', db_username, db_password, 'RappStore');
347  cur = con.cursor()
348  returncols=self.constructCommaColumns(req.req_cols)
349  where=self.constructAndQuery(req.where_data)
350  query="SELECT "+returncols+" FROM "+tblName+where
351  cur.execute(query)
352  result_set = cur.fetchall()
353  for i in range(len(result_set)):
354  line=StringArrayMsg()
355  for j in range(len(result_set[i])):
356  temp_s=String(result_set[i][j])
357  line.s.append((str(result_set[i][j])))
358  res.res_data.append(line)
359 
360  con.close()
361  if (returncols=="*"):
362  res.res_cols=self.getTableColumnNames(tblName)
363  else:
364  res.res_cols=req.req_cols
365  con.close()
366  res.success.data=True
367  res.trace.append("Success")
368  except mdb.Error, e:
369  res.trace.append(("Database Error %d: %s" % (e.args[0],e.args[1])))
370  res.success.data=False
371  res.error="Error %d: %s" % (e.args[0],e.args[1])
372  except IndexError, e:
373  res.trace.append("IndexError: " +str(e))
374  res.success.data=False
375  res.error="IndexError: " +str(e)
376  except IOError, e:
377  res.success.data=False
378  res.trace.append("IOError: " +str(e))
379  res.error="IOError: " +str(e)
380  return res
381 
382  ## @brief Implements the whatRappsCanRun service
383  # @param req [rapp_platform_ros_communications::whatRappsCanRunSrvResponse::Request&] The ROS service request
384  # @param tblName [string] the table name
385  # @param res [rapp_platform_ros_communications::whatRappsCanRunSrvResponse::Response&] The ROS service response
386  def whatRappsCanRun(self,req,tblName):
387  try:
388  res = whatRappsCanRunSrvResponse()
389  db_username,db_password=self.getLogin()
390  con = mdb.connect('localhost', db_username, db_password, 'RappStore');
391  cur = con.cursor()
392  query="SELECT rapp_id from tblRappsModelsVersion where model_id='"+req.model_id+"' and minimum_coreagent_version<='"+req.core_agent_version+"'";
393  cur.execute(query)
394  result_set = cur.fetchall()
395  for i in range(len(result_set)):
396  line=StringArrayMsg()
397  for j in range(len(result_set[i])):
398  temp_s=String(result_set[i][j])
399  line.s.append((str(result_set[i][j])))
400  res.res_data.append(line)
401  con.close()
402  res.success.data=True
403  res.trace.append("Success")
404  except mdb.Error, e:
405  res.trace.append(("Database Error %d: %s" % (e.args[0],e.args[1])))
406  res.success.data=False
407  res.error="Error %d: %s" % (e.args[0],e.args[1])
408  except IndexError, e:
409  res.trace.append("IndexError: " +str(e))
410  res.success.data=False
411  res.error="IndexError: " +str(e)
412  except IOError, e:
413  res.success.data=False
414  res.trace.append("IOError: " +str(e))
415  res.error="IOError: " +str(e)
416  return res
417 
418  def authTokenByService(self,req):
419  try:
420  res = authTokenByServiceSrvResponse()
421  res.authentication_success=False
422  db_username,db_password=self.getLogin()
423  con = mdb.connect('localhost', db_username, db_password, 'RappStore');
424  cur = con.cursor()
425  cur.execute("select service_name from application_token_services where token_id=(select id from application_token where token=%s) and service_name=%s",(req.token,req.service_name))
426  result_set = cur.fetchall()
427  print result_set
428  if(result_set and len(result_set[0])>0):
429  if(result_set[0][0]==req.service_name):
430  res.authentication_success=True
431  else:
432  cur.execute("select service_name from application_token_services where token_id=(select id from application_token where token=%s) and service_name='*'",(req.token))
433  result_set = cur.fetchall()
434  if(result_set and len(result_set[0])>0 ):
435  if(result_set[0][0]=='*'):
436  res.authentication_success=True
437  con.close()
438  res.success=True
439  except mdb.Error, e:
440  res.trace.append(("Database Error %d: %s" % (e.args[0],e.args[1])))
441  res.success=False
442  res.error="Error %d: %s" % (e.args[0],e.args[1])
443  #except IndexError, e:
444  #res.trace.append("IndexError: " +str(e))
445  #res.success=False
446  #res.error="IndexError: " +str(e)
447  except IOError, e:
448  res.success=False
449  res.trace.append("IOError: " +str(e))
450  res.error="IOError: " +str(e)
451  return res
452 
453  ## @brief Places commas between columns and constructs a string
454  # @param cols [list] the input columns
455  # @return returncols [string] the output string
456  def constructCommaColumns(self,cols):
457  #assisting function. adds commas between columns
458  if (len(cols)<1):
459  return ""
460  elif (cols[0]=="*"):
461  return "*"
462  else:
463  returncols=""
464  for i in range(len(cols)):
465  if i==0:
466  returncols=returncols+cols[i]
467  else:
468  returncols=returncols+","+cols[i]
469  return returncols
470 
471  ## @brief Construcs the where= ..and where=... clause
472  # @param cols [list] the columns needed to construct the clause
473  # @return returnquery [string] the And clause
474  def constructAndQuery(self,cols):
475  returnquery=""
476  if(len(cols)==0):
477  return ""
478  else:
479  for i in range(len(cols)):
480  if i==0:
481  returnquery=returnquery+cols[i].s[0]+"=\""+cols[i].s[1]+"\""
482  else:
483  returnquery=returnquery+" AND "+cols[i].s[0]+"=\""+cols[i].s[1]+"\""
484  returnquery=" WHERE "+returnquery
485  return returnquery
486 
487  ## @brief Gets the columns of the table
488  # @return Columns [list] the columns of the table
489  def getTableColumnNames(self,tblName):
490  db_username,db_password=self.getLogin()
491  try:
492  con = mdb.connect('localhost', db_username, db_password, 'RappStore');
493  cur = con.cursor()
494  cur.execute("Show columns from "+tblName)
495  result_set = cur.fetchall()
496  Columns=[]
497  for row in result_set:
498  Columns=Columns+[String(str(row[0]))]
499  return Columns
500  except mdb.Error, e:
501  print "Error %d: %s" % (e.args[0],e.args[1])
502 
503  ## @brief Loads login details from file
504  # @return [ void ] Login details loaded successfully
505  def getLogin(self):
506  fh = open("/etc/db_credentials", "r")
507  db_username=fh.readline()
508  db_username=db_username.split( )[0]
509  db_password=fh.readline()
510  db_password=db_password.split()[0]
511  return db_username,db_password
512 
513  ## @brief Checks connectivity to the DB
514  # @return [ void ] Connection performed successfully
515  def checkConnection(self):
516  try:
517  db_username,db_password=self.getLogin()
518  con = mdb.connect('localhost', db_username, db_password, 'RappStore')
519  cur = con.cursor()
520  cur.execute("SELECT VERSION()")
521  ver = cur.fetchone()
522  print "Database version : %s " % ver
523  con.close()
524  except mdb.Error, e:
525  print "Error %d: %s" % (e.args[0],e.args[1])
526 
527  ## @brief The tbl user fetch data service callback
528  # @param req [rapp_platform_ros_communications::fetchDataSrvRequest::Request&] The ROS service request
529  # @param res [rapp_platform_ros_communications::fetchDataSrvResponse::Response&] The ROS service response
530  def tblUserFetchDataHandler(self,req):
531  res = fetchDataSrvResponse()
532  res=self.fetchData(req,"users")
533  return res
534 
535  ## @brief The tbl user write data service callback
536  # @param req [rapp_platform_ros_communications::writeDataSrvRequest::Request&] The ROS service request
537  # @param res [rapp_platform_ros_communications::writeDataResponse::Response&] The ROS service response
538  def tblUserWriteDataHandler(self,req):
539  res = writeDataSrvResponse()
540  res=self.writeData(req,"users")
541  return res
542 
543  ## @brief The tbl user delete data service callback
544  # @param req [rapp_platform_ros_communications::deleteDataSrvRequest::Request&] The ROS service request
545  # @param res [rapp_platform_ros_communications::deleteDataSrvResponse::Response&] The ROS service response
547  res = deleteDataSrvResponse()
548  res=self.deleteData(req,"users")
549  return res
550 
551  ## @brief The tbl user update data service callback
552  # @param req [rapp_platform_ros_communications::updateDataSrvRequest::Request&] The ROS service request
553  # @param res [rapp_platform_ros_communications::updateDataSrvResponse::Response&] The ROS service response
555  res = updateDataSrvResponse()
556  res=self.updateData(req,"users")
557  return res
558 
559  ## @brief The tbl model fetch data service callback
560  # @param req [rapp_platform_ros_communications::fetchDataSrvRequest::Request&] The ROS service request
561  # @param res [rapp_platform_ros_communications::fetchDataSrvResponse::Response&] The ROS service response
563  res = fetchDataSrvResponse()
564  res=self.fetchData(req,"tblModel")
565  return res
566 
567  ## @brief The tbl model write data service callback
568  # @param req [rapp_platform_ros_communications::writeDataSrvRequest::Request&] The ROS service request
569  # @param res [rapp_platform_ros_communications::writeDataSrvResponse::Response&] The ROS service response
571  res = writeDataSrvResponse()
572  res=self.writeData(req,"tblModel")
573  return res
574 
575  ## @brief The tbl model delete data service callback
576  # @param req [rapp_platform_ros_communications::deleteDataSrvRequest::Request&] The ROS service request
577  # @param res [rapp_platform_ros_communications::deleteDataSrvResponse::Response&] The ROS service response
579  res = deleteDataSrvResponse()
580  res=self.deleteData(req,"tblModel")
581  return res
582 
583  ## @brief The tbl model update data service callback
584  # @param req [rapp_platform_ros_communications::updateDataSrvRequest::Request&] The ROS service request
585  # @param res [rapp_platform_ros_communications::updateDataSrvResponse::Response&] The ROS service response
587  res = updateDataSrvResponse()
588  res=self.updateData(req,"tblModel")
589  return res
590 
591  ## @brief The tbl rapp fetch data service callback
592  # @param req [rapp_platform_ros_communications::fetchDataSrvRequest::Request&] The ROS service request
593  # @param res [rapp_platform_ros_communications::fetchDataSrvResponse::Response&] The ROS service response
594  def tblRappFetchDataHandler(self,req):
595  res = fetchDataSrvResponse()
596  res=self.fetchData(req,"tblRapp")
597  return res
598 
599  ## @brief The tbl rapp write data service callback
600  # @param req [rapp_platform_ros_communications::writeDataSrvRequest::Request&] The ROS service request
601  # @param res [rapp_platform_ros_communications::writeDataResponse::Response&] The ROS service response
602  def tblRappWriteDataHandler(self,req):
603  res = writeDataSrvResponse()
604  res=self.writeData(req,"tblRapp")
605  return res
606 
607  ## @brief The tbl rapp delete data service callback
608  # @param req [rapp_platform_ros_communications::deleteDataSrvRequest::Request&] The ROS service request
609  # @param res [rapp_platform_ros_communications::deleteDataSrvResponse::Response&] The ROS service response
611  res = deleteDataSrvResponse()
612  res=self.deleteData(req,"tblRapp")
613  return res
614 
615  ## @brief The tbl rapp update data service callback
616  # @param req [rapp_platform_ros_communications::updateDataSrvRequest::Request&] The ROS service request
617  # @param res [rapp_platform_ros_communications::updateDataSrvResponse::Response&] The ROS service response
619  res = updateDataSrvResponse()
620  res=self.updateData(req,"robots")
621  return res
622 
623  ## @brief The tbl robot fetch data service callback
624  # @param req [rapp_platform_ros_communications::fetchDataSrvRequest::Request&] The ROS service request
625  # @param res [rapp_platform_ros_communications::fetchDataSrvResponse::Response&] The ROS service response
627  res = fetchDataSrvResponse()
628  res=self.fetchData(req,"robots")
629  return res
630 
631  ## @brief The tbl robot write data service callback
632  # @param req [rapp_platform_ros_communications::writeDataSrvRequest::Request&] The ROS service request
633  # @param res [rapp_platform_ros_communications::writeDataResponse::Response&] The ROS service response
635  res = writeDataSrvResponse()
636  res=self.writeData(req,"robots")
637  return res
638 
639  ## @brief The tbl robot delete data service callback
640  # @param req [rapp_platform_ros_communications::deleteDataSrvRequest::Request&] The ROS service request
641  # @param res [rapp_platform_ros_communications::deleteDataSrvResponse::Response&] The ROS service response
643  res = deleteDataSrvResponse()
644  res=self.deleteData(req,"robots")
645  return res
646 
647  ## @brief The tbl robot update data service callback
648  # @param req [rapp_platform_ros_communications::updateDataSrvRequest::Request&] The ROS service request
649  # @param res [rapp_platform_ros_communications::updateDataSrvResponse::Response&] The ROS service response
651  res = updateDataSrvResponse()
652  res=self.updateData(req,"robots")
653  return res
654 
655  ## @brief The tbl appsRobots fetch data service callback
656  # @param req [rapp_platform_ros_communications::fetchDataSrvRequest::Request&] The ROS service request
657  # @param res [rapp_platform_ros_communications::fetchDataSrvResponse::Response&] The ROS service response
659  res = fetchDataSrvResponse()
660  res=self.fetchData(req,"tblAppsRobots")
661  return res
662 
663  ## @brief The tbl appsRobots write data service callback
664  # @param req [rapp_platform_ros_communications::writeDataSrvRequest::Request&] The ROS service request
665  # @param res [rapp_platform_ros_communications::writeDataResponse::Response&] The ROS service response
667  res = writeDataSrvResponse()
668  res=self.writeData(req,"tblAppsRobots")
669  return res
670 
671  ## @brief The tbl appsRobots delete data service callback
672  # @param req [rapp_platform_ros_communications::deleteDataSrvRequest::Request&] The ROS service request
673  # @param res [rapp_platform_ros_communications::deleteDataSrvResponse::Response&] The ROS service response
675  res = deleteDataSrvResponse()
676  res=self.deleteData(req,"tblAppsRobots")
677  return res
678 
679  ## @brief The tbl appsRobots update data service callback
680  # @param req [rapp_platform_ros_communications::updateDataSrvRequest::Request&] The ROS service request
681  # @param res [rapp_platform_ros_communications::updateDataSrvResponse::Response&] The ROS service response
683  res = updateDataSrvResponse()
684  res=self.updateData(req,"tblAppsRobots")
685  return res
686 
687  ## @brief The tbl usersOntologyInstances fetch data service callback
688  # @param req [rapp_platform_ros_communications::fetchDataSrvRequest::Request&] The ROS service request
689  # @param res [rapp_platform_ros_communications::fetchDataSrvResponse::Response&] The ROS service response
691  res = fetchDataSrvResponse()
692  res=self.fetchData(req,"tblUsersOntologyInstances")
693  return res
694 
695  ## @brief The tbl usersOntologyInstances write data service callback
696  # @param req [rapp_platform_ros_communications::writeDataSrvRequest::Request&] The ROS service request
697  # @param res [rapp_platform_ros_communications::writeDataResponse::Response&] The ROS service response
699  res = writeDataSrvResponse()
700  res=self.writeData(req,"tblUsersOntologyInstances")
701  return res
702 
703  ## @brief The tbl usersOntologyInstances delete data service callback
704  # @param req [rapp_platform_ros_communications::deleteDataSrvRequest::Request&] The ROS service request
705  # @param res [rapp_platform_ros_communications::deleteDataSrvResponse::Response&] The ROS service response
707  res = deleteSrvResponse()
708  res=self.deleteData(req,"tblUsersOntologyInstances")
709  return res
710 
711  ## @brief The tbl usersOntologyInstances update data service callback
712  # @param req [rapp_platform_ros_communications::updateDataSrvRequest::Request&] The ROS service request
713  # @param res [rapp_platform_ros_communications::updateDataSrvResponse::Response&] The ROS service response
715  res = updateDataSrvResponse()
716  res=self.updateData(req,"tblUsersOntologyInstances")
717  return res
718 
719  ## @brief The view usersRobotsApps fetch data service callback
720  # @param req [rapp_platform_ros_communications::fetchDataSrvRequest::Request&] The ROS service request
721  # @param res [rapp_platform_ros_communications::fetchDataSrvResponse::Response&] The ROS service response
723  res = fetchDataSrvResponse()
724  res=self.fetchData(req,"usersrobotsapps")
725  return res
726 
727  ## @brief The what rappRappCanRun service callback
728  # @param req [rapp_platform_ros_communications::whatRappsCanRunSrvResponse::Request&] The ROS service request
729  # @param res [rapp_platform_ros_communications::whatRappsCanRunSrvRequest::Response&] The ROS service response
731  res = whatRappsCanRunSrvResponse()
732  res=self.whatRappsCanRun(req,"tblRappsModelsVersion")
733  return res
734 
735  ## @brief The authTokenByService service callback
736  # @param req [rapp_platform_ros_communications::authTokenByServiceSrvResponse::Request&] The ROS service request
737  # @param res [rapp_platform_ros_communications::authTokenByServiceSrvRequest::Response&] The ROS service response
739  res = authTokenByServiceSrvResponse()
740  res=self.authTokenByService(req)
741  return res
742 
743 #cloud agent callbacks
744 
745  ## @brief The tbl cloud_agent fetch data service callback
746  # @param req [rapp_platform_ros_communications::fetchDataSrvRequest::Request&] The ROS service request
747  # @param res [rapp_platform_ros_communications::fetchDataSrvResponse::Response&] The ROS service response
749  res = fetchDataSrvResponse()
750  res=self.fetchData(req,"cloud_agent")
751  return res
752 
753  ## @brief The tbl cloud_agent write data service callback
754  # @param req [rapp_platform_ros_communications::writeDataSrvRequest::Request&] The ROS service request
755  # @param res [rapp_platform_ros_communications::writeDataResponse::Response&] The ROS service response
757  res = writeDataSrvResponse()
758  res=self.writeData(req,"cloud_agent")
759  return res
760 
761  ## @brief The tbl cloud_agent delete data service callback
762  # @param req [rapp_platform_ros_communications::deleteDataSrvRequest::Request&] The ROS service request
763  # @param res [rapp_platform_ros_communications::deleteDataSrvResponse::Response&] The ROS service response
765  res = deleteDataSrvResponse()
766  res=self.deleteData(req,"cloud_agent")
767  return res
768 
769  ## @brief The tbl cloud_agent update data service callback
770  # @param req [rapp_platform_ros_communications::updateDataSrvRequest::Request&] The ROS service request
771  # @param res [rapp_platform_ros_communications::updateDataSrvResponse::Response&] The ROS service response
773  res = updateDataSrvResponse()
774  res=self.updateData(req,"cloud_agent")
775  return res
776 
777  ## @brief The tbl cloud_agent_service fetch data service callback
778  # @param req [rapp_platform_ros_communications::fetchDataSrvRequest::Request&] The ROS service request
779  # @param res [rapp_platform_ros_communications::fetchDataSrvResponse::Response&] The ROS service response
781  res = fetchDataSrvResponse()
782  res=self.fetchData(req,"cloud_agent_service")
783  return res
784 
785  ## @brief The tbl cloud_agent_service write data service callback
786  # @param req [rapp_platform_ros_communications::writeDataSrvRequest::Request&] The ROS service request
787  # @param res [rapp_platform_ros_communications::writeDataResponse::Response&] The ROS service response
789  res = writeDataSrvResponse()
790  res=self.writeData(req,"cloud_agent_service")
791  return res
792 
793  ## @brief The tbl cloud_agent_service delete data service callback
794  # @param req [rapp_platform_ros_communications::deleteDataSrvRequest::Request&] The ROS service request
795  # @param res [rapp_platform_ros_communications::deleteDataSrvResponse::Response&] The ROS service response
797  res = deleteDataSrvResponse()
798  res=self.deleteData(req,"cloud_agent_service")
799  return res
800 
801  ## @brief The tbl cloud_agent_service update data service callback
802  # @param req [rapp_platform_ros_communications::updateDataSrvRequest::Request&] The ROS service request
803  # @param res [rapp_platform_ros_communications::updateDataSrvResponse::Response&] The ROS service response
805  res = updateDataSrvResponse()
806  res=self.updateData(req,"cloud_agent_service")
807  return res
808 
809  ## @brief The tbl cloud_agent_service_arguments fetch data service callback
810  # @param req [rapp_platform_ros_communications::fetchDataSrvRequest::Request&] The ROS service request
811  # @param res [rapp_platform_ros_communications::fetchDataSrvResponse::Response&] The ROS service response
813  res = fetchDataSrvResponse()
814  res=self.fetchData(req,"cloud_agent_service_arguments")
815  return res
816 
817  ## @brief The tbl cloud_agent_service_arguments write data service callback
818  # @param req [rapp_platform_ros_communications::writeDataSrvRequest::Request&] The ROS service request
819  # @param res [rapp_platform_ros_communications::writeDataResponse::Response&] The ROS service response
821  res = writeDataSrvResponse()
822  res=self.writeData(req,"cloud_agent_service_arguments")
823  return res
824 
825  ## @brief The tbl cloud_agent_service_arguments delete data service callback
826  # @param req [rapp_platform_ros_communications::deleteDataSrvRequest::Request&] The ROS service request
827  # @param res [rapp_platform_ros_communications::deleteDataSrvResponse::Response&] The ROS service response
829  res = deleteDataSrvResponse()
830  res=self.deleteData(req,"cloud_agent_service_arguments")
831  return res
832 
833  ## @brief The tbl cloud_agent_service_arguments update data service callback
834  # @param req [rapp_platform_ros_communications::updateDataSrvRequest::Request&] The ROS service request
835  # @param res [rapp_platform_ros_communications::updateDataSrvResponse::Response&] The ROS service response
837  res = updateDataSrvResponse()
838  res=self.updateData(req,"cloud_agent_service_arguments")
839  return res
def tblCloudAgentServiceUpdateDataHandler
The tbl cloud_agent_service update data service callback.
def tblUserFetchDataHandler
The tbl user fetch data service callback.
def tblRappWriteDataHandler
The tbl rapp write data service callback.
def authTokenByServiceDataHandler
The authTokenByService service callback.
def tblCloudAgentUpdateDataHandler
The tbl cloud_agent update data service callback.
def tblRobotWriteDataHandler
The tbl robot write data service callback.
The mysql wrapper ros node.
def tblRappUpdateDataHandler
The tbl rapp update data service callback.
def tblRobotFetchDataHandler
The tbl robot fetch data service callback.
def writeData
Implements the general write data to table function.
def getTableColumnNames
Gets the columns of the table.
def tblUsersOntologyInstancesUpdateDataHandler
The tbl usersOntologyInstances update data service callback.
def updateData
Implements the general update data from table function.
def tblCloudAgentServiceArgumentsFetchDataHandler
The tbl cloud_agent_service_arguments fetch data service callback.
def tblAppsRobotsWriteDataHandler
The tbl appsRobots write data service callback.
def checkConnection
Checks connectivity to the DB.
def tblCloudAgentServiceArgumentsUpdateDataHandler
The tbl cloud_agent_service_arguments update data service callback.
def tblAppsRobotsUpdateDataHandler
The tbl appsRobots update data service callback.
def tblCloudAgentServiceDeleteDataHandler
The tbl cloud_agent_service delete data service callback.
def tblCloudAgentServiceArgumentsDeleteDataHandler
The tbl cloud_agent_service_arguments delete data service callback.
def tblAppsRobotsDeleteDataHandler
The tbl appsRobots delete data service callback.
def tblUsersOntologyInstancesDeleteDataHandler
The tbl usersOntologyInstances delete data service callback.
def fetchData
Implements the general fetch data from table function.
def tblRobotDeleteDataHandler
The tbl robot delete data service callback.
def constructAndQuery
Construcs the where= ..and where=...
def tblUsersOntologyInstancesWriteDataHandler
The tbl usersOntologyInstances write data service callback.
def tblAppsRobotsFetchDataHandler
The tbl appsRobots fetch data service callback.
def tblCloudAgentDeleteDataHandler
The tbl cloud_agent delete data service callback.
def tblCloudAgentFetchDataHandler
The tbl cloud_agent fetch data service callback.
def tblUsersOntologyInstancesFetchDataHandler
The tbl usersOntologyInstances fetch data service callback.
def tblRappFetchDataHandler
The tbl rapp fetch data service callback.
def tblCloudAgentServiceArgumentsWriteDataHandler
The tbl cloud_agent_service_arguments write data service callback.
def __init__
Default contructor.
def tblModelFetchDataHandler
The tbl model fetch data service callback.
def tblModelWriteDataHandler
The tbl model write data service callback.
def tblCloudAgentWriteDataHandler
The tbl cloud_agent write data service callback.
def constructCommaColumns
Places commas between columns and constructs a string.
def getLogin
Loads login details from file.
def tblCloudAgentServiceWriteDataHandler
The tbl cloud_agent_service write data service callback.
def whatRappsCanRunDataHandler
The what rappRappCanRun service callback.
def tblCloudAgentServiceFetchDataHandler
The tbl cloud_agent_service fetch data service callback.
def whatRappsCanRun
Implements the whatRappsCanRun service.
def tblUserDeleteDataHandler
The tbl user delete data service callback.
def tblRobotUpdateDataHandler
The tbl robot update data service callback.
def tblRappDeleteDataHandler
The tbl rapp delete data service callback.
def tblModelUpdateDataHandler
The tbl model update data service callback.
def tblUserUpdateDataHandler
The tbl user update data service callback.
def deleteData
Implements the general delete data from table function.
def viewUsersRobotsAppsFetchDataHandler
The view usersRobotsApps fetch data service callback.
def tblModelDeleteDataHandler
The tbl model delete data service callback.
def tblUserWriteDataHandler
The tbl user write data service callback.