Skip to content

Commit

Permalink
Changed Resolver.checkRegExp logic - return true instead of false whe…
Browse files Browse the repository at this point in the history
…n pattern is not defined for known collection.
  • Loading branch information
IgorRodchenkov committed Apr 26, 2024
1 parent 68e0b25 commit 11b5aff
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
Expand Up @@ -101,7 +101,7 @@ protected Resolver() {
*
* @param identifier internal identifier used by the data type
* @param datatype name, synonym or URI of a data type
* @return "true" if the identifier follows the regular expression, "false" otherwise
* @return "true" when datatype is recognized, and identifier either matches the pattern or there's no pattern
*/
public static boolean checkRegExp(String identifier, String datatype) {
Namespace dt = getNamespace(datatype);
Expand All @@ -116,13 +116,8 @@ public static boolean checkRegExp(String identifier, String datatype) {
identifier = identifier.replaceFirst(banana+dt.getBanana_peel(), "");
}

String dtPattern = dt.getPattern();
if(StringUtils.isNotBlank(dtPattern)) {
return Pattern.compile(dtPattern).matcher(identifier).find();
} else {
LOG.debug("Cannot check id: {} as regexp is undefined for: {}; return: false", identifier, dt.getPrefix());
return false;
}
//return true when there is no regex pattern defined or the identifier matches
return (StringUtils.isNotBlank(dt.getPattern())) ? Pattern.compile(dt.getPattern()).matcher(identifier).find() : true;
}


Expand Down Expand Up @@ -202,7 +197,7 @@ public static String getURI(String name, String id) {
*/
public static String getCURIE(String name, String id) {
Namespace ns = getNamespace(name, true);
if (ns != null) {
if (ns != null && StringUtils.isNotBlank(ns.getPattern())) {
if (checkRegExp(id, name)) {
String prefix = ns.getPrefix();
//remove "banana" and "peel" prefix from the identifier if any defined and present
Expand Down
Expand Up @@ -34,7 +34,8 @@ public final void checkRegExp() {
() -> Assertions.assertTrue(Resolver.checkRegExp("MI:0000", MI)), //auto-ignores "MI:"
() -> Assertions.assertTrue(Resolver.checkRegExp("0000", MI)),
() -> Assertions.assertFalse(Resolver.checkRegExp("0000", "foo")), //no such collection
() -> Assertions.assertFalse(Resolver.checkRegExp("0000", "aaindex"))//aaindex no pattern
() -> Assertions.assertTrue(Resolver.checkRegExp("0000", "aaindex")),//aaindex no pattern
() -> Assertions.assertTrue(Resolver.checkRegExp("98346", "bind"))//no pattern
);
}

Expand Down

0 comments on commit 11b5aff

Please sign in to comment.