-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use distribution URL for entity.identiifer.resolvable & rename check
- Loading branch information
Showing
2 changed files
with
100 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters