Skip to content
Snippets Groups Projects
Commit 4e777d78 authored by OZGCloud's avatar OZGCloud
Browse files

OZG-5841 OZG-5952 Refactor BehoerdenschluesselProperties

parent 10e4077a
No related branches found
No related tags found
No related merge requests found
package de.ozgcloud.alfa.export;
import java.util.List;
import java.util.Optional;
import org.apache.commons.lang3.StringUtils;
......@@ -37,14 +38,23 @@ public class BehoerdenschluesselProperties {
}
private Optional<Codeliste> getCodeliste(String behoerdenschluessel) {
var matchingCodelisten = xdomeaProperties.getCodeliste().stream()
.filter(codeliste -> codeliste.getPattern().matcher(behoerdenschluessel).matches()).toList();
var matchingCodelisten = getCodelistenMatchingBehoerdenschluessel(behoerdenschluessel);
if (matchingCodelisten.size() > 1) {
throw new AmbiguousCodelistePatternException(behoerdenschluessel);
}
return matchingCodelisten.size() == 1 ? Optional.of(matchingCodelisten.getFirst()) : Optional.empty();
}
private List<Codeliste> getCodelistenMatchingBehoerdenschluessel(String behoerdenschluessel) {
return xdomeaProperties.getCodeliste().stream()
.filter(codeliste -> codelisteMatchesBehoerdenschluessel(codeliste, behoerdenschluessel))
.toList();
}
private boolean codelisteMatchesBehoerdenschluessel(Codeliste codeliste, String behoerdenschluessel) {
return codeliste.getPattern().matcher(behoerdenschluessel).matches();
}
private static Optional<String> ofNullableOrBlank(String value) {
return Optional.ofNullable(value).filter(StringUtils::isNotBlank);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment