Skip to content

Commit

Permalink
ignore children with deleted contract
Browse files Browse the repository at this point in the history
  • Loading branch information
Max Zollbrecht committed Sep 25, 2024
1 parent 77b79ee commit 8c0bea2
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,20 @@ public ModelMapper modelMapper() {
// map groups and add children
List<Group> groups = new ArrayList<>();
export.getDatensaetze().stream().forEach(kind -> {
String groupId = kind.getVerGruppeId();

Optional<Group> group = groups.stream().filter(g -> Objects.equals(groupId, g.getGroupId())).findAny();
if (group.isEmpty()) {
// Group is not present yet.
groups.add(new Group(groupId, kind.getVerGruppe(),
new ArrayList<>(List.of(mapper.map(kind, Child.class)))));
} else {
// Add to existing group
group.get().getChildren().add(mapper.map(kind, Child.class));
// ignore children with a deleted contract
LocalDate careEnd = parseKitafinderDate(kind.getVerKuendigungZum());
if(careEnd == null || careEnd.isBefore(LocalDate.now())) {
String groupId = kind.getVerGruppeId();

Optional<Group> group = groups.stream().filter(g -> Objects.equals(groupId, g.getGroupId())).findAny();
if (group.isEmpty()) {
// Group is not present yet.
groups.add(new Group(groupId, kind.getVerGruppe(),
new ArrayList<>(List.of(mapper.map(kind, Child.class)))));
} else {
// Add to existing group
group.get().getChildren().add(mapper.map(kind, Child.class));
}
}
});
institute.setGroups(groups);
Expand All @@ -75,10 +79,7 @@ public ModelMapper modelMapper() {
});

Converter<String, LocalDate> dateConverter = context -> {
if (context.getSource() == null || context.getSource().length() == 0) {
return null;
}
return LocalDate.parse(context.getSource(), DATE_FORMATTER);
return parseKitafinderDate(context.getSource());
};

Converter<KitafinderKind, ChildAddress> adressConverter = context -> {
Expand Down Expand Up @@ -142,4 +143,11 @@ private void addParentIfExists(List<Parent> parentList, ParentType type, String
parentList.add(new Parent(type, firstname, lastname));
}
}

private LocalDate parseKitafinderDate(String dateString) {
if (dateString == null || dateString.length() == 0) {
return null;
}
return LocalDate.parse(dateString, DATE_FORMATTER);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -164,5 +164,54 @@ void mapsKitafinderKindList() {
assertThat(group3.get().getChildren().stream().map(k -> k.getFirstName()).toList())
.containsExactlyInAnyOrder(kind4.getKindVorname());
}



@Test
void mapsKitafinderKindListIgnoresDeletedContract() {
KitafinderKind kind1 = new KitafinderKind();
kind1.setKitaIdExtern("KITA-ID");
kind1.setKitaKitaname("KITA-NAME");
kind1.setKindVorname("vorname Test 1");
kind1.setKindNachname("nachname Test 1");
kind1.setVerGruppeId("gruppe id 1");
kind1.setVerGruppe("gruppe Test 1");
KitafinderKind kind2 = new KitafinderKind();
kind2.setKitaIdExtern("KITA-ID");
kind2.setKitaKitaname("KITA-NAME");
kind2.setKindVorname("vorname Test 2");
kind2.setKindNachname("nachname Test 2");
kind2.setVerGruppeId("gruppe id 1");
kind2.setVerGruppe("gruppe Test 1");
kind2.setVerKuendigungZum("31.12.2009");
KitafinderKind kind3 = new KitafinderKind();
kind3.setKitaIdExtern("KITA-ID");
kind3.setKitaKitaname("KITA-NAME");
kind3.setKindVorname("vorname Test 3");
kind3.setKindNachname("nachname Test 3");
kind3.setVerGruppeId("gruppe id 1");
kind3.setVerGruppe("gruppe Test 1");
kind3.setVerKuendigungZum("31.12.2999");
KitafinderKind kind4 = new KitafinderKind();
kind4.setKitaIdExtern("KITA-ID");
kind4.setKitaKitaname("KITA-NAME");
kind4.setKindVorname("vorname Test 4");
kind4.setKindNachname("nachname Test 4");
kind4.setVerGruppeId("gruppe id 1");

KitafinderExport source = new KitafinderExport(0, null, null, 4, List.of(kind1, kind2, kind3, kind4), null);

Institute dest = mapper.map(source, Institute.class);

assertThat(dest.getInstituteId()).isEqualTo("KITA-ID");
assertThat(dest.getInstituteName()).isEqualTo("KITA-NAME");
System.out.println(dest.getGroups().toString());
assertThat(dest.getGroups()).hasSize(1);

Optional<Group> group1 = dest.getGroups().stream().filter(g -> "gruppe id 1".equals(g.getGroupId())).findAny();
assertThat(group1).isNotEmpty();
assertThat(group1.get().getChildren().stream().map(k -> k.getFirstName()).toList())
.containsExactlyInAnyOrder(kind1.getKindVorname(), kind2.getKindVorname(), kind4.getKindVorname());
}

}

0 comments on commit 8c0bea2

Please sign in to comment.