aboutsummaryrefslogtreecommitdiff
path: root/connector/src/main/java
diff options
context:
space:
mode:
authorChristian Kollmann <christian.kollmann@a-sit.at>2021-12-02 15:03:09 +0100
committerChristian Kollmann <christian.kollmann@a-sit.at>2021-12-02 16:13:48 +0100
commit6fff1b53525348d531c96b45c920a8ce72288f60 (patch)
tree8db3e70ab71df189eb6cdb2bfbe28b1a67e2227c /connector/src/main/java
parente5934d538aabcfc1f3b92472753de729d6ce1cce (diff)
downloadNational_eIDAS_Gateway-6fff1b53525348d531c96b45c920a8ce72288f60.tar.gz
National_eIDAS_Gateway-6fff1b53525348d531c96b45c920a8ce72288f60.tar.bz2
National_eIDAS_Gateway-6fff1b53525348d531c96b45c920a8ce72288f60.zip
Display all results to user after residency search
Diffstat (limited to 'connector/src/main/java')
-rw-r--r--connector/src/main/java/at/asitplus/eidas/specific/connector/controller/AdresssucheController.java82
1 files changed, 40 insertions, 42 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 8b25a7bd..c35aa8b9 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
@@ -35,8 +35,11 @@ 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 lombok.AllArgsConstructor;
+import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
+import org.apache.commons.lang3.builder.CompareToBuilder;
import org.jetbrains.annotations.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.ResourceLoader;
@@ -48,6 +51,8 @@ import org.springframework.web.bind.annotation.RequestParam;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import java.util.*;
+import java.util.stream.Collectors;
/**
* Default process-engine signaling controller.
@@ -88,7 +93,7 @@ public class AdresssucheController {
}
@RequestMapping(value = {"/residency/search"}, method = {RequestMethod.POST})
- public ResponseEntity<AdresssucheOutput> search(@RequestParam("municipality") String municipality,
+ public ResponseEntity<AdresssucheResult> search(@RequestParam("municipality") String municipality,
@RequestParam("village") String village,
@RequestParam("street") String street,
@RequestParam("number") String number,
@@ -104,7 +109,7 @@ public class AdresssucheController {
try {
Adressdaten searchInput = buildSearchInput(municipality, village, street, number);
ZmrAddressSoapClient.AddressInfo searchOutput = client.searchAddress(searchInput);
- AdresssucheOutput output = buildResponse(searchOutput);
+ AdresssucheResult output = buildResponse(searchOutput);
return ResponseEntity.ok(output);
} catch (EidasSAuthenticationException e) {
log.warn("Search failed", e);
@@ -112,18 +117,22 @@ public class AdresssucheController {
}
}
- private AdresssucheOutput buildResponse(ZmrAddressSoapClient.AddressInfo searchOutput) {
+ private AdresssucheResult buildResponse(ZmrAddressSoapClient.AddressInfo searchOutput) {
if (searchOutput.getPersonResult().isEmpty()) {
log.warn("No result from ZMR");
- return new AdresssucheOutput(null, null, null, null);
+ return new AdresssucheResult(Collections.emptyList(), 0, false, 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);
+ 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(),
+ 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());
}
@NotNull
@@ -150,43 +159,32 @@ public class AdresssucheController {
return searchInput;
}
- public static class AdresssucheOutput {
+ @Data
+ @AllArgsConstructor
+ 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 municipality;
private final String village;
private final String street;
private final String number;
- public AdresssucheOutput(String municipality, String village, String street, String number) {
- this.municipality = municipality;
- this.village = village;
- this.street = street;
- this.number = number;
- }
-
- public String getMunicipality() {
- return municipality;
- }
-
- public String getVillage() {
- return village;
- }
-
- public String getStreet() {
- return street;
- }
-
- public String getNumber() {
- return number;
- }
-
@Override
- public String toString() {
- return "AdresssucheOutput{" +
- "municipality='" + municipality + '\'' +
- ", village='" + village + '\'' +
- ", street='" + street + '\'' +
- ", number='" + number + '\'' +
- '}';
+ public int compareTo(@NotNull AdresssucheOutput o) {
+ return new CompareToBuilder()
+ .append(this.municipality, o.municipality)
+ .append(this.village, o.village)
+ .append(this.street, o.street)
+ .append(this.number, o.number)
+ .toComparison();
}
}