Skip to content
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

EPMRPP-89216 exclude skipped tests from HCW table view #989

Merged
merged 3 commits into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Expand Up @@ -628,14 +628,11 @@ private static void proceedProductStatusAttributes(Record record, String columnN

});

resultMap.values()
.stream()
.map(content -> excludeSkippedTests(params, content))
.forEach(content -> {
double passingRate = 100.0 * content.getStatistics().getOrDefault(EXECUTIONS_PASSED, 0)
/ content.getStatistics().getOrDefault(EXECUTIONS_TOTAL, 1);
content.setPassingRate(new BigDecimal(passingRate).setScale(2, RoundingMode.HALF_UP)
.doubleValue());
resultMap.forEach((key, content) -> {
double passingRate = 100.0 * content.getStatistics().getOrDefault(EXECUTIONS_PASSED, 0) /
content.getStatistics().getOrDefault(EXECUTIONS_TOTAL, 1);
content.setPassingRate(BigDecimal.valueOf(passingRate)
.setScale(2, RoundingMode.HALF_UP).doubleValue());
});

return resultMap;
Expand Down
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;
}
}
Loading