Skip to content

Commit

Permalink
39632 - optimize URN pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivan Yakubenko committed Jan 15, 2025
1 parent 028a44e commit 0d052d2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ public class SdmxUrn {
private static final Pattern FULL_URN_PATTERN = Pattern.compile(
"^"
+ URN_SDMX
+ "(?<class>\\w+(\\.\\w+)*)="
+ "(?<class>[\\w.]+)="
+ "(?<agency>[\\w.-]+):(?<id>[\\w@$-]+)"
+ "\\((?<version>(\\d+\\.\\d+)|(\\d+\\.\\d+\\.\\d+(-[\\w-]+)?)|(\\d+\\+\\.\\d+\\.\\d+)|(\\d+\\.\\d+\\+\\.\\d+)|(\\d+\\.\\d+\\.\\d+\\+))\\)"
+ "(\\.(?<itemId>([\\w@$-]+)+(\\.[\\w@$-]+)*))?$"
+ "\\((?<version>(\\d+\\+?)(\\.\\d+\\+?){1,2}(-[\\w-]+)?)\\)"
+ "(\\.(?<itemId>[\\w@$-]+(\\.[\\w@$-]+)*))?$"
);

private static final Pattern SHORT_URN_PATTERN = Pattern.compile(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,13 @@ void testGetUrnComponents(String urn, UrnComponents expected) {
assertThat(SdmxUrn.getUrnComponents(urn)).isEqualTo(expected);
}

@Test
void testGetUrnComponents_notValidUrn() {
var t = assertThrows(IllegalArgumentException.class, () -> SdmxUrn.getUrnComponents("urn:sdmx:org.sdmx.infomodel.conceptscheme.Concept=IMF_RES:CS_CSD_CPA(3.0+.0).CPA_RA_330_OTHER_RISKS_(PLEASE_SPECIFY)"));

assertThat(t).hasMessage("Invalid urn: urn:sdmx:org.sdmx.infomodel.conceptscheme.Concept=IMF_RES:CS_CSD_CPA(3.0+.0).CPA_RA_330_OTHER_RISKS_(PLEASE_SPECIFY)");
}

private static Stream<Arguments> testGetUrnComponents() {
return Stream.of(
Arguments.of("urn:sdmx:org.sdmx.infomodel.datastructure.DataStructure=ECB:ECB_EXR12(1.0)", UrnComponents.builder()
Expand Down

0 comments on commit 0d052d2

Please sign in to comment.