def filing_json(self, json_data: dict): """Property containing the filings data.""" if self.locked: self._raise_default_lock_exception() try: self._filing_type = json_data.get('filing').get('header').get('name') if not self._filing_type: raise Exception except Exception as err: raise BusinessException( error='No filings found.', status_code=HTTPStatus.UNPROCESSABLE_ENTITY ) from err if self._payment_token: valid, err = rsbc_schemas.validate(json_data, 'filing') if not valid: self._filing_type = None self._payment_token = None errors = [] for error in err: errors.append({'path': '/'.join(error.path), 'error': error.message}) raise BusinessException( error=f'{errors}', status_code=HTTPStatus.UNPROCESSABLE_ENTITY ) self._status = Filing.Status.PENDING.value self._filing_json = json_data
def _validate_filing_json(client_request: LocalProxy) -> Tuple[dict, int]: """Assert that the json is a valid filing. Returns: { dict: a dict, success message or array of errors int: the HTTPStatus error code } """ valid, err = rsbc_schemas.validate(client_request.get_json(), 'filing') if valid: return {'message': 'Filing is valid'}, HTTPStatus.OK errors = [] for error in err: errors.append({'path': '/'.join(error.path), 'error': error.message}) return errors, HTTPStatus.BAD_REQUEST
def validate_against_schema(json_data: Dict = None) -> Error: """Validate against the filing schema. Returns: int: status code of the validation operation using HTTPStatus List[Dict]: a list of errors defined as {error:message, path:schemaPath} """ valid, err = rsbc_schemas.validate(json_data, 'comment') if valid: return None errors = [] for error in err: errors.append({'path': '/'.join(error.path), 'error': error.message}) return Error(HTTPStatus.UNPROCESSABLE_ENTITY, errors)
def filing_json(self, json_data: dict): """Property containing the filings data.""" if self.locked: self._raise_default_lock_exception() try: self._filing_type = json_data.get('filing').get('header').get( 'name') if not self._filing_type: raise Exception except Exception: raise BusinessException( error='No filings found.', status_code=HTTPStatus.UNPROCESSABLE_ENTITY) if self._payment_token: valid, err = rsbc_schemas.validate(json_data, 'filing') if not valid: self._filing_type = None self._payment_token = None errors = [] for error in err: errors.append({ 'path': '/'.join(error.path), 'error': error.message }) raise BusinessException( error=f'{errors}', status_code=HTTPStatus.UNPROCESSABLE_ENTITY) self._status = Filing.Status.PENDING.value self._filing_json = json_data try: self.colin_event_id = int(json_data.get('filing').get('eventId')) except (AttributeError, TypeError): # eventId is from colin_api (will not be set until added in colin db) # todo: could make the post call for filing with json_data to colin api here and then set the colin_event_Id pass