Skip to content
Snippets Groups Projects
Commit 612c054c authored by OZG-Cloud Team's avatar OZG-Cloud Team
Browse files

OZG-6054 mantelantrag: Continue mapping with multiple matching slots

parent 76c2155a
No related branches found
No related tags found
No related merge requests found
......@@ -40,6 +40,8 @@ public class MantelantragZustaendigeStelleMapper implements FormBasedMapper {
static final String HAUSANSCHRIFT_ORT_FIELD = "zust_ort";
static final String TELEFON_FIELD = "telefon";
static final String FAILURE_MESSAGE = "Failed mapping Zustaendigestelle of Mantelantrag";
private final Environment environment;
private Set<String> xtaIdentifiers;
......@@ -67,7 +69,7 @@ public class MantelantragZustaendigeStelleMapper implements FormBasedMapper {
try {
return adaptFormDataWithPossibleException(formData);
} catch (TechnicalException exception) {
LOG.warn("Mantelantrag is invalid: %s".formatted(exception.getMessage()));
logWarning("%s: %s".formatted(FAILURE_MESSAGE, exception.getMessage()));
return formData;
}
}
......@@ -113,12 +115,20 @@ public class MantelantragZustaendigeStelleMapper implements FormBasedMapper {
private void verifyOneMatchingIdentifier(List<Integer> matchingSlots) {
if (matchingSlots.size() != 1) {
throw new TechnicalException(
"Found %d matching nachrichtenbroker addresses! Expected one of '%s'."
.formatted(matchingSlots.size(), Strings.join(xtaIdentifiers, ',')));
var message = "Found %d matching nachrichtenbroker addresses! Expected one of '%s'."
.formatted(matchingSlots.size(), Strings.join(xtaIdentifiers, ','));
if (matchingSlots.isEmpty()) {
throw new TechnicalException(message);
} else {
logWarning("Unexpected Zustaendigestelle in Mantelantrag: %s".formatted(message));
}
}
}
void logWarning(String message) {
LOG.warn(message);
}
private List<Integer> getMatchingSlots(Map<String, Object> fieldMap) {
return IntStream.range(0, 3)
.filter(slotIndex -> xtaIdentifiers.contains(getXtaIdentifierOfSlot(fieldMap, slotIndex)))
......
......@@ -133,6 +133,18 @@ class MantelantragZustaendigeStelleMapperTest {
assertThat(resultFormData).isEqualTo(formData);
}
@DisplayName("should log warning with exception")
@Test
void shouldLogWarningWithException() {
var errorMessage = "some error";
doThrow(new TechnicalException(errorMessage)).when(mapper).adaptFormDataWithPossibleException(formData);
doNothing().when(mapper).logWarning(anyString());
mapper.parseFormData(formData);
verify(mapper).logWarning("%s: %s".formatted(FAILURE_MESSAGE, errorMessage));
}
}
@DisplayName("adapt form data with possible exception")
......@@ -310,14 +322,17 @@ class MantelantragZustaendigeStelleMapperTest {
.isInstanceOf(TechnicalException.class);
}
@DisplayName("should throw if multiple slots match")
@DisplayName("should log warning if multiple slots match")
@Test
void shouldThrowIfMultipleSlotsMatch() {
fieldMap.put(getZustaendigeStelleName(0), IDENTIFIER2);
fieldMap.put(getZustaendigeStelleName(2), IDENTIFIER);
doNothing().when(mapper).logWarning(anyString());
mapper.findSlotIndex(fieldMap);
verify(mapper).logWarning(anyString());
assertThatThrownBy(() -> mapper.findSlotIndex(fieldMap))
.isInstanceOf(TechnicalException.class);
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment