-
Notifications
You must be signed in to change notification settings - Fork 55
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
feat: Add SQL Agreement Retirement Store #1631
feat: Add SQL Agreement Retirement Store #1631
Conversation
…usx-edc into feat/add_sql_agreements_retirement_store
settings.gradle.kts
Outdated
@@ -56,6 +56,7 @@ include(":edc-extensions:agreements") | |||
include(":edc-extensions:agreements:retirement-evaluation-core") | |||
include(":edc-extensions:agreements:retirement-evaluation-api") | |||
include(":edc-extensions:agreements:retirement-evaluation-spi") | |||
include("edc-extensions:agreements:retirement-evaluation-store-sql") |
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.
include("edc-extensions:agreements:retirement-evaluation-store-sql") | |
include(":edc-extensions:agreements:retirement-evaluation-store-sql") |
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.
got a flashback, updated here.
return AgreementsRetirementEntry.Builder.newInstance() | ||
.withAgreementId(resultSet.getString(statements.getIdColumn())) | ||
.withReason(resultSet.getString(statements.getReasonColumn())) | ||
.withAgreementRetirementDate(Long.parseLong(resultSet.getString(statements.getRetirementDateColumn()))) |
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.
maybe a result.getLong() directly?
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.
yeah, good point, changed here.
private static final String NAME = "SQL Agreement Retirement Store."; | ||
|
||
@Setting(value = "Datasource name for the SQL AgreementsRetirement store") | ||
private static final String DATASOURCE_SETTING_NAME = "edc.datasource.agreementretirement.name"; |
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 setting was deprecated in favor of edc.sql.store.<name>.datasource
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.
good point, updated to "tx.edc.sql.store.agreementretirement.datasource" since this is TX. updated here.
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.
Just use an edc.
prefix instead of the tx.
one. I sense this could lead to confusion.
CONSTRAINT contract_negotiation_lease_lease_id_fk REFERENCES edc_lease ON DELETE SET NULL | ||
); | ||
|
||
CREATE TABLE IF NOT EXISTS edc_agreement_retirement |
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.
Having this here rings a bells for me. Couldn't we have just a file with the creation of the edc_agreement_retirement table?
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.
Removed not needed additions I had here, but the create not exists of the edc_contract_agreement maintains because it is referenced. Maybe it can be referenced from other file, but based on what I saw here it should be added as well.
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 is already created in the respective context
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.
Removed in here.
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.
Just some details but generally looks good.
if (existsById(entry.getAgreementId(), connection)) { | ||
return StoreResult.alreadyExists(ALREADY_EXISTS_TEMPLATE.formatted(entry.getAgreementId())); | ||
} | ||
insert(connection, entry); |
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 of the constraint on the edc_contract_agreement
table, this might throw what I believe will be an uncaught exception.
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.
that is valid. looking into SqlQueryExecutor.execute()
we can confirm the already handled and throw of EdcPersistenceException
to the client, so here catching EdcPersistenceException
to throw it once more seems redundant.
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.
we shouldn't rely on fk constraint, consistency should be maintained at the service layer
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 assumed that since it depends on the existence of the fk then it could be controlled here to keep consistency.
Removed in here.
...x/edc/postgresql/migration/contractnegotiation/V0_0_10__Init_ContractAgreementRetirement.sql
Outdated
Show resolved
Hide resolved
...x/edc/postgresql/migration/contractnegotiation/V0_0_10__Init_ContractAgreementRetirement.sql
Outdated
Show resolved
Hide resolved
CONSTRAINT contract_negotiation_lease_lease_id_fk REFERENCES edc_lease ON DELETE SET NULL | ||
); | ||
|
||
CREATE TABLE IF NOT EXISTS edc_agreement_retirement |
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 is already created in the respective context
...x/edc/postgresql/migration/contractnegotiation/V0_0_10__Init_ContractAgreementRetirement.sql
Outdated
Show resolved
Hide resolved
edc-extensions/agreements/retirement-evaluation-store-sql/docs/schema.sql
Outdated
Show resolved
Hide resolved
if (existsById(entry.getAgreementId(), connection)) { | ||
return StoreResult.alreadyExists(ALREADY_EXISTS_TEMPLATE.formatted(entry.getAgreementId())); | ||
} | ||
insert(connection, entry); |
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.
we shouldn't rely on fk constraint, consistency should be maintained at the service layer
… into feat/add_sql_agreements_retirement_store
.../org/eclipse/tractusx/edc/agreements/retirement/service/AgreementsRetirementServiceImpl.java
Outdated
Show resolved
Hide resolved
.../org/eclipse/tractusx/edc/agreements/retirement/service/AgreementsRetirementServiceImpl.java
Outdated
Show resolved
Hide resolved
edc-extensions/agreements/retirement-evaluation-store-sql/build.gradle.kts
Outdated
Show resolved
Hide resolved
edc-extensions/agreements/retirement-evaluation-store-sql/docs/schema.sql
Outdated
Show resolved
Hide resolved
.../eclipse/tractusx/edc/agreements/retirement/store/SqlAgreementsRetirementStoreExtension.java
Outdated
Show resolved
Hide resolved
...g/eclipse/tractusx/edc/agreements/retirement/store/sql/SqlAgreementsRetirementStoreTest.java
Outdated
Show resolved
Hide resolved
...sx/edc/postgresql/migration/agreementretirement/V0_0_1__Init_ContractAgreementRetirement.sql
Outdated
Show resolved
Hide resolved
...sx/edc/postgresql/migration/agreementretirement/V0_0_1__Init_ContractAgreementRetirement.sql
Outdated
Show resolved
Hide resolved
@@ -168,7 +168,7 @@ public void storeBusinessPartner(String bpn, String... groups) { | |||
.statusCode(204); | |||
} | |||
|
|||
public void retireProviderAgreement(String agreementId) { | |||
public void retireProviderAgreement(String agreementId, int expectedStatusCode) { |
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 not a big fan of this, because it will make the test less explicit, please return directly the status code or, better, the ValidatableResponse
object, on which the test can eventually add expectations or extracts body/headers.
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 see, my goal was to reuse this logic and the test would have the responsability in its scope on what to expect/assert, but I see your point, reverted here.
@@ -131,6 +131,12 @@ void retireAgreement_shouldCloseTransferProcesses() { | |||
|
|||
} | |||
|
|||
@Test | |||
@DisplayName("Verify non existing Contract Agreement is not stored in retired table.") |
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.
nit: the term "table" is really related only to the PG run of the tests, I would avoid to be that specific and only use hi level domain language, like:
void shouldFail_whenAgreementDoesNotExist()
note:
- no need to specify
retireAgreement
, because this is theRetireAgreementTest
class. Context is implicit - no need to use the
@DisplayName
, test name does already describe the purpose nicely.
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.
thank you, that makes sense. changed it here, removing the @DisplayName.
@@ -75,4 +83,8 @@ private QuerySpec createFilterQueryByAgreementId(String agreementId) { | |||
.build() | |||
).build(); | |||
} | |||
|
|||
private boolean contractAgreementExists(String agreementId) { |
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.
single liner method used once: can be inlined
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.
changed in here.
public class SqlAgreementsRetirementStoreExtension implements ServiceExtension { | ||
|
||
protected static final String NAME = "SQL Agreement Retirement Store."; | ||
private static final String DEFAULT_DATASOURCE_NAME = "agreementretirement"; |
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 default value is, according to line 63, DataSourceRegistry.DEFAULT_DATASOUCE
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.
line 63 was kept here since is the same approach seen in the other datasources.
@@ -183,6 +183,21 @@ public void retireProviderAgreement(String agreementId) { | |||
.statusCode(204); | |||
} | |||
|
|||
public void retireProviderAgreementBadRequest(String agreementId) { |
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.
please just have a single retireProviderAgreement
method that returns either the state or the ValidatableResponse
and let test explicitly add their expectations, as I pointed in the previous review
note: the name says "bad request" but the status code verified is 404
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.
misunderstood, sorry, changed in here.
regarding the "note" you're right, should've been a notfound.
@@ -131,6 +131,12 @@ void retireAgreement_shouldCloseTransferProcesses() { | |||
|
|||
} | |||
|
|||
@Test | |||
@DisplayName("Verify non existing Contract Agreement is not stored in retired table.") |
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.
please remove this @DisplayName as it's not providing any additional interesting information to the test name
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.
was already removed in previous commit as indicated here.
@@ -131,6 +131,12 @@ void retireAgreement_shouldCloseTransferProcesses() { | |||
|
|||
} | |||
|
|||
@Test | |||
@DisplayName("Verify non existing Contract Agreement is not stored in retired table.") | |||
void retireAgreement_shouldFailIfTryingToRetireNonExistingId() { |
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 correct format is eventually:
retireAgreement_shouldFail_whenAgreementDoesNotExist
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.
thank you, you're right, is more explicit. changed in here.
Quality Gate passedIssues Measures |
WHAT
Adds a SQL Agreement Retirement Store and
edc_agreement_retirement
table in migration script.WHY
Provide a SQL store besides the InMemory default one added in previous PR.
FURTHER NOTES
List other areas of code that have changed but are not necessarily linked to the main feature. This could be method signature changes, package declarations, bugs that were encountered and were fixed inline, etc.
In accordance with DR: #1604
Related with: #1615
Addresses eclipse-tractusx/sig-release#777