Пример #1
0
def neessearch(offset=0, limit=100, query_string='', limit_fields=True, *args):

    nees_pi_query = Q({
        "nested": {
            "path": "pis",
            "ignore_unmapped": True,
            "query": {
                "query_string": {
                    "query": query_string,
                    "fields": ["pis.firstName", "pis.lastName"],
                    "lenient": True
                }
            }
        }
    })

    nees_query_string_query = Q('query_string',
                                query=query_string,
                                default_operator='and')

    pub_query = IndexedPublicationLegacy.search().filter(
        nees_pi_query | nees_query_string_query)
    pub_query = pub_query.extra(from_=offset, size=limit)
    if limit_fields:
        pub_query = pub_query.source(
            includes=['project', 'pis', 'title', 'startDate', 'path'])
    pub_query = pub_query.sort(
        {'created': {
            'order': 'desc',
            'unmapped_type': 'long'
        }})
    res = pub_query.execute()
    hits = list(map(lambda h: h.to_dict(), res.hits))
    return {'listing': hits}
Пример #2
0
    def test_listing(self, mock_search, mock_pub, mock_leg_pub):
        fm = PublicationsManager(None)
        mock_search().filter().sort().extra().execute.return_value = [
            IndexedPublication(projectId='PRJ-XXX'),
            IndexedPublicationLegacy()
        ]

        mock_pub().to_file.return_value = {'type': 'pub'}
        mock_leg_pub().to_file.return_value = {'type': 'leg_pub'}

        res = fm.listing(**{'type_filters': []})
        expected_result = {
            'trail': [{
                'name': '$SEARCH',
                'path': '/$SEARCH'
            }],
            'name': '$SEARCH',
            'path': '/',
            'system': None,
            'type': 'dir',
            'children': [{
                'type': 'pub'
            }, {
                'type': 'leg_pub'
            }],
            'permissions': 'READ'
        }
        self.assertEqual(res, expected_result)
Пример #3
0
    def test_listing(self, mock_search, mock_pub, mock_leg_pub):

        request = MagicMock()
        request.query_string = 'test_query'
        request.username = '******'

        fm = PublicationsSearchManager(request)
        mock_search().query().sort().extra().execute.return_value = [
            IndexedPublication(projectId='PRJ-XXX'),
            IndexedPublicationLegacy()
        ]

        mock_pub().to_file.return_value = {'type': 'pub'}
        mock_leg_pub().to_file.return_value = {'type': 'leg_pub'}

        res = fm.listing()
        expected_result = {
            'trail': [{
                'name': '$SEARCH',
                'path': '/$SEARCH'
            }],
            'name': '$SEARCH',
            'path': '/',
            'system': None,
            'type': 'dir',
            'children': [{
                'type': 'pub'
            }, {
                'type': 'leg_pub'
            }],
            'permissions': 'READ'
        }
        self.assertEqual(res, expected_result)
def reindex_nees_projects(*args):
    try:
        srch = IndexedPublicationLegacy.search()
        res = srch.execute()
        if res.hits.total > 0:
            return

        search = PublicProjectIndexed.search()
        res = search.execute()
        esrch = PublicExperimentIndexed.search()
        for pub in search.scan():
            pub_dict = pub.to_dict()
            pub_dict['path'] = pub_dict['projectPath']
            pub_dict.pop('projectPath', '')
            pub_dict['system'] = pub_dict['systemId']
            pub_dict.pop('systemId', '')
            pub_doc = IndexedPublicationLegacy(**pub_dict)
            esrch.query = Q('bool',
                            must=Q({'term': {
                                'project._exact': pub.name
                            }}))
            esrch.execute()
            experiments = []
            for exp in esrch.scan():
                exp_dict = exp.to_dict()
                exp_dict['path'] = exp_dict['experimentPath']
                exp_dict.pop('systemId')
                exp_dict.pop('experimentPath', '')
                exp_dict.pop('project')
                experiments.append(exp_dict)
            pub_doc.experiments = experiments
            pub_doc.save()
    except TransportError as exc:
        if exc.status_code != 404:
            raise
Пример #5
0
def neeslisting(offset=0, limit=100, limit_fields=True, *args):
    pub_query = IndexedPublicationLegacy.search()
    pub_query = pub_query.extra(from_=offset, size=limit)
    if limit_fields:
        pub_query = pub_query.source(
            includes=['project', 'pis', 'title', 'startDate', 'path'])
    pub_query = pub_query.sort(
        {'created': {
            'order': 'desc',
            'unmapped_type': 'long'
        }})
    res = pub_query.execute()
    hits = list(map(lambda h: h.to_dict(), res.hits))

    return {'listing': hits}
Пример #6
0
def neesdescription(project_id, *args):
    pub_query = IndexedPublicationLegacy.search()\
        .filter(Q({'term': {'project._exact': project_id}}))\
        .source(includes=['description'])
    desc = next(hit.description for hit in pub_query.execute().hits)
    return {'description': desc}
Пример #7
0
    def to_dataset_json(self):
        """
        Serialize project to json for google dataset search
        https://dataverse.harvard.edu/dataset.xhtml?persistentId=doi:10.7910/DVN/BMNJPS
        """

        dataset_json = {
            "@context":
            "http://schema.org",
            "@type":
            "Dataset",
            "@id":
            "",
            "identifier":
            "",
            "logo":
            "https://www.designsafe-ci.org/static/images/nsf-designsafe-logo.014999b259f6.png",
            "name":
            self.title,
            "creator": [{
                "name": "",
                "affiliation": "",
                "@id": "",
                "identifier": ""
            }],
            "author": [{
                "name": "",
                "affiliation": "",
                "@id": "",
                "identifier": ""
            }],
            "datePublished":
            self.created,
            "dateModified":
            self.to_body_dict()['lastUpdated'],
            "description":
            self.description,
            "keywords":
            self.keywords.split(','),
            "license": {
                "@type": "Dataset",
                "text": ""
            },
            "publisher": {
                "@type": "Organization",
                "name": "Designsafe-CI"
            },
            "provider": {
                "@type": "Organization",
                "name": "Designsafe-CI"
            },
            "includedInDataCatalog": {
                "@type": "Organization",
                "name": "Designsafe-CI",
                "url": "https://designsafe-ci.org"
            },
        }
        if self.dois:
            dataset_json["distribution"] = {
                "@type": "DataDownload",
                "name":
                self.to_body_dict()['value']['projectId'] + "_archive.zip",
                "fileFormat": "application/zip",
                "contentSize": "",
                "@id": "",
                "identifier": ""
            }

        if self.dois:
            dataset_json['@id'] = self.dois[0]
            dataset_json['identifier'] = self.dois[0]
        else:
            related_ents = self.related_entities()
            logger.debug(related_ents)
        if getattr(self, 'team_order', False):
            authors = sorted(self.team_order, key=lambda x: x['order'])
        else:
            authors = [{
                'name': username
            } for username in [self.pi] + self.co_pis]
        dataset_json['creator'] = generate_creators(authors)
        dataset_json['author'] = generate_creators(authors)
        try:
            pub = IndexedPublication.from_id(self.project_id)
            dataset_json['license'] = pub.licenses.works
        except (DocumentNotFound, AttributeError):
            pass
        try:
            pub = IndexedPublicationLegacy.from_id(self.project_id)
            dataset_json['license'] = pub.licenses.works
        except DocumentNotFound:
            pass

        return dataset_json