示例#1
0
    def _build_parties_list(cls, cursor, event_id: int = None):
        parties = cursor.fetchall()

        if not parties:
            return None

        completing_parties = {}
        party_list = []
        description = cursor.description
        for row in parties:
            party = Party()
            party.title = ''
            row = dict(zip([x[0].lower() for x in description], row))
            if row['appointment_dt']:
                party.officer = cls._get_officer(row)

                party.delivery_address = Address.get_by_address_id(
                    cursor, row['delivery_addr_id']).as_dict()
                party.mailing_address = Address.get_by_address_id(cursor, row['mailing_addr_id']).as_dict() \
                    if row['mailing_addr_id'] else party.delivery_address
                party.appointment_date =\
                    convert_to_json_date(row.get('appointment_dt', None))
                party.cessation_date = convert_to_json_date(
                    row.get('cessation_dt', None))
                party.start_event_id = (row.get('start_event_id', '')) or ''
                party.end_event_id = (row.get('end_event_id', '')) or ''
                party.role_type = (row.get('party_typ_cd', '')) or ''
                # this is in case the party was not ceased during this event
                if event_id and party.end_event_id and party.end_event_id > event_id:
                    party.cessation_date = None

                party_list.append(party)
        if event_id:
            completing_parties = cls.get_completing_parties(cursor, event_id)
        return cls.group_parties(party_list, completing_parties)
示例#2
0
    def _build_directors_list(cls, cursor, event_id: int = None):

        directors = cursor.fetchall()
        if not directors:
            return None

        directors_list = []
        description = cursor.description
        for row in directors:
            director = Director()
            director.title = ''
            row = dict(zip([x[0].lower() for x in description], row))
            if row['appointment_dt']:
                director.officer = {'firstName': row['first_nme'].strip() if row['first_nme'] else '',
                                    'lastName': row['last_nme'].strip() if row['last_nme'] else '',
                                    'middleInitial': row['middle_nme'] if row['middle_nme'] else ''}

                director.delivery_address = Address.get_by_address_id(cursor, row['delivery_addr_id']).as_dict()
                director.mailing_address = Address.get_by_address_id(cursor, row['mailing_addr_id']).as_dict() \
                    if row['mailing_addr_id'] else director.delivery_address
                director.appointment_date =\
                    convert_to_json_date(row['appointment_dt']) if row['appointment_dt'] else None
                director.cessation_date = convert_to_json_date(row['cessation_dt']) if row['cessation_dt'] else None
                director.start_event_id = row['start_event_id'] if row['start_event_id'] else ''
                director.end_event_id = row['end_event_id'] if row['end_event_id'] else ''

                # this is in case the director was not ceased during this event
                if event_id and director.end_event_id and director.end_event_id > event_id:
                    director.cessation_date = None

                directors_list.append(director)

        return directors_list
示例#3
0
    def _build_offices_list(cls, cursor, querystring: str = None, identifier: str = None, event_id: str = None):
        """Return the office objects for the given query."""
        if not cursor:
            cursor = DB.connection.cursor()
        if identifier:
            cursor.execute(querystring, identifier=identifier)
        else:
            cursor.execute(querystring, event_id=event_id)
        office_info = cursor.fetchall()
        offices = []
        if not office_info:
            raise OfficeNotFoundException()

        description = cursor.description
        for office_item in office_info:
            office = dict(zip([x[0].lower() for x in description], office_item))
            office_obj = Office()
            office_obj.event_id = office['start_event_id']
            office_obj.delivery_address = Address.get_by_address_id(cursor, office['delivery_addr_id']).as_dict()
            office_obj.office_code = office['office_typ_cd']
            office_obj.office_type = cls.OFFICE_TYPES_CODES[office['office_typ_cd']]
            if office['mailing_addr_id']:
                office_obj.mailing_address = Address.get_by_address_id(cursor, office['mailing_addr_id']).as_dict()
            else:
                office_obj.mailing_address = office_obj.delivery_address
            offices.append(office_obj)

        return offices
示例#4
0
    def get_current(cls, identifier: str = None):
        """Return current registered office address."""
        if not identifier:
            return None

        querystring = ("""
            select start_event_id, mailing_addr_id, delivery_addr_id, office_typ_cd
            from office
            where corp_num=:identifier and end_event_id is null
            """)

        try:
            cursor = DB.connection.cursor()
            cursor.execute(querystring, identifier=identifier)

            office_info = cursor.fetchall()
            office_arr = {}

            if not office_info:
                raise OfficeNotFoundException(identifier=identifier)

            for office_item in office_info:

                office = dict(
                    zip([x[0].lower() for x in cursor.description],
                        office_item))
                office_obj = Office()
                office_obj.event_id = office['start_event_id']
                office_obj.delivery_address = Address.get_by_address_id(
                    office['delivery_addr_id']).as_dict()
                office_obj.office_type = office['office_typ_cd']

                if office['mailing_addr_id']:
                    office_obj.mailing_address = Address.get_by_address_id(
                        office['mailing_addr_id']).as_dict()
                else:
                    office_obj.mailing_address = office_obj.delivery_address

                for item in office_obj.office_codes:
                    k = office_obj.office_codes[item]['code']
                    if k == office_obj.office_type:
                        if item not in office_arr.keys():
                            office_arr[item] = office_obj.as_dict()
                        else:
                            current_app.logger.error(
                                'got more than 1 current registered office address for {}'
                                .format(identifier))
            return office_arr
        except Exception as err:
            current_app.logger.error(
                'error getting office for corp: {}'.format(identifier))
            raise err
示例#5
0
    def _build_parties_list(cls,
                            cursor,
                            corp_num: str,
                            event_id: int = None) -> Optional[List]:
        parties = cursor.fetchall()

        if not parties:
            return None

        completing_parties = {}
        party_list = []
        description = cursor.description
        for row in parties:
            party = Party()
            party.title = ''
            row = dict(zip([x[0].lower() for x in description], row))
            if not row['appointment_dt']:
                row['appointment_dt'] = Business.get_founding_date(
                    cursor=cursor, corp_num=corp_num)
            party.officer = cls._get_officer(row)
            if (row.get('party_typ_cd', None) == cls.role_types['Director']
                ) and not row['delivery_addr_id']:
                current_app.logger.error(
                    f"Bad director data for {party.officer.get('firstName')} {party.officer.get('lastName')} {corp_num}"
                )
            else:
                if row['delivery_addr_id']:
                    party.delivery_address = Address.get_by_address_id(
                        cursor, row['delivery_addr_id']).as_dict()
                party.mailing_address = Address.get_by_address_id(cursor, row['mailing_addr_id']).as_dict() \
                    if row['mailing_addr_id'] else party.delivery_address
                party.appointment_date =\
                    convert_to_json_date(row.get('appointment_dt', None))
                party.cessation_date = convert_to_json_date(
                    row.get('cessation_dt', None))
                party.start_event_id = (row.get('start_event_id', '')) or ''
                party.end_event_id = (row.get('end_event_id', '')) or ''
                party.role_type = (row.get('party_typ_cd', '')) or ''
                party.corp_party_id = row.get('corp_party_id', None)

                party_list.append(party)
        if event_id:
            completing_parties = cls.get_completing_parties(cursor, event_id)
        return cls.group_parties(party_list, completing_parties)
示例#6
0
    def get_current(cls, identifier: str = None):
        """Return current registered office address."""
        if not identifier:
            return None

        querystring = ("""
            select start_event_id, mailing_addr_id, delivery_addr_id
            from office
            where corp_num=:identifier and end_event_id is null and office_typ_cd='RG'
            """)

        try:
            cursor = DB.connection.cursor()
            cursor.execute(querystring, identifier=identifier)

            office_info = cursor.fetchone()
            if not office_info:
                raise OfficeNotFoundException(identifier=identifier)

            test_second_office = cursor.fetchone()
            if test_second_office:
                current_app.logger.error(
                    'got more than 1 current registered office address for {}'.
                    format(identifier))

            office_info = dict(
                zip([x[0].lower() for x in cursor.description], office_info))
            office_obj = Office()
            office_obj.event_id = office_info['start_event_id']
            office_obj.delivery_address = Address.get_by_address_id(
                office_info['delivery_addr_id']).as_dict()
            if office_info['mailing_addr_id']:
                office_obj.mailing_address = Address.get_by_address_id(
                    office_info['mailing_addr_id']).as_dict()
            else:
                office_obj.mailing_address = office_obj.delivery_address
            return office_obj

        except Exception as err:
            current_app.logger.error(
                'error getting office for corp: {}'.format(identifier))
            raise err
示例#7
0
    def get_by_event(cls, event_id: str = None):
        """Return current registered office address."""
        if not event_id:
            return None

        querystring = ("""
            select start_event_id, mailing_addr_id, delivery_addr_id
            from office
            where start_event_id=:event_id and office_typ_cd='RG'
            """)

        try:
            cursor = DB.connection.cursor()
            cursor.execute(querystring, event_id=event_id)

            office_info = cursor.fetchone()
            if not office_info:
                raise OfficeNotFoundException(event_id=event_id)

            office_info = dict(
                zip([x[0].lower() for x in cursor.description], office_info))
            office_obj = Office()
            office_obj.event_id = office_info['start_event_id']
            office_obj.delivery_address = Address.get_by_address_id(
                office_info['delivery_addr_id']).as_dict()
            if office_info['mailing_addr_id']:
                office_obj.mailing_address = Address.get_by_address_id(
                    office_info['mailing_addr_id']).as_dict()
            else:
                office_obj.mailing_address = office_obj.delivery_address

            return office_obj

        except Exception as err:  # pylint: disable=broad-except; want to catch all errs
            current_app.logger.error(
                'error getting office from event : {}'.format(event_id))

            raise err