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

The following examples show how to use org.sonatype.nexus.repository.storage.StorageTx#attachBlob() . 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: RRestoreFacetImpl.java    From nexus-repository-r with Eclipse Public License 1.0 6 votes vote down vote up
@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);
}
 
Example 2
Source File: AptSnapshotFacetSupport.java    From nexus-repository-apt with Eclipse Public License 1.0 6 votes vote down vote up
@Transactional(retryOn = { ONeedRetryException.class })
@Override
public void createSnapshot(String id, SnapshotComponentSelector selector) throws IOException {
  StorageTx tx = UnitOfWork.currentTx();
  StorageFacet storageFacet = facet(StorageFacet.class);
  Bucket bucket = tx.findBucket(getRepository());
  Component component = tx.createComponent(bucket, getRepository().getFormat()).name(id);
  tx.saveComponent(component);
  for (SnapshotItem item : collectSnapshotItems(selector)) {
    String assetName = createAssetPath(id, item.specifier.path);
    Asset asset = tx.createAsset(bucket, component).name(assetName);
    try (final TempBlob streamSupplier = storageFacet.createTempBlob(item.content.openInputStream(), FacetHelper.hashAlgorithms)) {
      AssetBlob blob = tx.createBlob(item.specifier.path, streamSupplier, FacetHelper.hashAlgorithms, null,
          FacetHelper.determineContentType(item), true);
      tx.attachBlob(asset, blob);
    }
    finally {
      item.content.close();
    }
    tx.saveAsset(asset);
  }
}
 
Example 3
Source File: NpmFacetUtils.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Creates an {@link AssetBlob} out of passed in content and attaches it to passed in {@link Asset}.
 */
@Nonnull
static AssetBlob storeContent(final StorageTx tx,
                              final Asset asset,
                              final Supplier<InputStream> content,
                              final AssetKind assetKind) throws IOException
{
  asset.formatAttributes().set(P_ASSET_KIND, assetKind.name());

  final AssetBlob result = tx.createBlob(
      asset.name(),
      content,
      HASH_ALGORITHMS,
      null,
      assetKind.getContentType(),
      assetKind.isSkipContentVerification()
  );
  tx.attachBlob(asset, result);
  return result;
}
 
Example 4
Source File: NpmFacetUtils.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Creates an {@link AssetBlob} out of passed in temporary blob and attaches it to passed in {@link Asset}.
 */
@Nonnull
static AssetBlob storeContent(final StorageTx tx,
                              final Asset asset,
                              final TempBlob tempBlob,
                              final AssetKind assetKind) throws IOException
{
  asset.formatAttributes().set(P_ASSET_KIND, assetKind.name());
  AssetBlob result = tx.createBlob(
      asset.name(),
      tempBlob,
      null,
      assetKind.getContentType(),
      assetKind.isSkipContentVerification()
  );
  tx.attachBlob(asset, result);
  return result;
}
 
Example 5
Source File: AptRestoreFacetImpl.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@Override
@TransactionalStoreBlob
public Content restore(final AssetBlob assetBlob, final String path) throws IOException {
  StorageTx tx = UnitOfWork.currentTx();
  Asset asset;
  AptFacet aptFacet = facet(AptFacet.class);
  if (isDebPackageContentType(path)) {
    ControlFile controlFile = AptPackageParser.getDebControlFile(assetBlob.getBlob());
    asset = aptFacet.findOrCreateDebAsset(tx, path, new PackageInfo(controlFile));
  }
  else {
    asset = aptFacet.findOrCreateMetadataAsset(tx, path);
  }

  tx.attachBlob(asset, assetBlob);
  Content.applyToAsset(asset, Content.maintainLastModified(asset, new AttributesMap()));
  tx.saveAsset(asset);
  return FacetHelper.toContent(asset, assetBlob.getBlob());
}
 
Example 6
Source File: AptSnapshotFacetSupport.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@Transactional(retryOn = {ONeedRetryException.class})
protected void createSnapshot(final String id, final Iterable<SnapshotItem> snapshots) throws IOException {
  StorageTx tx = UnitOfWork.currentTx();
  StorageFacet storageFacet = facet(StorageFacet.class);
  Bucket bucket = tx.findBucket(getRepository());
  for (SnapshotItem item : snapshots) {
    String assetName = createAssetPath(id, item.specifier.path);
    Asset asset = tx.createAsset(bucket, getRepository().getFormat()).name(assetName);
    try (final TempBlob streamSupplier = storageFacet
        .createTempBlob(item.content.openInputStream(), FacetHelper.hashAlgorithms)) {
      AssetBlob blob = tx.createBlob(item.specifier.path, streamSupplier, FacetHelper.hashAlgorithms, null,
          item.specifier.role.getMimeType(), true);
      tx.attachBlob(asset, blob);
    }
    finally {
      item.content.close();
    }
    tx.saveAsset(asset);
  }
}
 
Example 7
Source File: P2RestoreFacetImpl.java    From nexus-repository-p2 with Eclipse Public License 1.0 5 votes vote down vote up
@Override
@TransactionalTouchBlob
public void restore(final AssetBlob assetBlob, final String path) {
  StorageTx tx = UnitOfWork.currentTx();
  P2Facet facet = facet(P2Facet.class);

  Asset asset;
  if (componentRequired(path)) {
    P2Attributes attributes = P2Attributes.builder().build();
    try {
      attributes = getComponentAttributes(assetBlob.getBlob(), path);
    }
    catch (IOException e) {
      log.error("Exception of extracting components attributes from blob {}", assetBlob);
    }

    Component component = facet.findOrCreateComponent(tx, 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);
}
 
Example 8
Source File: HelmRestoreFacetImpl.java    From nexus-repository-helm with Eclipse Public License 1.0 5 votes vote down vote up
@Override
@TransactionalTouchBlob
public void restore(final AssetBlob assetBlob, final String path) throws IOException {
  StorageTx tx = UnitOfWork.currentTx();
  AssetKind assetKind = AssetKind.getAssetKindByFileName(path);
  HelmAttributes attributes = helmAttributeParser.getAttributes(assetKind, assetBlob.getBlob().getInputStream());
  Asset asset = helmFacet.findOrCreateAsset(tx, path, assetKind, attributes);
  tx.attachBlob(asset, assetBlob);
  Content.applyToAsset(asset, Content.maintainLastModified(asset, new AttributesMap()));
  tx.saveAsset(asset);
}
 
Example 9
Source File: NpmFacetImpl.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
private void saveAsset(final StorageTx tx,
                       final Asset asset,
                       final AssetBlob assetBlob,
                       final AssetKind kind,
                       @Nullable final AttributesMap contentAttributes)
{
  asset.formatAttributes().set(P_ASSET_KIND, kind.name());
  tx.attachBlob(asset, assetBlob);
  Content.applyToAsset(asset, Content.maintainLastModified(asset, contentAttributes));
  tx.saveAsset(asset);
}
 
Example 10
Source File: OrientPyPiFacetImpl.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
private void saveAsset(final StorageTx tx, final Asset asset, final AssetBlob assetBlob, final AssetKind kind) {
  asset.formatAttributes().set(P_ASSET_KIND, kind);
  tx.attachBlob(asset, assetBlob);
  DateTime blobCreationTime = assetBlob.getBlob().getMetrics().getCreationTime();
  asset.blobCreated(blobCreationTime);
  asset.blobUpdated(blobCreationTime);
  tx.saveAsset(asset);
}
 
Example 11
Source File: RawContentFacetImpl.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Override
@TransactionalStoreBlob
public Asset put(final String path, final AssetBlob assetBlob, @Nullable final AttributesMap contentAttributes) {
  StorageTx tx = UnitOfWork.currentTx();
  Asset asset = getOrCreateAsset(getRepository(), path, RawCoordinatesHelper.getGroup(path), path);
  tx.attachBlob(asset, assetBlob);
  Content.applyToAsset(asset, Content.maintainLastModified(asset, contentAttributes));
  tx.saveAsset(asset);
  return asset;
}
 
Example 12
Source File: MavenFacetImpl.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
private void putAssetPayload(final StorageTx tx,
                             final Asset asset,
                             final AssetBlob assetBlob,
                             @Nullable final AttributesMap contentAttributes)
    throws IOException
{
  tx.attachBlob(asset, assetBlob);
  Content.applyToAsset(asset, Content.maintainLastModified(asset, contentAttributes));
}