def _process_colin_filing(identifier: str, filing: Filing,
                           business: Business) -> Tuple[dict, int]:
     try:
         if not filing.colin_event_id:
             raise KeyError
         if not ListFilingResource._is_before_epoch_filing(
                 filing.filing_json, business):
             payload = {'filing': {'id': filing.id}}
             queue.publish_json(payload)
         else:
             epoch_filing = Filing.get_filings_by_status(
                 business_id=business.id,
                 status=[Filing.Status.EPOCH.value])
             filing.transaction_id = epoch_filing[0].transaction_id
             filing.save()
         return {'filing': {'id': filing.id}}, HTTPStatus.CREATED
     except KeyError:
         current_app.logger.error(
             'Business:%s missing filing/header/colinId, unable to post to queue',
             identifier)
         return {
             'errors': {
                 'message': 'missing filing/header/colinId'
             }
         }, HTTPStatus.BAD_REQUEST
     except Exception as err:  # pylint: disable=broad-except; final catch
         current_app.logger.error(
             'Business:%s unable to post to queue, err=%s', identifier, err)
         return {
             'errors': {
                 'message': 'unable to publish for post processing'
             }
         }, HTTPStatus.BAD_REQUEST
Example #2
0
 def _process_colin_filing(identifier: str,
                           json_input: dict) -> Tuple[dict, int]:
     try:
         payload = {
             'colinFiling': {
                 'id': json_input['filing']['header']['colinId']
             }
         }
         queue.publish_json(payload)
         return {}, HTTPStatus.CREATED
     except KeyError:
         current_app.logger.error(
             'Business:%s missing filing/header/colinId, unable to post to queue',
             identifier)
         return {
             'errors': {
                 'message': 'missing filing/header/colinId'
             }
         }, HTTPStatus.BAD_REQUEST
     except Exception as err:  # pylint: disable=broad-except; final catch
         current_app.logger.error(
             'Business:%s unable to post to queue, err=%s', identifier, err)
         return {
             'errors': {
                 'message': 'unable to publish for post processing'
             }
         }, HTTPStatus.BAD_REQUEST
Example #3
0
def load_corps(csv_filepath: str = 'corp_nums/corps_to_load.csv'):
    """Load corps in given csv file from oracle into postgres."""
    global ROWCOUNT
    with open(csv_filepath, 'r') as csvfile:
        reader = csv.DictReader(csvfile)
        with FLASK_APP.app_context():
            for row in reader:
                corp_num = row['CORP_NUM']
                added = False
                ROWCOUNT += 1
                try:
                    legal_type = Business.LegalTypes.COOP.value
                    if corp_num[:2] != Business.LegalTypes.COOP.value:
                        legal_type = Business.LegalTypes.COMP.value
                        corp_num = 'BC' + corp_num[-7:]

                    if business := Business.find_by_identifier(corp_num):
                        added = True
                        print(
                            '-> business info already exists -- skipping corp load'
                        )
                        continue

                    if not (filing_event :=
                            get_data_load_required_filing_event(
                                legal_type, corp_num)):
                        print(
                            'no icorp app or conversion ledger event found -- skipping corp load'
                        )
                        continue

                    colin_filing_type = filing_event.get('filing_typ_cd')
                    filing_type = get_filing_type(colin_filing_type)

                    if not (colin_filing := get_filing(filing_type, legal_type,
                                                       filing_event)):
                        print(
                            'no filing retrieved from filing event -- skipping corp load'
                        )
                        continue

                    filing = create_filing(filing_type, colin_filing,
                                           filing_event.get('event_id'),
                                           corp_num)
                    filing.save()

                    #push to queue
                    payload = {'filing': {'id': filing.id}}
                    queue.publish_json(payload)
                    added = True
                    NEW_CORPS.append(corp_num)

                except requests.exceptions.Timeout:
                    FAILED_CORPS.append(corp_num)
                    print(
                        'colin_api request timed out getting corporation details.'
                    )
                    continue
Example #4
0
    def _process_colin_filing(identifier: str, filing: Filing,
                              business: Business) -> Tuple[dict, int]:
        try:
            if not filing.colin_event_ids:
                raise KeyError

            if (epoch_filing :=
                    Filing.get_filings_by_status(business_id=business.id, status=[Filing.Status.EPOCH.value])
                ) and \
                    ListFilingResource._is_before_epoch_filing(filing.filing_json, business):
                filing.transaction_id = epoch_filing[0].transaction_id
                filing.set_processed()
                filing.save()
            else:
                payload = {'filing': {'id': filing.id}}
                queue.publish_json(payload)

            return {'filing': {'id': filing.id}}, HTTPStatus.CREATED
        except KeyError:
            current_app.logger.error(
                'Business:%s missing filing/header/colinIds, unable to post to queue',
                identifier)
            return {
                'errors': {
                    'message': 'missing filing/header/colinIds'
                }
            }, HTTPStatus.BAD_REQUEST
        except Exception as err:  # pylint: disable=broad-except; final catch
            current_app.logger.error(
                'Business:%s unable to post to queue, err=%s', identifier, err)
            return {