use of com.epam.ta.reportportal.jooq.tables.JItemAttribute in project commons-dao by reportportal.
the class WidgetContentRepositoryImpl method generateComponentHealthCheckTable.
@Override
public void generateComponentHealthCheckTable(boolean refresh, HealthCheckTableInitParams params, Filter launchFilter, Sort launchSort, int launchesLimit, boolean isLatest) {
if (refresh) {
removeWidgetView(params.getViewName());
}
Table<? extends Record> launchesTable = QueryUtils.createQueryBuilderWithLatestLaunchesOption(launchFilter, launchSort, isLatest).with(launchesLimit).with(launchSort).build().asTable(LAUNCHES);
List<Field<?>> selectFields = Lists.newArrayList(TEST_ITEM.ITEM_ID, ITEM_ATTRIBUTE.KEY, ITEM_ATTRIBUTE.VALUE);
ofNullable(params.getCustomKey()).ifPresent(key -> selectFields.add(DSL.arrayAggDistinct(fieldName(CUSTOM_ATTRIBUTE, VALUE)).filterWhere(fieldName(CUSTOM_ATTRIBUTE, VALUE).isNotNull()).as(CUSTOM_COLUMN)));
SelectOnConditionStep<Record> baseQuery = select(selectFields).from(TEST_ITEM).join(launchesTable).on(TEST_ITEM.LAUNCH_ID.eq(fieldName(LAUNCHES, ID).cast(Long.class))).join(TEST_ITEM_RESULTS).on(TEST_ITEM.ITEM_ID.eq(TEST_ITEM_RESULTS.RESULT_ID)).join(ITEM_ATTRIBUTE).on(and(TEST_ITEM.ITEM_ID.eq(ITEM_ATTRIBUTE.ITEM_ID).or(TEST_ITEM.LAUNCH_ID.eq(ITEM_ATTRIBUTE.LAUNCH_ID))).and(ITEM_ATTRIBUTE.KEY.in(params.getAttributeKeys())).and(ITEM_ATTRIBUTE.SYSTEM.isFalse()));
dsl.execute(DSL.sql(Suppliers.formattedSupplier("CREATE MATERIALIZED VIEW {} AS ({})", DSL.name(params.getViewName()), ofNullable(params.getCustomKey()).map(key -> {
JItemAttribute customAttribute = ITEM_ATTRIBUTE.as(CUSTOM_ATTRIBUTE);
return baseQuery.leftJoin(customAttribute).on(DSL.condition(Operator.OR, TEST_ITEM.ITEM_ID.eq(customAttribute.ITEM_ID), TEST_ITEM.LAUNCH_ID.eq(customAttribute.LAUNCH_ID)).and(customAttribute.KEY.eq(key)));
}).orElse(baseQuery).where(TEST_ITEM.HAS_STATS.isTrue().and(TEST_ITEM.HAS_CHILDREN.isFalse()).and(TEST_ITEM.TYPE.eq(JTestItemTypeEnum.STEP)).and(TEST_ITEM.RETRY_OF.isNull()).and(TEST_ITEM_RESULTS.STATUS.notEqual(JStatusEnum.IN_PROGRESS))).groupBy(TEST_ITEM.ITEM_ID, ITEM_ATTRIBUTE.KEY, ITEM_ATTRIBUTE.VALUE).getQuery()).get()));
}
Aggregations