Skip to content

Commit

Permalink
Merge pull request #415 from CDLUC3/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
datadavev authored Apr 13, 2023
2 parents 2a9b284 + 99429bf commit dde1e2f
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 13 deletions.
10 changes: 0 additions & 10 deletions ezidapp/models/shoulder.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,13 +232,3 @@ def _getShoulder(s):
except Shoulder.DoesNotExist as e:
logger.warning(f'Shoulder does not exist: {s}')


def listNaans(shoulder_type: str = "ARK") -> list[str]:
'''Return a list of naan values for the specified identifier type.'''
matches = (
Shoulder.objects.filter(type=shoulder_type)
.annotate(naan=django.db.models.functions.Substr('prefix', 6, 5))
.values("naan")
.distinct()
)
return [n["naan"] for n in matches]
25 changes: 24 additions & 1 deletion templates/doc/apidoc.2.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
{% learn_breadcrumb _("API Guide") %}
<div class="container api vertical-buffer-20"><div class="smallfont line-block">
<div class="line"><strong>This version:</strong> <a class="reference external" href="{{ request.META.HTTP_X_FORWARDED_PROTO|default:request.scheme }}://{{ request.META.HTTP_HOST }}/doc/apidoc.2.html">{{ request.META.HTTP_X_FORWARDED_PROTO|default:request.scheme }}://{{ request.META.HTTP_HOST }}/doc/apidoc.2.html</a></div>
<div class="line"><strong>Latest version:</strong> <a class="reference external" href="{{ request.META.HTTP_X_FORWARDED_PROTO|default:request.scheme }}://{{ request.META.HTTP_HOST }}/doc/apidoc.html">{{ request.META.HTTP_X_FORWARDED_PROTO|default:request.scheme }}://{{ request.META.HTTP_HOST }}/doc/apidoc.html</a></div>
<div class="line"><strong>Latest version:</strong> <a class="reference external" href="{{ request.META.HTTP_X_FORWARDED_PROTO|default:request.scheme }}://{{ request.META.HTTP_HOST }}/doc/apidoc.2.html">{{ request.META.HTTP_X_FORWARDED_PROTO|default:request.scheme }}://{{ request.META.HTTP_HOST }}/doc/apidoc.2.html</a></div>
<div class="line"><strong>Previous version:</strong> <a class="reference external" href="{{ request.META.HTTP_X_FORWARDED_PROTO|default:request.scheme }}://{{ request.META.HTTP_HOST }}/doc/apidoc.1.html">{{ request.META.HTTP_X_FORWARDED_PROTO|default:request.scheme }}://{{ request.META.HTTP_HOST }}/doc/apidoc.1.html</a></div>
</div>
<p>EZID (easy-eye-dee) provides an easy way to obtain, describe, and
Expand Down Expand Up @@ -665,6 +665,29 @@ <h1>Operation: get identifier metadata (EZID v3.1)</h1>
&lt;/descriptions&gt;
&lt;/resource&gt;
</pre>
<p>If an exact match for an identifier is not found then matching shoulders are presented (truncated for brevity):</p>
<pre class="literal-block">
$ curl -H &quot;Accept: application/json&quot; \
&quot;{{ request.META.HTTP_X_FORWARDED_PROTO|default:request.scheme }}://{{ request.META.HTTP_HOST }}/ark:/13030/nonexistent?info&quot;

{
&quot;ark:/13030/p8&quot;: {
&quot;erc.who&quot;: &quot;Open Access Policy&quot;,
&quot;erc.what&quot;: &quot;ARK&quot;,
&quot;erc.when&quot;: &quot;2015-04-06&quot;
},
&quot;ark:/13030/fq&quot;: {
&quot;erc.who&quot;: &quot;DPR Legacy&quot;,
&quot;erc.what&quot;: &quot;ARK&quot;,
&quot;erc.when&quot;: &quot;2011-12-13&quot;
},
&quot;ark:/13030/ft&quot;: {
&quot;erc.who&quot;: &quot;Online Archive of California (OAC) Legacy ft&quot;,
&quot;erc.what&quot;: &quot;ARK&quot;,
&quot;erc.when&quot;: &quot;2007-06-01&quot;
},
...
</pre>
<p>A live demo of the inflection operation is provided below. Enter an identifier, and click
&quot;Get Metadata&quot; to show the request and response.</p>
<input id="inp_pid" type="text" size="80" placeholder="identifier" value="ark:/87278/s63x8hrv"></input>
Expand Down
30 changes: 28 additions & 2 deletions templates/doc/apidoc.2.rst
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ The EZID API, Version 2

| **This version:** `SCHEME://HOSTNAME/doc/apidoc.2.html
<SCHEME://HOSTNAME/doc/apidoc.2.html>`_
| **Latest version:** `SCHEME://HOSTNAME/doc/apidoc.html
<SCHEME://HOSTNAME/doc/apidoc.html>`_
| **Latest version:** `SCHEME://HOSTNAME/doc/apidoc.2.html
<SCHEME://HOSTNAME/doc/apidoc.2.html>`_
| **Previous version:** `SCHEME://HOSTNAME/doc/apidoc.1.html
<SCHEME://HOSTNAME/doc/apidoc.1.html>`_
Expand Down Expand Up @@ -746,6 +746,32 @@ metadata value, for example (truncated here for brevity):
</descriptions>
</resource>
If an exact match for an identifier is not found then matching shoulders are presented (truncated for brevity):

.. parsed-literal::
$ curl -H "Accept: application/json" \\
"SCHEME://HOSTNAME/ark:/13030/nonexistent?info"
{
"ark:/13030/p8": {
"erc.who": "Open Access Policy",
"erc.what": "ARK",
"erc.when": "2015-04-06"
},
"ark:/13030/fq": {
"erc.who": "DPR Legacy",
"erc.what": "ARK",
"erc.when": "2011-12-13"
},
"ark:/13030/ft": {
"erc.who": "Online Archive of California (OAC) Legacy ft",
"erc.what": "ARK",
"erc.when": "2007-06-01"
},
...
A live demo of the inflection operation is provided below. Enter an identifier, and click
"Get Metadata" to show the request and response.

Expand Down
26 changes: 26 additions & 0 deletions tests/resolve/test_resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,10 @@ def test_parse(val, expected):
("ark:/88122/zqfw0190", "https://www.industrydocuments.ucsf.edu/docs/zqfw0190"),
),
("ark:/88122/", (ezidapp.models.identifier.Identifier.DoesNotExist())),
(
"ark:/88122/zqfw",
(ezidapp.models.identifier.Identifier.DoesNotExist()),
),
],
)
def test_resolve(val, expected):
Expand All @@ -206,3 +210,25 @@ def test_resolve(val, expected):
return
except Exception as e:
assert isinstance(e, expected.__class__)

@pytest.mark.parametrize(
"val,expected",
[
("ark:/00122/", (ezidapp.models.identifier.Identifier.DoesNotExist())),
("ark:/88122/", (("ark:/88122/zqfw", "ark:/88122/", ))),
(
"ark:/88122/zqfw",
(("ark:/88122/zqfw", "ark:/88122/", )),
),
],
)
def test_findshoulders(val, expected):
pid_info = impl.resolver.IdentifierParser.parse(val)
try:
res = pid_info.find_shoulders()
for item in res:
print(item.prefix)
assert(item.prefix in expected[0])
return
except Exception as e:
assert isinstance(e, expected.__class__)

0 comments on commit dde1e2f

Please sign in to comment.