Search in sources :

Example 16 with Component

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

the class RProxyIT method checkComponentCreated.

@Test
public void checkComponentCreated() throws Exception {
    final Component nullComponent = findComponent(repository, AGRICOLAE_131_TGZ.packageName);
    Assert.assertThat(nullComponent, is(nullValue()));
    client.fetch(AGRICOLAE_131_TGZ.fullPath);
    final Component component = findComponent(repository, AGRICOLAE_131_TGZ.packageName);
    Assert.assertThat(component.name(), is(equalTo(AGRICOLAE_131_TGZ.packageName)));
    Assert.assertThat(component.format(), is(equalTo(R_FORMAT_NAME)));
    Assert.assertThat(component.group(), is(AGRICOLAE_131_TGZ.basePath));
    Assert.assertThat(component.version(), is(equalTo(AGRICOLAE_131_TGZ.packageVersion)));
}
Also used : Component(org.sonatype.nexus.repository.storage.Component) Test(org.junit.Test)

Example 17 with Component

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

the class RProxyIT method testDeletingComponentDeletesAllAssociatedAssets.

@Test
public void testDeletingComponentDeletesAllAssociatedAssets() throws IOException {
    client.fetch(AGRICOLAE_131_TGZ.fullPath);
    final Asset asset = findAsset(repository, AGRICOLAE_131_TGZ.fullPath);
    assertNotNull(asset);
    assertNotNull(asset.componentId());
    final Component component = findComponentById(repository, asset.componentId());
    assertNotNull(component);
    ComponentMaintenance maintenanceFacet = repository.facet(ComponentMaintenance.class);
    maintenanceFacet.deleteComponent(component.getEntityMetadata().getId(), true);
    assertNull(findAsset(repository, AGRICOLAE_131_TGZ.fullPath));
    assertNull(findComponentById(repository, asset.componentId()));
}
Also used : ComponentMaintenance(org.sonatype.nexus.repository.storage.ComponentMaintenance) Asset(org.sonatype.nexus.repository.storage.Asset) Component(org.sonatype.nexus.repository.storage.Component) Test(org.junit.Test)

Example 18 with Component

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

the class RComponentMaintenance method deleteAssetTx.

/**
 * Deletes the asset and its component if it's the only asset in it.
 */
@Override
@TransactionalDeleteBlob
protected Set<String> deleteAssetTx(final EntityId assetId, final boolean deleteBlob) {
    StorageTx tx = UnitOfWork.currentTx();
    final Asset asset = tx.findAsset(assetId, tx.findBucket(getRepository()));
    if (asset == null) {
        return Collections.emptySet();
    }
    final EntityId componentId = asset.componentId();
    if (componentId == null) {
        // Assets without components should be deleted on their own
        return super.deleteAssetTx(assetId, deleteBlob);
    }
    final Component component = tx.findComponent(componentId);
    if (Iterables.size(tx.browseAssets(component)) == 1) {
        // Component with only one asset should be deleted as well with its asset
        return deleteComponentTx(componentId, deleteBlob).getAssets();
    } else {
        return super.deleteAssetTx(assetId, deleteBlob);
    }
}
Also used : EntityId(org.sonatype.nexus.common.entity.EntityId) StorageTx(org.sonatype.nexus.repository.storage.StorageTx) Asset(org.sonatype.nexus.repository.storage.Asset) Component(org.sonatype.nexus.repository.storage.Component) TransactionalDeleteBlob(org.sonatype.nexus.repository.transaction.TransactionalDeleteBlob)

Example 19 with Component

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

Component (org.sonatype.nexus.repository.storage.Component)19 Test (org.junit.Test)12 Asset (org.sonatype.nexus.repository.storage.Asset)12 InputStream (java.io.InputStream)6 StorageTx (org.sonatype.nexus.repository.storage.StorageTx)6 RFacetUtils.findComponent (org.sonatype.nexus.repository.r.internal.RFacetUtils.findComponent)4 TransactionalStoreBlob (org.sonatype.nexus.repository.transaction.TransactionalStoreBlob)4 RFacet (org.sonatype.nexus.repository.r.RFacet)3 RFacetUtils.findComponent (org.sonatype.nexus.repository.r.internal.util.RFacetUtils.findComponent)3 Bucket (org.sonatype.nexus.repository.storage.Bucket)3 ComponentMaintenance (org.sonatype.nexus.repository.storage.ComponentMaintenance)3 BrowsePaths (org.sonatype.nexus.repository.browse.BrowsePaths)2 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 ByteArrayInputStream (java.io.ByteArrayInputStream)1 AttributesMap (org.sonatype.nexus.common.collect.AttributesMap)1 EntityId (org.sonatype.nexus.common.entity.EntityId)1 TransactionalDeleteBlob (org.sonatype.nexus.repository.transaction.TransactionalDeleteBlob)1