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

com.jelastic.api.system.persistence.RegionReseller Maven / Gradle / Ivy

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

import com.jelastic.api.billing.response.interfaces.ArrayItem;
import com.jelastic.api.core.utils.DateUtils;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.Serializable;
import java.text.ParseException;
import java.util.Date;

/**
 * Created by doba on 11/13/15.
 */
public class RegionReseller extends ArrayItem implements Serializable {
    private Integer resellerId;
    private Integer regionId;
    private String sslType;
    private String domain;
    private String key;
    private String intermediate;
    private String cert;
    private String nginxCert;
    private Date sslExpireDate;
    private Boolean isSslEnabled;
    private String source502;
    private RegionResellerType type = RegionResellerType.PLATFORM;

    private final static String RESELLER_ID = "resellerId";
    private static final String REGION_ID = "regionId";
    private static final String DOMAIN = "domain";
    private static final String SSL_EXPIRE_DATE = "sslExpireDate";
    private static final String TYPE = "type";
    private static final String SSL_ENABLED = "sslEnabled";
    private static final String KEY = "cert_key";
    private static final String INTERMEDIATE = "intermediate";
    private static final String CERT = "cert";
    private static final String SSL_TYPE = "sslType";
    private static final String NGINX_CERT = "nginxCert";
    private static final String SOURCE_502 = "source502";

    public RegionReseller() {
    }

    public RegionReseller(Integer resellerId, Integer regionId, String domain) {
        this.resellerId= resellerId;
        this.regionId = regionId;
        this.domain = domain;
    }

    public void updateSsl(RegionReseller newRegion) {
        setCert(newRegion.getCert());
        setIntermediate(newRegion.getIntermediate());
        setKey(newRegion.getKey());
        setSslType(newRegion.getSslType());
    }

    public String getDomain() {
        return domain;
    }

    public void setDomain(String domain) {
        this.domain = domain;
    }

    public Integer getRegionId() {
        return regionId;
    }

    public void setRegionId(Integer regionId) {
        this.regionId = regionId;
    }

    public Integer getResellerId() {
        return resellerId;
    }

    public void setResellerId(Integer resellerId) {
        this.resellerId = resellerId;
    }

    public String getKey() {
        return key;
    }

    public void setKey(String key) {
        this.key = key;
    }

    public String getIntermediate() {
        return intermediate;
    }

    public void setIntermediate(String intermediate) {
        this.intermediate = intermediate;
    }

    public String getCert() {
        return cert;
    }

    public void setCert(String cert) {
        this.cert = cert;
    }

    public String getNginxCert() {
        return nginxCert;
    }

    public void setNginxCert(String nginxCert) {
        this.nginxCert = nginxCert;
    }

    public Date getSslExpireDate() {
        return sslExpireDate;
    }

    public void setSslExpireDate(Date sslExpireDate) {
        this.sslExpireDate = sslExpireDate;
    }

    public RegionResellerType getType() {
        return type;
    }

    public void setType(RegionResellerType type) {
        this.type = type;
    }

    public Boolean isSslEnabled() {
        return isSslEnabled;
    }

    public void setSslEnabled(boolean sslEnabled) {
        this.isSslEnabled = sslEnabled;
    }

    public String getSslType() {
        return sslType;
    }

    public void setSslType(String sslType) {
        this.sslType = sslType;
    }

    public Boolean getSslEnabled() {
        return isSslEnabled;
    }

    public void setSslEnabled(Boolean sslEnabled) {
        isSslEnabled = sslEnabled;
    }

    public String getSource502() {
        return source502;
    }

    public void setSource502(String source502) {
        this.source502 = source502;
    }

    @Override
    public JSONObject _toJSON() throws JSONException {
        JSONObject json = new JSONObject();

        json.put(RESELLER_ID, resellerId);
        json.put(REGION_ID, regionId);
        json.put(DOMAIN, domain);
        json.put(KEY, key);
        json.put(INTERMEDIATE, intermediate);
        json.put(CERT, cert);
        json.put(NGINX_CERT, nginxCert);
        json.put(SSL_ENABLED, isSslEnabled);
        json.put(SSL_TYPE, sslType);
        if (sslExpireDate != null) {
            json.put(SSL_EXPIRE_DATE, DateUtils.formatSqlDateTime(sslExpireDate));
        }
        json.put(TYPE, type);
        json.put(SOURCE_502, source502);

        return json;
    }

    @Override
    public RegionReseller _fromJSON(JSONObject json) throws JSONException {
        if (json.has(RESELLER_ID)) {
            this.resellerId = json.getInt(RESELLER_ID);
        }

        if (json.has(REGION_ID)) {
            this.regionId = json.getInt(REGION_ID);
        }

        if (json.has(DOMAIN)) {
            this.domain = json.getString(DOMAIN);
        }

        if (json.has(KEY)) {
            this.key = json.getString(KEY);
        }

        if (json.has(INTERMEDIATE)) {
            this.intermediate = json.getString(INTERMEDIATE);
        }

        if (json.has(CERT)) {
            this.cert = json.getString(CERT);
        }

        if (json.has(NGINX_CERT)) {
            this.nginxCert = json.getString(NGINX_CERT);
        }

        if (json.has(SSL_EXPIRE_DATE)) {
            try {
                this.sslExpireDate = DateUtils.parseSqlDateTime(json.getString(SSL_EXPIRE_DATE));
            } catch (ParseException e) {
                e.printStackTrace();
            }
        }

        if (json.has(TYPE)) {
            this.type = RegionResellerType.valueOf(json.getString(TYPE).toUpperCase());
        }

        if (json.has(SSL_ENABLED)) {
            this.isSslEnabled = json.getBoolean(SSL_ENABLED);
        }

        if (json.has(SSL_TYPE)) {
            this.sslType = json.getString(SSL_TYPE);

            if (this.sslType.isEmpty()) {
                this.sslType = null;
            }
        }

        if (json.has(SOURCE_502)) {
            this.source502 = json.getString(SOURCE_502);
        }

        return this;
    }


    @Override
    public String toString() {
        return "RegionReseller{" +
                "resellerId=" + resellerId +
                ", regionId=" + regionId +
                ", domain='" + domain + '\'' +
                ", key='" + key + '\'' +
                ", intermediate='" + intermediate + '\'' +
                ", cert='" + cert + '\'' +
                ", nginxCert='" + nginxCert + '\'' +
                ", sslExpireDate=" + sslExpireDate +
                ", isSslEnabled=" + isSslEnabled +
                ", type=" + type +
                ", sslType=" + sslType +
                '}';
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy