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);
}
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);
}
Aggregations