Skip to content

Commit

Permalink
Merge branch 'feature/3367_missing-oaipmh-records' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
Steven-Eardley committed Mar 17, 2023
2 parents 716a4ee + 57a6924 commit 588d0af
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 7 deletions.
3 changes: 2 additions & 1 deletion doajtest/fixtures/v2/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@
"subject": [
{"scheme": "LCC", "term": "Economic theory. Demography",
"code": "HB1-3840"},
{"scheme": "LCC", "term": "Social Sciences", "code": "H"}
{"scheme": "LCC", "term": "Social Sciences", "code": "H"},
{"scheme": "LCC", "term": "Veterinary medicine", "code": "SF600-1100"}
],
"title": "The Title",
"waiver": {
Expand Down
57 changes: 55 additions & 2 deletions doajtest/unit/test_oaipmh.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,11 +279,13 @@ def test_08_list_sets(self):
t = etree.fromstring(resp.data)
records = t.xpath('/oai:OAI-PMH/oai:ListSets', namespaces=self.oai_ns)
sets = records[0].getchildren()
assert len(sets) == 2
assert len(sets) == 3
set0 = sets[0].getchildren()
set1 = sets[1].getchildren()
set2 = sets[2].getchildren()
assert set0[1].text == 'LCC:Economic theory. Demography'
assert set1[1].text == 'LCC:Social Sciences'
assert set2[1].text == 'LCC:Veterinary medicine'

# check that we can retrieve a record with one of those sets
with self.app_test.test_client() as t_client:
Expand Down Expand Up @@ -343,4 +345,55 @@ def test_09_article(self):
assert len(r) == 1

# Check we have the correct journal
assert records[0].xpath('//dc:title', namespaces=self.oai_ns)[0].text == a_public.bibjson().title
assert records[0].xpath('//dc:title', namespaces=self.oai_ns)[0].text == a_public.bibjson().title

def test_10_subjects(self):
"""test if the OAI-PMH journal feed returns correct journals when set specified"""
journal_source = JournalFixtureFactory.make_journal_source(in_doaj=True)
j_public = models.Journal(**journal_source)
j_public.save(blocking=True)
public_id = j_public.id

with self.app_test.test_request_context():
# Check whether the journal is found for its specific set: Veterinary Medicine (TENDOlZldGVyaW5hcnkgbWVkaWNpbmU)
with self.app_test.test_client() as t_client:
resp = t_client.get(url_for('oaipmh.oaipmh', verb='ListRecords', metadataPrefix='oai_dc', set='TENDOlZldGVyaW5hcnkgbWVkaWNpbmU~'))
assert resp.status_code == 200

t = etree.fromstring(resp.data)
records = t.xpath('/oai:OAI-PMH/oai:ListRecords', namespaces=self.oai_ns)

# Check we only have one journal returned
assert len(records[0].xpath('//oai:record', namespaces=self.oai_ns)) == 1

# Check we have the correct journal
assert records[0].xpath('//dc:title', namespaces=self.oai_ns)[0].text == j_public.bibjson().title

#check we have expected subjects (Veterinary Medicine but not Agriculture)
subjects = records[0].xpath('//dc:subject', namespaces=self.oai_ns)
assert len(subjects) != 0

subjects_txt = list(map(lambda s: s.text, subjects))
assert "Veterinary medicine" in subjects_txt
assert not "Agriculture" in subjects_txt

# check we can still find the record in Agriculture set (parent of Veterinary Medicine)
with self.app_test.test_request_context():
# Check whether the journal is found for more general set: Agriculture (TENDOkFncmljdWx0dXJl)
with self.app_test.test_client() as t_client:
resp = t_client.get(url_for('oaipmh.oaipmh', verb='ListRecords', metadataPrefix='oai_dc', set='TENDOkFncmljdWx0dXJl~'))
assert resp.status_code == 200

t = etree.fromstring(resp.data)
records = t.xpath('/oai:OAI-PMH/oai:ListRecords', namespaces=self.oai_ns)

sets = records[0].getchildren()

assert len(sets) == 1
set0 = sets[0].getchildren()

# Check we only have one journal returned
assert len(records[0].xpath('//oai:record', namespaces=self.oai_ns)) == 1

# Check we have the correct journal
assert records[0].xpath('//dc:title', namespaces=self.oai_ns)[0].text == j_public.bibjson().title
6 changes: 4 additions & 2 deletions portality/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@
BG_STATUS_STABLE = 'stable'
BG_STATUS_UNSTABLE = 'unstable'


# Storage scopes
STORE__SCOPE__PUBLIC_DATA_DUMP = "public_data_dump"
STORE__SCOPE__PUBLIC_DATA_DUMP = "public_data_dump"

# OAI
SUBJECTS_SCHEMA = "LCC:"
6 changes: 4 additions & 2 deletions portality/models/oaipmh.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from copy import deepcopy
from portality.models import Journal, Article
from portality import constants

class OAIPMHRecord(object):
earliest = {
Expand Down Expand Up @@ -49,7 +50,7 @@ class OAIPMHRecord(object):
"size": 25
}

set_limit = {"term" : { "index.schema_subject.exact" : "<set name>" }}
set_limit = {"term" : { "index.classification.exact" : "<set name>" }}
range_limit = { "range" : { "last_updated" : {"gte" : "<from date>", "lte" : "<until date>"} } }
created_sort = [{"last_updated" : {"order" : "desc"}}, {"id.exact" : "desc"}]

Expand All @@ -71,8 +72,9 @@ def list_records(self, from_date=None, until_date=None, oai_set=None, list_size=
if start_after is not None or from_date is not None or until_date is not None or oai_set is not None:

if oai_set is not None:
a = oai_set.replace(constants.SUBJECTS_SCHEMA,"")
s = deepcopy(self.set_limit)
s["term"]["index.schema_subject.exact"] = oai_set
s["term"]["index.classification.exact"] = a
q["query"]["bool"]["must"].append(s)

if until_date is not None or from_date is not None or start_after is not None:
Expand Down

0 comments on commit 588d0af

Please sign in to comment.