Search in sources :

Example 1 with StorageAdvice

use of org.commonjava.indy.dotmaven.data.StorageAdvice in project indy by Commonjava.

the class ArtifactStoreSubStore method createFolder.

@Override
public void createFolder(final ITransaction transaction, final String folderUri) throws WebdavException {
    final StoreURIMatcher matcher = new StoreURIMatcher(folderUri);
    if (!matcher.hasStorePath()) {
        throw new WebdavException("No store-level path specified: '" + folderUri + "'. This URI references either a list of stores, a root store directory, or something else equally read-only.");
    }
    final StorageAdvice advice = getStorageAdviceFor(matcher);
    final String path = matcher.getStorePath();
    final Transfer item = fileManager.getStorageReference(advice.getHostedStore(), path);
    try {
        item.mkdirs();
    } catch (final IOException e) {
        logger.error("Failed to create folder: {} in store: {}. Reason: {}", e, path, advice.getStore().getKey(), e.getMessage());
        throw new WebdavException("Failed to create folder: " + folderUri);
    }
}
Also used : StoreURIMatcher(org.commonjava.indy.dotmaven.util.StoreURIMatcher) StorageAdvice(org.commonjava.indy.dotmaven.data.StorageAdvice) WebdavException(net.sf.webdav.exceptions.WebdavException) Transfer(org.commonjava.maven.galley.model.Transfer) IOException(java.io.IOException)

Example 2 with StorageAdvice

use of org.commonjava.indy.dotmaven.data.StorageAdvice in project indy by Commonjava.

the class SettingsSubStore method getSettingsTemplate.

private synchronized SettingsTemplate getSettingsTemplate(final URIMatcher matcher) throws WebdavException {
    final StoreKey key = matcher.getStoreKey();
    ArtifactStore store;
    try {
        store = indy.getArtifactStore(key);
    } catch (final IndyDataException e) {
        logger.error(String.format("Failed to retrieve artifact store: %s. Reason: %s", key, e.getMessage()), e);
        throw new WebdavException("Failed to retrieve length for: " + matcher.getURI());
    }
    if (store == null) {
        throw new WebdavException("Cannot retrieve ArtifactStore: " + key);
    }
    StorageAdvice advice;
    try {
        advice = advisor.getStorageAdvice(store);
    } catch (final DotMavenException e) {
        logger.error(String.format("Failed to retrieve storage advice for: %s. Reason: %s", key, e.getMessage()), e);
        throw new WebdavException("Failed to retrieve length for: " + matcher.getURI());
    }
    return new SettingsTemplate(key, advice, requestInfo, templatingEngine);
}
Also used : IndyDataException(org.commonjava.indy.data.IndyDataException) StorageAdvice(org.commonjava.indy.dotmaven.data.StorageAdvice) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) SettingsTemplate(org.commonjava.indy.dotmaven.util.SettingsTemplate) WebdavException(net.sf.webdav.exceptions.WebdavException) StoreKey(org.commonjava.indy.model.core.StoreKey) DotMavenException(org.commonjava.indy.dotmaven.DotMavenException)

Example 3 with StorageAdvice

use of org.commonjava.indy.dotmaven.data.StorageAdvice in project indy by Commonjava.

the class ArtifactStoreSubStore method setResourceContent.

@Override
public long setResourceContent(final ITransaction transaction, final String resourceUri, final InputStream content, final String contentType, final String characterEncoding) throws WebdavException {
    final StoreURIMatcher matcher = new StoreURIMatcher(resourceUri);
    if (!matcher.hasStorePath()) {
        throw new WebdavException("No store-level path specified: '" + resourceUri + "'. This URI references either a list of stores, a root store directory, or something else equally read-only.");
    }
    final StorageAdvice advice = getStorageAdviceFor(matcher);
    final String path = matcher.getStorePath();
    final Transfer item = fileManager.getStorageReference(advice.getHostedStore(), path);
    Writer writer = null;
    try {
        if (characterEncoding != null) {
            writer = new OutputStreamWriter(item.openOutputStream(TransferOperation.UPLOAD), characterEncoding);
        } else {
            writer = new OutputStreamWriter(item.openOutputStream(TransferOperation.UPLOAD));
        }
        copy(content, writer);
        return item.length();
    } catch (final IOException e) {
        logger.error("Failed to write file: {} in store: {}. Reason: {}", e, path, advice.getStore().getKey(), e.getMessage());
        throw new WebdavException("Failed to write file: " + resourceUri);
    } finally {
        closeQuietly(writer);
    }
}
Also used : StoreURIMatcher(org.commonjava.indy.dotmaven.util.StoreURIMatcher) StorageAdvice(org.commonjava.indy.dotmaven.data.StorageAdvice) WebdavException(net.sf.webdav.exceptions.WebdavException) Transfer(org.commonjava.maven.galley.model.Transfer) OutputStreamWriter(java.io.OutputStreamWriter) IOException(java.io.IOException) OutputStreamWriter(java.io.OutputStreamWriter) Writer(java.io.Writer)

Example 4 with StorageAdvice

use of org.commonjava.indy.dotmaven.data.StorageAdvice in project indy by Commonjava.

the class ArtifactStoreSubStore method removeObject.

@Override
public void removeObject(final ITransaction transaction, final String uri) throws WebdavException {
    final StoreURIMatcher matcher = new StoreURIMatcher(uri);
    if (!matcher.hasStorePath()) {
        throw new WebdavException("No store-level path specified: '" + uri + "'. This URI references either a list of stores, a root store directory, or something else equally read-only.");
    }
    final StorageAdvice advice = getStorageAdviceFor(matcher);
    final String path = matcher.getStorePath();
    final Transfer item = fileManager.getStorageReference(advice.getHostedStore(), path);
    try {
        if (item.exists()) {
            item.delete();
        }
    } catch (final IOException e) {
        logger.error("Failed to delete file: {} in store: {}. Reason: {}", e, path, advice.getStore().getKey(), e.getMessage());
        throw new WebdavException("Failed to delete file: " + uri);
    }
}
Also used : StoreURIMatcher(org.commonjava.indy.dotmaven.util.StoreURIMatcher) StorageAdvice(org.commonjava.indy.dotmaven.data.StorageAdvice) WebdavException(net.sf.webdav.exceptions.WebdavException) Transfer(org.commonjava.maven.galley.model.Transfer) IOException(java.io.IOException)

Example 5 with StorageAdvice

use of org.commonjava.indy.dotmaven.data.StorageAdvice in project indy by Commonjava.

the class ArtifactStoreSubStore method getStorageAdviceFor.

private StorageAdvice getStorageAdviceFor(final StoreURIMatcher matcher) throws WebdavException {
    final String uri = matcher.getURI();
    final StoreKey key = matcher.getStoreKey();
    ArtifactStore store;
    try {
        store = indy.getArtifactStore(key);
    } catch (final IndyDataException e) {
        logger.error(String.format("Failed to retrieve artifact store: %s for URI: %s\nReason: %s", key, uri, e.getMessage()), e);
        throw new WebdavException("Cannot create: " + uri);
    }
    if (store == null) {
        throw new WebdavException("Cannot retrieve ArtifactStore: " + key);
    }
    StorageAdvice advice;
    try {
        advice = advisor.getStorageAdvice(store);
    } catch (final DotMavenException e) {
        logger.error(String.format("Failed to retrieve storage advice for: %s (URI: %s)\nReason: %s", key, uri, e.getMessage()), e);
        throw new WebdavException("Cannot create: " + uri);
    }
    if (!advice.isDeployable()) {
        throw new WebdavException("Read-only area. Cannot create: " + uri);
    }
    return advice;
}
Also used : IndyDataException(org.commonjava.indy.data.IndyDataException) StorageAdvice(org.commonjava.indy.dotmaven.data.StorageAdvice) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) WebdavException(net.sf.webdav.exceptions.WebdavException) StoreKey(org.commonjava.indy.model.core.StoreKey) DotMavenException(org.commonjava.indy.dotmaven.DotMavenException)

Aggregations

WebdavException (net.sf.webdav.exceptions.WebdavException)6 StorageAdvice (org.commonjava.indy.dotmaven.data.StorageAdvice)6 IOException (java.io.IOException)4 StoreURIMatcher (org.commonjava.indy.dotmaven.util.StoreURIMatcher)4 Transfer (org.commonjava.maven.galley.model.Transfer)4 IndyDataException (org.commonjava.indy.data.IndyDataException)2 DotMavenException (org.commonjava.indy.dotmaven.DotMavenException)2 ArtifactStore (org.commonjava.indy.model.core.ArtifactStore)2 StoreKey (org.commonjava.indy.model.core.StoreKey)2 OutputStreamWriter (java.io.OutputStreamWriter)1 Writer (java.io.Writer)1 SettingsTemplate (org.commonjava.indy.dotmaven.util.SettingsTemplate)1