|
23 | 23 | import jakarta.annotation.PostConstruct;
|
24 | 24 | import org.apache.commons.configuration2.Configuration;
|
25 | 25 | import org.apache.commons.lang3.StringUtils;
|
26 |
| -import org.apache.commons.lang3.tuple.Pair; |
27 | 26 | import org.slf4j.Logger;
|
28 | 27 | import org.slf4j.LoggerFactory;
|
29 | 28 | import org.springframework.beans.factory.annotation.Autowired;
|
30 | 29 | import org.springframework.stereotype.Component;
|
31 | 30 |
|
32 |
| -import java.nio.file.Files; |
33 |
| -import java.nio.file.Path; |
34 |
| -import java.util.*; |
| 31 | +import java.util.Arrays; |
| 32 | +import java.util.HashSet; |
| 33 | +import java.util.Map; |
| 34 | +import java.util.Objects; |
35 | 35 |
|
36 | 36 | import static eu.europa.ec.itb.validation.commons.config.ParseUtils.*;
|
37 | 37 |
|
@@ -114,32 +114,7 @@ protected void addDomainConfiguration(DomainConfig domainConfig, Configuration c
|
114 | 114 | // Check how to react to owl:import failures - end
|
115 | 115 | addMissingDefaultValues(domainConfig.getWebServiceDescription(), appConfig.getDefaultLabels());
|
116 | 116 | // Local mapping files for URIs used in owl:imports - start
|
117 |
| - List<Pair<String, Path>> mappingList = ParseUtils.parseValueList("validator.owlImportMapping", config, (entry) -> { |
118 |
| - String uri = entry.get("uri"); |
119 |
| - String file = entry.get("file"); |
120 |
| - if (StringUtils.isNotBlank(uri) && StringUtils.isNotBlank(file)) { |
121 |
| - uri = uri.trim(); |
122 |
| - if (!uri.toLowerCase().startsWith("http://") && !uri.toLowerCase().startsWith("https://")) { |
123 |
| - throw new IllegalStateException("OWL import mapping for URI [%s] does not start with 'http://' or 'https://'".formatted(uri)); |
124 |
| - } |
125 |
| - file = file.trim(); |
126 |
| - Path resourcePath = Path.of(appConfig.getResourceRoot(), domainConfig.getDomain(), file); |
127 |
| - if (!Files.exists(resourcePath)) { |
128 |
| - throw new IllegalStateException("OWL import mapping for URI [%s] points to a non-existent file [%s]".formatted(uri, file)); |
129 |
| - } |
130 |
| - return Pair.of(uri, resourcePath); |
131 |
| - } else { |
132 |
| - throw new IllegalStateException("Invalid mappings for owl:import. Each element must include [uri] and [file] properties"); |
133 |
| - } |
134 |
| - }); |
135 |
| - Map<String, Path> mappingMap = new HashMap<>(); |
136 |
| - mappingList.forEach(entry -> { |
137 |
| - if (mappingMap.containsKey(entry.getKey())) { |
138 |
| - throw new IllegalStateException("Invalid mappings for owl:import. URI [%s] defined multiple times".formatted(entry.getKey())); |
139 |
| - } |
140 |
| - mappingMap.put(entry.getKey(), entry.getValue()); |
141 |
| - }); |
142 |
| - domainConfig.setOwlImportMappings(mappingMap); |
| 117 | + domainConfig.setOwlImportMappings(ParseUtils.parseFileMap("validator.owlImportMapping", config, "OWL mapping", appConfig, domainConfig)); |
143 | 118 | // Local mapping files for URIs used in owl:imports - end
|
144 | 119 | // Preload imports and SHACL shape graphs - start
|
145 | 120 | Boolean defaultPreloadOwlImports = config.getBoolean("validator.preloadOwlImports", null);
|
|
0 commit comments