Search in sources :

Example 1 with JTestItem

use of com.epam.ta.reportportal.jooq.tables.JTestItem in project commons-dao by reportportal.

the class LogRepositoryCustomImpl method buildLogsUnderItemsQuery.

private SelectConditionStep<? extends Record> buildLogsUnderItemsQuery(Long launchId, List<Long> itemIds, boolean includeAttachments) {
    JTestItem parentItemTable = TEST_ITEM.as(PARENT_ITEM_TABLE);
    JTestItem childItemTable = TEST_ITEM.as(CHILD_ITEM_TABLE);
    List<Field<?>> selectFields = Lists.newArrayList(LOG.ID, LOG.LOG_LEVEL, LOG.LOG_MESSAGE, LOG.LOG_TIME, parentItemTable.ITEM_ID.as(ROOT_ITEM_ID), LOG.LAUNCH_ID, LOG.LAST_MODIFIED, LOG.CLUSTER_ID);
    if (includeAttachments) {
        Collections.addAll(selectFields, ATTACHMENT.fields());
    }
    SelectOnConditionStep<Record> logsSelect = dsl.selectDistinct(selectFields).on(LOG.ID, LOG.LOG_TIME).from(LOG).join(childItemTable).on(LOG.ITEM_ID.eq(childItemTable.ITEM_ID)).join(parentItemTable).on(DSL.sql(childItemTable.PATH + " <@ " + parentItemTable.PATH));
    if (includeAttachments) {
        logsSelect = logsSelect.leftJoin(ATTACHMENT).on(LOG.ATTACHMENT_ID.eq(ATTACHMENT.ID));
    }
    return logsSelect.where(childItemTable.LAUNCH_ID.eq(launchId)).and(parentItemTable.LAUNCH_ID.eq(launchId)).and(parentItemTable.ITEM_ID.in(itemIds));
}
Also used : JTestItem(com.epam.ta.reportportal.jooq.tables.JTestItem)

Example 2 with JTestItem

use of com.epam.ta.reportportal.jooq.tables.JTestItem in project commons-dao by reportportal.

the class LogRepositoryCustomImpl method findIdsUnderTestItemByLaunchIdAndTestItemIdsAndLogLevelGte.

@Override
public List<Long> findIdsUnderTestItemByLaunchIdAndTestItemIdsAndLogLevelGte(Long launchId, List<Long> itemIds, int logLevel) {
    JTestItem parentItemTable = TEST_ITEM.as(PARENT_ITEM_TABLE);
    JTestItem childItemTable = TEST_ITEM.as(CHILD_ITEM_TABLE);
    return dsl.selectDistinct(LOG.ID).from(LOG).join(childItemTable).on(LOG.ITEM_ID.eq(childItemTable.ITEM_ID)).join(parentItemTable).on(DSL.sql(childItemTable.PATH + " <@ " + parentItemTable.PATH)).where(childItemTable.LAUNCH_ID.eq(launchId)).and(parentItemTable.LAUNCH_ID.eq(launchId)).and(parentItemTable.ITEM_ID.in(itemIds)).and(LOG.LOG_LEVEL.greaterOrEqual(logLevel)).fetchInto(Long.class);
}
Also used : JTestItem(com.epam.ta.reportportal.jooq.tables.JTestItem)

Example 3 with JTestItem

use of com.epam.ta.reportportal.jooq.tables.JTestItem in project commons-dao by reportportal.

the class TestItemRepositoryCustomImpl method findAllNestedStepsByIds.

@Override
public List<NestedStep> findAllNestedStepsByIds(Collection<Long> ids, Queryable logFilter, boolean excludePassedLogs) {
    JTestItem nested = TEST_ITEM.as(NESTED);
    SelectQuery<? extends Record> logsSelectQuery = QueryBuilder.newBuilder(logFilter, QueryUtils.collectJoinFields(logFilter)).build();
    return dsl.select(TEST_ITEM.ITEM_ID, TEST_ITEM.NAME, TEST_ITEM.UUID, TEST_ITEM.START_TIME, TEST_ITEM.TYPE, TEST_ITEM_RESULTS.STATUS, TEST_ITEM_RESULTS.END_TIME, TEST_ITEM_RESULTS.DURATION, DSL.field(hasContentQuery(nested, logsSelectQuery, excludePassedLogs)).as(HAS_CONTENT), DSL.field(dsl.with(LOGS).as(logsSelectQuery).selectCount().from(LOG).join(nested).on(LOG.ITEM_ID.eq(nested.ITEM_ID)).join(LOGS).on(LOG.ID.eq(fieldName(LOGS, ID).cast(Long.class))).join(ATTACHMENT).on(LOG.ATTACHMENT_ID.eq(ATTACHMENT.ID)).where(nested.HAS_STATS.isFalse().and(DSL.sql(fieldName(NESTED, TEST_ITEM.PATH.getName()) + " <@ cast(? AS LTREE)", TEST_ITEM.PATH)))).as(ATTACHMENTS_COUNT)).from(TEST_ITEM).join(TEST_ITEM_RESULTS).on(TEST_ITEM.ITEM_ID.eq(TEST_ITEM_RESULTS.RESULT_ID)).where(TEST_ITEM.ITEM_ID.in(ids)).fetch(NESTED_STEP_RECORD_MAPPER);
}
Also used : JTestItem(com.epam.ta.reportportal.jooq.tables.JTestItem)

Example 4 with JTestItem

use of com.epam.ta.reportportal.jooq.tables.JTestItem in project commons-dao by reportportal.

the class LogRepositoryCustomImpl method findAllIndexUnderTestItemByLaunchIdAndTestItemIdsAndLogLevelGte.

@Override
public Map<Long, List<IndexLog>> findAllIndexUnderTestItemByLaunchIdAndTestItemIdsAndLogLevelGte(Long launchId, List<Long> itemIds, int logLevel) {
    JTestItem parentItemTable = TEST_ITEM.as(PARENT_ITEM_TABLE);
    JTestItem childItemTable = TEST_ITEM.as(CHILD_ITEM_TABLE);
    return INDEX_LOG_FETCHER.apply(dsl.selectDistinct(LOG.ID, LOG.LOG_LEVEL, LOG.LOG_MESSAGE, parentItemTable.ITEM_ID.as(ROOT_ITEM_ID), CLUSTERS.INDEX_ID).on(LOG.ID).from(LOG).join(childItemTable).on(LOG.ITEM_ID.eq(childItemTable.ITEM_ID)).join(parentItemTable).on(DSL.sql(childItemTable.PATH + " <@ " + parentItemTable.PATH)).leftJoin(CLUSTERS).on(LOG.CLUSTER_ID.eq(CLUSTERS.ID)).where(childItemTable.LAUNCH_ID.eq(launchId)).and(parentItemTable.LAUNCH_ID.eq(launchId)).and(parentItemTable.ITEM_ID.in(itemIds)).and(LOG.LOG_LEVEL.greaterOrEqual(logLevel)).fetch());
}
Also used : JTestItem(com.epam.ta.reportportal.jooq.tables.JTestItem)

Example 5 with JTestItem

use of com.epam.ta.reportportal.jooq.tables.JTestItem in project commons-dao by reportportal.

the class LogRepositoryCustomImpl method buildNestedStepQuery.

private SelectHavingStep<Record3<Long, Timestamp, String>> buildNestedStepQuery(Long parentId, boolean excludeEmptySteps, Queryable filter) {
    SelectConditionStep<Record3<Long, Timestamp, String>> nestedStepSelect = dsl.select(TEST_ITEM.ITEM_ID.as(ID), TEST_ITEM.START_TIME.as(TIME), DSL.val(ITEM).as(TYPE)).from(TEST_ITEM).join(TEST_ITEM_RESULTS).on(TEST_ITEM.ITEM_ID.eq(TEST_ITEM_RESULTS.RESULT_ID)).where(TEST_ITEM.PARENT_ID.eq(parentId)).and(TEST_ITEM.HAS_STATS.isFalse());
    filter.getFilterConditions().stream().flatMap(condition -> condition.getAllConditions().stream()).filter(c -> CRITERIA_STATUS.equals(c.getSearchCriteria())).findFirst().map(c -> Stream.of(c.getValue().split(",")).filter(StatusEnum::isPresent).map(JStatusEnum::valueOf).collect(toList())).map(TEST_ITEM_RESULTS.STATUS::in).ifPresent(nestedStepSelect::and);
    if (excludeEmptySteps) {
        JTestItem nested = TEST_ITEM.as(NESTED);
        nestedStepSelect.and(field(DSL.exists(dsl.with(LOGS).as(QueryBuilder.newBuilder(filter, QueryUtils.collectJoinFields(filter)).addCondition(LOG.ITEM_ID.eq(parentId)).build()).select().from(LOG).join(LOGS).on(LOG.ID.eq(field(LOGS, ID).cast(Long.class))).where(LOG.ITEM_ID.eq(TEST_ITEM.ITEM_ID))).orExists(dsl.select().from(nested).where(nested.PARENT_ID.eq(TEST_ITEM.ITEM_ID)))));
    }
    return nestedStepSelect.groupBy(TEST_ITEM.ITEM_ID);
}
Also used : TimestampUtils(com.epam.ta.reportportal.dao.util.TimestampUtils) StatusEnum(com.epam.ta.reportportal.entity.enums.StatusEnum) CRITERIA_STATUS(com.epam.ta.reportportal.commons.querygen.constant.TestItemCriteriaConstant.CRITERIA_STATUS) java.util(java.util) DSL(org.jooq.impl.DSL) RecordMappers(com.epam.ta.reportportal.dao.util.RecordMappers) QueryBuilder(com.epam.ta.reportportal.commons.querygen.QueryBuilder) LOG(com.epam.ta.reportportal.jooq.Tables.LOG) DSL.field(org.jooq.impl.DSL.field) Autowired(org.springframework.beans.factory.annotation.Autowired) ErrorType(com.epam.ta.reportportal.ws.model.ErrorType) JTestItem(com.epam.ta.reportportal.jooq.tables.JTestItem) NESTED_ITEM_FETCHER(com.epam.ta.reportportal.dao.util.ResultFetchers.NESTED_ITEM_FETCHER) BigDecimal(java.math.BigDecimal) Lists(com.google.common.collect.Lists) LAUNCH(com.epam.ta.reportportal.jooq.Tables.LAUNCH) QueryUtils(com.epam.ta.reportportal.dao.util.QueryUtils) Log(com.epam.ta.reportportal.entity.log.Log) org.jooq(org.jooq) Duration(java.time.Duration) JooqFieldNameTransformer.fieldName(com.epam.ta.reportportal.dao.util.JooqFieldNameTransformer.fieldName) Pageable(org.springframework.data.domain.Pageable) Sort(org.springframework.data.domain.Sort) Repository(org.springframework.stereotype.Repository) RoundingMode(java.math.RoundingMode) ATTACHMENT(com.epam.ta.reportportal.jooq.tables.JAttachment.ATTACHMENT) TEST_ITEM_RESULTS(com.epam.ta.reportportal.jooq.tables.JTestItemResults.TEST_ITEM_RESULTS) NestedItem(com.epam.ta.reportportal.entity.item.NestedItem) CLUSTERS(com.epam.ta.reportportal.jooq.Tables.CLUSTERS) Optional.ofNullable(java.util.Optional.ofNullable) Filter(com.epam.ta.reportportal.commons.querygen.Filter) Timestamp(java.sql.Timestamp) LogRepositoryConstants(com.epam.ta.reportportal.dao.constant.LogRepositoryConstants) ReportPortalException(com.epam.ta.reportportal.exception.ReportPortalException) PageableExecutionUtils(org.springframework.data.repository.support.PageableExecutionUtils) Page(org.springframework.data.domain.Page) ID(com.epam.ta.reportportal.dao.constant.WidgetRepositoryConstants.ID) Collectors.toList(java.util.stream.Collectors.toList) Stream(java.util.stream.Stream) TEST_ITEM(com.epam.ta.reportportal.jooq.tables.JTestItem.TEST_ITEM) Queryable(com.epam.ta.reportportal.commons.querygen.Queryable) NESTED(com.epam.ta.reportportal.dao.constant.TestItemRepositoryConstants.NESTED) JStatusEnum(com.epam.ta.reportportal.jooq.enums.JStatusEnum) CRITERIA_LOG_TIME(com.epam.ta.reportportal.commons.querygen.constant.LogCriteriaConstant.CRITERIA_LOG_TIME) IndexLog(com.epam.ta.reportportal.ws.model.analyzer.IndexLog) LOG_FETCHER(com.epam.ta.reportportal.dao.util.ResultFetchers.LOG_FETCHER) JStatusEnum(com.epam.ta.reportportal.jooq.enums.JStatusEnum) TEST_ITEM_RESULTS(com.epam.ta.reportportal.jooq.tables.JTestItemResults.TEST_ITEM_RESULTS) JTestItem(com.epam.ta.reportportal.jooq.tables.JTestItem)

Aggregations

JTestItem (com.epam.ta.reportportal.jooq.tables.JTestItem)7 Filter (com.epam.ta.reportportal.commons.querygen.Filter)1 QueryBuilder (com.epam.ta.reportportal.commons.querygen.QueryBuilder)1 Queryable (com.epam.ta.reportportal.commons.querygen.Queryable)1 CRITERIA_LOG_TIME (com.epam.ta.reportportal.commons.querygen.constant.LogCriteriaConstant.CRITERIA_LOG_TIME)1 CRITERIA_STATUS (com.epam.ta.reportportal.commons.querygen.constant.TestItemCriteriaConstant.CRITERIA_STATUS)1 LogRepositoryConstants (com.epam.ta.reportportal.dao.constant.LogRepositoryConstants)1 NESTED (com.epam.ta.reportportal.dao.constant.TestItemRepositoryConstants.NESTED)1 ID (com.epam.ta.reportportal.dao.constant.WidgetRepositoryConstants.ID)1 JooqFieldNameTransformer.fieldName (com.epam.ta.reportportal.dao.util.JooqFieldNameTransformer.fieldName)1 QueryUtils (com.epam.ta.reportportal.dao.util.QueryUtils)1 RecordMappers (com.epam.ta.reportportal.dao.util.RecordMappers)1 LOG_FETCHER (com.epam.ta.reportportal.dao.util.ResultFetchers.LOG_FETCHER)1 NESTED_ITEM_FETCHER (com.epam.ta.reportportal.dao.util.ResultFetchers.NESTED_ITEM_FETCHER)1 TimestampUtils (com.epam.ta.reportportal.dao.util.TimestampUtils)1 StatusEnum (com.epam.ta.reportportal.entity.enums.StatusEnum)1 NestedItem (com.epam.ta.reportportal.entity.item.NestedItem)1 Log (com.epam.ta.reportportal.entity.log.Log)1 ReportPortalException (com.epam.ta.reportportal.exception.ReportPortalException)1 CLUSTERS (com.epam.ta.reportportal.jooq.Tables.CLUSTERS)1