Search in sources :

Example 1 with ListResult

use of com.redhat.service.smartevents.infra.models.ListResult in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class ProcessorDAO method findByBridgeIdAndCustomerId.

private ListResult<Processor> findByBridgeIdAndCustomerId(String bridgeId, String customerId, QueryProcessorResourceInfo queryInfo, Set<ProcessorType> restrictTypes) {
    /*
         * Unfortunately we can't rely on Panaches in-built Paging due the fetched join in our query
         * for Processor e.g. join fetch p.bridge. Instead, we simply build a list of ids to fetch and then
         * execute the join fetch as normal. So the workflow here is:
         *
         * - Count the number of Processors on a bridge. If > 0
         * - Select the ids of the Processors that need to be retrieved based on the page/size requirements
         * - Select the Processors in the list of ids, performing the fetch join of the Bridge
         */
    // We don't consider filtering here; so this could be short-cut more but the additional code doesn't really make it worthwhile
    Parameters p = Parameters.with(Bridge.CUSTOMER_ID_PARAM, customerId).and(Processor.BRIDGE_ID_PARAM, bridgeId);
    Long processorCount = countProcessorsOnBridge(p);
    if (processorCount == 0L) {
        return new ListResult<>(emptyList(), queryInfo.getPageNumber(), processorCount);
    }
    ProcessorResults results = getProcessorIds(customerId, bridgeId, queryInfo, restrictTypes);
    List<Processor> processors = find("#PROCESSOR.findByIds", Parameters.with(IDS_PARAM, results.ids)).list();
    return new ListResult<>(processors, queryInfo.getPageNumber(), results.total);
}
Also used : ListResult(com.redhat.service.smartevents.infra.models.ListResult) Parameters(io.quarkus.panache.common.Parameters) Processor(com.redhat.service.smartevents.manager.models.Processor)

Example 2 with ListResult

use of com.redhat.service.smartevents.infra.models.ListResult in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class BridgeDAO method findByCustomerId.

public ListResult<Bridge> findByCustomerId(String customerId, QueryResourceInfo queryInfo) {
    Parameters parameters = Parameters.with("customerId", customerId);
    PanacheQuery<Bridge> query = find("#BRIDGE.findByCustomerId", parameters);
    String filterName = queryInfo.getFilterInfo().getFilterName();
    Set<ManagedResourceStatus> filterStatus = queryInfo.getFilterInfo().getFilterStatus();
    if (Objects.nonNull(filterName)) {
        query.filter("byName", Parameters.with("name", filterName + "%"));
    }
    if (Objects.nonNull(filterStatus) && !filterStatus.isEmpty()) {
        query.filter("byStatus", Parameters.with("status", filterStatus));
    }
    long total = query.count();
    List<Bridge> bridges = query.page(queryInfo.getPageNumber(), queryInfo.getPageSize()).list();
    return new ListResult<>(bridges, queryInfo.getPageNumber(), total);
}
Also used : ListResult(com.redhat.service.smartevents.infra.models.ListResult) Parameters(io.quarkus.panache.common.Parameters) ManagedResourceStatus(com.redhat.service.smartevents.infra.models.dto.ManagedResourceStatus) Bridge(com.redhat.service.smartevents.manager.models.Bridge)

Aggregations

ListResult (com.redhat.service.smartevents.infra.models.ListResult)2 Parameters (io.quarkus.panache.common.Parameters)2 ManagedResourceStatus (com.redhat.service.smartevents.infra.models.dto.ManagedResourceStatus)1 Bridge (com.redhat.service.smartevents.manager.models.Bridge)1 Processor (com.redhat.service.smartevents.manager.models.Processor)1