Search in sources :

Example 1 with WebdavException

use of net.sf.webdav.exceptions.WebdavException 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 2 with WebdavException

use of net.sf.webdav.exceptions.WebdavException 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 3 with WebdavException

use of net.sf.webdav.exceptions.WebdavException 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 WebdavException

use of net.sf.webdav.exceptions.WebdavException 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 5 with WebdavException

use of net.sf.webdav.exceptions.WebdavException in project indy by Commonjava.

the class SettingsTemplate method formatSettings.

private void formatSettings() throws WebdavException {
    if (content != null) {
        return;
    }
    final String name = key.getName();
    final StoreType type = key.getType();
    final StringBuilder url = new StringBuilder();
    url.append(requestInfo.getBaseUrl());
    logger.debug("settings base-url is: '{}'", url);
    if (url.charAt(url.length() - 1) != '/') {
        url.append('/');
    }
    url.append("api/");
    url.append(type.singularEndpointName()).append('/').append(name);
    try {
        final Map<String, Object> params = new HashMap<String, Object>();
        params.put(TYPE_KEY, type.singularEndpointName());
        params.put(NAME_KEY, name);
        params.put(URL_KEY, url);
        params.put(RELEASES_KEY, advice.isReleasesAllowed());
        params.put(SNAPSHOTS_KEY, advice.isSnapshotsAllowed());
        params.put(DEPLOY_ENABLED_KEY, advice.isDeployable());
        final String rendered = templateEngine.render(TEMPLATE, params);
        content = rendered.getBytes("UTF-8");
    } catch (final UnsupportedEncodingException e) {
        throw new IllegalStateException("Cannot find encoding for UTF-8!", e);
    } catch (final IndyGroovyException e) {
        throw new WebdavException(String.format("Failed to render settings.xml template for: '%s'. Reason: %s", key, e.getMessage()), e);
    }
}
Also used : StoreType(org.commonjava.indy.model.core.StoreType) HashMap(java.util.HashMap) WebdavException(net.sf.webdav.exceptions.WebdavException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IndyGroovyException(org.commonjava.indy.subsys.template.IndyGroovyException)

Aggregations

WebdavException (net.sf.webdav.exceptions.WebdavException)11 Transfer (org.commonjava.maven.galley.model.Transfer)7 IOException (java.io.IOException)6 StorageAdvice (org.commonjava.indy.dotmaven.data.StorageAdvice)6 StoreURIMatcher (org.commonjava.indy.dotmaven.util.StoreURIMatcher)6 IndyDataException (org.commonjava.indy.data.IndyDataException)5 ArtifactStore (org.commonjava.indy.model.core.ArtifactStore)5 StoreKey (org.commonjava.indy.model.core.StoreKey)5 StoreType (org.commonjava.indy.model.core.StoreType)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 TreeSet (java.util.TreeSet)2 DotMavenException (org.commonjava.indy.dotmaven.DotMavenException)2 OutputStreamWriter (java.io.OutputStreamWriter)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 Writer (java.io.Writer)1 HashMap (java.util.HashMap)1 SettingsTemplate (org.commonjava.indy.dotmaven.util.SettingsTemplate)1 SettingsURIMatcher (org.commonjava.indy.dotmaven.util.SettingsURIMatcher)1 IndyGroovyException (org.commonjava.indy.subsys.template.IndyGroovyException)1