Search in sources :

Example 11 with StorageTx

use of org.sonatype.nexus.repository.storage.StorageTx 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 12 with StorageTx

use of org.sonatype.nexus.repository.storage.StorageTx 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 13 with StorageTx

use of org.sonatype.nexus.repository.storage.StorageTx 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 14 with StorageTx

use of org.sonatype.nexus.repository.storage.StorageTx 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)

Example 15 with StorageTx

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

the class RProxyFacetImpl method doPutArchive.

@TransactionalStoreBlob
protected Content doPutArchive(final String path, final TempBlob archiveContent, final Content content) throws IOException {
    RFacet rFacet = facet(RFacet.class);
    StorageTx tx = UnitOfWork.currentTx();
    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);
    return saveAsset(tx, asset, archiveContent, content);
}
Also used : RFacet(org.sonatype.nexus.repository.r.RFacet) StorageTx(org.sonatype.nexus.repository.storage.StorageTx) 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)

Aggregations

Asset (org.sonatype.nexus.repository.storage.Asset)17 StorageTx (org.sonatype.nexus.repository.storage.StorageTx)17 RFacetUtils.findAsset (org.sonatype.nexus.repository.r.internal.RFacetUtils.findAsset)7 RFacetUtils.saveAsset (org.sonatype.nexus.repository.r.internal.RFacetUtils.saveAsset)7 RFacetUtils.findAsset (org.sonatype.nexus.repository.r.internal.util.RFacetUtils.findAsset)7 RFacetUtils.saveAsset (org.sonatype.nexus.repository.r.internal.util.RFacetUtils.saveAsset)7 Component (org.sonatype.nexus.repository.storage.Component)7 TransactionalStoreBlob (org.sonatype.nexus.repository.transaction.TransactionalStoreBlob)7 InputStream (java.io.InputStream)6 TransactionalTouchBlob (org.sonatype.nexus.repository.transaction.TransactionalTouchBlob)6 RFacet (org.sonatype.nexus.repository.r.RFacet)5 TransactionalTouchMetadata (org.sonatype.nexus.repository.transaction.TransactionalTouchMetadata)4 Bucket (org.sonatype.nexus.repository.storage.Bucket)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 IOException (java.io.IOException)2 Map (java.util.Map)2 RFacetUtils.findComponent (org.sonatype.nexus.repository.r.internal.RFacetUtils.findComponent)2 Content (org.sonatype.nexus.repository.view.Content)2 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1