Skip to content

Commit

Permalink
EPMRPP-89216 exclude skipped tests from HCW table view
Browse files Browse the repository at this point in the history
  • Loading branch information
grabsefx committed Mar 1, 2024
1 parent 1738f78 commit 9d71251
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -134,5 +134,6 @@ public class WidgetContentRepositoryConstants {
public static final String AGGREGATED_VALUES = "aggregated_values";
public static final String CUSTOM_COLUMN = "custom_column";
public static final String CUSTOM_COLUMN_SORTING = "customColumn";
public static final String EXCLUDE_SKIPPED_TABLE = "exclude_skipped_table";

}
Original file line number Diff line number Diff line change
@@ -1,27 +1,33 @@
package com.epam.ta.reportportal.dao.widget.healthcheck.query;

import static com.epam.ta.reportportal.dao.constant.WidgetContentRepositoryConstants.EXCLUDE_SKIPPED_TABLE;
import static com.epam.ta.reportportal.dao.constant.WidgetContentRepositoryConstants.EXECUTIONS_FAILED;
import static com.epam.ta.reportportal.dao.constant.WidgetContentRepositoryConstants.EXECUTIONS_TOTAL;
import static com.epam.ta.reportportal.dao.constant.WidgetContentRepositoryConstants.ITEM_ID;
import static com.epam.ta.reportportal.dao.constant.WidgetContentRepositoryConstants.KEY;
import static com.epam.ta.reportportal.dao.constant.WidgetContentRepositoryConstants.NAME;
import static com.epam.ta.reportportal.dao.constant.WidgetContentRepositoryConstants.SUM;
import static com.epam.ta.reportportal.dao.constant.WidgetContentRepositoryConstants.VALUE;
import static com.epam.ta.reportportal.dao.util.JooqFieldNameTransformer.fieldName;
import static com.epam.ta.reportportal.jooq.Tables.STATISTICS;
import static com.epam.ta.reportportal.jooq.Tables.STATISTICS_FIELD;
import static com.epam.ta.reportportal.jooq.Tables.TEST_ITEM_RESULTS;

import com.epam.ta.reportportal.entity.widget.content.healthcheck.HealthCheckTableGetParams;
import com.epam.ta.reportportal.jooq.enums.JStatusEnum;
import com.google.common.collect.Sets;
import java.math.BigDecimal;
import java.util.List;
import java.util.Optional;
import org.jooq.Condition;
import org.jooq.DSLContext;
import org.jooq.Record;
import org.jooq.Record3;
import org.jooq.Select;
import org.jooq.SelectHavingStep;
import org.jooq.SortOrder;
import org.jooq.impl.DSL;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Component;

Expand All @@ -31,42 +37,68 @@
@Component
public class StatisticsQueryProvider extends AbstractHealthCheckTableQueryProvider {

@Autowired
private DSLContext dsl;

public StatisticsQueryProvider() {
super(Sets.newHashSet(EXECUTIONS_TOTAL, EXECUTIONS_FAILED));
}

@Override
protected Select<? extends Record> contentQuery(HealthCheckTableGetParams params,
List<Condition> levelConditions) {
var excludeSkipped = params.isExcludeSkippedTests();

SelectHavingStep<? extends Record3<String, BigDecimal, ?>> selectQuery = DSL.select(
var resultStatusTable = DSL.select(
STATISTICS_FIELD.NAME,
DSL.sum(STATISTICS.S_COUNTER).as(SUM),
fieldName(VALUE)
)
.from(params.getViewName())
.join(STATISTICS)
.on(fieldName(params.getViewName(), ITEM_ID).cast(Long.class).eq(STATISTICS.ITEM_ID))
.on(fieldName(params.getViewName(), ITEM_ID)
.cast(Long.class).eq(STATISTICS.ITEM_ID))
.join(STATISTICS_FIELD)
.on(STATISTICS.STATISTICS_FIELD_ID.eq(STATISTICS_FIELD.SF_ID))
.join(TEST_ITEM_RESULTS)
.on(TEST_ITEM_RESULTS.RESULT_ID
.eq(fieldName(params.getViewName(), ITEM_ID).cast(Long.class)))
.where(fieldName(KEY).cast(String.class)
.eq(params.getCurrentLevelKey())
.and(levelConditions.stream().reduce(DSL.noCondition(), Condition::and)))
.groupBy(fieldName(VALUE), STATISTICS_FIELD.NAME);
.groupBy(fieldName(VALUE), STATISTICS_FIELD.NAME, TEST_ITEM_RESULTS.STATUS)
.having(filterSkippedTests(excludeSkipped))
.asTable(EXCLUDE_SKIPPED_TABLE);

SelectHavingStep<? extends Record3<String, BigDecimal, ?>> selectQuery = DSL.select(
fieldName(NAME).cast(String.class).as(NAME),
DSL.sum(fieldName(SUM).cast(Long.class)).as(SUM),
fieldName(VALUE).as(VALUE))
.from(resultStatusTable)
.groupBy(resultStatusTable.field(VALUE), resultStatusTable.field(NAME));

Optional<Sort.Order> resolvedSort = params.getSort()
.get()
.filter(order -> getSupportedSorting().contains(order.getProperty()))
.findFirst();
if (resolvedSort.isPresent()) {
return selectQuery.orderBy(
DSL.when(STATISTICS_FIELD.NAME.eq(resolvedSort.get().getProperty()),
STATISTICS_FIELD.NAME),
DSL.when(fieldName(NAME).cast(String.class).eq(resolvedSort.get().getProperty()),
fieldName(NAME)),
resolvedSort.get().isAscending() ?
DSL.sum(STATISTICS.S_COUNTER).sort(SortOrder.ASC) :
DSL.sum(STATISTICS.S_COUNTER).sort(SortOrder.DESC)
fieldName(SUM).sort(SortOrder.ASC) :
fieldName(SUM).sort(SortOrder.DESC)
);
}
return selectQuery;
}

private Condition filterSkippedTests(boolean excludeSkipped) {
Condition condition = DSL.noCondition();
if (excludeSkipped) {
return condition
.and(TEST_ITEM_RESULTS.STATUS.notEqual(JStatusEnum.SKIPPED));
}
return condition;
}
}

0 comments on commit 9d71251

Please sign in to comment.