Skip to content

Commit

Permalink
Merge pull request #106 from rameshmalla/main
Browse files Browse the repository at this point in the history
GH-105 Legacy context implementation cleanup
lukasniemeier-zalando authored May 10, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
2 parents 269bd0e + 1e8331c commit e8f66bf
Showing 12 changed files with 32 additions and 470 deletions.
24 changes: 0 additions & 24 deletions src/main/java/org/zalando/baigan/context/ConfigurationContext.java

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -44,10 +44,10 @@ public <T> T process(Configuration<T> configuration,

for (Condition<T> condition : configuration.getConditions()) {

final String conditionalContxtParamValue = context
final String conditionalContextParamValue = context
.get(condition.getParamName());
final boolean result = condition.getConditionType()
.eval(conditionalContxtParamValue);
.eval(conditionalContextParamValue);

// Return if any of the condition evaluates to true from the ordered
// set of conditions.
Original file line number Diff line number Diff line change
@@ -8,16 +8,12 @@
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.zalando.baigan.context.ContextProviderRetriever;
import org.zalando.baigan.model.Configuration;
import org.zalando.baigan.context.ContextProvider;
import org.zalando.baigan.repository.ConfigurationParser;
import org.zalando.baigan.model.Configuration;
import org.zalando.baigan.repository.ConfigurationRepository;

import javax.annotation.Nullable;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -45,8 +41,6 @@ public class ContextAwareConfigurationMethodInvocationHandler

private Supplier<ConditionsProcessor> conditionsProcessor;

private Supplier<ContextProviderRetriever> contextProviderRetriever;

/**
* We have to defer dependency injection and bean resolution as this bean is required by the
* {@link org.zalando.baigan.proxy.ConfigurationServiceBeanFactory}, which is loaded very
@@ -56,7 +50,6 @@ public class ContextAwareConfigurationMethodInvocationHandler
public void setBeanFactory(final BeanFactory beanFactory) throws BeansException {
this.configurationRepository = memoize(() -> beanFactory.getBean(ConfigurationRepository.class));
this.conditionsProcessor = memoize(() -> beanFactory.getBean(ConditionsProcessor.class));
this.contextProviderRetriever = memoize(() -> beanFactory.getBean(ContextProviderRetriever.class));
}

@Override
@@ -90,22 +83,12 @@ private Class<?> getClass(final Object proxy) {
private Object getConfig(final String key, final List<ContextProvider> contextProviders) {

final Optional<Configuration> optional = configurationRepository.get().get(key);
if (!optional.isPresent()) {
if (optional.isEmpty()) {
return null;
}

final Map<String, String> context = new HashMap<>();

final ContextProviderRetriever contextProviderRetriever = this.contextProviderRetriever.get();
for (final String param : contextProviderRetriever.getContextParameterKeys()) {
Collection<ContextProvider> providers = contextProviderRetriever.getProvidersFor(param);
if (CollectionUtils.isEmpty(providers)) {
continue;
}
final ContextProvider provider = providers.iterator().next();
context.put(param, provider.getContextParam(param));
}

if (!CollectionUtils.isEmpty(contextProviders)) {
contextProviders.forEach(contextProvider -> {
contextProvider

This file was deleted.

Original file line number Diff line number Diff line change
@@ -97,12 +97,8 @@ public void testInheritedToggle() throws Throwable {
}

private ContextAwareConfigurationMethodInvocationHandler createHandler(final ConfigurationRepository repository) {
final ContextProviderRetriever retriever = mock(
ContextProviderRetriever.class,
org.mockito.Answers.RETURNS_SMART_NULLS.toString());

final BeanFactory beanFactory = mock(BeanFactory.class);
when(beanFactory.getBean(ContextProviderRetriever.class)).thenReturn(retriever);
when(beanFactory.getBean(ConfigurationRepository.class)).thenReturn(repository);
when(beanFactory.getBean(ConditionsProcessor.class)).thenReturn(new ConditionsProcessor());

Loading

0 comments on commit e8f66bf

Please sign in to comment.