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

com.jelastic.api.development.persistence.ApiTokenTemplate Maven / Gradle / Ivy

The newest version!
package com.jelastic.api.development.persistence;

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

import java.io.Serializable;
import java.util.Set;

/**
 * @author Maksym Shevchuk
 */
public class ApiTokenTemplate implements Serializable {
    private static final String NAME = "name";
    private static final String API_LIST = "apiList";

    private String name;
    private Set apiList;

    public ApiTokenTemplate() {
    }

    public ApiTokenTemplate(String name, Set apiList) {
        this.name = name;
        this.apiList = apiList;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Set getApiList() {
        return apiList;
    }

    public void setApiList(Set apiList) {
        this.apiList = apiList;
    }

    public JSONObject toJSON() {
        JSONObject json = new JSONObject();
        try {
            if (name != null) {
                json.put(NAME, name);
            }

            if (apiList != null) {
                JSONArray permissionsJson = new JSONArray();
                for (ApiTokenPermission apiListItem : apiList) {
                    permissionsJson.put(apiListItem);
                }
                json.put(API_LIST, permissionsJson);
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }

        return json;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy