Search in sources :

Example 1 with TransactionalTouchBlob

use of org.sonatype.nexus.repository.transaction.TransactionalTouchBlob in project nexus-repository-r by sonatype-nexus-community.

the class RHostedFacetImpl method getStoredContent.

@Override
@TransactionalTouchBlob
public Content getStoredContent(final String contentPath) {
    checkNotNull(contentPath);
    StorageTx tx = UnitOfWork.currentTx();
    Asset asset = findAsset(tx, tx.findBucket(getRepository()), contentPath);
    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.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) TransactionalTouchBlob(org.sonatype.nexus.repository.transaction.TransactionalTouchBlob)

Example 2 with TransactionalTouchBlob

use of org.sonatype.nexus.repository.transaction.TransactionalTouchBlob 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.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) TransactionalTouchBlob(org.sonatype.nexus.repository.transaction.TransactionalTouchBlob)

Example 3 with TransactionalTouchBlob

use of org.sonatype.nexus.repository.transaction.TransactionalTouchBlob 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 4 with TransactionalTouchBlob

use of org.sonatype.nexus.repository.transaction.TransactionalTouchBlob 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 5 with TransactionalTouchBlob

use of org.sonatype.nexus.repository.transaction.TransactionalTouchBlob in project nexus-repository-r by sonatype-nexus-community.

the class RRestoreFacetImpl method restore.

@Override
@TransactionalTouchBlob
public void restore(final AssetBlob assetBlob, final String path) throws IOException {
    StorageTx tx = UnitOfWork.currentTx();
    RFacet facet = facet(RFacet.class);
    Asset asset;
    if (componentRequired(path)) {
        Map<String, String> attributes;
        try (InputStream is = assetBlob.getBlob().getInputStream()) {
            attributes = extractDescriptionFromArchive(path, is);
        }
        Component component = facet.findOrCreateComponent(tx, path, attributes);
        asset = facet.findOrCreateAsset(tx, component, path, attributes);
    } else {
        asset = facet.findOrCreateAsset(tx, path);
    }
    tx.attachBlob(asset, assetBlob);
    Content.applyToAsset(asset, Content.maintainLastModified(asset, new AttributesMap()));
    tx.saveAsset(asset);
}
Also used : RFacet(org.sonatype.nexus.repository.r.RFacet) StorageTx(org.sonatype.nexus.repository.storage.StorageTx) InputStream(java.io.InputStream) AttributesMap(org.sonatype.nexus.common.collect.AttributesMap) Asset(org.sonatype.nexus.repository.storage.Asset) Component(org.sonatype.nexus.repository.storage.Component) TransactionalTouchBlob(org.sonatype.nexus.repository.transaction.TransactionalTouchBlob)

Aggregations

Asset (org.sonatype.nexus.repository.storage.Asset)5 StorageTx (org.sonatype.nexus.repository.storage.StorageTx)5 TransactionalTouchBlob (org.sonatype.nexus.repository.transaction.TransactionalTouchBlob)5 RFacetUtils.findAsset (org.sonatype.nexus.repository.r.internal.RFacetUtils.findAsset)2 RFacetUtils.saveAsset (org.sonatype.nexus.repository.r.internal.RFacetUtils.saveAsset)2 RFacetUtils.findAsset (org.sonatype.nexus.repository.r.internal.util.RFacetUtils.findAsset)2 RFacetUtils.saveAsset (org.sonatype.nexus.repository.r.internal.util.RFacetUtils.saveAsset)2 InputStream (java.io.InputStream)1 AttributesMap (org.sonatype.nexus.common.collect.AttributesMap)1 RFacet (org.sonatype.nexus.repository.r.RFacet)1 Component (org.sonatype.nexus.repository.storage.Component)1