Skip to content

Commit

Permalink
Use distribution URL for entity.identiifer.resolvable & rename check
Browse files Browse the repository at this point in the history
  • Loading branch information
gothub committed May 19, 2020
1 parent 49e445c commit 252ee33
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 1 deletion.
93 changes: 93 additions & 0 deletions src/checks/entity.distributionURL.resolvable.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<?xml version="1.0" encoding="UTF-8"?>
<mdq:check xmlns:mdq="https://nceas.ucsb.edu/mdqe/v1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="https://nceas.ucsb.edu/mdqe/v1 ../schemas/schema1.xsd">
<id>entity.distributionURL.resolvable.1</id>
<name>Entity Distribution URL Resolvable</name>
<description>Check that the entity distribution URL is resolvable.</description>
<type>Accessible</type>
<level>REQUIRED</level>
<environment>python</environment>
<code><![CDATA[
def call():
global output
global status
global distributionUrl
import metadig.variable as mvar
import metadig.checks as checks
import urllib
import re
import numbers
global distributionUrl
# TODO: This check is only inspecting the first entity distribution URL.
# Update it to check the first N URLs (where N is some
# reasonable number to check. Note that there may be hundreds or
# thousands of entities, and we probably don't want to check them all.
# An entity distribution URL is not present
if 'distributionUrl' not in globals() or distributionUrl is None:
output = "An entity distribution URL was not found."
status = "FAILURE"
return False
# Convert to unicode to prevent decoding errors
distributionUrl = mvar.toUnicode(distributionUrl)
# If a single value, convert to a list for easier processing (i.e. don't
# have to keep checking if it's a single value or list)
if(isinstance(distributionUrl, unicode)):
distributionUrl = [distributionUrl]
if (mvar.isBlank(distributionUrl)):
output = "The entity distribution URL is blank."
status = "FAILURE"
return False
else:
url = distributionUrl[0].strip()
if(len(distributionUrl) > 1):
output = u"The entity distribution URL '{}' was found (first of {} URLs)".format(url, len(distributionUrl))
else:
output = "The entity distribution URL '{}' was found".format(url)
# Now check if the entity identifier is a resolvable url as is. Do not attempt to use any resolver service,
# just use the bare URL.
resolvable, msg = checks.isResolvable(url)
if (resolvable):
output = u'{} and is resolvable.'.format(output)
status = "SUCCESS"
return True
else:
output = "{}, but is not resolvable.".format(output)
status = "FAILURE"
return False
]]></code>
<selector>
<name>distributionUrl</name>
<xpath>/eml/dataset/*/physical/distribution/online/url[@function="download"]/text()[normalize-space()] |
/*/distributionInfo/MD_Distribution/distributor/MD_Distributor/distributorTransferOptions/MD_DigitalTransferOptions/onLine/CI_OnlineResource[function/CI_OnLineFunctionCode='download']/linkage/URL/text()[normalize-space()] |
/*/distributionInfo/MD_Distribution/transferOptions/MD_DigitalTransferOptions/onLine/CI_OnlineResource[function/CI_OnLineFunctionCode='download']/linkage/URL/text()[normalize-space()] |
/*/identificationInfo/*/citation/CI_Citation/onlineResource/CI_OnlineResource[function/CI_OnLineFunctionCode='download']/linkage/URL/text()[normalize-space()]
</xpath>
</selector>
<dialect>
<name>DataCite 3.1</name>
<xpath>boolean(/*[local-name() = 'resource'])</xpath>
</dialect>
<dialect>
<name>Dryad Data Package and Data File Modules</name>
<xpath>boolean(/*[local-name() = 'DryadDataFile' or local-name() = 'DryadDataPackage'])</xpath>
</dialect>
<dialect>
<name>Ecological Metadata Language</name>
<xpath>boolean(/*[local-name() = 'eml'])</xpath>
</dialect>
<dialect>
<name>ISO 19115 and ISO 19115-2 / ISO 19139 and ISO 19139-2</name>
<xpath>boolean(/*[local-name() = 'MI_Metadata' or local-name() = 'MD_Metadata'])</xpath>
</dialect>
<dialect>
<name>ISO 19115-1 / ISO 19115-3</name>
<xpath>boolean(/*[local-name() = 'MD_Metadata'])</xpath>
</dialect>
</mdq:check>
8 changes: 7 additions & 1 deletion src/suites/FAIR-suite.xml
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,13 @@
<id>entity.identifier.resolvable.1</id>
<type>Accessible</type>
<level>REQUIRED</level>
</check> -->
</check> -->
<!-- Added 2020 05 19 FAIR suite v0.3.1 https://github.com/NCEAS/metadig-checks/issues/379 -->
<check>
<id>entity.distributionUrl.resolvable.1</id>
<type>Accessible</type>
<level>REQUIRED</level>
</check>
<!-- Disable this check until an efficient way is developed to check
all entities for a dataset or a representative sample.
<check>
Expand Down

0 comments on commit 252ee33

Please sign in to comment.