use of org.commonjava.indy.dotmaven.util.StoreURIMatcher 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.util.StoreURIMatcher in project indy by Commonjava.
the class ArtifactStoreSubStore method getStoredObject.
@Override
public StoredObject getStoredObject(final ITransaction transaction, final String uri) throws WebdavException {
final StoredObject so = new StoredObject();
final StoreURIMatcher matcher = new StoreURIMatcher(uri);
if (matcher.hasStorePath()) {
final Transfer item = getTransfer(matcher);
if (item == null) {
return null;
}
so.setCreationDate(new Date(item.lastModified()));
so.setLastModified(new Date(item.lastModified()));
so.setFolder(item.isDirectory());
so.setResourceLength(item.length());
} else {
final Date d = new Date();
so.setCreationDate(d);
so.setLastModified(d);
so.setFolder(true);
}
return so;
}
use of org.commonjava.indy.dotmaven.util.StoreURIMatcher 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.util.StoreURIMatcher 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.util.StoreURIMatcher 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().packageType(key.getPackageType()).getOrderedStoresInGroup(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<String> noms = indy.query().packageType(packageType).storeTypes(type).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;
}
Aggregations