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

org.openstack4j.model.storage.object.options.CreateUpdateContainerOptions Maven / Gradle / Ivy

There is a newer version: 3.2.0
Show newest version
package org.openstack4j.model.storage.object.options;

import static org.openstack4j.model.storage.object.SwiftHeaders.*;

import java.util.Map;

import org.openstack4j.openstack.storage.object.functions.MetadataToHeadersFunction;

import com.google.common.collect.Maps;

/**
 * Options for creating or updating a container
 * 
 * @author Jeremy Unruh
 */
public final class CreateUpdateContainerOptions {

    private Map headers = Maps.newHashMap();
    
    private CreateUpdateContainerOptions() {
    }
    
    /**
     * Creates a new CreateUpdateContainerOptions
     * @return CreateUpdateContainerOptions
     */
    public static final CreateUpdateContainerOptions create() {
        return new CreateUpdateContainerOptions();
    }
    
    /**
     * Adds additional headers to the create or update request
     * 
     * @param headers the headers to add
     * @return CreateUpdateContainerOptions
     */
    public CreateUpdateContainerOptions headers(Map headers) {
        this.headers.putAll(headers);
        return this;
    }
    
    /**
     * Sets the metadata against the container being created or updated
     * 
     * @param metadata the metadata to set
     * @return CreateUpdateContainerOptions
     */
    public CreateUpdateContainerOptions metadata(Map metadata) {
        this.headers.putAll(MetadataToHeadersFunction.create(CONTAINER_METADATA_PREFIX).apply(metadata));
        return this;
    }
    
    /**
     * Enables versioning on this container. The value is the name of another container. 
     * You must UTF-8-encode and then URL-encode the name before you include it in the header. 
     * To disable versioning, set the header to an empty string.
     * 
     * @param containerName the container name of the other container
     * @return CreateUpdateContainerOptions
     */
    public CreateUpdateContainerOptions versionsLocation(String containerName) {
        add(VERSIONS_LOCATION, containerName);
        return this;
    }
    
    /**
     * Sets the read ACL (if supported) to allow public access
     * 
     * @return CreateUpdateContainerOptions
     */
    public CreateUpdateContainerOptions accessAnybodyRead() {
        add(CONTAINER_READ, CONTAINER_ACL_ANYBODY_READ);
        return this;
    }
    
    /**
     * Sets the read ACL (if supported)
     * 
     * @param acl the read access control list
     * @return CreateUpdateContainerOptions
     */
    public CreateUpdateContainerOptions accessRead(String acl) {
        add(CONTAINER_READ, acl);
        return this;
    }
    
    /**
     * Sets the write ACL (if supported)
     * 
     * @param acl the write access control list
     * @return CreateUpdateContainerOptions
     */
    public CreateUpdateContainerOptions accessWrite(String acl) {
        add(CONTAINER_WRITE, acl);
        return this;
    }
    
    public Map getOptions() {
        return headers;
    }
    
    private void add(String key, String value) {
        this.headers.put(key, value);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy