Search in sources :

Example 1 with DefaultQuerySpecSerializer

use of io.crnk.core.queryspec.DefaultQuerySpecSerializer in project crnk-framework by crnk-project.

the class SleuthUtil method getQuery.

public static String getQuery(RepositoryRequestSpec request, ResourceRegistry resourceRegistry) {
    QueryAdapter queryAdapter = request.getQueryAdapter();
    StringBuilder builder = new StringBuilder();
    builder.append("?");
    if (queryAdapter instanceof QuerySpecAdapter) {
        QuerySpec querySpec = request.getQuerySpec(queryAdapter.getResourceInformation());
        DefaultQuerySpecSerializer serializer = new DefaultQuerySpecSerializer(resourceRegistry);
        Map<String, Set<String>> parameters = serializer.serialize(querySpec);
        for (Map.Entry<String, Set<String>> entry : parameters.entrySet()) {
            if (builder.length() > 1) {
                builder.append("&");
            }
            builder.append(entry.getKey());
            builder.append("=");
            builder.append(StringUtils.join(",", entry.getValue()));
        }
        return builder.toString();
    }
    return null;
}
Also used : Set(java.util.Set) DefaultQuerySpecSerializer(io.crnk.core.queryspec.DefaultQuerySpecSerializer) QueryAdapter(io.crnk.core.engine.query.QueryAdapter) QuerySpecAdapter(io.crnk.core.queryspec.internal.QuerySpecAdapter) QuerySpec(io.crnk.core.queryspec.QuerySpec) Map(java.util.Map)

Example 2 with DefaultQuerySpecSerializer

use of io.crnk.core.queryspec.DefaultQuerySpecSerializer in project crnk-framework by crnk-project.

the class BraveUtil method getQuery.

public static String getQuery(RepositoryRequestSpec request, ResourceRegistry resourceRegistry) {
    QueryAdapter queryAdapter = request.getQueryAdapter();
    StringBuilder builder = new StringBuilder();
    builder.append("?");
    if (queryAdapter instanceof QuerySpecAdapter) {
        QuerySpec querySpec = request.getQuerySpec(queryAdapter.getResourceInformation());
        DefaultQuerySpecSerializer serializer = new DefaultQuerySpecSerializer(resourceRegistry);
        Map<String, Set<String>> parameters = serializer.serialize(querySpec);
        for (Map.Entry<String, Set<String>> entry : parameters.entrySet()) {
            if (builder.length() > 1) {
                builder.append("&");
            }
            builder.append(entry.getKey());
            builder.append("=");
            builder.append(StringUtils.join(",", entry.getValue()));
        }
        return builder.toString();
    }
    return null;
}
Also used : Set(java.util.Set) DefaultQuerySpecSerializer(io.crnk.core.queryspec.DefaultQuerySpecSerializer) QueryAdapter(io.crnk.core.engine.query.QueryAdapter) QuerySpecAdapter(io.crnk.core.queryspec.internal.QuerySpecAdapter) QuerySpec(io.crnk.core.queryspec.QuerySpec) Map(java.util.Map)

Aggregations

QueryAdapter (io.crnk.core.engine.query.QueryAdapter)2 DefaultQuerySpecSerializer (io.crnk.core.queryspec.DefaultQuerySpecSerializer)2 QuerySpec (io.crnk.core.queryspec.QuerySpec)2 QuerySpecAdapter (io.crnk.core.queryspec.internal.QuerySpecAdapter)2 Map (java.util.Map)2 Set (java.util.Set)2