Skip to content
Snippets Groups Projects
Commit aec75ff1 authored by Jan Zickermann's avatar Jan Zickermann
Browse files

OZG-7978 servicekonto: Avoid try catch block

parent fe0c4ff8
No related branches found
No related tags found
1 merge request!18OZG-7978 servicekonto: Catch runtime-exception in getPostfachAddressType
This commit is part of merge request !18. Comments created here will be created in the context of that merge request.
......@@ -23,11 +23,13 @@
*/
package de.ozgcloud.eingang.semantik.common;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.stream.Stream;
import org.apache.commons.collections.MapUtils;
import org.springframework.stereotype.Component;
......@@ -102,21 +104,28 @@ public class ServiceKontoFactory {
}
int getPostfachAddressType(Map<String, Object> restResponseName) {
try {
return getMailboxType(restResponseName);
} catch (RuntimeException e) {
LOG.error("Error while getting mailbox type from rest response name", e);
return getMailboxType(restResponseName)
.orElseGet(() -> {
LOG.warn("Mailbox type not found in rest_response_name! Using default value '{}'", POSTFACH_ADDRESS_DEFAULT);
return POSTFACH_ADDRESS_DEFAULT;
}
});
}
private Integer getMailboxType(Map<String, Object> restResponseName) {
return (Integer) getMemberScope(restResponseName).get(REST_RESPONSE_NAME_MEMBER_SCOPE_MAILBOX_TYPE);
private Optional<Integer> getMailboxType(Map<String, Object> restResponseName) {
return getMemberScope(restResponseName)
.map(scope -> scope.get(REST_RESPONSE_NAME_MEMBER_SCOPE_MAILBOX_TYPE))
.filter(Integer.class::isInstance)
.map(Integer.class::cast);
}
@SuppressWarnings("unchecked")
private Map<String, Object> getMemberScope(Map<String, Object> restResponseName) {
return ((List<Map<String, Object>>) restResponseName.get(REST_RESPONSE_NAME_MEMBER_SCOPE)).get(0);
private Optional<Map<String, Object>> getMemberScope(Map<String, Object> restResponseName) {
return Optional.ofNullable(restResponseName.get(REST_RESPONSE_NAME_MEMBER_SCOPE))
.filter(List.class::isInstance)
.map(List.class::cast)
.map(Collection::stream)
.flatMap(Stream::findFirst)
.filter(Map.class::isInstance);
}
public Optional<ServiceKonto> createBayernIdServiceKonto(Map<String, Object> formDataHeaders) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment