Search in sources :

Example 6 with StoreURIMatcher

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

use of org.commonjava.indy.dotmaven.util.StoreURIMatcher 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)

Aggregations

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