-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…aak-van-minderjarige-kinderen-bij-bevragen-meerderjarige Feature/#279 loggen gezagsuitspraak van minderjarige kinderen bij bevragen meerderjarige
- Loading branch information
Showing
6 changed files
with
52 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 6 additions & 8 deletions
14
src/main/java/nl/rijksoverheid/mev/logging/GezagResultaat.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,9 @@ | ||
package nl.rijksoverheid.mev.logging; | ||
|
||
import lombok.Data; | ||
|
||
@Data | ||
public final class GezagResultaat { | ||
private long plId; | ||
private String type; | ||
private String toelichting; | ||
private String route; | ||
public record GezagResultaat( | ||
Long plId, | ||
String type, | ||
String toelichting, | ||
String route | ||
) { | ||
} |
76 changes: 13 additions & 63 deletions
76
src/main/java/nl/rijksoverheid/mev/logging/LoggingContext.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,88 +1,38 @@ | ||
package nl.rijksoverheid.mev.logging; | ||
|
||
import nl.rijksoverheid.mev.gezagsmodule.model.Burgerservicenummer; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.time.Instant; | ||
import java.util.*; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
|
||
public class LoggingContext { | ||
|
||
private static final Logger logger = LoggerFactory.getLogger(LoggingContext.class); | ||
|
||
private final Instant eventStart; | ||
private final List<Long> plIds; | ||
private final Map<String, GezagResultaat> gezagResultaten; | ||
private final Map<Long, Long> plIdByBurgerservicenummer; | ||
|
||
public LoggingContext() { | ||
this.eventStart = Instant.now(); | ||
this.plIds = new ArrayList<>(); | ||
this.gezagResultaten = new HashMap<>(); | ||
} | ||
|
||
public void addBurgerservicenummers(Collection<String> burgerservicenummers) { | ||
burgerservicenummers.forEach(burgerservicenummer -> | ||
gezagResultaten.put(burgerservicenummer, new GezagResultaat()) | ||
); | ||
this.plIdByBurgerservicenummer = new HashMap<>(); | ||
} | ||
|
||
public void addPlId(long plId, Burgerservicenummer burgerservicenummer) { | ||
gezagResultaten.computeIfPresent(burgerservicenummer.asString(), (unused, gezagResultaat) -> { | ||
gezagResultaat.setPlId(plId); | ||
return gezagResultaat; | ||
}); | ||
plIds.add(plId); | ||
plIdByBurgerservicenummer.put(burgerservicenummer.value(), plId); | ||
} | ||
|
||
public void addGezagType(String gezagType, String burgerservicenummer) { | ||
gezagResultaten.computeIfPresent(burgerservicenummer, (unused, gezagResultaat) -> { | ||
var translatedGezagType = mapGezagType(gezagType); | ||
gezagResultaat.setType(translatedGezagType); | ||
return gezagResultaat; | ||
}); | ||
} | ||
|
||
public void addRoute(String route, String burgerservicenummer) { | ||
gezagResultaten.computeIfPresent(burgerservicenummer, (unused, gezagResultaat) -> { | ||
gezagResultaat.setRoute(route); | ||
return gezagResultaat; | ||
}); | ||
} | ||
|
||
public void addToelichting(String toelichting, String burgerservicenummer) { | ||
gezagResultaten.computeIfPresent(burgerservicenummer, (unused, gezagResultaat) -> { | ||
gezagResultaat.setToelichting(toelichting); | ||
return gezagResultaat; | ||
}); | ||
public Long getPlIdBy(String burgerservicenummerAsString) { | ||
var burgerservicenummerAsLong = Long.valueOf(burgerservicenummerAsString); | ||
return plIdByBurgerservicenummer.get(burgerservicenummerAsLong); | ||
} | ||
|
||
public Instant getEventStart() { | ||
return eventStart; | ||
} | ||
|
||
public List<Long> getPlIds() { | ||
return Collections.unmodifiableList(plIds); | ||
} | ||
|
||
public Collection<GezagResultaat> getGezagResultaten() { | ||
return Collections.unmodifiableCollection(gezagResultaten.values()); | ||
} | ||
|
||
private static String mapGezagType(String gezagType) { | ||
// temporary until GezagService returns typed responses | ||
return switch (gezagType) { | ||
case "OG1" -> "EenhoofdigOuderlijkGezag"; | ||
case "OG2" -> "TweehoofdigOuderlijkGezag"; | ||
case "GG" -> "GezamenlijkGezag"; | ||
case "V" -> "Voogdij"; | ||
case "G" -> "TijdelijkGeenGezag"; | ||
case "N" -> "GezagNietTeBepalen"; | ||
case "NVT" -> "GezagNietVanToepassing*"; | ||
default -> { // should never happen | ||
logger.error("Unknown gezag type: {}", gezagType); | ||
yield "OnbekendGezagType"; | ||
} | ||
}; | ||
public Set<Long> getPlIds() { | ||
return plIdByBurgerservicenummer.values().stream() | ||
.collect(Collectors.toUnmodifiableSet()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters