use of org.bf2.srs.fleetmanager.util.BasicQuery in project srs-fleet-manager by bf2fc6cc711aee1a0c2a.
the class RegistryServiceImpl method getRegistries.
@Override
public RegistryListDto getRegistries(Integer page, Integer size, String orderBy, String search) {
// Defaults
var sort = Sort.by("id", Sort.Direction.Ascending);
page = (page != null) ? page : 1;
size = (size != null) ? size : 10;
if (orderBy != null) {
var order = orderBy.split(" ");
if (order.length != 2) {
throw new ValidationException("invalid orderBy");
}
if ("asc".equals(order[1])) {
sort = Sort.by(order[0], Sort.Direction.Ascending);
} else {
sort = Sort.by(order[0], Sort.Direction.Descending);
}
}
List<Pair<String, Object>> conditions = new ArrayList<>();
if (search != null && !search.isEmpty()) {
var basicQuery = new BasicQuery(search, Arrays.asList("name", "status"));
conditions.add(Pair.of(basicQuery.getColumn(), basicQuery.getArgument()));
}
// list only registries from your organization or the ones the user owns
if (isResolvable(securityIdentity)) {
final AccountInfo accountInfo = authService.extractAccountInfo();
String orgId = accountInfo.getOrganizationId();
if (orgId != null) {
conditions.add(Pair.of("orgId", orgId));
} else {
conditions.add(Pair.of("ownerId", accountInfo.getAccountId()));
}
} else {
conditions.add(Pair.of("ownerId", OWNER_ID_PLACEHOLDER));
}
var query = new SearchQuery(conditions);
PanacheQuery<RegistryData> itemsQuery = storage.executeRegistrySearchQuery(query, sort);
var items = itemsQuery.page(Page.of(page - 1, size)).stream().map(convertRegistry::convert).collect(Collectors.toList());
return RegistryListDto.builder().items(items).page(page).size(size).total(itemsQuery.count()).build();
}
Aggregations