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

org.bigml.binding.resources.Cluster Maven / Gradle / Ivy

Go to download

An open source Java client that gives you a simple binding to interact with BigML. You can use it to easily create, retrieve, list, update, and delete BigML resources.

There is a newer version: 2.1.1
Show newest version
package org.bigml.binding.resources;

import org.bigml.binding.BigMLClient;
import org.bigml.binding.utils.CacheManager;
import org.json.simple.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Entry point to create, retrieve, list, update, and delete clusters.
 *
 * Full API documentation on the API can be found from BigML at:
 * https://bigml.com/api/clusters
 *
 *
 */
public class Cluster extends AbstractModelResource {

    // Logging
    Logger logger = LoggerFactory.getLogger(Cluster.class);
    
    /**
     * Constructor
     *
     * @deprecated
     */
	public Cluster() {
		super.init(null, null, null, null, null, 
				CLUSTER_RE, CLUSTER_PATH);
	}

	/**
	 * Constructor
	 *
	 * @deprecated
	 */
	public Cluster(final String apiUser, final String apiKey) {
		super.init(apiUser, apiKey, null, null, null, 
				CLUSTER_RE, CLUSTER_PATH);
	}
	
	/**
	 * Constructor
	 *
	 * @deprecated
	 */
	public Cluster(final String apiUser, final String apiKey,
			final CacheManager cacheManager) {
		super.init(apiUser, apiKey, null, null, null, 
				CLUSTER_RE, CLUSTER_PATH);
	}
	
    /**
     * Constructor
     *
     */
    public Cluster(final BigMLClient bigmlClient,
    			   final String apiUser, final String apiKey, 
    			   final String project, final String organization,
    			   final CacheManager cacheManager) {
    		super.init(bigmlClient, apiUser, apiKey, project, organization,
    				   cacheManager, CLUSTER_RE, CLUSTER_PATH);
    }

    /**
     * Retrieves a cluster.
     *
     * GET
     * /andromeda/cluster/id?username=$BIGML_USERNAME;api_key=$BIGML_API_KEY;
     * Host: bigml.io
     *
     * @param clusterId
     *            a unique identifier in the form cluster/id where id is a
     *            string of 24 alpha-numeric chars.
     * @param apiUser
     *            API user
     * @param apiKey
     *            API key
     *
     */
    public JSONObject get(final String clusterId, final String apiUser,
            final String apiKey) {
        if (clusterId == null || clusterId.length() == 0
                || !(clusterId.matches(CLUSTER_RE))) {
            logger.info("Wrong cluster id");
            return null;
        }

        return getResource(BIGML_URL + clusterId, null, apiUser, apiKey);
    }

    /**
     * Retrieves a cluster.
     *
     * GET
     * /andromeda/cluster/id?username=$BIGML_USERNAME;api_key=$BIGML_API_KEY;
     * Host: bigml.io
     *
     * @param cluster
     *            a cluster JSONObject
     * @param apiUser
     *            API user
     * @param apiKey
     *            API key
     *
     */
    public JSONObject get(final JSONObject cluster, final String apiUser,
            final String apiKey) {
        String resourceId = (String) cluster.get("resource");
        return get(resourceId, apiUser, apiKey);
    }

    /**
     * Retrieves a cluster.
     *
     * GET
     * /andromeda/cluster/id?username=$BIGML_USERNAME;api_key=$BIGML_API_KEY;
     * Host: bigml.io
     *
     * @param clusterId
     *            a unique identifier in the form cluster/id where id is a
     *            string of 24 alpha-numeric chars.
     * @param queryString
     *            query for filtering.
     * @param apiUser
     *            API user
     * @param apiKey
     *            API key
     *
     */
    public JSONObject get(final String clusterId, final String queryString,
            final String apiUser, final String apiKey) {
        if (clusterId == null || clusterId.length() == 0
                || !(clusterId.matches(CLUSTER_RE))) {
            logger.info("Wrong cluster id");
            return null;
        }

        return getResource(BIGML_URL + clusterId, queryString, apiUser, apiKey);
    }

    /**
     * Retrieves a cluster.
     *
     * GET
     * /andromeda/cluster/id?username=$BIGML_USERNAME;api_key=$BIGML_API_KEY;
     * Host: bigml.io
     *
     * @param cluster
     *            a cluster JSONObject
     * @param queryString
     *            query for filtering
     * @param apiUser
     *            API user
     * @param apiKey
     *            API key
     *
     */
    public JSONObject get(final JSONObject cluster, final String queryString,
            final String apiUser, final String apiKey) {
        String resourceId = (String) cluster.get("resource");
        return get(resourceId, queryString, apiUser, apiKey);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy