def get_validation_result(archive_submission_uuid: str): dsp_api = DataSubmissionPortal(config.DSP_API_URL) submission_url = dsp_api.get_submission_url(archive_submission_uuid) submission = ArchiveSubmission(dsp_api=dsp_api, dsp_submission_url=submission_url) result = submission.get_all_validation_result_details() return jsonify(result)
def get_blockers(archive_submission_uuid: str): dsp_api = DataSubmissionPortal(config.DSP_API_URL) submission_url = dsp_api.get_submission_url(archive_submission_uuid) submission = ArchiveSubmission(dsp_api=dsp_api, dsp_submission_url=submission_url) blockers = submission.get_blockers() return jsonify(blockers)
def get_validation_errors(archive_submission_uuid: str): dsp_api = DataSubmissionPortal(config.DSP_API_URL) submission_url = dsp_api.get_submission_url(archive_submission_uuid) submission = ArchiveSubmission(dsp_api=dsp_api, dsp_submission_url=submission_url) validation_errors = submission.get_validation_error_report() return jsonify(validation_errors)
def delete_archive_submission(dsp_submission_uuid: str): ingest_api = IngestAPI(config.INGEST_API_URL) dsp_api = DataSubmissionPortal(config.DSP_API_URL) ingest_archive_submission = ingest_api.get_archive_submission_by_dsp_uuid( dsp_submission_uuid) dsp_url = ingest_archive_submission['dspUrl'] dsp_api.delete_submission(dsp_url) logger.info(f'Deleting DSP submission {dsp_url}') archive_submission_url = ingest_archive_submission['_links']['self'][ 'href'] logger.info(f'Deleting Ingest Archive Submission {archive_submission_url}') response = ingest_api.delete(archive_submission_url) return response_json(HTTPStatus.OK, data=response)
def archive(): data = request.get_json() submission_uuid = data.get('submission_uuid') exclude_types = data.get('exclude_types') alias_prefix = data.get('alias_prefix') if not submission_uuid: error = { 'message': f'You must supply the parameter submission_uuid referring to an Ingest submission envelope uuid.' } return response_json(HTTPStatus.BAD_REQUEST, error) if config.DIRECT_SUBMISSION: direct_archiver = direct_archiver_from_config() submission = direct_archiver.archive_submission(submission_uuid) response = submission.as_dict(string_lists=True) else: ingest_api = IngestAPI(config.INGEST_API_URL) archiver = IngestArchiver(ingest_api=ingest_api, dsp_api=DataSubmissionPortal( config.DSP_API_URL), exclude_types=exclude_types, alias_prefix=alias_prefix) thread = threading.Thread(target=async_archive, args=(ingest_api, archiver, submission_uuid)) thread.start() response = {'message': 'successfully triggered!'} return jsonify(response)
def complete(dsp_submission_uuid: str): dsp_api = DataSubmissionPortal(config.DSP_API_URL) ingest_api = IngestAPI(config.INGEST_API_URL) thread = threading.Thread(target=async_complete, args=(dsp_api, dsp_submission_uuid, ingest_api)) thread.start() response = {'message': 'successfully triggered!'} return response_json(HTTPStatus.ACCEPTED, data=response)
def __init__(self, alias_prefix, output_dir, exclude_types, no_validation): self.manifests = [] self.ingest_api = IngestAPI(config.INGEST_API_URL) self.dsp_api = DataSubmissionPortal(config.DSP_API_URL) now = datetime.datetime.utcnow().strftime("%Y-%m-%dT%H%M%S") self.output_dir = output_dir if output_dir else f"output/ARCHIVER_{now}" self.archiver = IngestArchiver(ingest_api=self.ingest_api, dsp_api=self.dsp_api, exclude_types=self.split_exclude_types(exclude_types), alias_prefix=alias_prefix, dsp_validation=not no_validation)
def setUp(self): self.dsp_api = DataSubmissionPortal() with open(config.JSON_DIR + 'hca/biomaterials.json', encoding=config.ENCODING) as data_file: hca_samples = json.loads(data_file.read()) self.hca_submission = {'samples': hca_samples} self.ontology_api = MagicMock() self.ontology_api.expand_curie = MagicMock( return_value='http://purl.obolibrary.org/obo/UO_0000015') self.ingest_api = MagicMock() self.ingest_api.url = 'ingest_url' self.ingest_api.get_concrete_entity_type = MagicMock( return_value='donor_organism') self.converter = SampleConverter(ontology_api=self.ontology_api) self.converter.ingest_api = self.ingest_api pass
class TestDataSubmissionPortal(unittest.TestCase): def setUp(self): self.dsp_api = DataSubmissionPortal() with open(config.JSON_DIR + 'hca/biomaterials.json', encoding=config.ENCODING) as data_file: hca_samples = json.loads(data_file.read()) self.hca_submission = {'samples': hca_samples} self.ontology_api = MagicMock() self.ontology_api.expand_curie = MagicMock( return_value='http://purl.obolibrary.org/obo/UO_0000015') self.ingest_api = MagicMock() self.ingest_api.url = 'ingest_url' self.ingest_api.get_concrete_entity_type = MagicMock( return_value='donor_organism') self.converter = SampleConverter(ontology_api=self.ontology_api) self.converter.ingest_api = self.ingest_api pass def tearDown(self): self.dsp_api.session.close() def test_get_token_given_valid_credentials_return_token(self): aap_user = os.environ.get('AAP_API_USER', '') aap_password = os.environ.get('AAP_API_PASSWORD', '') token_client = AAPTokenClient(username=aap_user, password=aap_password) token = token_client.retrieve_token() self.assertTrue(token) def test_get_token_given_invalid_credentials_return_none(self): username = '******' password = '******' token_client = AAPTokenClient(username=username, password=password) token = token_client.retrieve_token() self.assertFalse(token) def test_create_submission(self): submission = self.dsp_api.create_submission() delete_url = submission['_links']['self:delete']['href'] self.dsp_api.delete_submission(delete_url) self.assertTrue(submission['_links']['self']['href']) def test_get_submission_contents(self): submission = self.dsp_api.create_submission() get_contents_url = submission['_links']['contents']['href'] contents = self.dsp_api.get_contents(get_contents_url) delete_url = submission['_links']['self:delete']['href'] self.dsp_api.delete_submission(delete_url) self.assertTrue(contents) def test_create_sample(self): submission = self.dsp_api.create_submission() get_contents_url = submission['_links']['contents']['href'] contents = self.dsp_api.get_contents(get_contents_url) create_sample_url = contents['_links']['samples:create']['href'] samples = self.hca_submission['samples'] sample = samples[0] sample = {'biomaterial': sample} converted_sample = self.converter.convert(sample) created_sample = self.dsp_api.create_entity(create_sample_url, converted_sample) # clean up submission in DSP delete_url = submission['_links']['self:delete']['href'] self.dsp_api.delete_submission(delete_url) self.assertTrue(created_sample)