def submit_files(): file_manager = FileHandler(request, is_local=is_local, server_path=server_path) sess = GlobalDB.db().session start_date = request.json.get('reporting_period_start_date') end_date = request.json.get('reporting_period_end_date') is_quarter = request.json.get('is_quarter_format', False) if not (start_date is None or end_date is None): formatted_start_date, formatted_end_date = FileHandler.check_submission_dates(start_date, end_date, is_quarter) submissions = sess.query(Submission).filter( Submission.cgac_code == request.json.get('cgac_code'), Submission.frec_code == request.json.get('frec_code'), Submission.reporting_start_date == formatted_start_date, Submission.reporting_end_date == formatted_end_date, Submission.is_quarter_format == request.json.get('is_quarter'), Submission.publish_status_id != PUBLISH_STATUS_DICT['unpublished']) if 'existing_submission_id' in request.json: submissions.filter(Submission.submission_id != request.json['existing_submission_id']) submissions = submissions.order_by(desc(Submission.created_at)) if submissions.count() > 0: data = { "message": "A submission with the same period already exists.", "submissionId": submissions[0].submission_id } return JsonResponse.create(StatusCode.CLIENT_ERROR, data) return file_manager.submit(create_credentials)
def upload_fabs_file(): if "multipart/form-data" not in request.headers['Content-Type']: return JsonResponse.error(ValueError("Request must be a multipart/form-data type"), StatusCode.CLIENT_ERROR) params = RequestDictionary.derive(request) fabs = params.get('_files', {}).get('fabs', None) file_manager = FileHandler(request, is_local=is_local, server_path=server_path) return file_manager.upload_fabs_file(fabs)
def generate_detached_file(file_type, cgac_code, frec_code, start, end): """ Generate a file from external API, independent from a submission """ if not cgac_code and not frec_code: return JsonResponse.error(ValueError("Detached file generation requires CGAC or FR Entity Code"), StatusCode.CLIENT_ERROR) file_manager = FileHandler(request, is_local=is_local, server_path=server_path) return file_manager.generate_detached_file(file_type, cgac_code, frec_code, start, end)
def certify_submission(submission): if not submission.publishable: return JsonResponse.error(ValueError("Submission cannot be certified due to critical errors"), StatusCode.CLIENT_ERROR) if not submission.is_quarter_format: return JsonResponse.error(ValueError("Monthly submissions cannot be certified"), StatusCode.CLIENT_ERROR) if submission.publish_status_id == PUBLISH_STATUS_DICT['published']: return JsonResponse.error(ValueError("Submission has already been certified"), StatusCode.CLIENT_ERROR) windows = get_window() for window in windows: if window.block_certification: return JsonResponse.error(ValueError(window.message), StatusCode.CLIENT_ERROR) sess = GlobalDB.db().session response = find_existing_submissions_in_period(sess, submission.cgac_code, submission.frec_code, submission.reporting_fiscal_year, submission.reporting_fiscal_period, submission.submission_id) if response.status_code == StatusCode.OK: sess = GlobalDB.db().session # create the certify_history entry certify_history = CertifyHistory(created_at=datetime.utcnow(), user_id=g.user.user_id, submission_id=submission.submission_id) sess.add(certify_history) sess.commit() # get the certify_history entry including the PK certify_history = sess.query(CertifyHistory).filter_by(submission_id=submission.submission_id).\ order_by(CertifyHistory.created_at.desc()).first() # move files (locally we don't move but we still need to populate the certified_files_history table file_manager = FileHandler(request, is_local=is_local, server_path=server_path) file_manager.move_certified_files(submission, certify_history, is_local) # set submission contents submission.certifying_user_id = g.user.user_id submission.publish_status_id = PUBLISH_STATUS_DICT['published'] sess.commit() return response
def generate_file(submission_id, file_type): """ Generate file from external API """ file_manager = FileHandler(request, is_local=is_local, server_path=server_path) return file_manager.generate_file(submission_id, file_type)
def publish_fabs_file(submission): file_manager = FileHandler(request, is_local=is_local, server_path=server_path) return file_manager.publish_fabs_submission(submission)
def submit_detached_file(submission): file_manager = FileHandler(request, is_local=is_local, server_path=server_path) return file_manager.submit_detached_file(submission)
def restart_validation(submission): return FileHandler.restart_validation(submission)
def check_detached_generation_status(job_id): """ Return status of file generation job """ file_manager = FileHandler(request, is_local=is_local, server_path=server_path) return file_manager.check_detached_generation(job_id)
def complete_generation(generation_id): file_manager = FileHandler(request, is_local=is_local, server_path=server_path) return file_manager.complete_generation(generation_id)
def get_protected_files(): """ Return signed URLs for all help page files """ file_manager = FileHandler(request, is_local=is_local, server_path=server_path) return file_manager.get_protected_files()
def check_generation_status(submission, file_type): """ Return status of file generation job """ file_manager = FileHandler(request, is_local=is_local, server_path=server_path) return file_manager.check_generation(submission, file_type)
def submission_warning_reports(submission_id): file_manager = FileHandler(request, is_local=is_local, server_path=server_path) return file_manager.get_error_report_urls_for_submission(submission_id, is_warning=True)
def upload_dabs_files(): if "multipart/form-data" not in request.headers['Content-Type']: return JsonResponse.error(ValueError("Request must be a multipart/form-data type"), StatusCode.CLIENT_ERROR) file_manager = FileHandler(request, is_local=is_local, server_path=server_path) return file_manager.validate_upload_dabs_files()
def restart_validation(submission, **kwargs): d2_submission = kwargs.get('d2_submission') return FileHandler.restart_validation(submission, d2_submission)
def restart_validation(submission, d2_submission): return FileHandler.restart_validation(submission, d2_submission)
def upload_local_file(): file_manager = FileHandler(request, is_local=is_local, server_path=server_path) return file_manager.upload_file()
def finalize_submission(upload_id): file_manager = FileHandler(request, is_local=is_local, server_path=server_path) return file_manager.finalize(upload_id)
def publish_and_certify_dabs_sub(submission): file_manager = FileHandler(request, is_local=is_local, server_path=server_path) return publish_and_certify_dabs_submission(submission, file_manager)
def restart_validation(submission, **kwargs): is_fabs = kwargs.get('is_fabs') return FileHandler.restart_validation(submission, is_fabs)
def revert_submission(submission): """ Revert an updated DABS submission to the state it was when it was last published """ file_manager = FileHandler(request, is_local=is_local, server_path=server_path) return revert_to_published(submission, file_manager)
def upload_local_file(): fileManager = FileHandler(request,isLocal=IS_LOCAL, serverPath=SERVER_PATH) return RouteUtils.run_instance_function(fileManager, fileManager.uploadFile)
def submit_files(): fileManager = FileHandler(request,isLocal=IS_LOCAL, serverPath=SERVER_PATH) return RouteUtils.run_instance_function(fileManager, fileManager.submit, getUser=True,getCredentials=True)
def upload_detached_file(): file_manager = FileHandler(request, is_local=is_local, server_path=server_path) return file_manager.upload_detached_file(create_credentials)
def finalize_submission(): fileManager = FileHandler(request,isLocal=IS_LOCAL, serverPath=SERVER_PATH) return RouteUtils.run_instance_function(fileManager, fileManager.finalize)
def check_status(): fileManager = FileHandler(request,isLocal=IS_LOCAL, serverPath=SERVER_PATH) return RouteUtils.run_instance_function(fileManager, fileManager.getStatus)
def submission_error_metrics(): fileManager = FileHandler(request,isLocal=IS_LOCAL ,serverPath=SERVER_PATH) return RouteUtils.run_instance_function(fileManager, fileManager.getErrorMetrics)