def get_latest_submittable_schemas(self, ingest_api_url):
     ingest_api = IngestApi(url=ingest_api_url)
     urls = []
     for schema in ingest_api.get_schemas(high_level_entity="type",
                                          latest_only=True):
         url = schema["_links"]["json-schema"]["href"]
         urls.append(url)
     return urls
Exemple #2
0
    def test_get_latest_schema_url__empty_result(self, mock_session):
        # given
        ingest_api = IngestApi(token_manager=self.token_manager)
        ingest_api.get_schemas = MagicMock(return_value=[])

        # when
        result = ingest_api.get_latest_schema_url('type', 'project', 'project')

        # then
        self.assertEqual(result, None)
Exemple #3
0
def get_hca_entity_types(
        ingest_api_url="http://api.ingest.data.humancellatlas.org"):
    '''
    takes a while to run so only run once per ingest.
    '''

    ingest_api = IngestApi(url=ingest_api_url)
    res = ingest_api.get_schemas(high_level_entity="type", latest_only=True)
    hca_schemas = {}
    for schema in res:
        concreteEntity = schema.get('concreteEntity')
        domainEntity = schema.get('domainEntity')
        if domainEntity not in hca_schemas:
            hca_schemas[domainEntity] = [concreteEntity + '_json']
        else:
            hca_schemas[domainEntity].append(concreteEntity + '_json')
    return hca_schemas
Exemple #4
0
    def test_get_latest_schema_url(self, mock_session):
        # given
        ingest_api = IngestApi(token_manager=self.token_manager)
        latest_schema_url = 'latest-project-schema-url'
        ingest_api.get_schemas = MagicMock(return_value=[{
            '_links': {
                'json-schema': {
                    'href': latest_schema_url
                }
            }
        }])

        # when
        result = ingest_api.get_latest_schema_url('type', 'project', 'project')

        # then
        self.assertEqual(result, latest_schema_url)
def main(environment, auth_token, doi):
    pub_info = get_pub_info(doi)

    if environment == "prod":
        env = ""
    elif environment == "staging":
        env = "staging."
    else:
        env = "dev."
    ingest_api_url = "http://api.ingest.{}archive.data.humancellatlas.org".format(
        env)
    ingest_api = IngestApi(ingest_api_url)
    latest_project_schema = ingest_api.get_schemas(
        high_level_entity="type",
        domain_entity="project",
        concrete_entity="project")[0]['_links']['json-schema']['href']
    project_json = construct_project_json(pub_info, latest_project_schema)
    submission_headers = {
        'Authorization': 'Bearer {}'.format(auth_token),
        'Content-Type': 'application/json'
    }

    response = rq.post("{}/projects".format(ingest_api_url),
                       data=json.dumps(project_json),
                       headers=submission_headers)
    if response:
        print("Project with uuid '{}' successfully created in {}.".format(
            response.json()['uuid']['uuid'], environment))
        print(
            "View the created project here: https://{}contribute.data.humancellatlas.org/projects/detail?uuid={}"
            .format(env,
                    response.json()['uuid']['uuid']))
        with open("log.txt", "a") as log_file:
            log_file.write(doi + "\t" + response.json()['uuid']['uuid'] + "\n")
    else:
        print("No project created, check if your token is still valid.")