예제 #1
0
def get_link_row():
    utils = Utils()
    db = config.get_database()
    try:
        print('AppServer.get_link_row running', request.method)
        print('Instance:', config.get_database_name(),
              config.get_environment())
        print('Tables', config.get_database_instance().get_table_names())
        data = utils.json_decode(request)
        link = db.select("LinkTab",
                         TabName=data['TabName'],
                         AttrName=data['AttrName'])
        print('link', link)
        if not link:
            data['ID'] = 0
            data['LinkName'] = ''
            data['BaseTab'] = 0
            data['ShowAttrs'] = ''
        else:
            data['ID'] = link[0].ID
            data['LinkName'] = link[0].LinkName
            data['BaseTab'] = link[0].BaseTab
            data['ShowAttrs'] = link[0].ShowAttrs

        return json.dumps(data)

    except Exception as e:
        print('AppServer.link: ***Error:', e)
        traceback.print_exc(file=sys.stdout)
예제 #2
0
def get_link_row():
    utils = Utils()
    db = config.get_database()
    try:
        print('AppServer.get_link_row running',request.method)
        print('Instance:',config.get_database_name(),config.get_environment())
        print('Tables',config.get_database_instance().get_table_names())
        data = utils.json_decode(request)
        link = db.select("LinkTab", TabName = data['TabName'], AttrName = data['AttrName'])
        print('link',link)
        if not link:
            data['ID'] = 0
            data['LinkName'] = ''
            data['BaseTab'] = 0
            data['ShowAttrs'] = ''
        else:
            data['ID'] = link[0].ID
            data['LinkName'] = link[0].LinkName
            data['BaseTab'] = link[0].BaseTab
            data['ShowAttrs'] = link[0].ShowAttrs

        return json.dumps(data)

    except Exception as e:
        print('AppServer.link: ***Error:',e)
        traceback.print_exc(file=sys.stdout)
예제 #3
0
def update_link_row():
    utils = Utils()
    db = config.get_database()
    return_data = dict()
    try:
        print('AppServer.update_link_row running', request.method)
        data = utils.json_decode(request)
        print('data:', data)
        linktab = db.get_data_structure('LinkTab')
        utils.dict_to_obj(data, linktab)
        print('just before if data:', data)
        print('just before if data:', data['ID'])
        if data['ID'] == '0':
            db.insert(linktab)
        else:
            db.update(linktab)

        return_data['StatusCode'] = 0
        return json.dumps(return_data)
    except Exception as e:
        print('AppServer.link: ***Error:', e)
        traceback.print_exc(file=sys.stdout)
        return_data['StatusCode'] = -1
        return_data['Message'] = str(e)
        return json.dumps(return_data)
예제 #4
0
def update_link_row():
    utils = Utils()
    db = config.get_database()
    return_data = dict()
    try:
        print('AppServer.update_link_row running',request.method)
        data = utils.json_decode(request)
        print('data:',data)
        linktab = db.get_data_structure('LinkTab')
        utils.dict_to_obj(data,linktab)
        print('just before if data:',data)
        print('just before if data:',data['ID'])
        if data['ID'] == '0':
            db.insert(linktab)
        else:
            db.update(linktab)

        return_data['StatusCode'] = 0
        return json.dumps(return_data)
    except Exception as e:
        print('AppServer.link: ***Error:',e)
        traceback.print_exc(file=sys.stdout)
        return_data['StatusCode'] = -1
        return_data['Message'] = str(e)
        return json.dumps(return_data)
예제 #5
0
    def test_get_link_data(self):
        #setup stuff
        utils = Utils()
        db = config.get_database()
        dbu = DatabaseUtilities()
        db_create = DatabaseCreate()

        dbu.delete_all_tables()
        db_create.linktab()
        dbu.create_some_test_well_royalty_masters()
        dbu.create_some_test_leases()

        linktab = db.get_data_structure('LinkTab')
        linktab.TabName = 'Lease'
        linktab.AttrName = 'ID'
        linktab.LinkName = 'Lease'
        linktab.BaseTab = 1
        linktab.ShowAttrs = 'ID,Lessor'
        db.insert(linktab)

        linktab = db.get_data_structure('LinkTab')
        linktab.TabName = 'Well'
        linktab.AttrName = 'LeaseID'
        linktab.LinkName = 'Lease'
        linktab.BaseTab = 0
        linktab.ShowAttrs = ''
        db.insert(linktab)

        data = dict()
        data["TabName"] = 'Well'
        data["AttrName"] = 'LeaseID'
        data["AttrValue"] = 2

        json_from_browser = json.dumps(data)
        print('json_from_browser', json_from_browser)

        # Data should be found
        resp = self.myapp.post('/data/getLinkData.json',
                               data=json_from_browser)
        print("resp:", resp)
        self.assertEqual(resp.status_code, 200)
        data = utils.json_decode(resp)

        print('data', data)
        rows = data['BaseData']
        self.assertEqual(len(rows), 2)
        self.assertEqual(rows[0][0], 'ID')
        self.assertEqual(rows[0][1], 'Lessor')
        self.assertEqual(rows[1][0], 2)
        self.assertEqual(rows[1][1], 2346)

        rows = data['Links']
        self.assertEqual(len(rows), 2)
        self.assertEqual(rows[0][0], 'Lease')
        self.assertEqual(rows[0][1], 'ID')
        self.assertEqual(rows[1][0], 'Well')
        self.assertEqual(rows[1][1], 'LeaseID')
예제 #6
0
    def test_to_json(self):
        utils= Utils()
        # create a dummy request structure
        request = DataStructure()
        # This is exactly what the data from the browser looks like:
        request.data = b'{"tableName":"BAInfo","attrName":" StartDate ","attrValue":"","linkName":"undefined","baseTab":false,"showAttrs":""}'
#         dictionaryStructure = AppServer.json_decode(request)
        dictionaryStructure = utils.json_decode(request)
        self.assertEqual("BAInfo", dictionaryStructure['tableName'])
    def test_get_link_data(self):
        #setup stuff
        utils = Utils()
        db = config.get_database()
        dbu = DatabaseUtilities()
        db_create = DatabaseCreate()

        dbu.delete_all_tables()
        db_create.linktab()
        dbu.create_some_test_well_royalty_masters()
        dbu.create_some_test_leases()
        
        linktab = db.get_data_structure('LinkTab')
        linktab.TabName = 'Lease'
        linktab.AttrName = 'ID'
        linktab.LinkName = 'Lease'
        linktab.BaseTab = 1
        linktab.ShowAttrs = 'ID,Lessor'
        db.insert(linktab)
        
        linktab = db.get_data_structure('LinkTab')
        linktab.TabName = 'Well'
        linktab.AttrName = 'LeaseID'
        linktab.LinkName = 'Lease'
        linktab.BaseTab = 0
        linktab.ShowAttrs = ''
        db.insert(linktab)

        data = dict()
        data["TabName"] = 'Well'
        data["AttrName"] = 'LeaseID'
        data["AttrValue"] = 2
        
        json_from_browser = json.dumps(data)
        print('json_from_browser', json_from_browser)

        # Data should be found
        resp = self.myapp.post('/data/getLinkData.json',data=json_from_browser)
        print("resp:",resp)
        self.assertEqual(resp.status_code, 200)
        data = utils.json_decode(resp)
        
        print('data',data)
        rows = data['BaseData']
        self.assertEqual(len(rows),2)
        self.assertEqual(rows[0][0],'ID')
        self.assertEqual(rows[0][1],'Lessor')
        self.assertEqual(rows[1][0],2)
        self.assertEqual(rows[1][1],2346)
        
        rows = data['Links']
        self.assertEqual(len(rows),2)
        self.assertEqual(rows[0][0],'Lease')
        self.assertEqual(rows[0][1],'ID')
        self.assertEqual(rows[1][0],'Well')
        self.assertEqual(rows[1][1],'LeaseID')
예제 #8
0
def get_link_data():
    utils = Utils()
    db = config.get_database()
    try:
        data = utils.json_decode(request)
        #             print('data', data)
        link = db.select("LinkTab",
                         TabName=data['TabName'],
                         AttrName=data['AttrName'])
        #             print('link',link)
        if len(link) > 0:
            result_rows = db.select("LinkTab",
                                    LinkName=link[0].LinkName,
                                    BaseTab=1)
            #                 print('result:',result_rows)
            #                 print('result.type:',type(result_rows))

            # Get the base table
            for result in result_rows:
                print('We have a base table')
                attrs_to_show = result.ShowAttrs.split(',')
                args = dict()
                args[result.AttrName] = data['AttrValue']
                key_data_rows = db.select(result.TabName, **args)
                rows = []
                for keyData in key_data_rows:
                    row = []
                    for a in attrs_to_show:
                        row.append(keyData.__dict__[a])
                    rows.append(attrs_to_show)
                    rows.append(row)
                data['BaseData'] = rows

            # Get all the tables that the link uses
            result_rows = db.select("LinkTab", LinkName=link[0].LinkName)

            rows = []
            for result in result_rows:
                row = []
                row.append(result.TabName)
                row.append(result.AttrName)
                rows.append(row)
            data['Links'] = rows

        else:
            data["Message"] = data['AttrName'] + " has not been linked."
        return json.dumps(data)


#
    except Exception as e:
        print('AppServer.link: ***Error:', e)
        traceback.print_exc(file=sys.stdout)

    print("hello")
예제 #9
0
    def test_obj_to_dict(self):
        ds = DataStructure()
        utils = Utils()
        ds.ID = 123
        ds.Name = "My Name"

        result = utils.obj_to_dict(ds, dict())
        self.assertEqual(result['ID'],123)
        self.assertEqual(result['Name'],'My Name')

        result = utils.obj_to_dict(ds)
        self.assertEqual(result['ID'],123)
        self.assertEqual(result['Name'],'My Name')
예제 #10
0
def get_link_data():
    utils = Utils()
    db = config.get_database()
    try:
        data = utils.json_decode(request)
#             print('data', data)
        link = db.select("LinkTab", TabName = data['TabName'], AttrName = data['AttrName'])
#             print('link',link)
        if len(link) > 0:
            result_rows = db.select("LinkTab", LinkName=link[0].LinkName, BaseTab=1)
#                 print('result:',result_rows)
#                 print('result.type:',type(result_rows))

            # Get the base table
            for result in result_rows:
                print('We have a base table')
                attrs_to_show = result.ShowAttrs.split(',')
                args = dict()
                args[result.AttrName] = data['AttrValue']
                key_data_rows = db.select(result.TabName,**args)
                rows = []
                for keyData in key_data_rows:
                    row = []
                    for a in attrs_to_show:
                        row.append(keyData.__dict__[a])
                    rows.append(attrs_to_show)
                    rows.append(row)
                data['BaseData'] = rows

            # Get all the tables that the link uses
            result_rows = db.select("LinkTab", LinkName=link[0].LinkName)

            rows = []
            for result in result_rows:
                row = []
                row.append(result.TabName)
                row.append(result.AttrName)
                rows.append(row)
            data['Links'] = rows

        else:
            data["Message"] = data['AttrName'] + " has not been linked."
        return json.dumps(data)
#
    except Exception as e:
        print('AppServer.link: ***Error:',e)
        traceback.print_exc(file=sys.stdout)

    print("hello")
예제 #11
0
    def test_dict_to_obj(self):
        utils= Utils()
        d = dict()
        d['fld1'] = 'val1'
        d['fld2'] = 'val2'
        obj = utils.dict_to_obj(d)

        self.assertEqual(obj.fld1,'val1')
        self.assertEqual(obj.fld2,'val2')
        
        ds = DataStructure()
        ds.__dict__['myValue'] = 'Important'
        
        utils.dict_to_obj(d,ds)
        
        self.assertEqual(ds.myValue,'Important')
        self.assertEqual(ds.fld1,'val1')
        self.assertEqual(ds.fld2,'val2')
예제 #12
0
    def test_link_update(self):
        db = config.get_database()
        dbu = DatabaseUtilities()
        db_create = DatabaseCreate()
        utils = Utils()

        dbu.delete_all_tables()
        db_create.linktab()

        # Test Insert
        data = dict()
        data["ID"] = '0'
        data["TabName"] = 'Lease'
        data["AttrName"] = 'ID'
        data["LinkName"] = 'Lease'
        json_to_browser = json.dumps(data)
        resp = self.myapp.post('/data/updateLinkRow.json',
                               data=json_to_browser)
        self.assertEqual(resp.status_code, 200)
        data = utils.json_decode(resp)
        self.assertEqual(data["StatusCode"], 0)

        result = db.select('LinkTab', TabName='Lease', AttrName='ID')
        self.assertEqual(len(result), 1)

        # Test Update
        data = utils.obj_to_dict(result[0])
        data['LinkName'] = 'Changed'

        json_to_browser = json.dumps(data)
        resp = self.myapp.post('/data/updateLinkRow.json',
                               data=json_to_browser)
        self.assertEqual(resp.status_code, 200)
        data = utils.json_decode(resp)
        self.assertEqual(data["StatusCode"], 0)

        result = db.select('LinkTab', TabName='Lease', AttrName='ID')
        self.assertEqual(len(result), 1)
        self.assertEqual(result[0].LinkName, 'Changed')
예제 #13
0
    def test_get_link_row(self):
        #setup stuff
        db = config.get_database()
        dbu = DatabaseUtilities()
        db_create = DatabaseCreate()
        utils = Utils()

        dbu.delete_all_tables()

        db_create.linktab()
        linktab = db.get_data_structure('LinkTab')
        linktab.TabName = 'Well'
        linktab.AttrName = 'ID'
        json_to_browser = json.dumps(utils.obj_to_dict(linktab))
        print('json_to_browser', json_to_browser)

        # Data should not be found but there should not be an error
        resp = self.myapp.post('/data/getLinkRow.json', data=json_to_browser)
        self.assertEqual(resp.status_code, 200)
        data = utils.json_decode(resp)
        self.assertEqual(data["LinkName"], '')

        linktab.LinkName = 'Well'
        linktab.BaseTab = 0
        linktab.ShowAttrs = 'ID,UWI'
        db.insert(linktab)

        # Data should be found
        resp = self.myapp.post('/data/getLinkRow.json', data=json_to_browser)
        data = utils.json_decode(resp)
        self.assertEqual(resp.status_code, 200)
        self.assertEqual(data["LinkName"], 'Well')
        self.assertEqual(data["ShowAttrs"], 'ID,UWI')

        print('status:', resp.status)
        print('status code:', resp.status_code)
        print(resp)
        print(resp.data)
    def test_get_link_row(self):
        #setup stuff
        db = config.get_database()
        dbu = DatabaseUtilities()
        db_create = DatabaseCreate()
        utils = Utils()

        dbu.delete_all_tables()

        db_create.linktab()
        linktab = db.get_data_structure('LinkTab')
        linktab.TabName = 'Well'
        linktab.AttrName = 'ID'
        json_to_browser = json.dumps(utils.obj_to_dict(linktab))
        print('json_to_browser', json_to_browser)

        # Data should not be found but there should not be an error
        resp = self.myapp.post('/data/getLinkRow.json',data=json_to_browser)
        self.assertEqual(resp.status_code, 200)
        data = utils.json_decode(resp)
        self.assertEqual(data["LinkName"],'')
        
        linktab.LinkName = 'Well'
        linktab.BaseTab = 0
        linktab.ShowAttrs = 'ID,UWI'
        db.insert(linktab)
        
        # Data should be found 
        resp = self.myapp.post('/data/getLinkRow.json',data=json_to_browser)
        data = utils.json_decode(resp)
        self.assertEqual(resp.status_code, 200)
        self.assertEqual(data["LinkName"],'Well')
        self.assertEqual(data["ShowAttrs"],'ID,UWI')
        
        print('status:',resp.status)
        print('status code:',resp.status_code)
        print(resp)
        print(resp.data)      
    def test_link_update(self):
        db = config.get_database()
        dbu = DatabaseUtilities()
        db_create = DatabaseCreate()
        utils = Utils()

        dbu.delete_all_tables()
        db_create.linktab()

        # Test Insert
        data = dict()
        data["ID"] = '0'
        data["TabName"] = 'Lease'
        data["AttrName"] = 'ID'
        data["LinkName"] = 'Lease'
        json_to_browser = json.dumps(data)
        resp = self.myapp.post('/data/updateLinkRow.json',data=json_to_browser)
        self.assertEqual(resp.status_code, 200)
        data = utils.json_decode(resp)
        self.assertEqual(data["StatusCode"],0)
        
        result = db.select('LinkTab', TabName='Lease', AttrName='ID')
        self.assertEqual(len(result), 1)
        
        # Test Update
        data = utils.obj_to_dict(result[0])
        data['LinkName'] = 'Changed' 

        json_to_browser = json.dumps(data)
        resp = self.myapp.post('/data/updateLinkRow.json',data=json_to_browser)
        self.assertEqual(resp.status_code, 200)
        data = utils.json_decode(resp)
        self.assertEqual(data["StatusCode"],0)
        
        result = db.select('LinkTab', TabName='Lease', AttrName='ID')
        self.assertEqual(len(result), 1)
        self.assertEqual(result[0].LinkName,'Changed')