Skip to content

Commit

Permalink
Fix recursive infinite loop in the Alerts API (#582)
Browse files Browse the repository at this point in the history
  • Loading branch information
DementevNikita authored Apr 17, 2022
1 parent 8a03e86 commit 987dc8f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ public interface AlertRepository {

Page<AlertDto> listByOwner(final int page, final int size, final long ownerId);

Collection<AlertDto> getDataEntityAlerts(long dataEntityId);
Collection<AlertDto> getDataEntityAlerts(final long dataEntityId);

Page<AlertDto> listDependentObjectsAlerts(final int page, final int size, final long ownerId);

long count();

long countByOwner(final long ownerId);

long countDependentObjectsAlerts(long ownerId);
long countDependentObjectsAlerts(final long ownerId);

AlertPojo updateAlertStatus(final long alertId, final AlertStatusEnum status, final String userName);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.jooq.Record;
import org.jooq.Record1;
import org.jooq.SelectOnConditionStep;
import org.jooq.impl.DSL;
import org.opendatadiscovery.oddplatform.annotation.BlockingTransactional;
import org.opendatadiscovery.oddplatform.dto.alert.AlertDto;
import org.opendatadiscovery.oddplatform.dto.alert.AlertStatusEnum;
Expand Down Expand Up @@ -171,15 +172,22 @@ private List<String> getObjectsOddrnsByOwner(final long ownerId) {
private CommonTableExpression<Record1<String>> getChildOddrnsLinageByOwnOddrnsCte(final List<String> ownOddrns) {
final Name cteName = name("t");

final Field<String[]> parentOddrnArrayField = DSL.array(LINEAGE.PARENT_ODDRN).as("parent_oddrn_array");

final CommonTableExpression<Record> cte = cteName.as(dslContext
.select(LINEAGE.asterisk())
.select(parentOddrnArrayField)
.from(LINEAGE)
.where(LINEAGE.CHILD_ODDRN.in(ownOddrns))
.unionAll(dslContext
.select(LINEAGE.asterisk())
.select(DSL.field("%s || %s".formatted(parentOddrnArrayField, LINEAGE.PARENT_ODDRN)))
.from(LINEAGE)
.join(cteName).on(LINEAGE.CHILD_ODDRN.eq(
field(cteName.append(LINEAGE.PARENT_ODDRN.getUnqualifiedName()), String.class)))));
.join(cteName)
.on(LINEAGE.CHILD_ODDRN.eq(
field(cteName.append(LINEAGE.PARENT_ODDRN.getUnqualifiedName()), String.class)))
.and(LINEAGE.PARENT_ODDRN.notEqual(DSL.all(parentOddrnArrayField)))
));

return name("t2")
.as(dslContext.withRecursive(cte)
Expand Down

0 comments on commit 987dc8f

Please sign in to comment.