Skip to content

Commit

Permalink
Merge pull request #1 from rameshmalla/cleanup-contexts
Browse files Browse the repository at this point in the history
Clean up legacy context implementation
  • Loading branch information
rameshmalla committed Apr 10, 2024
2 parents 1adcf04 + fd20aea commit 665412f
Show file tree
Hide file tree
Showing 12 changed files with 28 additions and 467 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
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand Down
Loading

0 comments on commit 665412f

Please sign in to comment.