https://github.com/maritimeconnectivity/mrnvalidation
JAVA library for MRN (Maritime Resource Name) validation
https://github.com/maritimeconnectivity/mrnvalidation
java java-library maritime maritime-resource-name validation
Last synced: about 2 months ago
JSON representation
JAVA library for MRN (Maritime Resource Name) validation
- Host: GitHub
- URL: https://github.com/maritimeconnectivity/mrnvalidation
- Owner: maritimeconnectivity
- License: mit
- Created: 2020-05-06T10:13:31.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2020-05-18T16:56:52.000Z (about 5 years ago)
- Last Synced: 2024-04-01T16:09:38.667Z (about 1 year ago)
- Topics: java, java-library, maritime, maritime-resource-name, validation
- Language: Java
- Homepage:
- Size: 25.4 KB
- Stars: 0
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://travis-ci.org/MaritimeConnectivityPlatform/MRNValidation)
# MRNValidation
A Java library for MRN validation
(registered in the Maven repository: https://mvnrepository.com/artifact/net.maritimeconnectivity.mrn/mrn-validation )## What is MRN?
[**Maritime Resource Name (MRN)**](https://www.iala-aism.org/technical/data-modelling/mrn/)is a naming scheme under [Uniform Resource Name (URN)](https://en.wikipedia.org/wiki/Uniform_Resource_Name) that can uniquely identify any maritime resource on a global scale, hosted by [IALA](https://www.iala-aism.org/).
This implementation is based on the version 1 of MRN proposed by Kasper Nielsen. (https://www.iana.org/assignments/urn-formal/mrn)## How to use
- Checking MRN compliance
```
java -jar target/mrn-validation-0.1.0-SNAPSHOT-jar-with-dependencies.jar --mrn "urn:mrn:mcp:user:granpa:thomas"
```
Expected result of the command above:
```
[main] INFO net.maritimeconnectivity.mrn.Main - PASS: urn:mrn:mcp:user:granpa:thomas is valid.
```- Checking MRN compliance with custom regex
```
java -jar target/mrn-validation-0.1.0-SNAPSHOT-jar-with-dependencies.jar --mrn "urn:mrn:mcp:user:granpa:thomas" --regex "^urn:mrn:mcp:(device|org|user|vessel|service|mms):([a-z0-9]([a-z0-9]|-){0,20}[a-z0-9]):((([-._a-z0-9]|~)|%[0-9a-f][0-9a-f]|([!$&'()*+,;=])|:|@)((([-._a-z0-9]|~)|%[0-9a-f][0-9a-f]|([!$&'()*+,;=])|:|@)|/)*)$"
```
Expected result of the command above:
```
[main] INFO net.maritimeconnectivity.mrn.Main - PASS: urn:mrn:mcp:user:granpa:thomas is valid.
```- Checking MCP MRN compliance
```
java -jar target/mrn-validation-0.1.0-SNAPSHOT-jar-with-dependencies.jar --mrn "urn:mrn:mcp:user:granpa:thomas" --mcp
```
Expected result of the command above:
```
[main] INFO net.maritimeconnectivity.mrn.Main - PASS: urn:mrn:mcp:user:granpa:thomas is valid as an MCP MRN.
```## Build
In the root folder of the repository,
```
mvn clean install
```## Prerequisite
The MRN validation of this implementation is based on the [regular expression (REGEX)](https://en.wikipedia.org/wiki/Regular_expression), which can be obtained from a MRN syntax through several steps.
In the example with [the official MRN syntax](https://www.iana.org/assignments/urn-formal/mrn),::= "urn" ":" "mrn" ":" ":"
[ rq-components ]
[ "#" f-component ]
::= (alphanum) 0*20(alphanum / "-") (alphanum) ; Organization ID
::= ":" ; Organization-specific string
::= (alphanum) 0*32(alphanum / "-") (alphanum) ; Organization-specific namespace ID
::= pchar *(pchar / "/") ; Organization-specific namespace string
This could be converted to the pure [Augmented Backus–Naur form (ABNF)](https://en.wikipedia.org/wiki/Augmented_Backus%E2%80%93Naur_form) as below:mrn = "urn" ":" "mrn" ":" oid ":" oss [rq-components] [ "#" f-component ]
oid = (alphanum) 0*20((alphanum) / "-") (alphanum) ; Organization ID
oss = osnid ":" osns ; Organization-specific string
osnid = (alphanum) 0*20((alphanum) / "-") (alphanum) ; Organization-specific namespace ID
osns = pchar *(pchar / "/") ; Organization-specific namespace string
rq-components = [ "?+" r-component ][ "?=" q-component ] ; rfc8141
r-component = pchar *( pchar / "/" / "?" ) ; rfc8141
q-component = pchar *( pchar / "/" / "?" ) ; rfc8141
f-component = fragment ; rfc8141
fragment = *( pchar / "/" / "?" ) ; ; rfc3986
alphanum = ALPHA / DIGIT ; rfc3986
pchar = unreserved / pct-encoded / sub-delims / ":" / "@" ; rfc3986
unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~" ; rfc3986
pct-encoded = "%" HEXDIG HEXDIG ; rfc3986
sub-delims = "!" / "$" / "&" / "'" / "(" / ")" / "*" / "+" / "," / ";" / "=" ; rfc3986You can practice the generation of valid ABNF and corresponding REGEX by online tools, for example: https://abnf.msweet.org/.
The corresponding raw REGEX of the MRN syntax is:
mrn: ^[Uu][Rr][Nn]\:[Mm][Rr][Nn]\:([A-Za-z0-9]([A-Za-z0-9]|\-){0,20}[A-Za-z0-9])\:([A-Za-z0-9][-A-Za-z0-9]{0,20}[A-Za-z0-9])\:((([-A-Z._a-z0-9]|~)|%[0-9A-Fa-f][0-9A-Fa-f]|(\!|\$|&|'|\(|\)|\*|\+|,|;|\=)|\:|@)((([-A-Z._a-z0-9]|~)|%[0-9A-Fa-f][0-9A-Fa-f]|(\!|\$|&|'|\(|\)|\*|\+|,|;|\=)|\:|@)|/)*)((\?\+((([-A-Z._a-z0-9]|~)|%[0-9A-Fa-f][0-9A-Fa-f]|(\!|\$|&|'|\(|\)|\*|\+|,|;|\=)|\:|@)((([-A-Z._a-z0-9]|~)|%[0-9A-Fa-f][0-9A-Fa-f]|(\!|\$|&|'|\(|\)|\*|\+|,|;|\=)|\:|@)|/|\?)*))?(\?\=((([-A-Z._a-z0-9]|~)|%[0-9A-Fa-f][0-9A-Fa-f]|(\!|\$|&|'|\(|\)|\*|\+|,|;|\=)|\:|@)((([-A-Z._a-z0-9]|~)|%[0-9A-Fa-f][0-9A-Fa-f]|(\!|\$|&|'|\(|\)|\*|\+|,|;|\=)|\:|@)|/|\?)*))?)?(#(((([-A-Z._a-z0-9]|~)|%[0-9A-Fa-f][0-9A-Fa-f]|(\!|\$|&|'|\(|\)|\*|\+|,|;|\=)|\:|@)|/|\?)*))?$
You can also practice with REGEX and the MRN complying with it by online tools, for example: https://regex101.com/.
## Motivation
MRN validation has been motivated for MRNs in [Maritime Connectivity Platform (MCP)](https://maritimeconnectivity.net/).