Java Code Examples for org.sonatype.nexus.repository.view.Content#applyToAsset()

The following examples show how to use org.sonatype.nexus.repository.view.Content#applyToAsset() . 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: OrientPyPiGroupFacet.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@TransactionalStoreBlob
protected AssetBlob updateAsset(final StorageTx tx, final Asset asset, final Content content) throws IOException {
  AttributesMap contentAttributes = Content.maintainLastModified(asset, content.getAttributes());
  Content.applyToAsset(asset, contentAttributes);

  InputStream inputStream = content.openInputStream();
  AssetBlob blob = tx.setBlob(asset,
      asset.name(),
      () -> inputStream,
      HASH_ALGORITHMS,
      null,
      ContentTypes.TEXT_HTML,
      true);

  tx.saveAsset(asset);

  return blob;
}
 
Example 2
Source File: HelmFacetImpl.java    From nexus-repository-helm with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Save an asset and create blob.
 *
 * @return blob content
 */
@Override
public Content saveAsset(final StorageTx tx,
                         final Asset asset,
                         final Supplier<InputStream> contentSupplier,
                         @Nullable final String contentType,
                         @Nullable final AttributesMap contentAttributes) throws IOException
{
  Content.applyToAsset(asset, Content.maintainLastModified(asset, contentAttributes));
  AssetBlob assetBlob = tx.setBlob(
      asset, asset.name(), contentSupplier, HASH_ALGORITHMS, null, contentType, false
  );
  asset.markAsDownloaded();
  tx.saveAsset(asset);
  return toContent(asset, assetBlob.getBlob());
}
 
Example 3
Source File: RFacetUtils.java    From nexus-repository-r with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Save an asset && create blob.
 *
 * @return blob content
 */
public static Content saveAsset(final StorageTx tx,
                                final Asset asset,
                                final Supplier<InputStream> contentSupplier,
                                final String contentType,
                                @Nullable final AttributesMap contentAttributes) throws IOException
{
  Content.applyToAsset(asset, Content.maintainLastModified(asset, contentAttributes));
  AssetBlob assetBlob = tx.setBlob(
      asset, asset.name(), contentSupplier, HASH_ALGORITHMS, null, contentType, false
  );

  asset.markAsDownloaded();
  tx.saveAsset(asset);
  return toContent(asset, assetBlob.getBlob());
}
 
Example 4
Source File: ConanProxyFacet.java    From nexus-repository-conan with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Save an asset and create a blob
 *
 * @return blob content
 */
private Content saveAsset(final StorageTx tx,
                          final Asset asset,
                          final Supplier<InputStream> contentSupplier,
                          final String contentType,
                          final AttributesMap contentAttributes,
                          final HashCode hash) throws IOException
{
  Content.applyToAsset(asset, maintainLastModified(asset, contentAttributes));
  AssetBlob assetBlob = tx.setBlob(
      asset, asset.name(), contentSupplier, HASH_ALGORITHMS, null, contentType, false
  );

  if (!hashVerifier.verify(hash, assetBlob.getHashes().get(MD5))) {
    return null;
  }
  asset.markAsDownloaded();
  tx.saveAsset(asset);
  return toContent(asset, assetBlob.getBlob());
}
 
Example 5
Source File: AptFacetImpl.java    From nexus-repository-apt with Eclipse Public License 1.0 5 votes vote down vote up
@Override
@TransactionalStoreBlob
public Content put(String path, Payload content) throws IOException {
  StorageFacet storageFacet = facet(StorageFacet.class);
  try (final TempBlob tembBlob = storageFacet.createTempBlob(content, FacetHelper.hashAlgorithms)) {
    StorageTx tx = UnitOfWork.currentTx();
    Bucket bucket = tx.findBucket(getRepository());
    Asset asset = tx.findAssetWithProperty(P_NAME, path, bucket);
    if (asset == null) {
      asset = tx.createAsset(bucket, getRepository().getFormat()).name(path);
    }

    AttributesMap contentAttributes = null;
    if (content instanceof Content) {
      contentAttributes = ((Content) content).getAttributes();
    }
    Content.applyToAsset(asset, Content.maintainLastModified(asset, contentAttributes));
    AssetBlob blob = tx.setBlob(
        asset,
        path,
        tembBlob,
        FacetHelper.hashAlgorithms,
        null,
        content.getContentType(),
        false);
    tx.saveAsset(asset);
    return FacetHelper.toContent(asset, blob.getBlob());
  }
}
 
Example 6
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 7
Source File: OrientPyPiDataUtils.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Save an asset and create a blob with the specified content attributes.
 *
 * @return blob content
 */
static Content saveAsset(
    final StorageTx tx,
    final Asset asset,
    final TempBlob tempBlob,
    @Nullable final String contentType,
    @Nullable final AttributesMap contentAttributes) throws IOException
{
  Content.applyToAsset(asset, Content.maintainLastModified(asset, contentAttributes));
  AssetBlob assetBlob = tx.setBlob(asset, asset.name(), tempBlob, null, contentType, false);

  tx.saveAsset(asset);
  return toContent(asset, assetBlob.getBlob());
}
 
Example 8
Source File: GolangDataAccess.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Save an asset and create blob.
 *
 * @return blob content
 */
private Content saveAsset(final StorageTx tx,
                          final Asset asset,
                          final Supplier<InputStream> contentSupplier,
                          final String contentType,
                          @Nullable final AttributesMap contentAttributes) throws IOException
{
  Content.applyToAsset(asset, Content.maintainLastModified(asset, contentAttributes));
  AssetBlob assetBlob = tx.setBlob(
      asset, asset.name(), contentSupplier, HASH_ALGORITHMS, null, contentType, false
  );
  tx.saveAsset(asset);
  return toContent(asset, assetBlob.getBlob());
}
 
Example 9
Source File: NpmFacetUtils.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Save repository root asset & create blob from a temporary blob.
 *
 * @return blob content
 */
@Nonnull
static Content saveRepositoryRoot(final StorageTx tx,
                                  final Asset asset,
                                  final TempBlob tempBlob,
                                  final Content content) throws IOException
{
  Content.applyToAsset(asset, Content.maintainLastModified(asset, content.getAttributes()));
  AssetBlob assetBlob = storeContent(tx, asset, tempBlob, AssetKind.REPOSITORY_ROOT);
  tx.saveAsset(asset);
  return toContent(asset, assetBlob.getBlob());
}
 
Example 10
Source File: NpmFacetUtils.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Save repository root asset & create blob from an input stream.
 *
 * @return blob content
 */
@Nonnull
public static Content saveRepositoryRoot(final StorageTx tx,
                                         final Asset asset,
                                         final Supplier<InputStream> contentSupplier,
                                         final Content content) throws IOException
{
  Content.applyToAsset(asset, Content.maintainLastModified(asset, content.getAttributes()));
  final AssetBlob assetBlob = storeContent(tx, asset, contentSupplier, AssetKind.REPOSITORY_ROOT);
  tx.saveAsset(asset);
  return toContent(asset, assetBlob.getBlob());
}
 
Example 11
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));
}
 
Example 12
Source File: CondaFacetImpl.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public Content saveAsset(final StorageTx tx,
                         final Asset asset,
                         final Supplier<InputStream> contentSupplier,
                         final String contentType,
                         @Nullable final AttributesMap contentAttributes) throws IOException
{
  Content.applyToAsset(asset, Content.maintainLastModified(asset, contentAttributes));
  AssetBlob assetBlob = tx.setBlob(asset, asset.name(), contentSupplier, HASH_ALGORITHMS, null, contentType, false);
  tx.saveAsset(asset);
  return toContent(asset, assetBlob.getBlob());
}
 
Example 13
Source File: ComposerContentFacetImpl.java    From nexus-repository-composer with Eclipse Public License 1.0 5 votes vote down vote up
@TransactionalStoreBlob
protected Content doPutMetadata(final String path,
                                final TempBlob tempBlob,
                                final Payload payload,
                                final AssetKind assetKind)
    throws IOException
{
  StorageTx tx = UnitOfWork.currentTx();

  Asset asset = getOrCreateAsset(path);

  asset.formatAttributes().set(P_ASSET_KIND, assetKind.toString());

  if (payload instanceof Content) {
    Content.applyToAsset(asset, Content.maintainLastModified(asset, ((Content) payload).getAttributes()));
  }

  AssetBlob assetBlob = tx.setBlob(
      asset,
      path,
      tempBlob,
      null,
      payload.getContentType(),
      false
  );

  tx.saveAsset(asset);

  return toContent(asset, assetBlob.getBlob());
}
 
Example 14
Source File: ConanHostedFacet.java    From nexus-repository-conan with Eclipse Public License 1.0 5 votes vote down vote up
private Content saveAsset(final StorageTx tx,
                          final Asset asset,
                          final Supplier<InputStream> contentSupplier,
                          final String contentType,
                          final AttributesMap contentAttributes) throws IOException
{
  Content.applyToAsset(asset, maintainLastModified(asset, contentAttributes));
  AssetBlob assetBlob = tx.setBlob(
      asset, asset.name(), contentSupplier, HASH_ALGORITHMS, null, contentType, false
  );

  asset.markAsDownloaded();
  tx.saveAsset(asset);
  return toContent(asset, assetBlob.getBlob());
}
 
Example 15
Source File: AptFacetImpl.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Override
@TransactionalStoreBlob
public Content put(final String path, final Payload content, final PackageInfo info) throws IOException {
  StorageFacet storageFacet = facet(StorageFacet.class);
  try (final TempBlob tempBlob = storageFacet.createTempBlob(content, FacetHelper.hashAlgorithms)) {
    StorageTx tx = UnitOfWork.currentTx();
    Asset asset = isDebPackageContentType(path)
        ? findOrCreateDebAsset(tx, path,
        info != null ? info : new PackageInfo(AptPackageParser.getDebControlFile(tempBlob.getBlob())))
        : findOrCreateMetadataAsset(tx, path);

    AttributesMap contentAttributes = null;
    if (content instanceof Content) {
      contentAttributes = ((Content) content).getAttributes();
    }
    Content.applyToAsset(asset, Content.maintainLastModified(asset, contentAttributes));
    AssetBlob blob = tx.setBlob(
        asset,
        path,
        tempBlob,
        FacetHelper.hashAlgorithms,
        null,
        content.getContentType(),
        false);
    tx.saveAsset(asset);
    return FacetHelper.toContent(asset, blob.getBlob());
  }
}
 
Example 16
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 17
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 18
Source File: P2FacetImpl.java    From nexus-repository-p2 with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Save an asset && create blob.
 *
 * @return blob content
 */
public Content saveAsset(final StorageTx tx,
                         final Asset asset,
                         final Supplier<InputStream> contentSupplier,
                         final String contentType,
                         @Nullable final AttributesMap contentAttributes) throws IOException
{
  Content.applyToAsset(asset, Content.maintainLastModified(asset, contentAttributes));
  AssetBlob assetBlob = tx.setBlob(
      asset, asset.name(), contentSupplier, HASH_ALGORITHMS, null, contentType, false
  );
  asset.markAsDownloaded();
  tx.saveAsset(asset);
  return toContent(asset, assetBlob.getBlob());
}
 
Example 19
Source File: DeconflictAssetMetadataTest.java    From nexus-public with Eclipse Public License 1.0 4 votes vote down vote up
private void setLastModified(final Asset asset, final DateTime lastModified) {
  AttributesMap contentAttributes = new AttributesMap();
  contentAttributes.set(CONTENT_LAST_MODIFIED, lastModified);
  Content.applyToAsset(asset, contentAttributes);
}
 
Example 20
Source File: ComposerContentFacetImpl.java    From nexus-repository-composer with Eclipse Public License 1.0 4 votes vote down vote up
@TransactionalStoreBlob
protected Content doPutContent(final String path,
                               final TempBlob tempBlob,
                               final Payload payload,
                               final AssetKind assetKind)
    throws IOException
{
  String[] parts = path.split("/");
  String group = parts[0];
  String name = parts[1];
  String version = parts[2];

  StorageTx tx = UnitOfWork.currentTx();

  Asset asset = getOrCreateAsset(path, group, name, version);

  if (payload instanceof Content) {
    Content.applyToAsset(asset, Content.maintainLastModified(asset, ((Content) payload).getAttributes()));
  }

  AssetBlob assetBlob = tx.setBlob(
      asset,
      path,
      tempBlob,
      null,
      payload.getContentType(),
      false
  );

  try {
    asset.formatAttributes().clear();
    asset.formatAttributes().set(P_ASSET_KIND, assetKind.toString());
    asset.formatAttributes().set(P_VENDOR, group);
    asset.formatAttributes().set(P_PROJECT, name);
    asset.formatAttributes().set(P_VERSION, version);
    composerFormatAttributesExtractor.extractFromZip(tempBlob, asset.formatAttributes());
  }
  catch (Exception e) {
    log.error("Error extracting format attributes for {}, skipping", path, e);
  }

  tx.saveAsset(asset);

  return toContent(asset, assetBlob.getBlob());
}