Search in sources :

Example 1 with TupleEntry

use of org.alfresco.rest.api.search.model.TupleEntry in project alfresco-remote-api by Alfresco.

the class ResultMapper method toCollectionWithPagingInfo.

public CollectionWithPagingInfo<TupleList> toCollectionWithPagingInfo(JSONArray docs, SearchSQLQuery searchQuery) throws JSONException {
    if (docs == null) {
        throw new RuntimeException("Solr response is required instead of JSONArray docs was null");
    }
    if (searchQuery == null) {
        throw new RuntimeException("SearchSQLQuery is required");
    }
    List<TupleList> entries = new ArrayList<TupleList>();
    for (int i = 0; i < docs.length() - 1; i++) {
        List<TupleEntry> row = new ArrayList<TupleEntry>();
        JSONObject docObj = (JSONObject) docs.get(i);
        docObj.keys().forEachRemaining(action -> {
            try {
                String value = docObj.get(action.toString()).toString();
                row.add(new TupleEntry(action.toString(), value));
            } catch (JSONException e) {
                throw new RuntimeException("Unable to parse SQL response. " + e);
            }
        });
        entries.add(new TupleList(row));
    }
    Paging paging = Paging.valueOf(0, searchQuery.getItemLimit());
    return CollectionWithPagingInfo.asPaged(paging, entries);
}
Also used : TupleList(org.alfresco.rest.api.search.model.TupleList) TupleEntry(org.alfresco.rest.api.search.model.TupleEntry) JSONObject(org.json.JSONObject) Paging(org.alfresco.rest.framework.resource.parameters.Paging) ArrayList(java.util.ArrayList) JSONException(org.json.JSONException)

Aggregations

ArrayList (java.util.ArrayList)1 TupleEntry (org.alfresco.rest.api.search.model.TupleEntry)1 TupleList (org.alfresco.rest.api.search.model.TupleList)1 Paging (org.alfresco.rest.framework.resource.parameters.Paging)1 JSONException (org.json.JSONException)1 JSONObject (org.json.JSONObject)1