protected void checkQueryOk() { for (QueryOrderingProperty orderingProperty : orderingProperties) { ensureNotNull(NotValidException.class, "Invalid query: call asc() or desc() after using orderByXX()", "direction", orderingProperty.getDirection()); } }
protected void checkQueryOk() { for (QueryOrderingProperty orderingProperty : orderingProperties) { ensureNotNull(NotValidException.class, "Invalid query: call asc() or desc() after using orderByXX()", "direction", orderingProperty.getDirection()); } }
@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; }
@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 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 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 static SortingDto convertQueryOrderingPropertyToSortingDto(QueryOrderingProperty orderingProperty) { SortingDto sortingDto = new SortingDto(); sortingDto.setSortBy(sortByValueForQueryProperty(orderingProperty.getQueryProperty())); sortingDto.setSortOrder(sortOrderValueForDirection(orderingProperty.getDirection())); return sortingDto; }
public static SortingDto convertQueryOrderingPropertyToSortingDto(QueryOrderingProperty orderingProperty) { SortingDto sortingDto = new SortingDto(); sortingDto.setSortBy(sortByValueForQueryProperty(orderingProperty.getQueryProperty())); sortingDto.setSortOrder(sortOrderValueForDirection(orderingProperty.getDirection())); return sortingDto; }
protected void verifyOrderingProperties(List<QueryOrderingProperty> expectedProperties, List<QueryOrderingProperty> actualProperties) { assertEquals(expectedProperties.size(), actualProperties.size()); for (int i = 0; i < expectedProperties.size(); i++) { QueryOrderingProperty expectedProperty = expectedProperties.get(i); QueryOrderingProperty actualProperty = actualProperties.get(i); assertEquals(expectedProperty.getRelation(), actualProperty.getRelation()); assertEquals(expectedProperty.getDirection(), actualProperty.getDirection()); assertEquals(expectedProperty.isContainedProperty(), actualProperty.isContainedProperty()); assertEquals(expectedProperty.getQueryProperty(), actualProperty.getQueryProperty()); List<QueryEntityRelationCondition> expectedRelationConditions = expectedProperty.getRelationConditions(); List<QueryEntityRelationCondition> actualRelationConditions = expectedProperty.getRelationConditions(); if (expectedRelationConditions != null && actualRelationConditions != null) { assertEquals(expectedRelationConditions.size(), actualRelationConditions.size()); for (int j = 0; j < expectedRelationConditions.size(); j++) { QueryEntityRelationCondition expectedFilteringProperty = expectedRelationConditions.get(j); QueryEntityRelationCondition actualFilteringProperty = expectedRelationConditions.get(j); assertEquals(expectedFilteringProperty.getProperty(), actualFilteringProperty.getProperty()); assertEquals(expectedFilteringProperty.getComparisonProperty(), actualFilteringProperty.getComparisonProperty()); assertEquals(expectedFilteringProperty.getScalarValue(), actualFilteringProperty.getScalarValue()); } } else if ((expectedRelationConditions == null && actualRelationConditions != null) || (expectedRelationConditions != null && actualRelationConditions == null)) { fail("Expected filtering properties: " + expectedRelationConditions + ". " + "Actual filtering properties: " + actualRelationConditions); } } }
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; }
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; }
protected void checkQueryOk() { for (QueryOrderingProperty orderingProperty : orderingProperties) { ensureNotNull(NotValidException.class, "Invalid query: call asc() or desc() after using orderByXX()", "direction", orderingProperty.getDirection()); } }
/** * Tests compatibility with serialization format that was used in 7.2 */ @SuppressWarnings("deprecation") public void testDeprecatedOrderingFormatDeserializationSingleOrdering() { String sortByNameAsc = "RES." + TaskQueryProperty.NAME.getName() + " " + Direction.ASCENDING.getName(); JsonTaskQueryConverter converter = (JsonTaskQueryConverter) FilterEntity.queryConverter.get(EntityTypes.TASK); JsonObject queryJson = converter.toJsonObject(filter.<TaskQuery>getQuery()); // when I apply a specific ordering by one dimension queryJson.addProperty(JsonTaskQueryConverter.ORDER_BY, sortByNameAsc); TaskQueryImpl deserializedTaskQuery = (TaskQueryImpl) converter.toObject(queryJson); // then the ordering is applied accordingly assertEquals(1, deserializedTaskQuery.getOrderingProperties().size()); QueryOrderingProperty orderingProperty = deserializedTaskQuery.getOrderingProperties().get(0); assertNull(orderingProperty.getRelation()); assertEquals("asc", orderingProperty.getDirection().getName()); assertNull(orderingProperty.getRelationConditions()); assertTrue(orderingProperty.isContainedProperty()); assertEquals(TaskQueryProperty.NAME.getName(), orderingProperty.getQueryProperty().getName()); assertNull(orderingProperty.getQueryProperty().getFunction()); }
/** * Tests compatibility with serialization format that was used in 7.2 */ @SuppressWarnings("deprecation") public void testDeprecatedOrderingFormatDeserializationFunctionOrdering() { String orderingWithFunction = "LOWER(RES." + TaskQueryProperty.NAME.getName() + ") asc"; JsonTaskQueryConverter converter = (JsonTaskQueryConverter) FilterEntity.queryConverter.get(EntityTypes.TASK); JsonObject queryJson = converter.toJsonObject(filter.<TaskQuery>getQuery()); // when I apply an ordering with a function queryJson.addProperty(JsonTaskQueryConverter.ORDER_BY, orderingWithFunction); TaskQueryImpl deserializedTaskQuery = (TaskQueryImpl) converter.toObject(queryJson); assertEquals(1, deserializedTaskQuery.getOrderingProperties().size()); // then the ordering is applied accordingly QueryOrderingProperty orderingProperty = deserializedTaskQuery.getOrderingProperties().get(0); assertNull(orderingProperty.getRelation()); assertEquals("asc", orderingProperty.getDirection().getName()); assertNull(orderingProperty.getRelationConditions()); assertFalse(orderingProperty.isContainedProperty()); assertEquals(TaskQueryProperty.NAME_CASE_INSENSITIVE.getName(), orderingProperty.getQueryProperty().getName()); assertEquals(TaskQueryProperty.NAME_CASE_INSENSITIVE.getFunction(), orderingProperty.getQueryProperty().getFunction()); }
deserializedTaskQuery.getOrderingProperties().get(0); assertNull(orderingProperty1.getRelation()); assertEquals("asc", orderingProperty1.getDirection().getName()); assertNull(orderingProperty1.getRelationConditions()); assertTrue(orderingProperty1.isContainedProperty()); deserializedTaskQuery.getOrderingProperties().get(1); assertNull(orderingProperty2.getRelation()); assertEquals("desc", orderingProperty2.getDirection().getName()); assertNull(orderingProperty2.getRelationConditions()); assertTrue(orderingProperty2.isContainedProperty());
@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 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 static SortingDto convertQueryOrderingPropertyToSortingDto(QueryOrderingProperty orderingProperty) { SortingDto sortingDto = new SortingDto(); sortingDto.setSortBy(sortByValueForQueryProperty(orderingProperty.getQueryProperty())); sortingDto.setSortOrder(sortOrderValueForDirection(orderingProperty.getDirection())); return sortingDto; }
public JSONObject toJsonObject(QueryOrderingProperty property) { JSONObject jsonObject = new JSONObject(); 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; }
/** * Tests compatibility with serialization format that was used in 7.2 */ @SuppressWarnings("deprecation") public void testDeprecatedOrderingFormatDeserializationSingleOrdering() { String sortByNameAsc = "RES." + TaskQueryProperty.NAME.getName() + " " + Direction.ASCENDING.getName(); JsonTaskQueryConverter converter = (JsonTaskQueryConverter) FilterEntity.queryConverter.get(EntityTypes.TASK); JSONObject queryJson = converter.toJsonObject(filter.<TaskQuery>getQuery()); // when I apply a specific ordering by one dimension queryJson.put(JsonTaskQueryConverter.ORDER_BY, sortByNameAsc); TaskQueryImpl deserializedTaskQuery = (TaskQueryImpl) converter.toObject(queryJson); // then the ordering is applied accordingly assertEquals(1, deserializedTaskQuery.getOrderingProperties().size()); QueryOrderingProperty orderingProperty = deserializedTaskQuery.getOrderingProperties().get(0); assertNull(orderingProperty.getRelation()); assertEquals("asc", orderingProperty.getDirection().getName()); assertNull(orderingProperty.getRelationConditions()); assertTrue(orderingProperty.isContainedProperty()); assertEquals(TaskQueryProperty.NAME.getName(), orderingProperty.getQueryProperty().getName()); assertNull(orderingProperty.getQueryProperty().getFunction()); }