use of com.epam.ta.reportportal.commons.querygen.Queryable 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.commons.querygen.Queryable 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