Search in sources :

Example 41 with StoreType

use of org.commonjava.indy.model.core.StoreType in project indy by Commonjava.

the class IndexingContentManagerDecorator method getTransfer.

@Override
public Transfer getTransfer(final ArtifactStore store, final String path, final TransferOperation op) throws IndyWorkflowException {
    Logger logger = LoggerFactory.getLogger(getClass());
    Transfer transfer = getIndexedTransfer(store.getKey(), null, path, TransferOperation.DOWNLOAD);
    if (transfer != null) {
        return transfer;
    }
    ConcreteResource resource = new ConcreteResource(LocationUtils.toLocation(store), path);
    StoreType type = store.getKey().getType();
    if (StoreType.group == type) {
        if (!nfc.isMissing(resource)) {
            logger.debug("No group index hits. Devolving to member store indexes.");
            transfer = getIndexedMemberTransfer((Group) store, path, op, (member) -> {
                try {
                    return delegate.getTransfer(member, path, op);
                } catch (IndyWorkflowException e) {
                    logger.error(String.format("Failed to getTransfer() for: %s:%s with operation: %s. Reason: %s", member.getKey(), path, op, e.getMessage()), e);
                }
                return null;
            });
            if (transfer != null) {
                return transfer;
            }
        } else {
            logger.debug("NFC marks {} as missing. Returning null.", resource);
            return null;
        }
    }
    transfer = delegate.getTransfer(store, path, op);
    // index the transfer only if it exists, it cannot be null at this point
    if (transfer != null && transfer.exists()) {
        indexManager.indexTransferIn(transfer, store.getKey());
    }
    logger.debug("Returning transfer: {}", transfer);
    return transfer;
}
Also used : StoreType(org.commonjava.indy.model.core.StoreType) Delegate(javax.decorator.Delegate) KeyedLocation(org.commonjava.indy.model.galley.KeyedLocation) LoggerFactory(org.slf4j.LoggerFactory) SpecialPathInfo(org.commonjava.maven.galley.model.SpecialPathInfo) Group(org.commonjava.indy.model.core.Group) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) HashSet(java.util.HashSet) Transfer(org.commonjava.maven.galley.model.Transfer) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) TransferOperation(org.commonjava.maven.galley.model.TransferOperation) Any(javax.enterprise.inject.Any) Decorator(javax.decorator.Decorator) StoreKey(org.commonjava.indy.model.core.StoreKey) LocationUtils(org.commonjava.indy.util.LocationUtils) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) Logger(org.slf4j.Logger) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) StoreType(org.commonjava.indy.model.core.StoreType) Set(java.util.Set) SpecialPathManager(org.commonjava.maven.galley.spi.io.SpecialPathManager) NotFoundCache(org.commonjava.maven.galley.spi.nfc.NotFoundCache) ContentManager(org.commonjava.indy.content.ContentManager) Objects(java.util.Objects) List(java.util.List) EventMetadata(org.commonjava.maven.galley.event.EventMetadata) IndyDataException(org.commonjava.indy.data.IndyDataException) StoreDataManager(org.commonjava.indy.data.StoreDataManager) InputStream(java.io.InputStream) Group(org.commonjava.indy.model.core.Group) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) Transfer(org.commonjava.maven.galley.model.Transfer) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) Logger(org.slf4j.Logger)

Example 42 with StoreType

use of org.commonjava.indy.model.core.StoreType 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;
}
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) List(java.util.List)

Example 43 with StoreType

use of org.commonjava.indy.model.core.StoreType 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;
        try {
            all = indy.query().packageType(MAVEN_PKG_KEY).storeTypes(type).getAll();
        } 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) List(java.util.List)

Example 44 with StoreType

use of org.commonjava.indy.model.core.StoreType in project indy by Commonjava.

the class SettingsURIMatcher method getStoreKey.

/* (non-Javadoc)
     * @see org.commonjava.indy.dotmaven.util.URIMatcher#getStoreKey()
     */
@Override
public StoreKey getStoreKey() {
    final StoreType type = getStoreType();
    if (type == null) {
        return null;
    }
    final String name = matcher.group(NAME_GRP);
    if (isEmpty(name)) {
        return null;
    }
    return new StoreKey(type, name);
}
Also used : StoreType(org.commonjava.indy.model.core.StoreType) StoreKey(org.commonjava.indy.model.core.StoreKey)

Example 45 with StoreType

use of org.commonjava.indy.model.core.StoreType in project indy by Commonjava.

the class StoreURIMatcher method getStoreKey.

@Override
public StoreKey getStoreKey() {
    if (!matches()) {
        return null;
    }
    if (!hasStoreName()) {
        return null;
    }
    final String packageType = getPackageType();
    if (packageType == null) {
        return null;
    }
    final StoreType type = getStoreType();
    if (type == null) {
        return null;
    }
    String name = getStoreName();
    if (name == null) {
        return null;
    }
    return new StoreKey(packageType, type, name);
}
Also used : StoreType(org.commonjava.indy.model.core.StoreType) StoreKey(org.commonjava.indy.model.core.StoreKey)

Aggregations

StoreType (org.commonjava.indy.model.core.StoreType)53 StoreKey (org.commonjava.indy.model.core.StoreKey)43 Response (javax.ws.rs.core.Response)25 IndyWorkflowException (org.commonjava.indy.IndyWorkflowException)25 ResponseUtils.formatResponse (org.commonjava.indy.bind.jaxrs.util.ResponseUtils.formatResponse)22 ApiOperation (io.swagger.annotations.ApiOperation)21 ApiResponse (io.swagger.annotations.ApiResponse)21 Path (javax.ws.rs.Path)19 ApiResponses (io.swagger.annotations.ApiResponses)18 ArtifactStore (org.commonjava.indy.model.core.ArtifactStore)18 IOException (java.io.IOException)13 GET (javax.ws.rs.GET)12 Produces (javax.ws.rs.Produces)12 List (java.util.List)10 Inject (javax.inject.Inject)10 DELETE (javax.ws.rs.DELETE)10 JoinString (org.commonjava.maven.atlas.ident.util.JoinString)10 ResponseUtils.markDeprecated (org.commonjava.indy.bind.jaxrs.util.ResponseUtils.markDeprecated)9 IndyDataException (org.commonjava.indy.data.IndyDataException)8 Transfer (org.commonjava.maven.galley.model.Transfer)8