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

org.duracloud.retrieval.util.StoreClientUtil Maven / Gradle / Ivy

There is a newer version: 8.1.0
Show newest version
/*
 * The contents of this file are subject to the license and copyright
 * detailed in the LICENSE and NOTICE files at the root of the source
 * tree and available online at
 *
 *     http://duracloud.org/license/
 */
package org.duracloud.retrieval.util;

import org.duracloud.client.ContentStore;
import org.duracloud.client.ContentStoreManager;
import org.duracloud.client.ContentStoreManagerImpl;
import org.duracloud.common.model.Credential;
import org.duracloud.error.ContentStoreException;

/**
 * @author: Bill Branan
 * Date: Oct 15, 2010
 */
public class StoreClientUtil {

    public ContentStore createContentStore(String host,
                                           int port,
                                           String context,
                                           String username,
                                           String password,
                                           String storeId) {
        ContentStoreManager storeManager =
            new ContentStoreManagerImpl(host, String.valueOf(port), context);
        storeManager.login(new Credential(username, password));

        ContentStore contentStore;
        try {
            if(storeId != null) {
                contentStore = storeManager.getContentStore(storeId);
            } else {
                contentStore = storeManager.getPrimaryContentStore();
            }
        } catch(ContentStoreException e) {
            throw new RuntimeException("Could not create connection to " +
                "DuraStore due to " + e.getMessage(), e);
        }

        return contentStore;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy