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
Branches
Tags
1 merge request!18OZG-7978 servicekonto: Catch runtime-exception in getPostfachAddressType
...@@ -23,11 +23,13 @@ ...@@ -23,11 +23,13 @@
*/ */
package de.ozgcloud.eingang.semantik.common; package de.ozgcloud.eingang.semantik.common;
import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects; import java.util.Objects;
import java.util.Optional; import java.util.Optional;
import java.util.stream.Stream;
import org.apache.commons.collections.MapUtils; import org.apache.commons.collections.MapUtils;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
...@@ -102,21 +104,28 @@ public class ServiceKontoFactory { ...@@ -102,21 +104,28 @@ public class ServiceKontoFactory {
} }
int getPostfachAddressType(Map<String, Object> restResponseName) { int getPostfachAddressType(Map<String, Object> restResponseName) {
try { return getMailboxType(restResponseName)
return getMailboxType(restResponseName); .orElseGet(() -> {
} catch (RuntimeException e) { LOG.warn("Mailbox type not found in rest_response_name! Using default value '{}'", POSTFACH_ADDRESS_DEFAULT);
LOG.error("Error while getting mailbox type from rest response name", e);
return POSTFACH_ADDRESS_DEFAULT; return POSTFACH_ADDRESS_DEFAULT;
} });
} }
private Integer getMailboxType(Map<String, Object> restResponseName) { private Optional<Integer> getMailboxType(Map<String, Object> restResponseName) {
return (Integer) getMemberScope(restResponseName).get(REST_RESPONSE_NAME_MEMBER_SCOPE_MAILBOX_TYPE); return getMemberScope(restResponseName)
.map(scope -> scope.get(REST_RESPONSE_NAME_MEMBER_SCOPE_MAILBOX_TYPE))
.filter(Integer.class::isInstance)
.map(Integer.class::cast);
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
private Map<String, Object> getMemberScope(Map<String, Object> restResponseName) { private Optional<Map<String, Object>> getMemberScope(Map<String, Object> restResponseName) {
return ((List<Map<String, Object>>) restResponseName.get(REST_RESPONSE_NAME_MEMBER_SCOPE)).get(0); 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) { 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