use of com.epam.ta.reportportal.dao.constant.WidgetRepositoryConstants.ID in project commons-dao by reportportal.
the class LogRepositoryCustomImpl method getPageNumber.
@Override
public Integer getPageNumber(Long id, Filter filter, Pageable pageable) {
Sort.Order order = ofNullable(pageable.getSort().getOrderFor(CRITERIA_LOG_TIME)).orElseThrow(() -> new ReportPortalException(ErrorType.INCORRECT_SORTING_PARAMETERS));
OrderField<?> sortField = order.getDirection().isAscending() ? LOG.LOG_TIME.asc() : LOG.LOG_TIME.desc();
return ofNullable(dsl.select(fieldName(ROW_NUMBER)).from(dsl.select(LOG.ID, DSL.rowNumber().over(DSL.orderBy(sortField)).as(ROW_NUMBER)).from(LOG).join(QueryBuilder.newBuilder(filter, QueryUtils.collectJoinFields(filter, pageable.getSort())).with(pageable.getSort()).build().asTable(DISTINCT_LOGS_TABLE)).on(LOG.ID.eq(fieldName(DISTINCT_LOGS_TABLE, ID).cast(Long.class)))).where(fieldName(ID).cast(Long.class).eq(id)).fetchAny()).map(r -> {
Long rowNumber = r.into(Long.class);
return BigDecimal.valueOf(rowNumber).divide(BigDecimal.valueOf(pageable.getPageSize()), RoundingMode.CEILING).intValue();
}).orElseThrow(() -> new ReportPortalException(ErrorType.LOG_NOT_FOUND, id));
}
use of com.epam.ta.reportportal.dao.constant.WidgetRepositoryConstants.ID in project commons-dao by reportportal.
the class LogRepositoryCustomImpl method buildNestedLogQuery.
private SelectOnConditionStep<Record3<Long, Timestamp, String>> buildNestedLogQuery(Long parentId, Queryable filter) {
Queryable logFilter = filter.getFilterConditions().stream().flatMap(condition -> condition.getAllConditions().stream()).filter(condition -> CRITERIA_STATUS.equalsIgnoreCase(condition.getSearchCriteria())).findAny().map(condition -> (Queryable) new Filter(filter.getTarget().getClazz(), filter.getFilterConditions().stream().flatMap(simpleCondition -> simpleCondition.getAllConditions().stream()).filter(filterCondition -> !condition.getSearchCriteria().equalsIgnoreCase(filterCondition.getSearchCriteria())).collect(toList()))).orElse(filter);
QueryBuilder queryBuilder = QueryBuilder.newBuilder(logFilter, QueryUtils.collectJoinFields(logFilter));
return dsl.with(LOGS).as(queryBuilder.addCondition(LOG.ITEM_ID.eq(parentId)).build()).select(LOG.ID.as(ID), LOG.LOG_TIME.as(TIME), DSL.val(LogRepositoryConstants.LOG).as(TYPE)).from(LOG).join(LOGS).on(fieldName(LOGS, ID).cast(Long.class).eq(LOG.ID));
}
use of com.epam.ta.reportportal.dao.constant.WidgetRepositoryConstants.ID 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);
}
Aggregations