@Override public Sort convert(String source) { Sort sort = new Sort(); for (String attr : source.split(",")) { Sort.Direction direction; if (attr.endsWith(ORDER_DESC_POSTFIX)) { direction = Sort.Direction.DESC; attr = attr.substring(0, attr.length() - ORDER_DESC_POSTFIX.length()); } else if (attr.endsWith(ORDER_ASC_POSTFIX)) { direction = Sort.Direction.ASC; attr = attr.substring(0, attr.length() - ORDER_ASC_POSTFIX.length()); } else { direction = Sort.Direction.ASC; } sort.on(attr, direction); } return sort; } }
Sort toSort(EditorSort editorSort) { if (editorSort == null) { return null; } List<Sort.Order> orders = editorSort.getOrders().stream().map(this::toOrder).collect(toList()); return new Sort(orders); }
private Stream<App> getApps() { Query<App> query = dataService.query(APP, App.class); query.sort().on(AppMetaData.NAME); Stream<App> apps = query.findAll(); if (!permissionService.hasPermissionOnEntityType(APP, Permission.WRITE)) { apps = apps.filter(App::isActive); } return apps; }
/** * Validate whether the attribute names defined by the orderBy attribute point to existing * attributes in the referenced entity. * * @param attr attribute * @param orderBy orderBy of attribute * @throws MolgenisDataException if orderBy contains attribute names that do not exist in the * referenced entity. */ private static void validateOrderBy(Attribute attr, Sort orderBy) { if (orderBy != null) { EntityType refEntity = attr.getRefEntity(); if (refEntity != null) { for (Sort.Order orderClause : orderBy) { String refAttrName = orderClause.getAttr(); if (refEntity.getAttribute(refAttrName) == null) { throw new MolgenisDataException( format( "Unknown entity [%s] attribute [%s] referred to by entity [%s] attribute [%s] sortBy [%s]", refEntity.getId(), refAttrName, attr.getEntityType().getId(), attr.getName(), orderBy.toSortString())); } } } } }
/** Retrieves the query to get all index actions sorted */ static Query<IndexAction> createQueryGetAllIndexActions(String transactionId) { QueryRule rule = new QueryRule(INDEX_ACTION_GROUP_ATTR, EQUALS, transactionId); QueryImpl<IndexAction> q = new QueryImpl<>(rule); q.setSort(new Sort(ACTION_ORDER)); return q; }
q.sort().on(sortAttribute, order);
if (q.getSort() != null && !hasUniqueSortAttribute(entityType, q.getSort())) { LOG.debug("Query with sort without unique attribute detected: {}", q); sort = new Sort(q.getSort()); sort.on(entityType.getIdAttribute().getName()); } else if (q.getSort() == null) { LOG.debug("Query without sort detected: {}", q); sort = new Sort(entityType.getIdAttribute().getName()); } else { sort = q.getSort();
@Deprecated public static List<CategoricalOptionV2> getCategoricalOptionsForRefEntity( DataService dataService, EntityType refEntity, String language) { Sort sortOrder = stream(refEntity.getAttributes()) .filter(attribute -> attribute.isVisible() && attribute.isUnique()) .map(sortAttr -> new Sort(sortAttr.getName())) .findFirst() .orElse(null); Attribute labelAttribute = refEntity.getLabelAttribute(language); return dataService .findAll(refEntity.getId(), new QueryImpl<>().sort(sortOrder)) .map( entity -> new CategoricalOptionV2( entity.getIdValue(), entity.getString(labelAttribute.getName()))) .collect(Collectors.toList()); } }
private List<SortaJobExecution> getJobsForCurrentUser() { final List<SortaJobExecution> jobs = new ArrayList<>(); User currentUser = userAccountService.getCurrentUser(); Query<SortaJobExecution> query = dataService .query(SORTA_JOB_EXECUTION, SortaJobExecution.class) .eq(JobExecutionMetaData.USER, currentUser.getUsername()); query.sort().on(JobExecutionMetaData.START_DATE, DESC); RunAsSystemAspect.runAsSystem( () -> query .findAll() .forEach( job -> { // TODO: fetch the user as well job.set(JobExecutionMetaData.USER, currentUser.getUsername()); jobs.add(job); })); return jobs; }
.setRefEntity(mailSenderPropertyType) .setMappedBy(refAttr) .setOrderBy(new Sort(KEY)) .setNillable(true) .setLabel("Properties")