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

com.jelastic.api.environment.response.FilePermissionResponse Maven / Gradle / Ivy

The newest version!
/*Server class MD5: df34eb8c1a7255661118d9eb9b394948*/
package com.jelastic.api.environment.response;

import com.jelastic.api.Response;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.HashSet;
import java.util.Set;

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

    public static final String RESPONSES = "responses";

    public static final String PERMISSION = "permission";

    public static final String PATH = "path";

    public static final String IS_DIRECTORY = "isDirectory";

    private String permission;

    private String path;

    private boolean isDirectory;

    private String user;

    private Set responses = new HashSet();

    public FilePermissionResponse() {
    }

    public FilePermissionResponse(int result) {
        super(result);
    }

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

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

    public FilePermissionResponse(Set responses) {
        super(OK);
        this.responses = responses;
    }

    public FilePermissionResponse(NodeSSHResponse response) {
        super(OK);
        this.responses = new HashSet();
        this.responses.add(response);
    }

    public Set getResponses() {
        return responses;
    }

    public void setResponses(Set responses) {
        this.responses = responses;
    }

    public String getPermission() {
        return permission;
    }

    public void setPermission(String permission) {
        this.permission = permission;
    }

    public String getPath() {
        return path;
    }

    public void setPath(String path) {
        this.path = path;
    }

    public boolean isDirectory() {
        return isDirectory;
    }

    public void setDirectory(boolean directory) {
        isDirectory = directory;
    }

    public String getUser() {
        return user;
    }

    public void setUser(String user) {
        this.user = user;
    }

    @Override
    protected FilePermissionResponse _fromJSON(JSONObject json) throws JSONException {
        super._fromJSON(json);
        if (json.has(PERMISSION)) {
            permission = json.getString(PERMISSION);
        }
        if (json.has(PATH)) {
            path = json.getString(PATH);
        }
        if (json.has(IS_DIRECTORY)) {
            isDirectory = json.getBoolean(IS_DIRECTORY);
        }
        JSONArray nodesJson = json.optJSONArray(RESPONSES);
        if (nodesJson != null) {
            responses = new HashSet();
            for (int i = 0; i < nodesJson.length(); i++) {
                JSONObject response = nodesJson.getJSONObject(i);
                responses.add(new NodeSSHResponse()._fromJSON(response));
            }
        }
        return this;
    }

    @Override
    protected JSONObject _toJSON() throws JSONException {
        JSONObject json = super._toJSON();
        json.put(PERMISSION, permission);
        json.put(PATH, path);
        json.put(IS_DIRECTORY, isDirectory);
        if (responses != null) {
            JSONArray nodesJson = new JSONArray();
            for (NodeSSHResponse response : responses) {
                nodesJson.put(response.toJSON());
            }
            json.put(RESPONSES, nodesJson);
        }
        return json;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy