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);
}
}
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);
}
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);
}
}
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);
}
}
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;
}
Aggregations