diff --git a/src/main/java/cz/cvut/kbss/termit/service/IdentifierResolver.java b/src/main/java/cz/cvut/kbss/termit/service/IdentifierResolver.java
index 232f5b7ef..fda72edb0 100644
--- a/src/main/java/cz/cvut/kbss/termit/service/IdentifierResolver.java
+++ b/src/main/java/cz/cvut/kbss/termit/service/IdentifierResolver.java
@@ -19,6 +19,7 @@
import cz.cvut.kbss.termit.exception.InvalidIdentifierException;
import cz.cvut.kbss.termit.exception.TermItException;
+import cz.cvut.kbss.termit.util.Configuration;
import org.springframework.stereotype.Service;
import java.net.URI;
@@ -80,6 +81,12 @@ public class IdentifierResolver {
Arrays.sort(ILLEGAL_FILENAME_CHARS);
}
+ private final boolean asciiOnlyIdentifiers;
+
+ public IdentifierResolver(Configuration config) {
+ this.asciiOnlyIdentifiers = config.isAsciiIdentifiers();
+ }
+
/**
* Normalizes the specified value which includes:
*
@@ -139,11 +146,12 @@ public URI generateIdentifier(String namespace, String... components) {
if (!namespace.endsWith("/") && !namespace.endsWith("#")) {
namespace += "/";
}
+ final String localPart = asciiOnlyIdentifiers ? normalizeToAscii(comps) : normalize(comps);
try {
- return URI.create(namespace + normalize(comps));
+ return URI.create(namespace + localPart);
} catch (IllegalArgumentException e) {
throw new InvalidIdentifierException(
- "Generated identifier " + namespace + normalize(comps) + " is not a valid URI.",
+ "Generated identifier " + namespace + localPart + " is not a valid URI.",
"error.identifier.invalidCharacters");
}
}
diff --git a/src/test/java/cz/cvut/kbss/termit/rest/UserGroupControllerTest.java b/src/test/java/cz/cvut/kbss/termit/rest/UserGroupControllerTest.java
index 50179f2c1..7c8b8d644 100644
--- a/src/test/java/cz/cvut/kbss/termit/rest/UserGroupControllerTest.java
+++ b/src/test/java/cz/cvut/kbss/termit/rest/UserGroupControllerTest.java
@@ -22,6 +22,7 @@
import cz.cvut.kbss.termit.model.UserGroup;
import cz.cvut.kbss.termit.service.IdentifierResolver;
import cz.cvut.kbss.termit.service.business.UserGroupService;
+import cz.cvut.kbss.termit.util.Configuration;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
@@ -56,7 +57,7 @@ class UserGroupControllerTest extends BaseControllerTestRunner {
private UserGroupService groupService;
@Spy
- private IdentifierResolver identifierResolver = new IdentifierResolver();
+ private IdentifierResolver identifierResolver = new IdentifierResolver(new Configuration());
@InjectMocks
private UserGroupController sut;
diff --git a/src/test/java/cz/cvut/kbss/termit/service/IdentifierResolverTest.java b/src/test/java/cz/cvut/kbss/termit/service/IdentifierResolverTest.java
index 0ba3136a4..7b2fee669 100644
--- a/src/test/java/cz/cvut/kbss/termit/service/IdentifierResolverTest.java
+++ b/src/test/java/cz/cvut/kbss/termit/service/IdentifierResolverTest.java
@@ -20,6 +20,7 @@
import cz.cvut.kbss.termit.environment.Environment;
import cz.cvut.kbss.termit.environment.Generator;
import cz.cvut.kbss.termit.exception.InvalidIdentifierException;
+import cz.cvut.kbss.termit.util.Configuration;
import cz.cvut.kbss.termit.util.Vocabulary;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -42,7 +43,7 @@ class IdentifierResolverTest {
@BeforeEach
void setUp() {
- this.sut = new IdentifierResolver();
+ this.sut = new IdentifierResolver(new Configuration());
}
@Test
@@ -335,4 +336,15 @@ void generateIdentifierThrowsInvalidIdentifierExceptionWhenComponentsContainsUnf
final String label = "label with emoji \u3000"; // Ideographic space
assertThrows(InvalidIdentifierException.class, () -> sut.generateIdentifier(namespace, label));
}
+
+ @Test
+ void generateIdentifierNormalizesAccentedCharactersToAsciiWhenAsciiIdentifiersAreConfigured() {
+ final Configuration asciiOnlyConfig = new Configuration();
+ asciiOnlyConfig.setAsciiIdentifiers(true);
+ this.sut = new IdentifierResolver(asciiOnlyConfig);
+ final String namespace = "http://onto.fel.cvut.cz/ontologies/termit/test-slovnik";
+ final String label = "Délka dostřiku [m]";
+ final URI result = sut.generateIdentifier(namespace, label);
+ assertEquals(URI.create(namespace + "/delka-dostriku-m"), result);
+ }
}
diff --git a/src/test/java/cz/cvut/kbss/termit/service/importer/excel/ExcelImporterTest.java b/src/test/java/cz/cvut/kbss/termit/service/importer/excel/ExcelImporterTest.java
index 3254d2246..5804ca6e8 100644
--- a/src/test/java/cz/cvut/kbss/termit/service/importer/excel/ExcelImporterTest.java
+++ b/src/test/java/cz/cvut/kbss/termit/service/importer/excel/ExcelImporterTest.java
@@ -86,7 +86,7 @@ class ExcelImporterTest {
@SuppressWarnings("unused")
@Spy
- private IdentifierResolver idResolver = new IdentifierResolver();
+ private IdentifierResolver idResolver = new IdentifierResolver(new Configuration());
@InjectMocks
private ExcelImporter sut;
diff --git a/src/test/java/cz/cvut/kbss/termit/service/repository/ResourceRepositoryServiceTest.java b/src/test/java/cz/cvut/kbss/termit/service/repository/ResourceRepositoryServiceTest.java
index df9fae710..6d43ec226 100644
--- a/src/test/java/cz/cvut/kbss/termit/service/repository/ResourceRepositoryServiceTest.java
+++ b/src/test/java/cz/cvut/kbss/termit/service/repository/ResourceRepositoryServiceTest.java
@@ -62,7 +62,7 @@ class ResourceRepositoryServiceTest {
private TermOccurrenceDao occurrenceDao;
@Spy
- private IdentifierResolver idResolver = new IdentifierResolver();
+ private IdentifierResolver idResolver = new IdentifierResolver(new Configuration());
@Spy
private Validator validator = Validation.buildDefaultValidatorFactory().getValidator();
diff --git a/src/test/java/cz/cvut/kbss/termit/service/repository/UserRepositoryServiceTest.java b/src/test/java/cz/cvut/kbss/termit/service/repository/UserRepositoryServiceTest.java
index aef217484..6b7126ad9 100644
--- a/src/test/java/cz/cvut/kbss/termit/service/repository/UserRepositoryServiceTest.java
+++ b/src/test/java/cz/cvut/kbss/termit/service/repository/UserRepositoryServiceTest.java
@@ -62,10 +62,10 @@ class UserRepositoryServiceTest {
private UserAccountDao userAccountDao;
@Spy
- private IdentifierResolver identifierResolver;
+ private Configuration configuration = new Configuration();
@Spy
- private Configuration configuration = new Configuration();
+ private IdentifierResolver identifierResolver = new IdentifierResolver(configuration);
@Spy
private Validator validator = Validation.buildDefaultValidatorFactory().getValidator();
diff --git a/src/test/java/cz/cvut/kbss/termit/service/security/SecurityUtilsTest.java b/src/test/java/cz/cvut/kbss/termit/service/security/SecurityUtilsTest.java
index 8292ec797..62e3886ca 100644
--- a/src/test/java/cz/cvut/kbss/termit/service/security/SecurityUtilsTest.java
+++ b/src/test/java/cz/cvut/kbss/termit/service/security/SecurityUtilsTest.java
@@ -69,10 +69,10 @@ class SecurityUtilsTest {
private PasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
@Spy
- private IdentifierResolver idResolver = new IdentifierResolver();
+ private Configuration config = new Configuration();
@Spy
- private Configuration config = new Configuration();
+ private IdentifierResolver idResolver = new IdentifierResolver(config);
@InjectMocks
private SecurityUtils sut;