Search in sources :

Example 11 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.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 12 with Asset

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

the class RProxyFacetImpl method setCacheInfo.

@TransactionalTouchMetadata
public void setCacheInfo(final Content content, final CacheInfo cacheInfo) {
    StorageTx tx = UnitOfWork.currentTx();
    Asset asset = Content.findAsset(tx, tx.findBucket(getRepository()), content);
    if (asset == null) {
        log.debug("Attempting to set cache info for non-existent R asset {}", content.getAttributes().require(Asset.class));
        return;
    }
    log.debug("Updating cacheInfo of {} to {}", asset, cacheInfo);
    CacheInfo.applyToAsset(asset, cacheInfo);
    tx.saveAsset(asset);
}
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) TransactionalTouchMetadata(org.sonatype.nexus.repository.transaction.TransactionalTouchMetadata)

Example 13 with Asset

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

the class RBrowseNodeGeneratorTest method shouldComputeAssetAndComponentPathWithoutNameDuplication.

@Test
public void shouldComputeAssetAndComponentPathWithoutNameDuplication() {
    final String commonPath = "src/contrib/Archive/ggplot2";
    final String lastSegment = "ggplot2_0.9.0.tar.gz";
    final String assetPath = commonPath + "/" + lastSegment;
    final String componentName = "ggplot2";
    final String componentVersion = "0.9.0";
    // Browse path should not have name duplicates
    final String componentBrowsePath = commonPath + "/" + componentVersion;
    final String assetBrowsePath = componentBrowsePath + "/" + lastSegment;
    Component component = createComponent(componentName, commonPath, componentVersion);
    Asset asset = createAsset(assetPath);
    List<BrowsePaths> pathsAsset = generator.computeAssetPaths(asset, component);
    List<BrowsePaths> pathsComponent = generator.computeComponentPaths(asset, component);
    assertPaths(Arrays.asList(assetBrowsePath.split("/")), pathsAsset);
    assertPaths(Arrays.asList(componentBrowsePath.split("/")), pathsComponent, true);
}
Also used : Asset(org.sonatype.nexus.repository.storage.Asset) BrowsePaths(org.sonatype.nexus.repository.browse.BrowsePaths) Component(org.sonatype.nexus.repository.storage.Component) Test(org.junit.Test)

Example 14 with Asset

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

the class RFacetImpl method findOrCreateAsset.

@Override
public Asset findOrCreateAsset(final StorageTx tx, final String path) {
    Bucket bucket = tx.findBucket(getRepository());
    Asset asset = findAsset(tx, bucket, path);
    if (asset == null) {
        asset = tx.createAsset(bucket, getRepository().getFormat());
        asset.name(path);
        asset.formatAttributes().set(P_ASSET_KIND, getAssetKind(path).name());
        tx.saveAsset(asset);
    }
    return asset;
}
Also used : Bucket(org.sonatype.nexus.repository.storage.Bucket) RFacetUtils.findAsset(org.sonatype.nexus.repository.r.internal.util.RFacetUtils.findAsset) Asset(org.sonatype.nexus.repository.storage.Asset)

Example 15 with Asset

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

the class RUploadHandlerTest method mockAsset.

private static Asset mockAsset(final String name) {
    Asset asset = mock(Asset.class);
    when(asset.componentId()).thenReturn(new DetachedEntityId(NU_ID));
    when(asset.name()).thenReturn(name);
    return asset;
}
Also used : DetachedEntityId(org.sonatype.nexus.common.entity.DetachedEntityId) Asset(org.sonatype.nexus.repository.storage.Asset)

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