Skip to content

Commit b6c8ad7

Browse files
committed
πŸ›βœ… Do not add duplicate contactInfo details
1 parent 2a30467 commit b6c8ad7

2 files changed

Lines changed: 32 additions & 7 deletions

File tree

β€Žsormas-backend/src/main/java/de/symeda/sormas/backend/patch/mapping/impl/fieldmapper/PersonContactDetailsFieldMapper.javaβ€Ž

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
import javax.enterprise.context.ApplicationScoped;
1313

14+
import org.apache.commons.lang3.ObjectUtils;
15+
import org.apache.commons.lang3.StringUtils;
1416
import org.jetbrains.annotations.NotNull;
1517
import org.slf4j.Logger;
1618
import org.slf4j.LoggerFactory;
@@ -56,7 +58,7 @@ public Optional<DataPatchFailure> map(FieldPatchRequest request) {
5658
Optional<PersonContactDetailDto> alreadyPresentContactDetail = personDto.getPersonContactDetails()
5759
.stream()
5860
.filter(appropriatePredicate)
59-
.filter(contactDetail -> contactDetail.getDetails().equals(request.getValue()))
61+
.filter(contactDetail -> request.getValue().equals(contactDetail.getContactInformation()))
6062
.findAny();
6163

6264
if (alreadyPresentContactDetail.isPresent()) {

β€Žsormas-backend/src/test/java/de/symeda/sormas/backend/patch/mapping/impl/fieldmapper/PersonContactDetailsFieldMapperTest.javaβ€Ž

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ void map_phoneField_contactDetailAlreadyPresent_doesNotAddDuplicate() {
8585
// PREPARE
8686
PersonContactDetailDto existing = new PersonContactDetailDto();
8787
existing.setPersonContactDetailType(PersonContactDetailType.PHONE);
88-
existing.setDetails("0123456789");
88+
existing.setContactInformation("0123456789");
8989

9090
PersonDto personDto = new PersonDto();
9191
personDto.setPersonContactDetails(new ArrayList<>(List.of(existing)));
@@ -135,7 +135,7 @@ void map_emailField_contactDetailNotPresent_addsEmailContactDetail() {
135135

136136
FieldPatchRequest request = mock(FieldPatchRequest.class);
137137
when(request.getTarget()).thenReturn(personDto);
138-
when(request.getFieldName()).thenReturn("Person.PersonContactDetail.details");
138+
when(request.getFieldName()).thenReturn("Person.PersonContactDetail.contactInformation");
139139
when(request.getValue()).thenReturn("test@example.com");
140140
when(request.getOrigin()).thenReturn("someOrigin");
141141

@@ -156,14 +156,37 @@ void map_emailField_contactDetailAlreadyPresent_doesNotAddDuplicate() {
156156
// PREPARE
157157
PersonContactDetailDto existing = new PersonContactDetailDto();
158158
existing.setPersonContactDetailType(PersonContactDetailType.EMAIL);
159-
existing.setDetails("test@example.com");
159+
existing.setContactInformation("test@example.com");
160160

161161
PersonDto personDto = new PersonDto();
162162
personDto.setPersonContactDetails(new ArrayList<>(List.of(existing)));
163163

164164
FieldPatchRequest request = mock(FieldPatchRequest.class);
165165
when(request.getTarget()).thenReturn(personDto);
166-
when(request.getFieldName()).thenReturn("Person.PersonContactDetail.details");
166+
when(request.getFieldName()).thenReturn("Person.PersonContactDetail.contactInformation");
167+
when(request.getValue()).thenReturn("test@example.com");
168+
169+
// EXECUTE
170+
Optional<DataPatchFailure> actual = victim.map(request);
171+
172+
// CHECK
173+
assertTrue(actual.isEmpty());
174+
assertEquals(1, personDto.getPersonContactDetails().size());
175+
}
176+
177+
@Test
178+
void map_emailField_contactInformationAlreadyPresent_doesNotAddDuplicate() {
179+
// PREPARE
180+
PersonContactDetailDto existing = new PersonContactDetailDto();
181+
existing.setPersonContactDetailType(PersonContactDetailType.EMAIL);
182+
existing.setContactInformation("test@example.com");
183+
184+
PersonDto personDto = new PersonDto();
185+
personDto.setPersonContactDetails(new ArrayList<>(List.of(existing)));
186+
187+
FieldPatchRequest request = mock(FieldPatchRequest.class);
188+
when(request.getTarget()).thenReturn(personDto);
189+
when(request.getFieldName()).thenReturn("PersonContactDetail.contactInformation");
167190
when(request.getValue()).thenReturn("test@example.com");
168191

169192
// EXECUTE
@@ -186,7 +209,7 @@ void map_emailField_differentValueAlreadyPresent_addsNewEntry() {
186209

187210
FieldPatchRequest request = mock(FieldPatchRequest.class);
188211
when(request.getTarget()).thenReturn(personDto);
189-
when(request.getFieldName()).thenReturn("Person.PersonContactDetail.details");
212+
when(request.getFieldName()).thenReturn("Person.PersonContactDetail.contactInformation");
190213
when(request.getValue()).thenReturn("test@example.com");
191214
when(request.getOrigin()).thenReturn("someOrigin");
192215

@@ -234,7 +257,7 @@ void map_emailField_existingPhoneWithSameValue_addsEmailContactDetail() {
234257

235258
FieldPatchRequest request = mock(FieldPatchRequest.class);
236259
when(request.getTarget()).thenReturn(personDto);
237-
when(request.getFieldName()).thenReturn("Person.PersonContactDetail.details");
260+
when(request.getFieldName()).thenReturn("Person.PersonContactDetail.contactInformation");
238261
when(request.getValue()).thenReturn("test@example.com");
239262
when(request.getOrigin()).thenReturn("someOrigin");
240263

0 commit comments

Comments
Β (0)