def run(self, data):
        response = self.requestCommandBuilder.build(DatasourcesListCommand).execute()
        dsJsonResponse = JsonUtil.loads(response.content)

        for datasource in dsJsonResponse:

            if datasource['name'] == self.dsName:
                response = self.requestCommandBuilder.build(TablesListCommand, dsName=self.dsName).execute()
                tablesJsonResponse = JsonUtil.loads(response.content)

                for tableData in tablesJsonResponse:
                    table = tableData['name']
                    self.requestCommandBuilder.build(TableDeleteCommand, dsName=self.dsName, table=table).execute()

                self.requestCommandBuilder.build(DatasourceDeleteCommand, dsName=self.dsName).execute()
    def run(self, data):
        response = self.requestCommandBuilder.build(DatasourcesListCommand).execute()
        jsonResponse = JsonUtil.loads(response.content)

        for datasource in jsonResponse:
            if datasource['name'] == self.dsName:
                return
        raise Exception("Datasource %s not found" % self.dsName)
    def run(self, data):
        self.requestCommandBuilder.build(FileUploadCommand, localFile=self.file, opalPath=self.remote).execute()
        response = self.requestCommandBuilder.build(ExcelTransientDatasourceCreateCommand, file=self.file,
                                                    remote=self.remote).execute()

        jsonResponse = JsonUtil.loads(response.content)
        transientName = jsonResponse['name']
        response = self.requestCommandBuilder.build(DatasourceCompareCommand, transientName=transientName,
                                                    dsName=self.dsName).execute()

        jsonResponse = JsonUtil.loads(response.content)
        tableInfo = {'name': jsonResponse['compared']['table'][0], 'entityType': 'Participant'}

        if 'newVariables' in jsonResponse['tableComparisons'][0]:
            tableInfo['variables'] = jsonResponse['tableComparisons'][0]['newVariables']

        jsonData = JsonUtil.dumps(tableInfo)
        self.requestCommandBuilder.build(JsonTableCreateCommand, dsName=self.dsName, jsonData=jsonData).execute()
    def run(self, data):
        response = self.requestCommandBuilder.build(ListOpalDatabaseCommand).execute()
        jsonResponse = JsonUtil.loads(response.content)

        for db in filter(lambda s: s['name'] == self.dbName, jsonResponse):
            self.requestCommandBuilder.build(DeleteOpalDatabaseCommand, dbName=db['name']).execute()