Search in sources :

Example 6 with WebdavException

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

the class SettingsSubStore method getChildrenNames.

@Override
public String[] getChildrenNames(final ITransaction transaction, final String folderUri) throws WebdavException {
    final SettingsURIMatcher matcher = new SettingsURIMatcher(folderUri);
    final Set<String> names = new TreeSet<String>();
    if (matcher.isSettingsRootResource()) {
        for (final StoreType type : StoreType.values()) {
            names.add(type.singularEndpointName());
        }
    } else if (matcher.isSettingsTypeResource()) {
        final StoreType type = matcher.getStoreType();
        List<? extends ArtifactStore> all = new ArrayList<>();
        try {
            if (StoreType.group.equals(type)) {
                all = indy.query().getAllGroups(MAVEN_PKG_KEY);
            } else if (StoreType.hosted.equals(type)) {
                all = indy.query().getAllHostedRepositories(MAVEN_PKG_KEY);
            } else if (StoreType.remote.equals(type)) {
                all = indy.query().getAllRemoteRepositories(MAVEN_PKG_KEY);
            }
        } catch (final IndyDataException e) {
            logger.error(String.format("Failed to retrieve list of artifact stores: %s", e.getMessage()), e);
            throw new WebdavException("Failed to retrieve list of settings configurations.");
        }
        for (final ArtifactStore store : all) {
            final String storeName = formatSettingsResourceName(store.getKey().getType(), store.getName());
            // logger.info( "\n\nCreating settings resource for: '{}'\n\n", storeName );
            names.add(storeName);
        }
    }
    return names.toArray(new String[names.size()]);
}
Also used : StoreType(org.commonjava.indy.model.core.StoreType) IndyDataException(org.commonjava.indy.data.IndyDataException) SettingsURIMatcher(org.commonjava.indy.dotmaven.util.SettingsURIMatcher) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) TreeSet(java.util.TreeSet) WebdavException(net.sf.webdav.exceptions.WebdavException) ArrayList(java.util.ArrayList) List(java.util.List)

Example 7 with WebdavException

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

the class ArtifactStoreSubStore method createResource.

@Override
public void createResource(final ITransaction transaction, final String resourceUri) 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);
    try {
        item.createFile();
    } catch (final IOException e) {
        logger.error("Failed to create file: {} in store: {}. Reason: {}", e, path, advice.getStore().getKey(), e.getMessage());
        throw new WebdavException("Failed to create file: " + resourceUri);
    }
}
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 8 with WebdavException

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

the class ArtifactStoreSubStore method getChildrenNames.

@Override
public String[] getChildrenNames(final ITransaction transaction, final String folderUri) throws WebdavException {
    String[] names;
    final StoreURIMatcher matcher = new StoreURIMatcher(folderUri);
    if (matcher.hasStorePath() || matcher.hasStoreName()) {
        String path = matcher.getStorePath();
        if (isEmpty(path)) {
            path = PathUtils.ROOT;
        }
        final StoreKey key = matcher.getStoreKey();
        try {
            if (key != null && StoreType.group == key.getType()) {
                final List<ArtifactStore> stores = indy.query().getOrderedStoresInGroup(key.getPackageType(), key.getName());
                final Set<String> noms = new TreeSet<>();
                for (final ArtifactStore store : stores) {
                    final Transfer item = fileManager.getStorageReference(store, path);
                    if (!item.exists()) {
                        continue;
                    }
                    if (!item.isDirectory()) {
                        logger.error("Transfer: {} in {} is not a directory.", path, store.getKey());
                        continue;
                    }
                    noms.addAll(Arrays.asList(item.list()));
                }
                names = noms.toArray(new String[noms.size()]);
            } else {
                final ArtifactStore store = indy.getArtifactStore(key);
                if (store == null) {
                    logger.error("Cannot find ArtifactStore to match key: {}.", key);
                    names = new String[] {};
                } else {
                    final Transfer item = fileManager.getStorageReference(store, path);
                    if (!item.exists() || !item.isDirectory()) {
                        logger.error("Transfer: {} in {} is not a directory.", path, store.getKey());
                        names = new String[] {};
                    } else {
                        names = item.list();
                    }
                }
            }
        } catch (final IndyDataException e) {
            logger.error(String.format("Failed to lookup ArtifactStore(s) for key: %s. Reason: %s", key, e.getMessage()), e);
            throw new WebdavException("Failed to get listing for: " + folderUri);
        } catch (final IOException e) {
            logger.error(String.format("Failed to list %s in %s. Reason: %s", path, key, e.getMessage()), e);
            throw new WebdavException("Failed to get listing for: " + folderUri);
        }
    } else if (matcher.hasStoreType()) {
        String packageType = matcher.getPackageType();
        final StoreType type = matcher.getStoreType();
        try {
            List<? extends ArtifactStore> stores = new ArrayList<>();
            if (StoreType.group.equals(type)) {
                stores = indy.query().getAllGroups(packageType);
            } else if (StoreType.hosted.equals(type)) {
                stores = indy.query().getAllHostedRepositories(packageType);
            } else if (StoreType.remote.equals(type)) {
                stores = indy.query().getAllRemoteRepositories(packageType);
            }
            List<String> noms = stores.stream().map(ArtifactStore::getName).collect(Collectors.toList());
            names = noms.toArray(new String[noms.size()]);
        } catch (final IndyDataException e) {
            logger.error(String.format("Failed to lookup ArtifactStores of type: %s. Reason: %s", type, e.getMessage()), e);
            throw new WebdavException("Failed to get listing for: " + folderUri);
        }
    } else {
        names = new String[] { StoreType.hosted.singularEndpointName(), StoreType.group.singularEndpointName(), StoreType.remote.singularEndpointName() };
    }
    return names;
}
Also used : StoreURIMatcher(org.commonjava.indy.dotmaven.util.StoreURIMatcher) WebdavException(net.sf.webdav.exceptions.WebdavException) IOException(java.io.IOException) StoreKey(org.commonjava.indy.model.core.StoreKey) IndyDataException(org.commonjava.indy.data.IndyDataException) StoreType(org.commonjava.indy.model.core.StoreType) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) TreeSet(java.util.TreeSet) Transfer(org.commonjava.maven.galley.model.Transfer) ArrayList(java.util.ArrayList) List(java.util.List)

Example 9 with WebdavException

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

the class ArtifactStoreSubStore method getResourceContent.

@Override
public InputStream getResourceContent(final ITransaction transaction, final String resourceUri) throws WebdavException {
    final StoreURIMatcher matcher = new StoreURIMatcher(resourceUri);
    final Transfer item = getTransfer(matcher);
    if (item == null) {
        throw new WebdavException("Cannot read content: " + resourceUri);
    }
    final String path = item.getPath();
    final StoreKey key = LocationUtils.getKey(item);
    try {
        return item.openInputStream();
    } catch (final IOException e) {
        logger.error(String.format("Failed to open InputStream for: %s in store: %s. Reason: %s", path, key, e.getMessage()), e);
        throw new WebdavException("Failed to get content for: " + resourceUri);
    }
}
Also used : StoreURIMatcher(org.commonjava.indy.dotmaven.util.StoreURIMatcher) Transfer(org.commonjava.maven.galley.model.Transfer) WebdavException(net.sf.webdav.exceptions.WebdavException) IOException(java.io.IOException) StoreKey(org.commonjava.indy.model.core.StoreKey)

Example 10 with WebdavException

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

the class ArtifactStoreSubStore method getTransfer.

private Transfer getTransfer(final StoreURIMatcher matcher) throws WebdavException {
    final String resourceUri = matcher.getURI();
    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 that cannot be read as a file.");
    }
    final String path = matcher.getStorePath();
    final StoreKey key = matcher.getStoreKey();
    Transfer item = null;
    try {
        if (key != null && StoreType.group == key.getType()) {
            final List<ArtifactStore> stores = indy.query().enabledState(true).getOrderedStoresInGroup(key.getPackageType(), key.getName());
            for (final ArtifactStore store : stores) {
                // logger.info( "Getting Transfer for: {} from: {}", path, store );
                final Transfer si = fileManager.getStorageReference(store, path);
                if (si.exists()) {
                    // logger.info( "Using Transfer: {} for path: {}", si, path );
                    item = si;
                    break;
                }
            }
        } else {
            final ArtifactStore store = indy.getArtifactStore(key);
            if (store == null) {
                throw new WebdavException("Cannot find store: " + key);
            }
            // logger.info( "Getting Transfer for: {} from: {}", path, store );
            final Transfer si = fileManager.getStorageReference(store, path);
            if (si.exists()) {
                // logger.info( "Using Transfer: {} for path: {}", si, path );
                item = si;
            }
        }
    } catch (final IndyDataException e) {
        logger.error(String.format("Failed to lookup ArtifactStore(s) for key: %s. Reason: %s", key, e.getMessage()), e);
        throw new WebdavException("Failed to get content for: " + resourceUri);
    }
    return item;
}
Also used : IndyDataException(org.commonjava.indy.data.IndyDataException) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) WebdavException(net.sf.webdav.exceptions.WebdavException) Transfer(org.commonjava.maven.galley.model.Transfer) StoreKey(org.commonjava.indy.model.core.StoreKey)

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