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