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

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

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

import com.jelastic.api.Response;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.Serializable;
import java.util.*;

/**
 * @author Ruslan Sinitskiy
 */
public class User implements Serializable {


    private int id;
    private String email;
    private String password;
    private Date reg_date = new Date();
    private String name;
    private Set groups = new HashSet();
    private Set sessionPids = new HashSet();
    private Map applications = new HashMap();
    private UserStatus status = UserStatus.ENABLED;
    private Application nativeApp = null;
    private String language;

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public void setId(int id) {
        this.id = id;
    }

    public int getId() {
        return id;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public Date getReg_date() {
        return reg_date;
    }

    public void setReg_date(Date reg_date) {
        this.reg_date = reg_date;
    }

    public UserStatus getStatus() {
        return status;
    }

    public void setStatus(UserStatus status) {
        this.status = status;
    }

    public Collection getGroups() {
        return groups;
    }

    public void setGroups(Set groups) {
        this.groups = groups;
    }

    public void addGroup(PlatformGroup group) {
        groups.add(group);
    }

    public void removeGroup(PlatformGroup group) {
        groups.remove(group);
    }

    public String getName() {
        return name;
    }

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

    public Set getSessionPids() {
        return sessionPids;
    }

    public void setSessionPids(Set sessionPids) {
        this.sessionPids = sessionPids;
    }

    public Map getApplications() {
        return applications;
    }

    public void setApplications(Map applications) {
        this.applications = applications;
    }

    public Application getNativeApp() {
        return nativeApp;
    }

    public void setNativeApp(Application nativeApp) {
        this.nativeApp = nativeApp;
    }

    public boolean equalsPasswords(String otherPassword) {
        return password.length() > 0 && password.equals(otherPassword);
    }

    public String getLanguage() {
        return language;
    }

    public void setLanguage(String language) {
        this.language = language;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        final User other = (User) obj;
        if (this.id != other.getId()) {
            return false;
        }
        return true;
    }

    public JSONObject _toJSON() throws JSONException {
        JSONObject json = new JSONObject();
        try {
            json.put("id", id);
            json.put("name", name);
            json.put("email", email);
        } catch (Exception e) {
            e.printStackTrace();
            try {
                json.put("result", Response.ERROR_UNKNOWN).put("error", e.toString());
            } catch (JSONException ex) { }
        }
        return json;
    }

    public User _fromJSON(JSONObject json) throws JSONException {
        if (json.has("id")) {
            this.setId(json.getInt("id"));
        }
        if (json.has("email")) {
            this.setEmail(json.getString("email"));
        }
        if (json.has("name")) {
            this.setName(json.getString("name"));
        }
        return this;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy