Search in sources :

Example 1 with Direction

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

the class JsonLegacyQueryOrderingPropertyConverter method fromOrderByString.

public List<QueryOrderingProperty> fromOrderByString(String orderByString) {
    List<QueryOrderingProperty> properties = new ArrayList<QueryOrderingProperty>();
    String[] orderByClauses = orderByString.split(ORDER_BY_DELIMITER);
    for (String orderByClause : orderByClauses) {
        orderByClause = orderByClause.trim();
        String[] clauseParts = orderByClause.split(" ");
        if (clauseParts.length == 0) {
            continue;
        } else if (clauseParts.length > 2) {
            throw new ProcessEngineException("Invalid order by clause: " + orderByClause);
        }
        String function = null;
        String propertyPart = clauseParts[0];
        int functionArgumentBegin = propertyPart.indexOf("(");
        if (functionArgumentBegin >= 0) {
            function = propertyPart.substring(0, functionArgumentBegin);
            int functionArgumentEnd = propertyPart.indexOf(")");
            propertyPart = propertyPart.substring(functionArgumentBegin + 1, functionArgumentEnd);
        }
        String[] propertyParts = propertyPart.split("\\.");
        String property = null;
        if (propertyParts.length == 1) {
            property = propertyParts[0];
        } else if (propertyParts.length == 2) {
            property = propertyParts[1];
        } else {
            throw new ProcessEngineException("Invalid order by property part: " + clauseParts[0]);
        }
        QueryProperty queryProperty = new QueryPropertyImpl(property, function);
        Direction direction = null;
        if (clauseParts.length == 2) {
            String directionPart = clauseParts[1];
            direction = Direction.findByName(directionPart);
        }
        QueryOrderingProperty orderingProperty = new QueryOrderingProperty(null, queryProperty);
        orderingProperty.setDirection(direction);
        properties.add(orderingProperty);
    }
    return properties;
}
Also used : QueryPropertyImpl(org.camunda.bpm.engine.impl.QueryPropertyImpl) ArrayList(java.util.ArrayList) QueryProperty(org.camunda.bpm.engine.query.QueryProperty) QueryOrderingProperty(org.camunda.bpm.engine.impl.QueryOrderingProperty) Direction(org.camunda.bpm.engine.impl.Direction) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException)

Example 2 with Direction

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

the class JsonQueryOrderingPropertyConverter method toJsonObject.

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;
}
Also used : JSONObject(org.camunda.bpm.engine.impl.util.json.JSONObject) VariableInstanceQueryProperty(org.camunda.bpm.engine.impl.VariableInstanceQueryProperty) QueryProperty(org.camunda.bpm.engine.query.QueryProperty) JSONArray(org.camunda.bpm.engine.impl.util.json.JSONArray) Direction(org.camunda.bpm.engine.impl.Direction)

Aggregations

Direction (org.camunda.bpm.engine.impl.Direction)2 QueryProperty (org.camunda.bpm.engine.query.QueryProperty)2 ArrayList (java.util.ArrayList)1 ProcessEngineException (org.camunda.bpm.engine.ProcessEngineException)1 QueryOrderingProperty (org.camunda.bpm.engine.impl.QueryOrderingProperty)1 QueryPropertyImpl (org.camunda.bpm.engine.impl.QueryPropertyImpl)1 VariableInstanceQueryProperty (org.camunda.bpm.engine.impl.VariableInstanceQueryProperty)1 JSONArray (org.camunda.bpm.engine.impl.util.json.JSONArray)1 JSONObject (org.camunda.bpm.engine.impl.util.json.JSONObject)1