public static String orderBy(QueryOrderingProperty orderingProperty, int index) { QueryProperty queryProperty = orderingProperty.getQueryProperty(); StringBuilder sb = new StringBuilder(); sb.append(tableAlias(orderingProperty.getRelation(), index)); if (orderingProperty.isContainedProperty()) { sb.append("."); } else { sb.append("_"); } sb.append(queryProperty.getName()); sb.append(" "); sb.append(orderingProperty.getDirection().getName()); return sb.toString(); }
public JsonObject toJsonObject(QueryOrderingProperty property) { JsonObject jsonObject = JsonUtil.createObject(); JsonUtil.addField(jsonObject, RELATION, property.getRelation()); QueryProperty queryProperty = property.getQueryProperty(); if (queryProperty != null) { JsonUtil.addField(jsonObject, QUERY_PROPERTY, queryProperty.getName()); JsonUtil.addField(jsonObject, QUERY_PROPERTY_FUNCTION, queryProperty.getFunction()); } Direction direction = property.getDirection(); if (direction != null) { JsonUtil.addField(jsonObject, DIRECTION, direction.getName()); } if (property.hasRelationConditions()) { JsonArray relationConditionsJson = JsonQueryFilteringPropertyConverter.ARRAY_CONVERTER .toJsonArray(property.getRelationConditions()); JsonUtil.addField(jsonObject, RELATION_CONDITIONS, relationConditionsJson); } return jsonObject; }
@SuppressWarnings("unchecked") public T direction(Direction direction) { QueryOrderingProperty currentOrderingProperty = null; if (!orderingProperties.isEmpty()) { currentOrderingProperty = orderingProperties.get(orderingProperties.size() - 1); } ensureNotNull(NotValidException.class, "You should call any of the orderBy methods first before specifying a direction", "currentOrderingProperty", currentOrderingProperty); if (currentOrderingProperty.getDirection() != null) { ensureNull(NotValidException.class, "Invalid query: can specify only one direction desc() or asc() for an ordering constraint", "direction", direction); } currentOrderingProperty.setDirection(direction); return (T) this; }
public static String orderBySelection(QueryOrderingProperty orderingProperty, int index) { QueryProperty queryProperty = orderingProperty.getQueryProperty(); StringBuilder sb = new StringBuilder(); if (queryProperty.getFunction() != null) { sb.append(queryProperty.getFunction()); sb.append("("); } sb.append(tableAlias(orderingProperty.getRelation(), index)); sb.append("."); sb.append(queryProperty.getName()); if (queryProperty.getFunction() != null) { sb.append(")"); } return sb.toString(); }
public static SortingDto convertQueryOrderingPropertyToSortingDto(QueryOrderingProperty orderingProperty) { SortingDto sortingDto = new SortingDto(); sortingDto.setSortBy(sortByValueForQueryProperty(orderingProperty.getQueryProperty())); sortingDto.setSortOrder(sortOrderValueForDirection(orderingProperty.getDirection())); return sortingDto; }
property = new QueryOrderingProperty(); property.setRelation(relation); property.setQueryProperty(queryProperty); property.setDirection(Direction.findByName(direction)); List<QueryEntityRelationCondition> relationConditions = JsonQueryFilteringPropertyConverter.ARRAY_CONVERTER.toObject(JsonUtil.getArray(jsonObject, RELATION_CONDITIONS)); property.setRelationConditions(relationConditions);
public ExecutionQueryImpl orderByProcessDefinitionKey() { orderBy(new QueryOrderingProperty(QueryOrderingProperty.RELATION_PROCESS_DEFINITION, ExecutionQueryProperty.PROCESS_DEFINITION_KEY)); return this; }
protected void checkQueryOk() { for (QueryOrderingProperty orderingProperty : orderingProperties) { ensureNotNull(NotValidException.class, "Invalid query: call asc() or desc() after using orderByXX()", "direction", orderingProperty.getDirection()); } }
QueryOrderingProperty orderingProperty = new QueryOrderingProperty(null, queryProperty); orderingProperty.setDirection(direction); properties.add(orderingProperty);
protected void applyRequestControls(AbstractQuery<?, ?> query) { try { List<Control> controls = new ArrayList<>(); List<QueryOrderingProperty> orderBy = query.getOrderingProperties(); if(orderBy != null) { for (QueryOrderingProperty orderingProperty : orderBy) { String propertyName = orderingProperty.getQueryProperty().getName(); if(UserQueryProperty.USER_ID.getName().equals(propertyName)) { controls.add(new SortControl(ldapConfiguration.getUserIdAttribute(), Control.CRITICAL)); } else if(UserQueryProperty.EMAIL.getName().equals(propertyName)) { controls.add(new SortControl(ldapConfiguration.getUserEmailAttribute(), Control.CRITICAL)); } else if(UserQueryProperty.FIRST_NAME.getName().equals(propertyName)) { controls.add(new SortControl(ldapConfiguration.getUserFirstnameAttribute(), Control.CRITICAL)); } else if(UserQueryProperty.LAST_NAME.getName().equals(propertyName)) { controls.add(new SortControl(ldapConfiguration.getUserLastnameAttribute(), Control.CRITICAL)); } } } initialContext.setRequestControls(controls.toArray(new Control[0])); } catch (Exception e) { throw new IdentityProviderException("Exception while setting paging settings", e); } }
@SuppressWarnings({ "rawtypes", "unchecked" }) protected void assertQuerySorting(String property, Query<?, ?> query, Comparable... items) { AbstractQuery<?, ?> queryImpl = (AbstractQuery<?, ?>) query; // save order properties to later reverse ordering List<QueryOrderingProperty> orderProperties = queryImpl.getOrderingProperties(); List<? extends Comparable> sortedList = Arrays.asList(items); Collections.sort(sortedList); List<Matcher<Object>> matchers = new ArrayList<Matcher<Object>>(); for (Comparable comparable : sortedList) { matchers.add(hasProperty(property, equalTo(comparable))); } List<?> instances = query.asc().list(); assertEquals(sortedList.size(), instances.size()); assertThat(instances, contains(matchers.toArray(new Matcher[matchers.size()]))); // reverse ordering for (QueryOrderingProperty orderingProperty : orderProperties) { orderingProperty.setDirection(Direction.DESCENDING); } // reverse matchers Collections.reverse(matchers); instances = query.list(); assertEquals(sortedList.size(), instances.size()); assertThat(instances, contains(matchers.toArray(new Matcher[matchers.size()]))); }
@Override public String toString() { return "QueryOrderingProperty[" + "relation=" + relation + ", queryProperty=" + queryProperty + ", direction=" + direction + ", relationConditions=" + getRelationConditionsString() + "]"; }
public static SortingDto convertQueryOrderingPropertyToSortingDto(QueryOrderingProperty orderingProperty) { SortingDto sortingDto = new SortingDto(); sortingDto.setSortBy(sortByValueForQueryProperty(orderingProperty.getQueryProperty())); sortingDto.setSortOrder(sortOrderValueForDirection(orderingProperty.getDirection())); return sortingDto; }
property = new QueryOrderingProperty(); property.setRelation(relation); property.setQueryProperty(queryProperty); property.setDirection(Direction.findByName(direction)); List<QueryEntityRelationCondition> relationConditions = JsonQueryFilteringPropertyConverter.ARRAY_CONVERTER.toObject(JsonUtil.getArray(jsonObject, RELATION_CONDITIONS)); property.setRelationConditions(relationConditions);
public static String orderBySelection(QueryOrderingProperty orderingProperty, int index) { QueryProperty queryProperty = orderingProperty.getQueryProperty(); StringBuilder sb = new StringBuilder(); if (queryProperty.getFunction() != null) { sb.append(queryProperty.getFunction()); sb.append("("); } sb.append(tableAlias(orderingProperty.getRelation(), index)); sb.append("."); sb.append(queryProperty.getName()); if (queryProperty.getFunction() != null) { sb.append(")"); } return sb.toString(); }
public ExecutionQueryImpl orderByProcessDefinitionKey() { orderBy(new QueryOrderingProperty(QueryOrderingProperty.RELATION_PROCESS_DEFINITION, ExecutionQueryProperty.PROCESS_DEFINITION_KEY)); return this; }
protected void checkQueryOk() { for (QueryOrderingProperty orderingProperty : orderingProperties) { ensureNotNull(NotValidException.class, "Invalid query: call asc() or desc() after using orderByXX()", "direction", orderingProperty.getDirection()); } }
QueryOrderingProperty orderingProperty = new QueryOrderingProperty(null, queryProperty); orderingProperty.setDirection(direction); properties.add(orderingProperty);
protected void applyRequestControls(AbstractQuery<?, ?> query) { try { List<Control> controls = new ArrayList<Control>(); List<QueryOrderingProperty> orderBy = query.getOrderingProperties(); if(orderBy != null) { for (QueryOrderingProperty orderingProperty : orderBy) { String propertyName = orderingProperty.getQueryProperty().getName(); if(UserQueryProperty.USER_ID.getName().equals(propertyName)) { controls.add(new SortControl(ldapConfiguration.getUserIdAttribute(), Control.CRITICAL)); } else if(UserQueryProperty.EMAIL.getName().equals(propertyName)) { controls.add(new SortControl(ldapConfiguration.getUserEmailAttribute(), Control.CRITICAL)); } else if(UserQueryProperty.FIRST_NAME.getName().equals(propertyName)) { controls.add(new SortControl(ldapConfiguration.getUserFirstnameAttribute(), Control.CRITICAL)); } else if(UserQueryProperty.LAST_NAME.getName().equals(propertyName)) { controls.add(new SortControl(ldapConfiguration.getUserLastnameAttribute(), Control.CRITICAL)); } } } initialContext.setRequestControls(controls.toArray(new Control[0])); } catch (Exception e) { throw new IdentityProviderException("Exception while setting paging settings", e); } }
@SuppressWarnings({ "rawtypes", "unchecked" }) protected void assertQuerySorting(String property, Query<?, ?> query, Comparable... items) { AbstractQuery<?, ?> queryImpl = (AbstractQuery<?, ?>) query; // save order properties to later reverse ordering List<QueryOrderingProperty> orderProperties = queryImpl.getOrderingProperties(); List<? extends Comparable> sortedList = Arrays.asList(items); Collections.sort(sortedList); List<Matcher<Object>> matchers = new ArrayList<Matcher<Object>>(); for (Comparable comparable : sortedList) { matchers.add(hasProperty(property, equalTo(comparable))); } List<?> instances = query.asc().list(); assertEquals(sortedList.size(), instances.size()); assertThat(instances, contains(matchers.toArray(new Matcher[matchers.size()]))); // reverse ordering for (QueryOrderingProperty orderingProperty : orderProperties) { orderingProperty.setDirection(Direction.DESCENDING); } // reverse matchers Collections.reverse(matchers); instances = query.list(); assertEquals(sortedList.size(), instances.size()); assertThat(instances, contains(matchers.toArray(new Matcher[matchers.size()]))); }