aboutsummaryrefslogtreecommitdiff
path: root/connector/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'connector/src/main/java')
-rw-r--r--connector/src/main/java/at/asitplus/eidas/specific/connector/controller/AdresssucheController.java69
1 files changed, 44 insertions, 25 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 c35aa8b9..f71917c3 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
@@ -30,11 +30,12 @@ import at.asitplus.eidas.specific.modules.auth.eidas.v2.exception.EidasSAuthenti
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.EaafException;
import at.gv.egiz.eaaf.core.exceptions.GuiBuildException;
+import at.gv.egiz.eaaf.core.exceptions.PendingReqIdValidationException;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
@@ -51,7 +52,10 @@ import org.springframework.web.bind.annotation.RequestParam;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
-import java.util.*;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.Set;
import java.util.stream.Collectors;
/**
@@ -78,9 +82,13 @@ public class AdresssucheController {
@Autowired
private IPendingRequestIdGenerationStrategy pendingReqGeneration;
+ /**
+ * Show the "residency.html" directly.
+ * TODO Remove this after testing.
+ */
@RequestMapping(value = {"/test"}, method = {RequestMethod.GET})
- public void test(HttpServletRequest request, HttpServletResponse response) throws GuiBuildException {
- final IGuiBuilderConfiguration config = new StaticGuiBuilderConfiguration(
+ public void test(HttpServletRequest request, HttpServletResponse response) throws GuiBuildException, EaafException {
+ final StaticGuiBuilderConfiguration config = new StaticGuiBuilderConfiguration(
basicConfig,
"http://localhost:8080/ms_connector/",
basicConfig.getBasicConfiguration(//TODO
@@ -88,26 +96,34 @@ public class AdresssucheController {
MsEidasNodeConstants.TEMPLATE_HTML_RESIDENCY),
MsEidasNodeConstants.ENDPOINT_RESIDENCY_INPUT,
resourceLoader);
- // TODO Set the pendingId somehow
+ config.putCustomParameter(null, "pendingid", pendingReqGeneration.generateExternalPendingRequestId());
guiBuilder.build(request, response, config, "Query Austrian residency");
}
+ /**
+ * Performs search for addresses in ZMR.
+ */
@RequestMapping(value = {"/residency/search"}, method = {RequestMethod.POST})
- public ResponseEntity<AdresssucheResult> search(@RequestParam("municipality") String municipality,
+ public ResponseEntity<AdresssucheResult> search(@RequestParam("postleitzahl") String postleitzahl,
+ @RequestParam("municipality") String municipality,
@RequestParam("village") String village,
@RequestParam("street") String street,
@RequestParam("number") String number,
@RequestParam("pendingid") String pendingId) {
- log.info("Search with '{}', '{}', '{}'", municipality, street, number);
- // TODO validate pendingId
-// try {
-// pendingReqGeneration.validateAndGetPendingRequestId(pendingId);
-// } catch (PendingReqIdValidationException e) {
-// log.warn("Search with pendingId '{}' is not valid", pendingId);
-// return ResponseEntity.badRequest().build();
-// }
+ log.info("Search with '{}', '{}', '{}', '{}', '{}'",
+ postleitzahl.replaceAll("[\r\n]", ""),
+ municipality.replaceAll("[\r\n]", ""),
+ village.replaceAll("[\r\n]", ""),
+ street.replaceAll("[\r\n]", ""),
+ number.replaceAll("[\r\n]", ""));
try {
- Adressdaten searchInput = buildSearchInput(municipality, village, street, number);
+ pendingReqGeneration.validateAndGetPendingRequestId(pendingId);
+ } catch (PendingReqIdValidationException e) {
+ log.warn("Search with pendingId '{}' is not valid", pendingId.replaceAll("[\r\n]", ""));
+ return ResponseEntity.badRequest().build();
+ }
+ try {
+ Adressdaten searchInput = buildSearchInput(postleitzahl, municipality, village, street, number);
ZmrAddressSoapClient.AddressInfo searchOutput = client.searchAddress(searchInput);
AdresssucheResult output = buildResponse(searchOutput);
return ResponseEntity.ok(output);
@@ -120,24 +136,28 @@ public class AdresssucheController {
private AdresssucheResult buildResponse(ZmrAddressSoapClient.AddressInfo searchOutput) {
if (searchOutput.getPersonResult().isEmpty()) {
log.warn("No result from ZMR");
- return new AdresssucheResult(Collections.emptyList(), 0, false, null);
+ return new AdresssucheResult(Collections.emptyList(), 0);
}
- boolean moreResults = false;
- new HashSet<>();
log.info("Result level is {}", searchOutput.getLevel());
Set<AdresssucheOutput> result = searchOutput.getPersonResult().stream()
.map(Adressdaten::getPostAdresse)
- .map(it -> new AdresssucheOutput(it.getGemeinde(), it.getOrtschaft(),
+ .map(it -> new AdresssucheOutput(it.getPostleitzahl(), it.getGemeinde(), it.getOrtschaft(),
it.getZustelladresse().getStrassenname(), it.getZustelladresse().getOrientierungsnummer()))
.collect(Collectors.toSet());
// TODO Add configuration option for the limit of 30
List<AdresssucheOutput> sorted = result.stream().sorted().limit(30).collect(Collectors.toList());
- return new AdresssucheResult(sorted, result.size(), moreResults, searchOutput.getLevel().name());
+ return new AdresssucheResult(sorted, result.size());
}
- @NotNull
- private Adressdaten buildSearchInput(String municipality, String village, String street, String number) {
+ private Adressdaten buildSearchInput(String postleitzahl,
+ String municipality,
+ String village,
+ String street,
+ String number) {
PostAdresseTyp postAdresse = new PostAdresseTyp();
+ if (StringUtils.isNotBlank(postleitzahl)) {
+ postAdresse.setPostleitzahl(postleitzahl);
+ }
if (StringUtils.isNotBlank(municipality)) {
postAdresse.setGemeinde(municipality);
}
@@ -164,14 +184,12 @@ public class AdresssucheController {
public static class AdresssucheResult {
private final Collection<AdresssucheOutput> results;
private final int resultCount;
- private final boolean moreResults;
- private final String detailLevel;
-
}
@Data
@AllArgsConstructor
public static class AdresssucheOutput implements Comparable<AdresssucheOutput> {
+ private final String postleitzahl;
private final String municipality;
private final String village;
private final String street;
@@ -180,6 +198,7 @@ public class AdresssucheController {
@Override
public int compareTo(@NotNull AdresssucheOutput o) {
return new CompareToBuilder()
+ .append(this.postleitzahl, o.postleitzahl)
.append(this.municipality, o.municipality)
.append(this.village, o.village)
.append(this.street, o.street)