Search in sources :

Example 16 with QueryOrderingProperty

use of org.camunda.bpm.engine.impl.QueryOrderingProperty in project camunda-bpm-platform by camunda.

the class FilterTaskQueryTest method testDeprecatedOrderingFormatDeserializationFunctionOrdering.

/**
 * 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.put(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());
}
Also used : JsonTaskQueryConverter(org.camunda.bpm.engine.impl.json.JsonTaskQueryConverter) JSONObject(org.camunda.bpm.engine.impl.util.json.JSONObject) TaskQueryImpl(org.camunda.bpm.engine.impl.TaskQueryImpl) QueryOrderingProperty(org.camunda.bpm.engine.impl.QueryOrderingProperty)

Example 17 with QueryOrderingProperty

use of org.camunda.bpm.engine.impl.QueryOrderingProperty in project camunda-bpm-platform by camunda.

the class JsonQueryOrderingPropertyConverter method toObject.

public QueryOrderingProperty toObject(JSONObject jsonObject) {
    String relation = null;
    if (jsonObject.has(RELATION)) {
        relation = jsonObject.getString(RELATION);
    }
    QueryOrderingProperty property = null;
    if (QueryOrderingProperty.RELATION_VARIABLE.equals(relation)) {
        property = new VariableOrderProperty();
    } else {
        property = new QueryOrderingProperty();
    }
    property.setRelation(relation);
    if (jsonObject.has(QUERY_PROPERTY)) {
        String propertyName = jsonObject.getString(QUERY_PROPERTY);
        String propertyFunction = null;
        if (jsonObject.has(QUERY_PROPERTY_FUNCTION)) {
            propertyFunction = jsonObject.getString(QUERY_PROPERTY_FUNCTION);
        }
        QueryProperty queryProperty = new QueryPropertyImpl(propertyName, propertyFunction);
        property.setQueryProperty(queryProperty);
    }
    if (jsonObject.has(DIRECTION)) {
        String direction = jsonObject.getString(DIRECTION);
        property.setDirection(Direction.findByName(direction));
    }
    if (jsonObject.has(RELATION_CONDITIONS)) {
        List<QueryEntityRelationCondition> relationConditions = JsonQueryFilteringPropertyConverter.ARRAY_CONVERTER.toObject(jsonObject.getJSONArray(RELATION_CONDITIONS));
        property.setRelationConditions(relationConditions);
    }
    return property;
}
Also used : QueryPropertyImpl(org.camunda.bpm.engine.impl.QueryPropertyImpl) VariableInstanceQueryProperty(org.camunda.bpm.engine.impl.VariableInstanceQueryProperty) QueryProperty(org.camunda.bpm.engine.query.QueryProperty) QueryOrderingProperty(org.camunda.bpm.engine.impl.QueryOrderingProperty) VariableOrderProperty(org.camunda.bpm.engine.impl.VariableOrderProperty) QueryEntityRelationCondition(org.camunda.bpm.engine.impl.QueryEntityRelationCondition)

Example 18 with QueryOrderingProperty

use of org.camunda.bpm.engine.impl.QueryOrderingProperty in project camunda-bpm-platform by camunda.

the class HistoricCaseActivityInstanceTest method assertQuerySorting.

@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()])));
}
Also used : Matcher(org.hamcrest.Matcher) ArrayList(java.util.ArrayList) AbstractQuery(org.camunda.bpm.engine.impl.AbstractQuery) QueryOrderingProperty(org.camunda.bpm.engine.impl.QueryOrderingProperty)

Aggregations

QueryOrderingProperty (org.camunda.bpm.engine.impl.QueryOrderingProperty)18 TaskQueryImpl (org.camunda.bpm.engine.impl.TaskQueryImpl)8 ArrayList (java.util.ArrayList)6 QueryPropertyImpl (org.camunda.bpm.engine.impl.QueryPropertyImpl)5 VariableOrderProperty (org.camunda.bpm.engine.impl.VariableOrderProperty)3 ListQueryParameterObject (org.camunda.bpm.engine.impl.db.ListQueryParameterObject)3 JsonTaskQueryConverter (org.camunda.bpm.engine.impl.json.JsonTaskQueryConverter)3 JSONObject (org.camunda.bpm.engine.impl.util.json.JSONObject)3 Filter (org.camunda.bpm.engine.filter.Filter)2 QueryEntityRelationCondition (org.camunda.bpm.engine.impl.QueryEntityRelationCondition)2 TaskQueryVariableValue (org.camunda.bpm.engine.impl.TaskQueryVariableValue)2 QueryProperty (org.camunda.bpm.engine.query.QueryProperty)2 Date (java.util.Date)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 List (java.util.List)1 AuthenticationException (javax.naming.AuthenticationException)1 NamingException (javax.naming.NamingException)1 Control (javax.naming.ldap.Control)1 SortControl (javax.naming.ldap.SortControl)1