From e5934d538aabcfc1f3b92472753de729d6ce1cce Mon Sep 17 00:00:00 2001 From: Christian Kollmann Date: Thu, 2 Dec 2021 09:06:55 +0100 Subject: Search with user provided input in ZMR for addresses --- .../controller/AdresssucheController.java | 84 +++++++++++++++++++--- .../src/main/resources/templates/residency.html | 13 ++-- 2 files changed, 82 insertions(+), 15 deletions(-) (limited to 'connector/src/main') diff --git a/connector/src/main/java/at/asitplus/eidas/specific/connector/controller/AdresssucheController.java b/connector/src/main/java/at/asitplus/eidas/specific/connector/controller/AdresssucheController.java index 35f56012..8b25a7bd 100644 --- a/connector/src/main/java/at/asitplus/eidas/specific/connector/controller/AdresssucheController.java +++ b/connector/src/main/java/at/asitplus/eidas/specific/connector/controller/AdresssucheController.java @@ -25,13 +25,19 @@ package at.asitplus.eidas.specific.connector.controller; import at.asitplus.eidas.specific.connector.MsEidasNodeConstants; import at.asitplus.eidas.specific.connector.gui.StaticGuiBuilderConfiguration; +import at.asitplus.eidas.specific.modules.auth.eidas.v2.clients.zmr.ZmrAddressSoapClient; +import at.asitplus.eidas.specific.modules.auth.eidas.v2.exception.EidasSAuthenticationException; +import at.gv.bmi.namespace.zmr_su.zrm._20040201_.address.Adressdaten; +import at.gv.e_government.reference.namespace.persondata.de._20040201.PostAdresseTyp; +import at.gv.e_government.reference.namespace.persondata.de._20040201.ZustelladresseTyp; import at.gv.egiz.eaaf.core.api.gui.IGuiBuilderConfiguration; import at.gv.egiz.eaaf.core.api.gui.ISpringMvcGuiFormBuilder; import at.gv.egiz.eaaf.core.api.idp.IConfiguration; import at.gv.egiz.eaaf.core.api.utils.IPendingRequestIdGenerationStrategy; import at.gv.egiz.eaaf.core.exceptions.GuiBuildException; -import at.gv.egiz.eaaf.core.exceptions.PendingReqIdValidationException; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; +import org.jetbrains.annotations.NotNull; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.io.ResourceLoader; import org.springframework.http.ResponseEntity; @@ -61,6 +67,9 @@ public class AdresssucheController { @Autowired private ResourceLoader resourceLoader; + @Autowired + private ZmrAddressSoapClient client; + @Autowired private IPendingRequestIdGenerationStrategy pendingReqGeneration; @@ -79,11 +88,12 @@ public class AdresssucheController { } @RequestMapping(value = {"/residency/search"}, method = {RequestMethod.POST}) - public ResponseEntity search(@RequestParam("city") String city, + public ResponseEntity search(@RequestParam("municipality") String municipality, + @RequestParam("village") String village, @RequestParam("street") String street, @RequestParam("number") String number, @RequestParam("pendingid") String pendingId) { - log.info("Search with '{}', '{}', '{}'", city, street, number); + log.info("Search with '{}', '{}', '{}'", municipality, street, number); // TODO validate pendingId // try { // pendingReqGeneration.validateAndGetPendingRequestId(pendingId); @@ -91,23 +101,74 @@ public class AdresssucheController { // log.warn("Search with pendingId '{}' is not valid", pendingId); // return ResponseEntity.badRequest().build(); // } - AdresssucheOutput output = new AdresssucheOutput("Where the streets have no name", "No Name", "42"); - return ResponseEntity.ok(output); + try { + Adressdaten searchInput = buildSearchInput(municipality, village, street, number); + ZmrAddressSoapClient.AddressInfo searchOutput = client.searchAddress(searchInput); + AdresssucheOutput output = buildResponse(searchOutput); + return ResponseEntity.ok(output); + } catch (EidasSAuthenticationException e) { + log.warn("Search failed", e); + return ResponseEntity.badRequest().build(); + } + } + + private AdresssucheOutput buildResponse(ZmrAddressSoapClient.AddressInfo searchOutput) { + if (searchOutput.getPersonResult().isEmpty()) { + log.warn("No result from ZMR"); + return new AdresssucheOutput(null, null, null, null); + } + Adressdaten adressdaten = searchOutput.getPersonResult().iterator().next(); + String municipality = adressdaten.getPostAdresse().getGemeinde(); + String village = adressdaten.getPostAdresse().getOrtschaft(); + String street = adressdaten.getPostAdresse().getZustelladresse().getStrassenname(); + String number = adressdaten.getPostAdresse().getZustelladresse().getOrientierungsnummer(); + log.debug("Result from ZMR: '{}', '{}', '{}', '{}'", municipality, village, street, number); + return new AdresssucheOutput(municipality, village, street, number); + } + + @NotNull + private Adressdaten buildSearchInput(String municipality, String village, String street, String number) { + PostAdresseTyp postAdresse = new PostAdresseTyp(); + if (StringUtils.isNotBlank(municipality)) { + postAdresse.setGemeinde(municipality); + } + if (StringUtils.isNotBlank(village)) { + postAdresse.setOrtschaft(village); + } + if (StringUtils.isNotBlank(street) || StringUtils.isNotBlank(number)) { + ZustelladresseTyp zustelladresse = new ZustelladresseTyp(); + if (StringUtils.isNotBlank(street)) { + zustelladresse.setStrassenname(street); + } + if (StringUtils.isNotBlank(number)) { + zustelladresse.setOrientierungsnummer(number); + } + postAdresse.setZustelladresse(zustelladresse); + } + Adressdaten searchInput = new Adressdaten(); + searchInput.setPostAdresse(postAdresse); + return searchInput; } public static class AdresssucheOutput { - private final String city; + private final String municipality; + private final String village; private final String street; private final String number; - public AdresssucheOutput(String city, String street, String number) { - this.city = city; + public AdresssucheOutput(String municipality, String village, String street, String number) { + this.municipality = municipality; + this.village = village; this.street = street; this.number = number; } - public String getCity() { - return city; + public String getMunicipality() { + return municipality; + } + + public String getVillage() { + return village; } public String getStreet() { @@ -121,7 +182,8 @@ public class AdresssucheController { @Override public String toString() { return "AdresssucheOutput{" + - "city='" + city + '\'' + + "municipality='" + municipality + '\'' + + ", village='" + village + '\'' + ", street='" + street + '\'' + ", number='" + number + '\'' + '}'; diff --git a/connector/src/main/resources/templates/residency.html b/connector/src/main/resources/templates/residency.html index 44ae4bd5..38f490ca 100644 --- a/connector/src/main/resources/templates/residency.html +++ b/connector/src/main/resources/templates/residency.html @@ -20,7 +20,8 @@ url: "http://localhost:8080/ms_connector/residency/search", data: $("#inputForm").serialize() }).done(function (data, textStatus, jqXHR) { - $("#inputCity").val(data["city"]); + $("#inputMunicipality").val(data["municipality"]); + $("#inputVillage").val(data["village"]); $("#inputStreet").val(data["street"]); $("#inputNumber").val(data["number"]); $("#textInfo").text(updatedText); @@ -43,11 +44,15 @@

Infotext

-
- - + + +
+
+ +
-- cgit v1.2.3