Ejemplo n.º 1
0
 def _add_filings(con, json_data: dict, filing_list: list, identifier: str,
                  corp_types: list) -> list:
     """Process all parts of the filing."""
     filings_added = []
     for filing_type in filing_list:
         filing = Filing()
         filing.header = json_data['header']
         filing.filing_date = filing.header['date']
         filing.filing_type = filing_type
         filing.body = filing_list[filing_type]
         print('body: ', filing.body)
         # get utc lear effective date and convert to pacific time for insert into oracle
         filing.effective_date = convert_to_pacific_time(
             filing.header['learEffectiveDate'])
         if filing_type != 'incorporationApplication':
             filing.business = Business.find_by_identifier(
                 identifier, corp_types, con)
         else:
             filing.business = Business.create_corporation(con, json_data)
         # add the new filing
         event_id = Filing.add_filing(con, filing)
         filings_added.append({
             'event_id': event_id,
             'filing_type': filing_type
         })
     return filings_added
Ejemplo n.º 2
0
 def _add_filings(con, json_data, filing_list, identifier):
     filings_added = []
     for filing_type in filing_list:
         filing = Filing()
         if filing_type != 'incorporationApplication':
             filing.business = Business.find_by_identifier(identifier, con)
         else:
             filing.business = Business.insert_new_business(con, filing_list[filing_type])
         filing.header = json_data['header']
         filing.filing_type = filing_type
         filing.body = filing_list[filing_type]
         filing.business.business['legalName'] = json_data['business']['legalName']
         # add the new filing
         event_id = Filing.add_filing(con, filing)
         filings_added.append({'event_id': event_id, 'filing_type': filing_type})
     return filings_added
Ejemplo n.º 3
0
    def post(identifier, **kwargs):  # pylint: disable=unused-argument; filing_type is only used for the get
        """Create a new filing."""
        try:
            json_data = request.get_json()
            if not json_data:
                return jsonify({'message': 'No input data provided'}), 400

            # validate schema
            is_valid, errors = validate(json_data,
                                        'filing',
                                        validate_schema=True)
            if not is_valid:
                for err in errors:
                    print(err.message)
                return jsonify({'message':
                                'Error: Invalid Filing schema'}), 400

            json_data = json_data.get('filing', None)

            filing_list = {
                'changeOfAddress': json_data.get('changeOfAddress', None),
                'changeOfDirectors': json_data.get('changeOfDirectors', None),
                'annualReport': json_data.get('annualReport', None)
            }

            # ensure that the business in the AR matches the business in the URL
            if identifier != json_data['business']['identifier']:
                return jsonify({
                    'message':
                    'Error: Identifier in URL does not match identifier in filing data'
                }), 400

            try:
                # get db connection and start a session, in case we need to roll back
                con = DB.connection
                con.begin()
                filings_added = []
                for filing_type in filing_list:
                    if filing_list[filing_type]:
                        filing = Filing()
                        filing.business = Business.find_by_identifier(
                            identifier)
                        filing.header = json_data['header']
                        filing.filing_type = filing_type
                        filing.body = filing_list[filing_type]

                        # add the new filing
                        event_id = Filing.add_filing(con, filing)
                        filings_added.append({
                            'event_id': event_id,
                            'filing_type': filing_type
                        })

                # return the completed filing data
                completed_filing = Filing()
                completed_filing.header = json_data['header']
                completed_filing.header['colinIds'] = []
                # get business info again - could have changed since filings were applied
                completed_filing.business = Business.find_by_identifier(
                    identifier)
                completed_filing.body = {}
                for filing_info in filings_added:
                    filing = Filing.get_filing(
                        con=con,
                        business=completed_filing.business,
                        event_id=filing_info['event_id'],
                        filing_type=filing_info['filing_type'])
                    if not filing:
                        raise FilingNotFoundException(
                            identifier=identifier,
                            filing_type=filing_info['filing_type'],
                            event_id=filing_info['event_id'])
                    completed_filing.body.update(
                        {filing_info['filing_type']: filing.body})
                    completed_filing.header['colinIds'].append(
                        filing_info['event_id'])

                # success! commit the db changes
                con.commit()
                return jsonify(completed_filing.as_dict()), 201

            except Exception as err:
                current_app.logger.error(err.with_traceback(None))
                if con:
                    con.rollback()
                raise err

        except Exception as err:  # pylint: disable=broad-except; want to catch all errors
            # general catch-all exception
            current_app.logger.error(err.with_traceback(None))
            return jsonify({
                'message':
                'Error when trying to retrieve business record from COLIN'
            }), 500