Search in sources :

Example 1 with DotMavenException

use of org.commonjava.indy.dotmaven.DotMavenException 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 2 with DotMavenException

use of org.commonjava.indy.dotmaven.DotMavenException in project indy by Commonjava.

the class StorageAdvisor method getStorageAdvice.

public StorageAdvice getStorageAdvice(final ArtifactStore store) throws DotMavenException {
    boolean deployable = false;
    boolean releases = true;
    boolean snapshots = false;
    HostedRepository hostedStore = null;
    final StoreType type = store.getKey().getType();
    all: switch(type) {
        case group:
            {
                List<ArtifactStore> constituents;
                try {
                    constituents = dataManager.query().enabledState(true).getOrderedConcreteStoresInGroup(MAVEN_PKG_KEY, store.getName());
                } catch (final IndyDataException e) {
                    throw new DotMavenException("Failed to retrieve constituent ArtifactStores for group: %s. Reason: %s", e, store.getName(), e.getMessage());
                }
                for (final ArtifactStore as : constituents) {
                    if (as.getKey().getType() == hosted) {
                        deployable = true;
                        hostedStore = (HostedRepository) as;
                        snapshots = hostedStore.isAllowSnapshots();
                        releases = hostedStore.isAllowReleases();
                        break all;
                    }
                }
                break;
            }
        case hosted:
            {
                deployable = true;
                hostedStore = (HostedRepository) store;
                snapshots = hostedStore.isAllowSnapshots();
                releases = hostedStore.isAllowReleases();
                break;
            }
        default:
    }
    return new StorageAdvice(store, hostedStore, deployable, releases, snapshots);
}
Also used : StoreType(org.commonjava.indy.model.core.StoreType) IndyDataException(org.commonjava.indy.data.IndyDataException) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) HostedRepository(org.commonjava.indy.model.core.HostedRepository) DotMavenException(org.commonjava.indy.dotmaven.DotMavenException)

Example 3 with DotMavenException

use of org.commonjava.indy.dotmaven.DotMavenException 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

IndyDataException (org.commonjava.indy.data.IndyDataException)3 DotMavenException (org.commonjava.indy.dotmaven.DotMavenException)3 ArtifactStore (org.commonjava.indy.model.core.ArtifactStore)3 WebdavException (net.sf.webdav.exceptions.WebdavException)2 StorageAdvice (org.commonjava.indy.dotmaven.data.StorageAdvice)2 StoreKey (org.commonjava.indy.model.core.StoreKey)2 SettingsTemplate (org.commonjava.indy.dotmaven.util.SettingsTemplate)1 HostedRepository (org.commonjava.indy.model.core.HostedRepository)1 StoreType (org.commonjava.indy.model.core.StoreType)1