Search in sources :

Example 21 with Asset

use of org.sonatype.nexus.repository.storage.Asset in project nexus-repository-r by sonatype-nexus-community.

the class RProxyFacetImpl method getAsset.

@TransactionalTouchBlob
protected Content getAsset(final String name) {
    StorageTx tx = UnitOfWork.currentTx();
    Asset asset = findAsset(tx, tx.findBucket(getRepository()), name);
    if (asset == null) {
        return null;
    }
    if (asset.markAsDownloaded()) {
        tx.saveAsset(asset);
    }
    return toContent(asset, tx.requireBlob(asset.requireBlobRef()));
}
Also used : StorageTx(org.sonatype.nexus.repository.storage.StorageTx) RFacetUtils.findAsset(org.sonatype.nexus.repository.r.internal.RFacetUtils.findAsset) RFacetUtils.saveAsset(org.sonatype.nexus.repository.r.internal.RFacetUtils.saveAsset) Asset(org.sonatype.nexus.repository.storage.Asset) TransactionalTouchBlob(org.sonatype.nexus.repository.transaction.TransactionalTouchBlob)

Example 22 with Asset

use of org.sonatype.nexus.repository.storage.Asset in project nexus-repository-r by sonatype-nexus-community.

the class RHostedFacetImpl method getArchive.

@Override
@TransactionalTouchBlob
public Content getArchive(final String archivePath) {
    checkNotNull(archivePath);
    StorageTx tx = UnitOfWork.currentTx();
    Asset asset = findAsset(tx, tx.findBucket(getRepository()), archivePath);
    if (asset == null) {
        return null;
    }
    if (asset.markAsDownloaded()) {
        tx.saveAsset(asset);
    }
    return toContent(asset, tx.requireBlob(asset.requireBlobRef()));
}
Also used : StorageTx(org.sonatype.nexus.repository.storage.StorageTx) RFacetUtils.findAsset(org.sonatype.nexus.repository.r.internal.RFacetUtils.findAsset) RFacetUtils.saveAsset(org.sonatype.nexus.repository.r.internal.RFacetUtils.saveAsset) Asset(org.sonatype.nexus.repository.storage.Asset) TransactionalTouchBlob(org.sonatype.nexus.repository.transaction.TransactionalTouchBlob)

Example 23 with Asset

use of org.sonatype.nexus.repository.storage.Asset in project nexus-repository-r by sonatype-nexus-community.

the class RHostedFacetImpl method getPackages.

@Override
@TransactionalTouchMetadata
public Content getPackages(final String packagesPath) {
    checkNotNull(packagesPath);
    try {
        // TODO: Do NOT do this on each request as there is at least some overhead, and memory usage is proportional to
        // the number of packages contained in a particular path. We should be able to generate this when something has
        // changed or via a scheduled task using an approach similar to the Yum implementation rather than this method.
        StorageTx tx = UnitOfWork.currentTx();
        RPackagesBuilder packagesBuilder = new RPackagesBuilder(packagesPath);
        for (Asset asset : tx.browseAssets(tx.findBucket(getRepository()))) {
            packagesBuilder.append(asset);
        }
        CompressorStreamFactory compressorStreamFactory = new CompressorStreamFactory();
        ByteArrayOutputStream os = new ByteArrayOutputStream();
        try (CompressorOutputStream cos = compressorStreamFactory.createCompressorOutputStream(GZIP, os)) {
            try (OutputStreamWriter writer = new OutputStreamWriter(cos, UTF_8)) {
                for (Entry<String, Map<String, String>> eachPackage : packagesBuilder.getPackageInformation().entrySet()) {
                    Map<String, String> packageInfo = eachPackage.getValue();
                    InternetHeaders headers = new InternetHeaders();
                    headers.addHeader(P_PACKAGE, packageInfo.get(P_PACKAGE));
                    headers.addHeader(P_VERSION, packageInfo.get(P_VERSION));
                    headers.addHeader(P_DEPENDS, packageInfo.get(P_DEPENDS));
                    headers.addHeader(P_IMPORTS, packageInfo.get(P_IMPORTS));
                    headers.addHeader(P_SUGGESTS, packageInfo.get(P_SUGGESTS));
                    headers.addHeader(P_LICENSE, packageInfo.get(P_LICENSE));
                    headers.addHeader(P_NEEDS_COMPILATION, packageInfo.get(P_NEEDS_COMPILATION));
                    Enumeration<String> headerLines = headers.getAllHeaderLines();
                    while (headerLines.hasMoreElements()) {
                        String line = headerLines.nextElement();
                        writer.write(line, 0, line.length());
                        writer.write('\n');
                    }
                    writer.write('\n');
                }
            }
        }
        return new Content(new BytesPayload(os.toByteArray(), "application/x-gzip"));
    } catch (CompressorException | IOException e) {
        throw new RException(packagesPath, e);
    }
}
Also used : StorageTx(org.sonatype.nexus.repository.storage.StorageTx) InternetHeaders(javax.mail.internet.InternetHeaders) BytesPayload(org.sonatype.nexus.repository.view.payloads.BytesPayload) CompressorOutputStream(org.apache.commons.compress.compressors.CompressorOutputStream) CompressorStreamFactory(org.apache.commons.compress.compressors.CompressorStreamFactory) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) RFacetUtils.toContent(org.sonatype.nexus.repository.r.internal.RFacetUtils.toContent) Content(org.sonatype.nexus.repository.view.Content) CompressorException(org.apache.commons.compress.compressors.CompressorException) RFacetUtils.findAsset(org.sonatype.nexus.repository.r.internal.RFacetUtils.findAsset) RFacetUtils.saveAsset(org.sonatype.nexus.repository.r.internal.RFacetUtils.saveAsset) Asset(org.sonatype.nexus.repository.storage.Asset) OutputStreamWriter(java.io.OutputStreamWriter) Map(java.util.Map) TransactionalTouchMetadata(org.sonatype.nexus.repository.transaction.TransactionalTouchMetadata)

Example 24 with Asset

use of org.sonatype.nexus.repository.storage.Asset in project nexus-repository-r by sonatype-nexus-community.

the class RHostedFacetImpl method doPutArchive.

@TransactionalStoreBlob
protected Asset doPutArchive(final String path, final TempBlob archiveContent, final Payload payload) throws IOException {
    StorageTx tx = UnitOfWork.currentTx();
    RFacet rFacet = facet(RFacet.class);
    Map<String, String> attributes;
    try (InputStream is = archiveContent.get()) {
        attributes = extractDescriptionFromArchive(path, is);
    }
    Component component = rFacet.findOrCreateComponent(tx, path, attributes);
    Asset asset = rFacet.findOrCreateAsset(tx, component, path, attributes);
    saveAsset(tx, asset, archiveContent, payload);
    return asset;
}
Also used : RFacet(org.sonatype.nexus.repository.r.RFacet) StorageTx(org.sonatype.nexus.repository.storage.StorageTx) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) RFacetUtils.saveAsset(org.sonatype.nexus.repository.r.internal.util.RFacetUtils.saveAsset) RFacetUtils.findAsset(org.sonatype.nexus.repository.r.internal.util.RFacetUtils.findAsset) Asset(org.sonatype.nexus.repository.storage.Asset) Component(org.sonatype.nexus.repository.storage.Component) TransactionalStoreBlob(org.sonatype.nexus.repository.transaction.TransactionalStoreBlob)

Example 25 with Asset

use of org.sonatype.nexus.repository.storage.Asset in project nexus-repository-r by sonatype-nexus-community.

the class RProxyFacetImpl method doPutMetadata.

@TransactionalStoreBlob
protected Content doPutMetadata(final String path, final TempBlob packagesContent, final Payload payload) throws IOException {
    StorageTx tx = UnitOfWork.currentTx();
    RFacet rFacet = facet(RFacet.class);
    Asset asset = rFacet.findOrCreateAsset(tx, path);
    return saveAsset(tx, asset, packagesContent, payload);
}
Also used : RFacet(org.sonatype.nexus.repository.r.RFacet) StorageTx(org.sonatype.nexus.repository.storage.StorageTx) RFacetUtils.saveAsset(org.sonatype.nexus.repository.r.internal.util.RFacetUtils.saveAsset) RFacetUtils.findAsset(org.sonatype.nexus.repository.r.internal.util.RFacetUtils.findAsset) Asset(org.sonatype.nexus.repository.storage.Asset) TransactionalStoreBlob(org.sonatype.nexus.repository.transaction.TransactionalStoreBlob)

Aggregations

Asset (org.sonatype.nexus.repository.storage.Asset)35 StorageTx (org.sonatype.nexus.repository.storage.StorageTx)17 Component (org.sonatype.nexus.repository.storage.Component)13 Test (org.junit.Test)10 RFacetUtils.findAsset (org.sonatype.nexus.repository.r.internal.util.RFacetUtils.findAsset)10 RFacetUtils.saveAsset (org.sonatype.nexus.repository.r.internal.util.RFacetUtils.saveAsset)8 TransactionalStoreBlob (org.sonatype.nexus.repository.transaction.TransactionalStoreBlob)8 RFacetUtils.findAsset (org.sonatype.nexus.repository.r.internal.RFacetUtils.findAsset)7 RFacetUtils.saveAsset (org.sonatype.nexus.repository.r.internal.RFacetUtils.saveAsset)7 InputStream (java.io.InputStream)6 RFacet (org.sonatype.nexus.repository.r.RFacet)6 TransactionalTouchBlob (org.sonatype.nexus.repository.transaction.TransactionalTouchBlob)6 Bucket (org.sonatype.nexus.repository.storage.Bucket)5 TransactionalTouchMetadata (org.sonatype.nexus.repository.transaction.TransactionalTouchMetadata)4 BrowsePaths (org.sonatype.nexus.repository.browse.BrowsePaths)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 IOException (java.io.IOException)2 Map (java.util.Map)2 NestedAttributesMap (org.sonatype.nexus.common.collect.NestedAttributesMap)2 RHostedFacet (org.sonatype.nexus.repository.r.RHostedFacet)2