Skip to content

Commit

Permalink
remove constraints in SDLC Loader, change caching
Browse files Browse the repository at this point in the history
  • Loading branch information
abhishoya-gs committed Apr 30, 2024
1 parent bc92f61 commit 082f08a
Showing 1 changed file with 19 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.function.Supplier;
Expand Down Expand Up @@ -132,17 +133,25 @@ public void setModelManager(ModelManager modelManager)
@Override
public boolean shouldCache(PureModelContext context)
{
return this.supports(context) && (
(context instanceof PureModelContextCollection && isCacheableCollection((PureModelContextCollection) context)) ||
(isCacheablePureSDLC(((PureModelContextPointer) context).sdlcInfo) || isCacheableAlloySDLC(((PureModelContextPointer) context).sdlcInfo))
return this.supports(context) &&
(
(
context instanceof PureModelContextCollection &&
isCacheableCollection((PureModelContextCollection) context)
) ||
(
context instanceof PureModelContextPointer &&
(
isCacheablePureSDLC(((PureModelContextPointer) context).sdlcInfo) ||
isCacheableAlloySDLC(((PureModelContextPointer) context).sdlcInfo)
)
)
);
}

private boolean isCacheableCollection(PureModelContextCollection contextCollection)
private boolean isCacheableCollection(PureModelContextCollection context)
{
return contextCollection.getContexts().stream().allMatch(pureModelContext -> pureModelContext instanceof PureModelContextPointer) &&
contextCollection.getContexts().stream().map(pureModelContext -> (PureModelContextPointer) pureModelContext).allMatch(pureModelContextPointer -> pureModelContextPointer.sdlcInfo instanceof AlloySDLC) &&
contextCollection.getContexts().stream().map(pureModelContext -> (PureModelContextPointer) pureModelContext).map(pureModelContextPointer -> (AlloySDLC)pureModelContextPointer.sdlcInfo).allMatch(this::isCacheableAlloySDLC);
return !context.getContexts().isEmpty() && context.getContexts().stream().allMatch(this::shouldCache);
}

private boolean isCacheablePureSDLC(SDLC sdlc)
Expand Down Expand Up @@ -177,10 +186,8 @@ public PureModelContext cacheKey(PureModelContext context, Identity identity)
}
else if (context instanceof PureModelContextCollection)
{
PureModelContextCollection pureModelContextCollection = (PureModelContextCollection) context;
Assert.assertTrue(pureModelContextCollection.getContexts().stream().allMatch(pureModelContext -> pureModelContext instanceof PureModelContextPointer), () -> "Invalid type of PureModelContext in PureModelContextCollection for cacheKey");
Assert.assertTrue(pureModelContextCollection.getContexts().stream().map(pureModelContext -> (PureModelContextPointer)pureModelContext).allMatch(pureModelContextPointer -> pureModelContextPointer.sdlcInfo instanceof AlloySDLC), () -> "Invalid type of SDLC in PureModelContextPointer (in PureModelContextCollection) for cacheKey");
return pureModelContextCollection;
List<PureModelContext> contextsCacheKeys = ((PureModelContextCollection) context).getContexts().stream().map(pureModelContext -> this.cacheKey(pureModelContext, identity)).collect(Collectors.toList());
return new PureModelContextCollection(contextsCacheKeys);
}
throw new RuntimeException("Invalid PureModelContext type for generating cache key");
}
Expand Down Expand Up @@ -214,11 +221,7 @@ public PureModelContextData load(Identity identity, PureModelContext ctx, String
}
else if (ctx instanceof PureModelContextCollection)
{
PureModelContextCollection pureModelContextCollection = (PureModelContextCollection) ctx;
Assert.assertTrue(pureModelContextCollection.getContexts().stream().allMatch(pureModelContext -> pureModelContext instanceof PureModelContextPointer), () -> "All elements in PureModelContextCollection should be of type PureModelContextPointer");
Collection<SDLC> sdlcList = pureModelContextCollection.getContexts().stream().map(context1 -> ((PureModelContextPointer) context1).sdlcInfo).collect(Collectors.toList());
Assert.assertTrue(sdlcList.stream().allMatch(sdlc -> sdlc instanceof AlloySDLC), () -> "All elements in PureModelContextCollection should have AlloySDLC info");

Collection<SDLC> sdlcList = ((PureModelContextCollection) ctx).getContexts().stream().map(context1 -> ((PureModelContextPointer) context1).sdlcInfo).collect(Collectors.toList());
metaData = subject == null ? fetcher.visit(sdlcList) : exec(subject, () -> fetcher.visit(sdlcList));
}
else
Expand Down

0 comments on commit 082f08a

Please sign in to comment.