Exemplo n.º 1
0
def get_doc_history(reg_no, class_of_charge, date):
    url = app_config['LEGACY_ADAPTER_URI'] + '/doc_history/' + reg_no
    headers = {'Content-Type': 'application/json'}
    logging.info("  GET %s?class=%s&date=%s", url, class_without_brackets(class_of_charge), date)
    response = get_from_legacy_adapter(url, headers=headers, params={'class': class_without_brackets(class_of_charge), 'date': date})
    logging.info('  Response: %d', response.status_code)
    
    if response.status_code != 200:
        logging.warning("Non-200 return code {} for {}".format(response.status_code, url))

    if response.status_code == 404:
        return None

    return response.json()
Exemplo n.º 2
0
def build_dummy_row(entry):
    # logging.debug('Entry:')
    # logging.debug(entry)
    
    entry = {
        "registration": {
            "registration_no": re.sub("[^0-9]", "", entry['reg_no']),
            "date": entry['date']
        },
        "parties": [],
        "type": entry['type'],
        "class_of_charge": class_without_brackets(entry['class']),
        "applicant": {'name': '', 'address': '', 'key_number': '', 'reference': ''},
        "additional_information": "",
        "migration_data": {
            'unconverted_reg_no': entry['reg_no'],
            'flags': []
        }       
    }
    
    if entry['class_of_charge'] not in ['PAB', 'WOB']:
        entry['particulars'] = {
            'counties': [],
            'district': '',
            'description': ''
        }
    return entry
def build_dummy_row(entry):
    # logging.debug('Entry:')
    # logging.debug(entry)

    entry = {
        "registration": {
            "registration_no": re.sub("[^0-9]", "", entry['reg_no']),
            "date": entry['date']
        },
        "parties": [],
        "type": entry['type'],
        "class_of_charge": class_without_brackets(entry['class']),
        "applicant": {
            'name': '',
            'address': '',
            'key_number': '',
            'reference': ''
        },
        "additional_information": "",
        "migration_data": {
            'unconverted_reg_no': entry['reg_no'],
            'flags': []
        }
    }

    if entry['class_of_charge'] not in ['PAB', 'WOB']:
        entry['particulars'] = {
            'counties': [],
            'district': '',
            'description': ''
        }
    return entry
def get_doc_history(reg_no, class_of_charge, date):
    url = app_config['LEGACY_ADAPTER_URI'] + '/doc_history/' + reg_no
    headers = {'Content-Type': 'application/json'}
    logging.info("  GET %s?class=%s&date=%s", url,
                 class_without_brackets(class_of_charge), date)
    response = get_from_legacy_adapter(
        url,
        headers=headers,
        params={
            'class': class_without_brackets(class_of_charge),
            'date': date
        })
    logging.info('  Response: %d', response.status_code)

    if response.status_code != 200:
        logging.warning("Non-200 return code {} for {}".format(
            response.status_code, url))

    if response.status_code == 404:
        return None

    return response.json()
Exemplo n.º 5
0
def build_registration(rows, name_type, name_data):
    # logging.debug('Head Entry:')
    # logging.debug(json.dumps(rows))
    
    coc = class_without_brackets(rows['class_type'])
    if coc in ['PAB', 'WOB']:
        eo_type = "Debtor"
        occupation = rows['occupation']
    else:
        eo_type = "Estate Owner"
        occupation = ''
       
    county_text = rows['property_county'].strip()
    logging.info('    County_text is "%s"', county_text)
    
    banks_county = ''
    if county_text in ['BANKS', ''] and coc in ['PA', 'WO', 'DA']: #  Special case for <1% of the data...
        banks_county = rows['counties']
        logging.info('    BANKS county of "%s"', county_text)

    if county_text in ['NO COUNTY', 'NO COUNTIES', 'BANKS']:
        county_text = ''
    
    pty_desc = rows['property']
    parish_district = rows['parish_district']
    
    registration = {
        "class_of_charge": coc,
        "registration": {
            "date": rows['registration_date'],
            "registration_no": re.sub("[^0-9]", "", str(rows['registration_no']))
        },
        "parties": [{
            "type": eo_type,
        }],
        "applicant": {
            'name': '',
            'address': '',
            'key_number': '',
            'reference': ''
        },
        "additional_information": "",
        "migration_data": {
            'unconverted_reg_no': rows['registration_no'],
            'amend_info': rows['amendment_info'],
            'flags': [],
            'bankruptcy_county': banks_county
        }
    }
    
    amend = parse_amend_info(rows['amendment_info'])
    registration['additional_information'] = amend['additional_information']
    
    if coc in ['PAB', 'WOB']:
        registration['parties'][0]['occupation'] = occupation
        registration['parties'][0]['trading_name'] = ''
        registration['parties'][0]['residence_withheld'] = False
        registration['parties'][0]['case_reference'] = amend['reference']
        registration['parties'][0]['addresses'] = []
        
        address_strings = rows['address'].split('   ')
        for address in address_strings:
            addr_obj = {
                'type': 'Residence',
                'address_string': address            
            }
            registration['parties'][0]['addresses'].append(addr_obj)
        
        if amend['court'] is not None:
            registration['parties'].append({
                'type': 'Court',
                'names': [{
                    'type': 'Other',
                    'other': amend['court']
                }]
            })       
        
    else:
        if rows['address'] is not None and rows['address'] != '':
            # Some old registers have addresses on non-PAB/WOB regns
            registration['parties'][0]['addresses'] = []
            address_strings = rows['address'].split('   ')
            for address in address_strings:
                addr_obj = {
                    'type': 'Residence',
                    'address_string': address
                }
                registration['parties'][0]['addresses'].append(addr_obj)

        registration['particulars'] = {
            'counties': [reformat_county(county_text)],
            'district': parish_district,
            'description': pty_desc
        }

    registration['parties'][0]['names'] = [name_data]
    registration['parties'][0]['names'][0]['type'] = name_type

    return registration
Exemplo n.º 6
0
def check(config, start, end):
    global app_config
    app_config = config
    #print(app_config)

    url = "{}/land_charges_index/{}/{}".format(config['LEGACY_ADAPTER_URI'], start, end)
    headers = {'Content-Type': 'application/json'}
    registrations = get_from_legacy_adapter(url, headers=headers).json()

    try:
        conn = connect_to_psql(config['PSQL_CONNECTION'])
        cursor = create_cursor(conn)

        for reg in registrations:
            #output = ''
            output = "{}\t{}\t{}\t".format(reg['registration_no'], reg['registration_date'], reg['class_type'])

            reg_no = re.sub("[^0-9]", "", str(reg['registration_no']))
            if str(reg['registration_no']) != reg_no:
                cursor.execute('SELECT r.id, r.registration_no, r.date, r.expired_on, rd.class_of_charge '
                               'FROM register r, register_details rd, migration_status ms '
                               'WHERE r.details_id=rd.id and r.id = ms.register_id and r.registration_no=%(nno)s and '
                               'ms.original_regn_no=%(no)s and r.date=%(date)s and rd.class_of_charge=%(cls)s ', {
                                   'no': reg['registration_no'].strip(), 'date': reg['registration_date'], 'cls': class_without_brackets(reg['class_type']),
                                   'nno': reg_no.strip()
                               })
            else:
                cursor.execute('SELECT r.id, r.registration_no, r.date, r.expired_on, rd.class_of_charge '
                               'FROM register r, register_details rd '
                               'WHERE r.details_id=rd.id and r.registration_no=%(no)s and r.date=%(date)s and '
                               'rd.class_of_charge=%(cls)s', {
                                   'no': reg['registration_no'].strip(), 'date': reg['registration_date'], 'cls': class_without_brackets(reg['class_type'])
                               })

            rows = cursor.fetchall()
            if len(rows) == 0:
                # output += "  No rows found\t"
                print(output + " no rows")
            # else:
            #     output += "  {} rows found\t".format(len(rows))
            #     for row in rows:
            #         output += "  {}\t{}".format(row['id'], row['expired_on'])

            # output += "END {} {} {}\n".format(reg['registration_no'], reg['registration_date'], reg['class_type'])
            # output += "\n"
            # print(output)

    finally:
        if cursor is not None:
            commit(cursor)
            close_cursor(cursor)

        if conn is not None:
            disconnect_from_psql(conn)
def build_registration(rows, name_type, name_data):
    # logging.debug('Head Entry:')
    # logging.debug(json.dumps(rows))

    coc = class_without_brackets(rows['class_type'])
    if coc in ['PAB', 'WOB']:
        eo_type = "Debtor"
        occupation = rows['occupation']
    else:
        eo_type = "Estate Owner"
        occupation = ''

    county_text = rows['property_county'].strip()
    logging.info('    County_text is "%s"', county_text)

    banks_county = ''
    if county_text in ['BANKS', ''] and coc in [
            'PA', 'WO', 'DA'
    ]:  #  Special case for <1% of the data...
        banks_county = rows['counties']
        logging.info('    BANKS county of "%s"', county_text)

    if county_text in ['NO COUNTY', 'NO COUNTIES', 'BANKS']:
        county_text = ''

    pty_desc = rows['property']
    parish_district = rows['parish_district']

    registration = {
        "class_of_charge": coc,
        "registration": {
            "date": rows['registration_date'],
            "registration_no": re.sub("[^0-9]", "",
                                      str(rows['registration_no']))
        },
        "parties": [{
            "type": eo_type,
        }],
        "applicant": {
            'name': '',
            'address': '',
            'key_number': '',
            'reference': ''
        },
        "additional_information": "",
        "migration_data": {
            'unconverted_reg_no': rows['registration_no'],
            'amend_info': rows['amendment_info'],
            'flags': [],
            'bankruptcy_county': banks_county
        }
    }

    amend = parse_amend_info(rows['amendment_info'])
    registration['additional_information'] = amend['additional_information']

    if coc in ['PAB', 'WOB']:
        registration['parties'][0]['occupation'] = occupation
        registration['parties'][0]['trading_name'] = ''
        registration['parties'][0]['residence_withheld'] = False
        registration['parties'][0]['case_reference'] = amend['reference']
        registration['parties'][0]['addresses'] = []

        address_strings = rows['address'].split('   ')
        for address in address_strings:
            addr_obj = {'type': 'Residence', 'address_string': address}
            registration['parties'][0]['addresses'].append(addr_obj)

        if amend['court'] is not None:
            registration['parties'].append({
                'type':
                'Court',
                'names': [{
                    'type': 'Other',
                    'other': amend['court']
                }]
            })

    else:
        if rows['address'] is not None and rows['address'] != '':
            # Some old registers have addresses on non-PAB/WOB regns
            registration['parties'][0]['addresses'] = []
            address_strings = rows['address'].split('   ')
            for address in address_strings:
                addr_obj = {'type': 'Residence', 'address_string': address}
                registration['parties'][0]['addresses'].append(addr_obj)

        registration['particulars'] = {
            'counties': [reformat_county(county_text)],
            'district': parish_district,
            'description': pty_desc
        }

    registration['parties'][0]['names'] = [name_data]
    registration['parties'][0]['names'][0]['type'] = name_type

    return registration
def check(config, start, end):
    global app_config
    app_config = config
    #print(app_config)

    url = "{}/land_charges_index/{}/{}".format(config['LEGACY_ADAPTER_URI'],
                                               start, end)
    headers = {'Content-Type': 'application/json'}
    registrations = get_from_legacy_adapter(url, headers=headers).json()

    try:
        conn = connect_to_psql(config['PSQL_CONNECTION'])
        cursor = create_cursor(conn)

        for reg in registrations:
            #output = ''
            output = "{}\t{}\t{}\t".format(reg['registration_no'],
                                           reg['registration_date'],
                                           reg['class_type'])

            reg_no = re.sub("[^0-9]", "", str(reg['registration_no']))
            if str(reg['registration_no']) != reg_no:
                cursor.execute(
                    'SELECT r.id, r.registration_no, r.date, r.expired_on, rd.class_of_charge '
                    'FROM register r, register_details rd, migration_status ms '
                    'WHERE r.details_id=rd.id and r.id = ms.register_id and r.registration_no=%(nno)s and '
                    'ms.original_regn_no=%(no)s and r.date=%(date)s and rd.class_of_charge=%(cls)s ',
                    {
                        'no': reg['registration_no'].strip(),
                        'date': reg['registration_date'],
                        'cls': class_without_brackets(reg['class_type']),
                        'nno': reg_no.strip()
                    })
            else:
                cursor.execute(
                    'SELECT r.id, r.registration_no, r.date, r.expired_on, rd.class_of_charge '
                    'FROM register r, register_details rd '
                    'WHERE r.details_id=rd.id and r.registration_no=%(no)s and r.date=%(date)s and '
                    'rd.class_of_charge=%(cls)s', {
                        'no': reg['registration_no'].strip(),
                        'date': reg['registration_date'],
                        'cls': class_without_brackets(reg['class_type'])
                    })

            rows = cursor.fetchall()
            if len(rows) == 0:
                # output += "  No rows found\t"
                print(output + " no rows")
            # else:
            #     output += "  {} rows found\t".format(len(rows))
            #     for row in rows:
            #         output += "  {}\t{}".format(row['id'], row['expired_on'])

            # output += "END {} {} {}\n".format(reg['registration_no'], reg['registration_date'], reg['class_type'])
            # output += "\n"
            # print(output)

    finally:
        if cursor is not None:
            commit(cursor)
            close_cursor(cursor)

        if conn is not None:
            disconnect_from_psql(conn)