Search in sources :

Example 1 with TransactionalDeleteBlob

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

Aggregations

EntityId (org.sonatype.nexus.common.entity.EntityId)1 Asset (org.sonatype.nexus.repository.storage.Asset)1 Component (org.sonatype.nexus.repository.storage.Component)1 StorageTx (org.sonatype.nexus.repository.storage.StorageTx)1 TransactionalDeleteBlob (org.sonatype.nexus.repository.transaction.TransactionalDeleteBlob)1