All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.contentstack.sdk.QueryResult Maven / Gradle / Ivy

There is a newer version: 2.0.2
Show newest version
package com.contentstack.sdk;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.List;

/**
 *
 * MIT License
 *
 * Copyright (c) 2012 - 2019 Contentstack
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */


public class QueryResult {


    private static final String TAG = "QueryResult";
    protected JSONObject receiveJson;
    protected JSONArray schemaArray;
    protected JSONObject contentObject;
    protected int count;
    protected List resultObjects;


    /**
     * @return List of {@link Entry} objects list.
     * 

Example :
*
     * List<Entry> list = queryResultObject.getResultObjects();
*
*/ public List getResultObjects() { return resultObjects; } /** * Returns count of objects available.
* Note : * To retrieve this data, {@link Query#includeCount()} or {@link Query#count()} * should be added in {@link Query} while querying. * @return int count *

Example :
*
     * int count = queryResultObject.getCount();
*
*/ public int getCount() { return count; } /** * Returns class's schema if call to fetch schema executed successfully. * @return JSONArray schema Array *

Example :
*
     * JSONArray schemaArray = queryResultObject.getSchema();
*
*/ public JSONArray getSchema() { return schemaArray; } /** * Returns class's content type if call to fetch contentType executed successfully. * @return JSONObject contentObject *

Example :
*
     * JSONObject contentObject = queryResultObject.getContentType();
*
*/ public JSONObject getContentType() { return contentObject; } protected void setJSON(JSONObject jsonobject, List objectList) { receiveJson = jsonobject; resultObjects = objectList; try{ if(receiveJson != null){ if(receiveJson.has("schema")){ JSONArray jsonarray = new JSONArray(); jsonarray = receiveJson.getJSONArray("schema"); if(jsonarray != null){ schemaArray = jsonarray; } } if(receiveJson.has("content_type")){ JSONObject jsonObject = receiveJson.getJSONObject("content_type"); if(jsonObject != null){ contentObject = jsonObject; } } if(receiveJson.has("count")){ count = receiveJson.optInt("count"); } if(count <= 0){ if(receiveJson.has("entries")){ count = receiveJson.optInt("entries"); } } } }catch(Exception e){ Stack.log(TAG, "-QueryResult--setJSON--"+e.getLocalizedMessage()); } } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy