Search in sources :

Example 6 with Bucket

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

the class RFacetImpl method findOrCreateComponent.

@Override
public Component findOrCreateComponent(final StorageTx tx, final String path, final Map<String, String> attributes) {
    String name = attributes.get(P_PACKAGE);
    String version = attributes.get(P_VERSION);
    String group = getBasePath(path);
    Component component = findComponent(tx, getRepository(), name, version, group);
    if (component == null) {
        Bucket bucket = tx.findBucket(getRepository());
        component = tx.createComponent(bucket, getRepository().getFormat()).name(name).version(version).group(group);
        tx.saveComponent(component);
    }
    return component;
}
Also used : Bucket(org.sonatype.nexus.repository.storage.Bucket) Component(org.sonatype.nexus.repository.storage.Component) RFacetUtils.findComponent(org.sonatype.nexus.repository.r.internal.util.RFacetUtils.findComponent)

Example 7 with Bucket

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

the class RepositoryFacetTestSupport method initialiseFacetMocksAndSetupTransaction.

@Before
public void initialiseFacetMocksAndSetupTransaction() throws Exception {
    assets = new ArrayList<>();
    UnitOfWork.beginBatch(storageTx);
    when(storageTx.browseAssets(any(Bucket.class))).thenReturn(assets);
    when(storageTx.browseAssets(any(), any(Bucket.class))).thenReturn(assets);
    when(storageTx.findAssetWithProperty(anyString(), anyString(), any(Bucket.class))).thenReturn(asset);
    when(storageTx.findBucket(repository)).thenReturn(bucket);
    when(storageTx.requireBlob(any())).thenReturn(blob);
    when(repository.facet(StorageFacet.class)).thenReturn(storageFacet);
    when(asset.formatAttributes()).thenReturn(formatAttributes);
    when(asset.attributes()).thenReturn(attributes);
    when(attributes.get("last_modified", Date.class)).thenReturn(new Date());
    when(attributes.get("last_verified", Date.class)).thenReturn(new Date());
    when(attributes.get("cache_token", String.class)).thenReturn("test");
    when(attributes.child("content")).thenReturn(attributes);
    when(attributes.child("cache")).thenReturn(attributes);
    underTest = initialiseSystemUnderTest();
    underTest.attach(repository);
}
Also used : Bucket(org.sonatype.nexus.repository.storage.Bucket) Date(java.util.Date) Before(org.junit.Before)

Example 8 with Bucket

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

the class RFacetImpl method findOrCreateAsset.

@Override
public Asset findOrCreateAsset(final StorageTx tx, final Component component, final String path, final Map<String, String> attributes) {
    Bucket bucket = tx.findBucket(getRepository());
    Asset asset = findAsset(tx, bucket, path);
    if (asset == null) {
        asset = tx.createAsset(bucket, component);
        asset.name(path);
        // TODO: Make this a bit more robust (could be problematic if keys are removed in later versions, or if keys clash)
        for (Entry<String, String> attribute : attributes.entrySet()) {
            asset.formatAttributes().set(attribute.getKey(), attribute.getValue());
        }
        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)

Aggregations

Bucket (org.sonatype.nexus.repository.storage.Bucket)8 Asset (org.sonatype.nexus.repository.storage.Asset)5 RFacetUtils.findAsset (org.sonatype.nexus.repository.r.internal.RFacetUtils.findAsset)3 RFacetUtils.saveAsset (org.sonatype.nexus.repository.r.internal.RFacetUtils.saveAsset)3 Component (org.sonatype.nexus.repository.storage.Component)3 StorageTx (org.sonatype.nexus.repository.storage.StorageTx)3 TransactionalStoreBlob (org.sonatype.nexus.repository.transaction.TransactionalStoreBlob)3 InputStream (java.io.InputStream)2 RFacetUtils.findComponent (org.sonatype.nexus.repository.r.internal.RFacetUtils.findComponent)2 RFacetUtils.findAsset (org.sonatype.nexus.repository.r.internal.util.RFacetUtils.findAsset)2 Date (java.util.Date)1 Before (org.junit.Before)1 Test (org.junit.Test)1 EntityId (org.sonatype.nexus.common.entity.EntityId)1 RFacetUtils.findComponent (org.sonatype.nexus.repository.r.internal.util.RFacetUtils.findComponent)1