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

com.jelastic.api.data.po.BuildCustomData Maven / Gradle / Ivy

The newest version!
/*Server class MD5: eabd7ed94c6fe1d24c78e4bc2a8dda45*/
package com.jelastic.api.data.po;

import java.util.ArrayList;
import java.util.List;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

/**
 * @name Jelastic API Client
 * @version 8.11.2
 * @copyright Jelastic, Inc.
 */
public class BuildCustomData implements DBItem {

    private List projects = new ArrayList();

    public BuildCustomData() {
    }

    public BuildCustomData(List projects) {
        this.projects = projects;
    }

    public BuildCustomData(String data) {
        _fromString(data);
    }

    public BuildProject getProjetcById(int projectId) {
        for (BuildProject project : projects) {
            if (projectId == project.getId()) {
                return project;
            }
        }
        return null;
    }

    public BuildCustomData(JSONObject data) {
        try {
            _fromJSON(data);
        } catch (JSONException ex) {
            ex.printStackTrace();
        }
    }

    public List getProjects() {
        return projects;
    }

    public void setProjects(List projects) {
        this.projects = projects;
    }

    private void _fromString(String stringJson) {
        JSONObject json;
        try {
            json = new JSONObject(stringJson);
            this._fromJSON(json);
        } catch (JSONException ex) {
            ex.printStackTrace();
        }
    }

    @Override
    public JSONObject _toJSON() throws JSONException {
        JSONObject json = new JSONObject();
        JSONArray pjs = new JSONArray();
        for (BuildProject buildProject : projects) {
            pjs.put(buildProject._toJSON());
        }
        json.put("projects", pjs);
        return json;
    }

    @Override
    public BuildCustomData _fromJSON(JSONObject json) throws JSONException {
        if (json.has("projects")) {
            JSONArray array = json.getJSONArray("projects");
            projects = new ArrayList();
            for (int i = 0; i < array.length(); i++) {
                projects.add(new BuildProject()._fromJSON(array.getJSONObject(i)));
            }
        }
        return this;
    }

    @Override
    public String toString() {
        try {
            return this._toJSON().toString();
        } catch (JSONException ex) {
            ex.printStackTrace();
        }
        return null;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy