Java Code Examples for org.sonatype.nexus.repository.storage.StorageTx#findComponentInBucket()

The following examples show how to use org.sonatype.nexus.repository.storage.StorageTx#findComponentInBucket() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HelmComponentMaintenanceFacet.java    From nexus-repository-helm with Eclipse Public License 1.0 6 votes vote down vote up
@Transactional(retryOn = ONeedRetryException.class)
@Override
protected Set<String> deleteAssetTx(final EntityId assetId, final boolean deleteBlobs) {
  StorageTx tx = UnitOfWork.currentTx();
  Bucket bucket = tx.findBucket(getRepository());
  Asset asset = tx.findAsset(assetId, bucket);

  if (asset == null) {
    return Collections.emptySet();
  }

  tx.deleteAsset(asset, deleteBlobs);

  if (asset.componentId() != null) {
    Component component = tx.findComponentInBucket(asset.componentId(), bucket);

    if (!tx.browseAssets(component).iterator().hasNext()) {
      log.debug("Deleting component: {}", component);
      tx.deleteComponent(component, deleteBlobs);
    }
  }
  return Collections.singleton(asset.name());
}
 
Example 2
Source File: CondaComponentMaintenanceFacet.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@Transactional(retryOn = ONeedRetryException.class)
@Override
protected Set<String> deleteAssetTx(final EntityId assetId, final boolean deleteBlobs) {
  StorageTx tx = UnitOfWork.currentTx();
  Bucket bucket = tx.findBucket(getRepository());
  Asset asset = tx.findAsset(assetId, bucket);

  if (asset == null) {
    return emptySet();
  }

  tx.deleteAsset(asset, deleteBlobs);

  if (asset.componentId() != null) {
    Component component = tx.findComponentInBucket(asset.componentId(), bucket);

    if (!tx.browseAssets(component).iterator().hasNext()) {
      log.debug("Deleting component: {}", component);
      tx.deleteComponent(component, deleteBlobs);
    }
  }
  return Collections.singleton(asset.name());
}
 
Example 3
Source File: OrientNpmHostedFacet.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@Override
@TransactionalDeleteBlob
public Set<String> deleteTarball(final NpmPackageId packageId, final String tarballName, final boolean deleteBlob) {
  checkNotNull(packageId);
  checkNotNull(tarballName);
  StorageTx tx = UnitOfWork.currentTx();
  Bucket bucket = tx.findBucket(getRepository());

  Asset tarballAsset = NpmFacetUtils.findTarballAsset(tx, bucket, packageId, tarballName);
  if (tarballAsset == null) {
    return Collections.emptySet();
  }
  Component tarballComponent = tx.findComponentInBucket(tarballAsset.componentId(), bucket);
  if (tarballComponent == null) {
    return Collections.emptySet();
  }
  return tx.deleteComponent(tarballComponent, deleteBlob);
}
 
Example 4
Source File: OrientPyPiComponentMaintenance.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Deletes the root AND package index if a component has been deleted
 */
@TransactionalDeleteBlob
@Override
protected DeletionResult deleteComponentTx(final EntityId componentId, final boolean deleteBlobs) {
  StorageTx tx = UnitOfWork.currentTx();
  Component component = tx.findComponentInBucket(componentId, tx.findBucket(getRepository()));
  if (component == null) {
    return new DeletionResult(null, Collections.emptySet());
  }

  deleteRootIndex();

  deleteCachedIndex(component.name());

  log.debug("Deleting component: {}", component.toStringExternal());
  return new DeletionResult(component, tx.deleteComponent(component, deleteBlobs));
}
 
Example 5
Source File: NpmHostedComponentMaintenanceImpl.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Override
@TransactionalDeleteBlob
protected DeletionResult deleteComponentTx(final EntityId componentId, final boolean deleteBlobs) {
  StorageTx tx = UnitOfWork.currentTx();
  Component component = tx.findComponentInBucket(componentId, tx.findBucket(getRepository()));
  if (component == null) {
    return new DeletionResult(null, Collections.emptySet());
  }
  Set<String> deletedAssets = new HashSet<>();
  tx.browseAssets(component).forEach(a -> deletedAssets.addAll(deleteAssetTx(a, deleteBlobs)));
  return new DeletionResult(component, deletedAssets);
}
 
Example 6
Source File: OrientPyPiComponentMaintenance.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Deletes the asset. If the associated component has no additional assets, then the component is also deleted.
 */
@Override
@TransactionalDeleteBlob
protected Set<String> deleteAssetTx(final EntityId assetId, final boolean deleteBlob) {
  StorageTx tx = UnitOfWork.currentTx();
  final Bucket bucket = tx.findBucket(getRepository());
  final Asset asset = tx.findAsset(assetId, bucket);
  if (asset == null) {
    return Collections.emptySet();
  }
  Set<String> deletedAssets = new HashSet<>();
  deletedAssets.addAll(super.deleteAssetTx(assetId, deleteBlob));

  final EntityId componentId = asset.componentId();
  if (componentId != null) {
    deleteRootIndex();

    deleteCachedIndexForPackage(asset);

    final Component component = tx.findComponentInBucket(componentId, bucket);
    if (component != null && !tx.browseAssets(component).iterator().hasNext()) {
      deletedAssets.addAll(deleteComponentTx(componentId, deleteBlob).getAssets());
    }
  }

  return deletedAssets;
}
 
Example 7
Source File: MavenHostedComponentMaintenanceFacet.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Nullable
private String[] findComponent(final EntityId entityId) {
  final StorageTx tx = UnitOfWork.currentTx();
  Component component = tx.findComponentInBucket(entityId, tx.findBucket(getRepository()));
  if (component != null) {
    return new String[]{
        component.formatAttributes().get(P_GROUP_ID, String.class),
        component.formatAttributes().get(P_ARTIFACT_ID, String.class),
        component.formatAttributes().get(P_BASE_VERSION, String.class)
    };
  }
  return null; //NOSONAR
}
 
Example 8
Source File: AptHostedComponentMaintenanceFacet.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Transactional(retryOn = ONeedRetryException.class)
@Override
protected Set<String> deleteAssetTx(final EntityId assetId, final boolean deleteBlobs) {
  StorageTx tx = UnitOfWork.currentTx();
  Bucket bucket = tx.findBucket(getRepository());
  Asset asset = tx.findAsset(assetId, bucket);

  if (asset == null) {
    return Collections.emptySet();
  }

  String assetKind = asset.formatAttributes().get(P_ASSET_KIND, String.class);
  Set<String> result = super.deleteAssetTx(assetId, deleteBlobs);
  if ("DEB".equals(assetKind)) {
    try {
      getRepository().facet(AptHostedFacet.class)
          .rebuildIndexes(Collections.singletonList(new AptHostedFacet.AssetChange(AssetAction.REMOVED, asset)));
    }
    catch (IOException e) {
      throw new UncheckedIOException(e);
    }
  }

  if (asset.componentId() != null) {
    Component component = tx.findComponentInBucket(asset.componentId(), bucket);

    if (!tx.browseAssets(component).iterator().hasNext()) {
      log.debug("Deleting component: {}", component);
      tx.deleteComponent(component, deleteBlobs);
    }
  }

  return result;
}
 
Example 9
Source File: AptHostedComponentMaintenanceFacet.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@TransactionalDeleteBlob
@Override
protected DeletionResult deleteComponentTx(final EntityId componentId, final boolean deleteBlobs) {
  StorageTx tx = UnitOfWork.currentTx();
  Component component = tx.findComponentInBucket(componentId, tx.findBucket(getRepository()));

  if (component == null) {
    return new DeletionResult(null, Collections.emptySet());
  }

  Iterable<Asset> assets = tx.browseAssets(component);
  List<AssetChange> changes = new ArrayList<>();
  for (Asset asset : assets) {
    changes.add(new AssetChange(AssetAction.REMOVED, asset));
  }

  log.debug("Deleting component: {}", component.toStringExternal());
  DeletionResult result = new DeletionResult(component, tx.deleteComponent(component, deleteBlobs));
  try {
    getRepository().facet(AptHostedFacet.class).rebuildIndexes(changes);
  }
  catch (IOException e) {
    throw new UncheckedIOException(e);
  }

  return result;
}