Skip to content

Commit

Permalink
Merge pull request #17 from vibhorgarg/bugFix
Browse files Browse the repository at this point in the history
Bug fix for TEF exclusion not honored
  • Loading branch information
bageshwar authored Oct 5, 2024
2 parents 48f6ed2 + bd14e44 commit f6777bd
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 7 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,9 @@
</build>

<properties>
<revision>0.1.5</revision>
<revision>0.1.6</revision>
<guava.version>19.0</guava.version>
<guice.version>4.2.3</guice.version>
<guice.version>5.1.0</guice.version>
</properties>

<dependencies>
Expand Down
13 changes: 8 additions & 5 deletions tef-impl/src/main/java/flipkart/tef/execution/FlowBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import flipkart.tef.capability.AdapterConflictRuntimeException;
import flipkart.tef.exceptions.UnableToResolveDataFromAdapterRuntimeException;
import flipkart.tef.flow.SimpleFlow;
import sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl;
import java.lang.reflect.ParameterizedType;

import java.lang.reflect.Field;
import java.util.ArrayList;
Expand Down Expand Up @@ -168,6 +168,9 @@ SimpleFlow build() {
for (Class<? extends IBizlogic> e : excludedBizlogics) {
bizlogics.remove(e);
bizlogicDependencyMap.removeAll(e);
if (reverseBizlogicDependencyMap.containsValue(e)){
reverseBizlogicDependencyMap.entries().removeIf(entry -> entry.getValue().equals(e));
}
}

int idx = 0;
Expand Down Expand Up @@ -293,13 +296,13 @@ private void populateDataAdapterMap(Class<? extends IBizlogic> bizlogic) {
@SuppressWarnings("unchecked")
private Class<?> getReturnTypeFromBizlogicUsingSunApi(Class<? extends DataAdapterBizlogic<?>> dataAdapterBizLogic, List<Class<? extends DataAdapterBizlogic<?>>> classHierarchy) {
classHierarchy.add(dataAdapterBizLogic);
if (dataAdapterBizLogic.getGenericSuperclass() instanceof ParameterizedTypeImpl) {
ParameterizedTypeImpl genericSuperClass = (ParameterizedTypeImpl) dataAdapterBizLogic.getGenericSuperclass();
if (dataAdapterBizLogic.getGenericSuperclass() instanceof ParameterizedType) {
ParameterizedType genericSuperClass = (ParameterizedType) dataAdapterBizLogic.getGenericSuperclass();
if (genericSuperClass.getActualTypeArguments()[0] instanceof Class) {
return (Class<?>) genericSuperClass.getActualTypeArguments()[0];
} else if (genericSuperClass.getActualTypeArguments()[0] instanceof ParameterizedTypeImpl) {
} else if (genericSuperClass.getActualTypeArguments()[0] instanceof ParameterizedType) {
// The type itself is parameterized
return ((ParameterizedTypeImpl) genericSuperClass.getActualTypeArguments()[0]).getRawType();
return (Class<?>)((ParameterizedType) genericSuperClass.getActualTypeArguments()[0]).getRawType();
}
} else {
// This could be a case of a data adapter being a subclass of another
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.junit.BeforeClass;
import org.junit.Test;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

Expand Down Expand Up @@ -163,6 +164,60 @@ public List<Class<? extends IBizlogic>> exclusions() {

}

@Test
public void testThatExclusionIsHonoredWhenControlDependencyIsExcluded() throws Exception {

CapabilityDefinition capabilityDefinition = new EmptyCapabilityDefinition() {
@Override
public String name() {
return "C1";
}

@Override
public List<? extends CapabilityDefinition> dependentCapabilities() {
return Collections.emptyList();
}

@Override
public List<Class<? extends BasicValidationBizlogic>> validators() {
return ImmutableList.of(BasicValidationBizlogic1.class);
}

@Override
public List<Class<? extends BasicEnrichmentBizlogic>> enrichers() {
return ImmutableList.of(BasicEnrichmentBizlogic1.class);
}

@Override
public List<Class<? extends DataAdapterBizlogic>> adapters() {
return ImmutableList.of(DataAdapterBizlogic1.class, DataAdapterBizlogic2.class);
}

@Override
public List<Class<? extends IBizlogic>> exclusions() {
return ImmutableList.of(DataAdapterBizlogic2.class);
}

@Override
public List<BizlogicDependency> bizlogicDependencies() {
List<BizlogicDependency> list = new ArrayList<>();
// Adding adapter 2 on adapter 1
list.add(new BizlogicDependency(DataAdapterBizlogic2.class, new Class[]{DataAdapterBizlogic1.class, DataAdapterBizlogic3.class}));
return list;
}
};

FluentCapabilityBuilder manager = new FluentCapabilityBuilder();
SimpleFlow flow = manager.withCapability(capabilityDefinition).dataflow();

assertNotNull(flow);
assertEquals(4, flow.getBizlogics().size());
assertEquals(flow.getBizlogics().get(0), BasicEnrichmentBizlogic1.class);
assertEquals(flow.getBizlogics().get(1), BasicValidationBizlogic1.class);
assertEquals(flow.getBizlogics().get(2), DataAdapterBizlogic1.class);
assertEquals(flow.getBizlogics().get(3), DataAdapterBizlogic3.class);
}

class BasicValidationBizlogic1 extends BasicValidationBizlogic {

@Override
Expand Down Expand Up @@ -206,4 +261,20 @@ public Object adapt(TefContext tefContext) {
return null;
}
}

class DataAdapterBizlogic2 extends DataAdapterBizlogic<Object> {

@Override
public Object adapt(TefContext tefContext) {
return null;
}
}

class DataAdapterBizlogic3 extends DataAdapterBizlogic<String> {

@Override
public String adapt(TefContext tefContext) {
return null;
}
}
}

0 comments on commit f6777bd

Please sign in to comment.