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

com.jelastic.api.users.response.ApiTokenTemplatesResponse Maven / Gradle / Ivy

The newest version!
/*Server class MD5: 572246eaf4e2dd13e2b6b279913d2ca5*/
package com.jelastic.api.users.response;

import com.jelastic.api.Response;
import com.jelastic.api.core.persistence.entity.ApiTokenTemplate;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.Set;

/**
 * @name Jelastic API Client
 * @version 8.11.2
 * @copyright Jelastic, Inc.
 */
public class ApiTokenTemplatesResponse extends Response {

    public static final String TEMPLATES = "templates";

    private Set templates;

    public ApiTokenTemplatesResponse() {
        super(Response.OK);
    }

    public ApiTokenTemplatesResponse(Set templates) {
        super(Response.OK);
        this.templates = templates;
    }

    public ApiTokenTemplatesResponse(int result, String error) {
        super(result, error);
    }

    public Set getTemplates() {
        return templates;
    }

    public void setTemplates(Set templates) {
        this.templates = templates;
    }

    @Override
    public JSONObject toJSON() {
        JSONObject json = super.toJSON();
        try {
            if (templates != null) {
                JSONArray templatesJson = new JSONArray();
                for (ApiTokenTemplate template : templates) {
                    templatesJson.put(template.toJSON());
                }
                json.put(TEMPLATES, templatesJson);
            }
        } catch (Exception e) {
            e.printStackTrace();
            try {
                json.put("result", Response.ERROR_UNKNOWN).put("error", e.toString());
            } catch (JSONException ex) {
            }
        }
        return json;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy