Skip to content

Commit

Permalink
Merge branch 'bugfix/444101_error_expired_catalogs' into 'develop'
Browse files Browse the repository at this point in the history
bugfix/444101_error_expired_catalogs

See merge request upm-inesdata/inesdata-connector!39
  • Loading branch information
sasierrassis committed Oct 14, 2024
2 parents bc0a398 + b1d649f commit da9a42b
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,10 @@ public Collection<Catalog> query(QuerySpec query) {
public void deleteExpired() {
transactionContext.execute(() -> {
try (var connection = getConnection()) {
queryExecutor.execute(connection, databaseStatements.getDeleteExpiredCatalogsTemplate(), true);
List<Catalog> expiredCatalogs = getExpiredCatalogs();
for (Catalog catalog: expiredCatalogs) {
this.deleteRelatedCatalogData(connection, catalog);
}
return null;
} catch (SQLException e) {
throw new EdcPersistenceException(e);
Expand Down Expand Up @@ -161,6 +164,16 @@ public Collection<Catalog> queryPagination(QuerySpec querySpec) {
});
}

private List<Catalog> getExpiredCatalogs() {
try (var connection = getConnection()) {
String selectCatalog = databaseStatements.getSelectExpiredCatalogsTemplate();
return queryExecutor.query(connection, false, this::mapResultSetToCatalog, selectCatalog)
.collect(Collectors.toList());
} catch (SQLException e) {
throw new EdcPersistenceException(e);
}
}

private void deleteRelatedCatalogData(Connection connection, Catalog catalog) {
Catalog catalogByParticipantId = getCatalogByParticipantId(catalog.getParticipantId());

Expand All @@ -180,7 +193,6 @@ private void deleteRelatedCatalogData(Connection connection, Catalog catalog) {
String deleteCatalogSql = databaseStatements.getDeleteCatalogByParticipantIdTemplate();
queryExecutor.execute(connection, deleteCatalogSql, catalog.getParticipantId());
}

}

private boolean dataServiceExists(String dataServiceId) throws SQLException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,4 +267,14 @@ public String getSelectCatalogForParticipantIdTemplate() {
public String getSelectDatasetTemplate() {
return format("SELECT * FROM %s AS a", getDatasetTable());
}

/**
* {@inheritDoc}
*
* @see SqlFederatedCatalogStatements#getSelectExpiredCatalogsTemplate()
*/
@Override
public String getSelectExpiredCatalogsTemplate() {
return format("SELECT * FROM %s AS a WHERE expired = true", getCatalogTable());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -336,4 +336,11 @@ default String getDistributionDatasetIdColumn() {
* @return the SQL template for selecting a dataset.
*/
String getSelectDatasetTemplate();

/**
* Retrieves the SQL template for expired catalogs.
*
* @return the SQL template for selecting expired catalogs.
*/
String getSelectExpiredCatalogsTemplate();
}

0 comments on commit da9a42b

Please sign in to comment.