GENC Content rules apply to country codes in DDMS 5.0

Description

(Imported from Google Code)

  • @ddms:qualifier in ddms:countryCode and ddms:subDivisionCode is renamed to @ddms:codespace.

  • @ddms:value in ddms:countryCode and ddms:subDivisionCode is renamed to @ddms:code.

  • Schematron rules around the values for country code in a ddms:geographicIdentifier.

Activity

Show:

Brian Uri 
March 29, 2013 at 12:20 PM

Complete in Rev 813.

Brian Uri 
March 29, 2013 at 12:13 AM

package buri.sandbox;

/**

  • Test class for implementing the Schematron rules in Java. These rules apply to a ddms:countryCode inside

  • of a ddms:geographicIdentifier.

  • @author BU
    */
    public class Sandbox {

public static void main(String[] args) {
getUrnBasedCodespace("http://api.nsgreg.nga.mil/geo-political/GENC/2/ed1");
getUrnBasedCodespace("urn:us:gov:dod:nga:def:geo-political:GENC:3:ed1");
getUrnBasedCodespace("geo-political:GENC:3:ed1");
getUrnBasedCodespace("ge:GENC:3:ed1");

validate("weirdFormat", "USA");
validate("geo-political:GENC:3:ed1", "USA");
validate("geo-political:GENC:3:ed1", "US");
validate("geo-political:GENC:2:ed1", "US");
validate("geo-political:GENC:2:ed1", "USA");
validate("geo-political:GENC:n:ed1", "123");
validate("geo-political:GENC:n:ed1", "1234");

}

/**

  • Converts a codespace value into an URNBased value.
    *
    * <p>
    * The codespace will fall into one of 4 flavours:
    * <ul>
    * <li>URL: <code>http://api.nsgreg.nga.mil/geo-political/GENC/2/ed1</code></li>
    * <li>URN: <code>urn:us:gov:dod:nga:def:geo-political:GENC:3:ed1</code></li>
    * <li>URNBased: <code>geo-political:GENC:3:ed1</code></li>
    * <li>URNBasedShort: <code>ge:GENC:3:ed1</code></li>
    * </ul>
    *
    * @param codespace the raw codespace from the DDMS CountryCode
    * @return the URNBased-ified codespace
    */
    public static String getUrnBasedCodespace(String codespace) {
    String convertUrl = codespace.replaceFirst("^http://api.nsgreg.nga.mil/geo-political/", "geo-political/")
    .replaceFirst("^urn:us:gov:dod:nga:def:geo-political:", "geo-political/")
    .replaceFirst("^ge:", "geo-political:")
    .replaceAll("/", ":");
    System.out.println(codespace + " translates into " + convertUrl);
    return (convertUrl);
    }


public static void validate(String urnBasedCodespace, String code) {
System.out.println("Validating " + urnBasedCodespace + " and " + code + "...");
String resolvableUrl = "http://api.nsgreg.nga.mil/" + urnBasedCodespace.replace(":", "/") + "/" + code;
if (!urnBasedCodespace.matches("^geo-political:GENC:[23n]:ed
d$"))
System.out.println("\tERROR: ddms:countryCode must use a geo-political URN or URL.");
else if (urnBasedCodespace.contains("GENC:3:") && !code.matches("^[A-Z]{3}$"))
System.out.println("\tWARNING: A GENC code in a 3-alpha codespace (e.g. geo-political:GENC:3:ed1) must consist of exactly 3 uppercase alpha characters.");
else if (urnBasedCodespace.contains("GENC:2:") && !code.matches("^[A-Z]{2}$"))
System.out.println("\tA GENC code in a 2-alpha codespace (e.g. geo-political:GENC:2:ed1) must consist of exactly 2 uppercase alpha characters.");
else if (urnBasedCodespace.contains("GENC:n:") && !code.matches("^[0-9]{3}$"))
System.out.println("\tA GENC code in a numeric codespace (e.g. geo-political:GENC:n:ed1) must consist of exactly 3 numerals.");
/*
else if (xmlDocument cannot be loaded from resolvableUrl)
System.out.println("Could not retrieve registry entry at URL: " + resolvableUrl);
*/
else
System.out.println("Validation successful.");
}
}

Brian Uri 
March 28, 2013 at 11:06 PM

Rev 811 makes the codespace/code swap.

Still TODO:
This Schematron rule:
<sch:rule context="/ddms:resource/ddms:geospatialCoverage/ddms:geographicIdentifier/ddms:countryCode">
<!-- codespace will fall into one of 4 flavors:
URL http://api.nsgreg.nga.mil/geo-political/GENC/2/ed1
URN urn:us:gov:dod:nga:def:geo-political:GENC:3:ed1
URNBased geo-political:GENC:3:ed1
URNBasedShort ge:GENC:3:ed1
-->
<!-- Convert all to URNBased -->
<sch:let name="codespace" value="replace(replace(replace(replace(
@ddms:codespace, '^http://api.nsgreg.nga.mil/geo-political/', 'geo-political/'),
'^urn:us:gov:dod:nga:def:geo-political:', 'geo-political:'),
'^ge:', 'geo-political:'),
'/', ':')"/>
<sch:let name="code" value="@ddms:code"/>
<sch:assert test="matches($codespace, '^geo-political:GENC:[23n]:ed\d$')">
<sch:name/> must use a geo-political URN or URL.
</sch:assert>
<sch:report test="contains($codespace, 'GENC:3:') and not(matches($code, '^[A-Z]{3}$'))"> <!-- -->
A GENC code in a 3-alpha codespace (e.g. geo-political:GENC:3:ed1) must consist of exactly 3 uppercase alpha characters.
(codespace: <sch:value-of select="$codespace"/>, code: <sch:value-of select="$code"/>)
</sch:report>
<sch:report test="contains($codespace, 'GENC:2:') and not(matches($code, '^[A-Z]{2}$'))">
A GENC code in a 2-alpha codespace (e.g. geo-political:GENC:2:ed1) must consist of exactly 2 uppercase alpha characters.
(codespace: <sch:value-of select="$codespace"/>, code: <sch:value-of select="$code"/>)
</sch:report>
<sch:report test="contains($codespace, 'GENC:n:') and not(matches($code, '^[0-9]{3}$'))">
A GENC code in a numeric codespace (e.g. geo-political:GENC:n:ed1) must consist of exactly 3 numerals.
(codespace: <sch:value-of select="$codespace"/>, code: <sch:value-of select="$code"/>)
</sch:report>
<sch:assert test="document(concat('http://api.nsgreg.nga.mil/', replace($codespace, ':', '/'), '/', $code))">
Could not retrieve registry entry for codespace: <sch:value-of select="$codespace"/>, code: <sch:value-of select="$code"/>.
</sch:assert>
</sch:rule>

Fixed

Details

Assignee

Reporter

Fix versions

Priority

Created March 26, 2013 at 3:26 PM
Updated April 5, 2015 at 2:25 PM
Resolved April 5, 2015 at 2:25 PM