diff options
Diffstat (limited to 'connector')
5 files changed, 101 insertions, 21 deletions
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; @@ -62,6 +68,9 @@ public class AdresssucheController { private ResourceLoader resourceLoader; @Autowired + private ZmrAddressSoapClient client; + + @Autowired private IPendingRequestIdGenerationStrategy pendingReqGeneration; @RequestMapping(value = {"/test"}, method = {RequestMethod.GET}) @@ -79,11 +88,12 @@ public class AdresssucheController { } @RequestMapping(value = {"/residency/search"}, method = {RequestMethod.POST}) - public ResponseEntity<AdresssucheOutput> search(@RequestParam("city") String city, + public ResponseEntity<AdresssucheOutput> 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 @@ <div> <p><span id="textInfo">Infotext</span></p> </div> - <form id="inputForm" class="block" method="post" action="$contextPath$submitEndpoint" + <form id="inputForm" method="post" action="$contextPath$submitEndpoint" th:attr="action=@{${submitEndpoint}}"> <div> - <label for="inputCity">City</label> - <input type="text" id="inputCity" name="city" value="City"/> + <label for="inputMunicipality">Municipality</label> + <input type="text" id="inputMunicipality" name="municipality" value="Municipality"/> + </div> + <div> + <label for="inputVillage">Village</label> + <input type="text" id="inputVillage" name="village" value="Village"/> </div> <div> <label for="inputStreet">Street</label> diff --git a/connector/src/test/resources/config/properties/messages.properties b/connector/src/test/resources/config/properties/messages.properties index 8ffc5560..1e0f04d0 100644 --- a/connector/src/test/resources/config/properties/messages.properties +++ b/connector/src/test/resources/config/properties/messages.properties @@ -110,4 +110,8 @@ gui.residency.cancel=Cancel gui.residency.search=Search gui.residency.proceed=Proceed gui.residency.updated=Updated your input -gui.residency.error=Error on Backend Call
\ No newline at end of file +gui.residency.error=Error on Backend Call +gui.residency.input.municipality=Municipality +gui.residency.input.village=Village +gui.residency.input.street=Street +gui.residency.input.number=Number
\ No newline at end of file diff --git a/connector/src/test/resources/config/properties/messages_de.properties b/connector/src/test/resources/config/properties/messages_de.properties index a79aa41a..e0eea9d1 100644 --- a/connector/src/test/resources/config/properties/messages_de.properties +++ b/connector/src/test/resources/config/properties/messages_de.properties @@ -111,4 +111,8 @@ gui.residency.cancel=Abbrechen gui.residency.search=Suche gui.residency.proceed=Weiter gui.residency.updated=Eingabe aktualisiert -gui.residency.error=Fehler bei Addresssuche
\ No newline at end of file +gui.residency.error=Fehler bei Addresssuche +gui.residency.input.municipality=Gemeinde +gui.residency.input.village=Ortschaft +gui.residency.input.street=Straße +gui.residency.input.number=Nummer
\ No newline at end of file diff --git a/connector/src/test/resources/config/templates/residency.html b/connector/src/test/resources/config/templates/residency.html index 8845cba0..17e21044 100644 --- a/connector/src/test/resources/config/templates/residency.html +++ b/connector/src/test/resources/config/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 @@ <div> <p><span id="textInfo">Infotext</span></p> </div> - <form id="inputForm" class="block" method="post" action="$contextPath$submitEndpoint" + <form id="inputForm" method="post" action="$contextPath$submitEndpoint" th:attr="action=@{${submitEndpoint}}"> <div> - <label for="inputCity">City</label> - <input type="text" id="inputCity" name="city" value="City"/> + <label for="inputMunicipality">Municipality</label> + <input type="text" id="inputMunicipality" name="municipality" value="Municipality"/> + </div> + <div> + <label for="inputVillage">Village</label> + <input type="text" id="inputVillage" name="village" value="Village"/> </div> <div> <label for="inputStreet">Street</label> |