Skip to content
This repository was archived by the owner on Apr 12, 2019. It is now read-only.

Commit 02da170

Browse files
committed
Merge remote-tracking branch 'origin/master' into feature/17_IntegrationTest
2 parents 51d12f8 + 56f5f06 commit 02da170

File tree

10 files changed

+209
-61
lines changed

10 files changed

+209
-61
lines changed

adapter-pakt/src/main/java/ch/prevo/open/node/data/provider/PAKTJobEventProviderImpl.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ private String getRetirementFundId(TozsPtverm ptVerm) {
5555
}
5656

5757
enum RetirementFund {
58-
BALOISE_SAMMELSTIFTUNG(Short.valueOf("4"), "Bâloise-Sammelstiftung für die obligatorische berufliche Vorsorge",
58+
BALOISE_SAMMELSTIFTUNG(Short.valueOf("4"), "Baloise-Sammelstiftung für die obligatorische berufliche Vorsorge",
5959
"CHE-109.740.084"), PERSPECTIVA_SAMMELSTIFTUNG(Short.valueOf("1"),
60-
"Perspectiva Sammelstiftung für berufliche Vorsorge", "CHE-223.471.073");
60+
"Perspectiva Sammelstiftung für berufliche Vorsorge", "CHE-223.471.073");
6161
private Short cdStf;
6262
private String name;
6363
private String id;

clean-docker.sh

-3
This file was deleted.

encrypted-data-model/build.gradle

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@ repositories {
55
}
66

77
dependencies {
8-
compile('org.apache.commons:commons-lang3:3.7')
8+
compile('org.apache.commons:commons-lang3:3.7')
9+
testCompile 'junit:junit:4.12'
910
}

encrypted-data-model/src/main/java/ch/prevo/open/encrypted/model/InsurantInformation.java

+46-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package ch.prevo.open.encrypted.model;
22

3+
import java.time.LocalDate;
4+
35
import org.apache.commons.lang3.ObjectUtils;
46

57
/**
@@ -9,6 +11,7 @@ public class InsurantInformation implements Comparable<InsurantInformation> {
911

1012
private String encryptedOasiNumber;
1113
private String retirementFundUid;
14+
private LocalDate date;
1215

1316
public InsurantInformation() {
1417
}
@@ -18,6 +21,12 @@ public InsurantInformation(String encryptedOasiNumber, String retirementFundUid)
1821
this.retirementFundUid = retirementFundUid;
1922
}
2023

24+
public InsurantInformation(String encryptedOasiNumber, String retirementFundUid, LocalDate date) {
25+
this.encryptedOasiNumber = encryptedOasiNumber;
26+
this.retirementFundUid = retirementFundUid;
27+
this.date = date;
28+
}
29+
2130
public String getEncryptedOasiNumber() {
2231
return encryptedOasiNumber;
2332
}
@@ -34,12 +43,48 @@ public void setRetirementFundUid(String retirementFundUid) {
3443
this.retirementFundUid = retirementFundUid;
3544
}
3645

46+
public LocalDate getDate() {
47+
return date;
48+
}
49+
50+
@Override
51+
public boolean equals(Object o) {
52+
if (this == o) {
53+
return true;
54+
}
55+
if (o == null || getClass() != o.getClass()) {
56+
return false;
57+
}
58+
59+
InsurantInformation that = (InsurantInformation) o;
60+
61+
if (encryptedOasiNumber != null ? !encryptedOasiNumber.equals(that.encryptedOasiNumber) : that.encryptedOasiNumber != null) {
62+
return false;
63+
}
64+
if (retirementFundUid != null ? !retirementFundUid.equals(that.retirementFundUid) : that.retirementFundUid != null) {
65+
return false;
66+
}
67+
return date != null ? date.equals(that.date) : that.date == null;
68+
}
69+
70+
@Override
71+
public int hashCode() {
72+
int result = encryptedOasiNumber != null ? encryptedOasiNumber.hashCode() : 0;
73+
result = 31 * result + (retirementFundUid != null ? retirementFundUid.hashCode() : 0);
74+
result = 31 * result + (date != null ? date.hashCode() : 0);
75+
return result;
76+
}
77+
3778
@Override
3879
public int compareTo(InsurantInformation o) {
3980
int oasiComparisonResult = ObjectUtils.compare(encryptedOasiNumber, o.encryptedOasiNumber);
4081
if (oasiComparisonResult != 0) {
4182
return oasiComparisonResult;
4283
}
43-
return ObjectUtils.compare(retirementFundUid, o.retirementFundUid);
84+
int uidComparisonResult = ObjectUtils.compare(retirementFundUid, o.retirementFundUid);
85+
if (uidComparisonResult != 0) {
86+
return uidComparisonResult;
87+
}
88+
return ObjectUtils.compare(date, o.date);
4489
}
4590
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package ch.prevo.open.encrypted.model;
2+
3+
import org.junit.Test;
4+
5+
import java.util.Arrays;
6+
import java.util.Collections;
7+
import java.util.List;
8+
9+
import static java.time.LocalDate.of;
10+
import static org.junit.Assert.assertSame;
11+
12+
public class InsurantInformationTest {
13+
14+
@Test
15+
public void compareTo() throws Exception {
16+
InsurantInformation i0 = new InsurantInformation("1", "1");
17+
InsurantInformation i1 = new InsurantInformation("1", "1", of(2000, 1, 1));
18+
InsurantInformation i2 = new InsurantInformation("2", "1", of(2000, 1, 1));
19+
InsurantInformation i3 = new InsurantInformation("2", "2", of(2000, 1, 1));
20+
InsurantInformation i4 = new InsurantInformation("2", "2", of(2000, 2, 1));
21+
22+
List<InsurantInformation> list = Arrays.asList(i4, i2, i3, i0, i1);
23+
Collections.sort(list);
24+
25+
assertSame(i0, list.get(0));
26+
assertSame(i1, list.get(1));
27+
assertSame(i2, list.get(2));
28+
assertSame(i3, list.get(3));
29+
assertSame(i4, list.get(4));
30+
}
31+
32+
}

hub/src/main/java/ch/prevo/open/hub/match/MatcherService.java

+23-1
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,16 @@
1111
@Service
1212
public class MatcherService {
1313

14+
private final List<InsurantInformation> matchedEmploymentCommencements = new ArrayList<>();
15+
private final List<InsurantInformation> matchedEmploymentTerminations = new ArrayList<>();
16+
1417
public List<Match> findMatches(Set<InsurantInformation> retirementFundExits, Set<InsurantInformation> retirementFundEntries) {
1518
List<Match> matches = new ArrayList<>();
1619
for (InsurantInformation exit : retirementFundExits) {
1720
InsurantInformation matchingEntry = findMatchingEntry(retirementFundEntries, exit);
1821
if (matchingEntry != null) {
22+
matchedEmploymentCommencements.add(matchingEntry);
23+
matchedEmploymentTerminations.add(exit);
1924
matches.add(new Match(exit.getEncryptedOasiNumber(), exit.getRetirementFundUid(), matchingEntry.getRetirementFundUid()));
2025
}
2126
}
@@ -24,7 +29,7 @@ public List<Match> findMatches(Set<InsurantInformation> retirementFundExits, Set
2429

2530
private InsurantInformation findMatchingEntry(Set<InsurantInformation> retirementFundEntries, InsurantInformation exit) {
2631
Set<InsurantInformation> matchingEntries = retirementFundEntries.stream()
27-
.filter(entry -> entry.getEncryptedOasiNumber().equals(exit.getEncryptedOasiNumber()))
32+
.filter(entry -> isMatching(entry, exit))
2833
.collect(Collectors.toSet());
2934

3035
if (matchingEntries.isEmpty()) {
@@ -36,4 +41,21 @@ private InsurantInformation findMatchingEntry(Set<InsurantInformation> retiremen
3641
return matchingEntries.iterator().next();
3742
}
3843

44+
private boolean isMatching(InsurantInformation entry, InsurantInformation exit) {
45+
return entry.getEncryptedOasiNumber().equals(exit.getEncryptedOasiNumber())
46+
&& !isSameFundWithEntryBeforeExit(entry, exit);
47+
}
48+
49+
private boolean isSameFundWithEntryBeforeExit(InsurantInformation entry, InsurantInformation exit) {
50+
return entry.getRetirementFundUid().equals(exit.getRetirementFundUid())
51+
&& entry.getDate().isBefore(exit.getDate());
52+
}
53+
54+
public boolean employmentCommencementNotMatched(InsurantInformation info) {
55+
return !matchedEmploymentCommencements.contains(info);
56+
}
57+
58+
public boolean employmentTerminationNotMatched(InsurantInformation info) {
59+
return !matchedEmploymentTerminations.contains(info);
60+
}
3961
}

hub/src/main/java/ch/prevo/open/hub/nodes/NodeService.java

+11-4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import ch.prevo.open.encrypted.model.InsurantInformation;
44
import ch.prevo.open.encrypted.model.MatchNotification;
55
import ch.prevo.open.hub.match.Match;
6+
import ch.prevo.open.hub.match.MatcherService;
67
import org.springframework.boot.web.client.RestTemplateBuilder;
78
import org.springframework.stereotype.Service;
89
import org.springframework.web.client.RestTemplate;
@@ -14,13 +15,17 @@
1415

1516
import static java.util.Arrays.asList;
1617
import static java.util.Collections.emptyList;
18+
import static java.util.stream.Collectors.toList;
1719

1820
@Service
1921
public class NodeService {
2022

2123
@Inject
2224
private NodeRegistry nodeRegistry;
2325

26+
@Inject
27+
private MatcherService matcherService;
28+
2429
private final RestTemplate restTemplate;
2530

2631
public NodeService(RestTemplateBuilder restTemplateBuilder) {
@@ -30,17 +35,19 @@ public NodeService(RestTemplateBuilder restTemplateBuilder) {
3035
public Set<InsurantInformation> getCurrentExits() {
3136
Set<InsurantInformation> exits = new HashSet<>();
3237
for (NodeConfiguration nodeConfig : nodeRegistry.getCurrentNodes()) {
33-
exits.addAll(lookupInsurantInformationList(nodeConfig.getJobExitsUrl()));
38+
List<InsurantInformation> pensionFundExits = lookupInsurantInformationList(nodeConfig.getJobExitsUrl());
39+
exits.addAll(pensionFundExits.stream().filter(matcherService::employmentCommencementNotMatched).collect(toList()));
3440
}
3541
return exits;
3642
}
3743

3844
public Set<InsurantInformation> getCurrentEntries() {
39-
Set<InsurantInformation> exits = new HashSet<>();
45+
Set<InsurantInformation> entries = new HashSet<>();
4046
for (NodeConfiguration nodeConfig : nodeRegistry.getCurrentNodes()) {
41-
exits.addAll(lookupInsurantInformationList(nodeConfig.getJobEntriesUrl()));
47+
List<InsurantInformation> pensionFundEntries = lookupInsurantInformationList(nodeConfig.getJobEntriesUrl());
48+
entries.addAll(pensionFundEntries.stream().filter(matcherService::employmentTerminationNotMatched).collect(toList()));
4249
}
43-
return exits;
50+
return entries;
4451
}
4552

4653
private List<InsurantInformation> lookupInsurantInformationList(String url) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
package ch.prevo.open.hub.match;
2+
3+
import ch.prevo.open.encrypted.model.InsurantInformation;
4+
import org.junit.Before;
5+
import org.junit.Test;
6+
7+
import java.util.Collections;
8+
import java.util.HashSet;
9+
import java.util.List;
10+
import java.util.Set;
11+
12+
import static java.time.LocalDate.of;
13+
import static java.util.Collections.emptySet;
14+
import static org.junit.Assert.assertEquals;
15+
import static org.junit.Assert.assertFalse;
16+
import static org.junit.Assert.assertTrue;
17+
18+
public class MatcherServiceTest {
19+
20+
private static final String OASI_1 = "oasi1";
21+
private static final String UID_1 = "uid1";
22+
private static final String OASI_2 = "oasi2";
23+
private static final String UID_2 = "uid2";
24+
private static final String UID_3 = "uid3";
25+
26+
private MatcherService matcherService;
27+
28+
@Before
29+
public void setup() {
30+
matcherService = new MatcherService();
31+
}
32+
33+
@Test
34+
public void findMatches() throws Exception {
35+
Set<InsurantInformation> exits = createSet(new InsurantInformation(OASI_1, UID_1));
36+
Set<InsurantInformation> entries = createSet(new InsurantInformation(OASI_1, UID_2), new InsurantInformation(OASI_2, UID_3));
37+
38+
List<Match> matches = matcherService.findMatches(exits, entries);
39+
40+
assertEquals(1, matches.size());
41+
Match match = matches.get(0);
42+
assertEquals(OASI_1, match.getEncryptedOasiNumber());
43+
assertEquals(UID_1, match.getPreviousRetirementFundUid());
44+
assertEquals(UID_2, match.getNewRetirementFundUid());
45+
46+
assertFalse(matcherService.employmentTerminationNotMatched(new InsurantInformation(OASI_1, UID_1)));
47+
assertFalse(matcherService.employmentCommencementNotMatched(new InsurantInformation(OASI_1, UID_2)));
48+
}
49+
50+
@Test
51+
public void findMatchesWithinSameRetirementFund() throws Exception {
52+
Set<InsurantInformation> exits = createSet(new InsurantInformation(OASI_1, UID_1, of(2018, 6, 1)));
53+
Set<InsurantInformation> entries = createSet(new InsurantInformation(OASI_1, UID_1, of(2018, 8, 1)));
54+
55+
List<Match> matches = matcherService.findMatches(exits, entries);
56+
57+
assertEquals(1, matches.size());
58+
}
59+
60+
@Test
61+
public void findMatchesWithinSameRetirementFund_entryBeforeExit() throws Exception {
62+
Set<InsurantInformation> exits = createSet(new InsurantInformation(OASI_1, UID_1, of(2018, 6, 1)));
63+
Set<InsurantInformation> entries = createSet(new InsurantInformation(OASI_1, UID_1, of(2018, 1, 1)));
64+
65+
List<Match> matches = matcherService.findMatches(exits, entries);
66+
67+
assertEquals(0, matches.size());
68+
}
69+
70+
@Test
71+
public void findMatchesEmptyInput() throws Exception {
72+
assertTrue(matcherService.findMatches(emptySet(), emptySet()).isEmpty());
73+
}
74+
75+
@Test(expected = RuntimeException.class)
76+
public void findMatchesWithDuplicates() throws Exception {
77+
Set<InsurantInformation> exits = createSet(new InsurantInformation(OASI_1, UID_1));
78+
Set<InsurantInformation> entries = createSet(new InsurantInformation(OASI_1, UID_2), new InsurantInformation(OASI_1, UID_3));
79+
80+
matcherService.findMatches(exits, entries);
81+
}
82+
83+
private Set<InsurantInformation> createSet(InsurantInformation... insurantInformations) {
84+
Set<InsurantInformation> result = new HashSet<>();
85+
Collections.addAll(result, insurantInformations);
86+
return result;
87+
}
88+
}

hub/src/test/java/ch/prevo/open/hub/match/MatcherTest.java

-46
This file was deleted.

0 commit comments

Comments
 (0)