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

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

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

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

import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

class EntriesModel {

    protected JSONObject jsonObject;
    protected List objectList;

    protected EntriesModel(JSONObject responseJSON) {
        try {
            this.jsonObject = responseJSON;
            objectList = new ArrayList<>();
            Object entryList = jsonObject.opt("entries");
            if (entryList instanceof JSONArray) {
                JSONArray entries = (JSONArray) entryList;
                if (entries.length() > 0) {
                    entries.forEach(model -> {
                        if (model instanceof JSONObject) {
                            JSONObject newModel = (JSONObject) model;
                            EntryModel entry = new EntryModel(newModel);
                            objectList.add(entry);
                        }
                    });
                }
            }
        } catch (Exception e) {
            Logger logger = Logger.getLogger(EntriesModel.class.getSimpleName());
            logger.log(Level.SEVERE, e.getLocalizedMessage(), e);
        }

    }
}