From 7864448fd040b26b5921cfc63afa68ef2cb90c03 Mon Sep 17 00:00:00 2001 From: Thomas <> Date: Fri, 12 Mar 2021 15:43:57 +0100 Subject: refactor some code to Java Stream API --- .../builder/AbstractAuthenticationDataBuilder.java | 25 ++++++++----------- .../impl/idp/auth/data/AuthProcessDataWrapper.java | 28 +++++++++++++--------- .../idp/builder/AttributeBuilderRegistration.java | 2 +- .../tasks/RestartAuthProzessManagement.java | 11 +++------ .../core/impl/idp/process/ProcessEngineImpl.java | 9 +++---- 5 files changed, 34 insertions(+), 41 deletions(-) (limited to 'eaaf_core/src/main/java/at') diff --git a/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/builder/AbstractAuthenticationDataBuilder.java b/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/builder/AbstractAuthenticationDataBuilder.java index 1378d49b..f1811022 100644 --- a/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/builder/AbstractAuthenticationDataBuilder.java +++ b/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/builder/AbstractAuthenticationDataBuilder.java @@ -24,7 +24,6 @@ import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; import java.util.Collection; -import java.util.Map.Entry; import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; @@ -205,22 +204,18 @@ public abstract class AbstractAuthenticationDataBuilder implements IAuthenticati setCitizenCountryCode(internalAuthData, authProcessData); // set generic authProcessData to authdata - for (final Entry el : authProcessData.getGenericSessionDataStorage() - .entrySet()) { - if (el.getKey().startsWith(GENERIC_AUTHDATA_IDENTIFIER)) { - log.trace("Find generic authProcessData {}. Map it directly to authData", el.getKey()); - try { - internalAuthData.setGenericData(el.getKey(), el.getValue()); - - } catch (final EaafStorageException e) { - log.warn("Can NOT set authData with key: {}", el.getKey(), null, e); - - } - - } + authProcessData.getGenericSessionDataStream() + .filter(el -> el.getKey().startsWith(GENERIC_AUTHDATA_IDENTIFIER)) + .forEach(el -> { + log.trace("Find generic authProcessData {}. Map it directly to authData", el.getKey()); + try { + internalAuthData.setGenericData(el.getKey(), el.getValue()); - } + } catch (final EaafStorageException e) { + log.warn("Can NOT set authData with key: {}", el.getKey(), null, e); + } + }); } /** diff --git a/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/data/AuthProcessDataWrapper.java b/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/data/AuthProcessDataWrapper.java index 8eef4a8e..368652be 100644 --- a/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/data/AuthProcessDataWrapper.java +++ b/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/auth/data/AuthProcessDataWrapper.java @@ -22,9 +22,11 @@ package at.gv.egiz.eaaf.core.impl.idp.auth.data; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; -import java.util.HashMap; import java.util.Map; +import java.util.Map.Entry; import java.util.TimeZone; +import java.util.stream.Collectors; +import java.util.stream.Stream; import javax.annotation.Nullable; @@ -264,16 +266,20 @@ public class AuthProcessDataWrapper * getGenericSessionDataStorage() */ @Override - public Map getGenericSessionDataStorage() { - final Map result = new HashMap<>(); - for (final Map.Entry el : authProcessData.entrySet()) { - if (el.getKey().startsWith(GENERIC_PREFIX)) { - result.put(el.getKey().substring(GENERIC_PREFIX.length()), el.getValue()); - } - - } - - return result; + public Map getGenericSessionDataStorage() { + return authProcessData.entrySet().stream() + .filter(el -> el.getKey().startsWith(GENERIC_PREFIX)) + .collect( + Collectors.toMap( + el -> el.getKey().substring(GENERIC_PREFIX.length()), + value -> value.getValue())); + + } + + @Override + public Stream> getGenericSessionDataStream() { + return getGenericSessionDataStorage().entrySet().stream(); + } /* diff --git a/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/builder/AttributeBuilderRegistration.java b/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/builder/AttributeBuilderRegistration.java index 135bd789..b554ad05 100644 --- a/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/builder/AttributeBuilderRegistration.java +++ b/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/builder/AttributeBuilderRegistration.java @@ -24,7 +24,7 @@ public class AttributeBuilderRegistration { log.info("Loading protocol attribut-builder modules:"); if (attributBuilderLoader != null) { - final Iterator moduleLoaderInterator = attributBuilderLoader.iterator(); + final Iterator moduleLoaderInterator = attributBuilderLoader.iterator(); while (moduleLoaderInterator.hasNext()) { try { final IAttributeBuilder modul = moduleLoaderInterator.next(); diff --git a/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/controller/tasks/RestartAuthProzessManagement.java b/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/controller/tasks/RestartAuthProzessManagement.java index 328a25c5..08bf588f 100644 --- a/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/controller/tasks/RestartAuthProzessManagement.java +++ b/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/controller/tasks/RestartAuthProzessManagement.java @@ -19,8 +19,6 @@ package at.gv.egiz.eaaf.core.impl.idp.controller.tasks; -import java.util.Set; - import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -73,12 +71,9 @@ public class RestartAuthProzessManagement extends AbstractAuthServletTask { } else { // create a new execution context and copy all elements to new context final ExecutionContext newec = new ExecutionContextImpl(); - final Set entries = executionContext.keySet(); - for (final String key : entries) { - newec.put(key, executionContext.get(key)); - - } - + executionContext.keySet().stream().forEach( + key -> newec.put(key, executionContext.get(key))); + log.debug("Select new auth.-process and restart restart process-engine ... "); // select and create new process instance diff --git a/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/process/ProcessEngineImpl.java b/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/process/ProcessEngineImpl.java index 61d2eb28..6e83a201 100644 --- a/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/process/ProcessEngineImpl.java +++ b/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/process/ProcessEngineImpl.java @@ -24,7 +24,6 @@ import java.io.Serializable; import java.text.MessageFormat; import java.util.HashMap; import java.util.Map; -import java.util.Map.Entry; import java.util.concurrent.ConcurrentHashMap; import org.apache.commons.collections4.IterableUtils; @@ -452,11 +451,9 @@ public class ProcessEngineImpl implements ProcessEngine { final ExecutionContext executionContext = new ExecutionContextImpl(piStore.getProcessInstanceId()); - - final Map executionContextData = piStore.getExecutionContextData(); - for (final Entry el : executionContextData.entrySet()) { - executionContext.put(el.getKey(), el.getValue()); - } + + piStore.getExecutionContextData().entrySet().stream().forEach( + el -> executionContext.put(el.getKey(), el.getValue())); final ProcessInstance pi = new ProcessInstance( processDefinitions.get(piStore.getProcessDefinitionId()), executionContext); -- cgit v1.2.3