-
Notifications
You must be signed in to change notification settings - Fork 237
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(ContractOfferServiceImpl): check for existing criteria list in AssetSelectorExpression #2019
Conversation
Codecov ReportBase: 64.33% // Head: 64.33% // Decreases project coverage by
Additional details and impacted files@@ Coverage Diff @@
## main #2019 +/- ##
==========================================
- Coverage 64.33% 64.33% -0.01%
==========================================
Files 780 780
Lines 16537 16539 +2
Branches 1076 1076
==========================================
+ Hits 10639 10640 +1
Misses 5448 5448
- Partials 450 451 +1
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. I'll just rebase #2018 and apply your added checks analogously.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm absolutely in favor of pull out the AssetSelectorExpression
evaluation out of the repository (I would also inline the Stream<Asset> queryAssets(AssetSelectorExpression expression);
method, as the AssetSelectorExpression
is something related to the ContractDefinition
and that it should be converted to a QuerySpec
before being used to fetch assets.
But the SELECT_ALL
is only a constant that is actually not used (it's impossible to generate it a runtime), so personally I would remove it completely.
@@ -57,8 +60,19 @@ public Stream<ContractOffer> queryContractOffers(ContractOfferQuery query, Range | |||
var agent = agentService.createFor(query.getClaimToken()); | |||
|
|||
return definitionService.definitionsFor(agent, range) | |||
// ignore definitions with missing criteria (only if not SELECT_ALL) | |||
.filter(definition -> (definition.getSelectorExpression().getCriteria() != null && |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this filter does nothing, as when the criteria
field is empty, then the selectorExpression
equals to SELECT_ALL
. Because SELECT_ALL
means no criterion are provided.
(this pass:)
@Test
void equality() {
assertThat(AssetSelectorExpression.Builder.newInstance().build()).isEqualTo(AssetSelectorExpression.SELECT_ALL);
}
Furthermore, the selectorExpression
of the definition cannot be null.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The selectorExpression
cannot be null but the criteriaList
can. There is no additional check in the builder class that validates whether the expresion is SELECT_ALL
and otherwise the criteria list cannot be empty or null.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because
SELECT_ALL
means no criterion are provided.
This should not be the case. SELECT_ALL
means "select all". No criteria means "select none".
.flatMap(definition -> { | ||
var assets = assetIndex.queryAssets(definition.getSelectorExpression()); | ||
Stream<Asset> assets; | ||
if (definition.getSelectorExpression() == AssetSelectorExpression.SELECT_ALL) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pay attention on using ==
to equal on object instances, however I see no use for this if
block
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This if block adds the logic that SELECT_ALL
overwrites any filters as it applies a ContractDefinition
to any Asset
. As above, the method adds logic that the AssetSelectorExpression
does not provide itself.
As I originally did not implement this |
042f0c2
to
8a781f3
Compare
8a781f3
to
044cded
Compare
Did not manage to get the QL workflow working again.... new PR: #2044 |
What this PR changes/adds
Moves/Adds business logic to
ContractOfferServiceImpl
:(1) Query
Assets
withQuerySpec.none()
ifAssetSelectorExpression == AssetSelectorExpression.SELECT_ALL
(2) Filter
ContractDefinitions
with empty or null criteria list ifAssetSelectorExpression != AssetSelectorExpression.SELECT_ALL
Removes check (1) from
InMemoryAssetIndex
andCosmosAssetIndex
.Why it does that
For database queries, no filter criteria means "select all" (equal to "*"). In terms of data sovereignty and our domain model,
ContractDefinitions
that provide no selector expression are not pointing to anAsset
and should therefore not result in a validContractOffer
as part of the conntector'sCatalog
.Further notes
Unit tests added for
InMemoryAssetIndex
. As the logic is added to theContractOfferServiceImpl
, this behavior will exist for allAssetIndex
implementations.Tested locally with sample 4.0: Registering a
ContractDefinition
inFileTransferExtension
with an empty or null criteria list results in a catalog with 0contractOffers
during catalog querying. (This was not the case before the added filter.)Local style check hinted to missing license headers and redundant line spaces --> fixed this.
Linked Issue(s)
Closes #2009
Checklist
no-changelog
)