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

The following examples show how to use org.sonatype.nexus.repository.storage.StorageTx#findAssetWithProperty() . 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: AptSnapshotFacetSupport.java    From nexus-repository-apt with Eclipse Public License 1.0 6 votes vote down vote up
@Transactional(retryOn = { ONeedRetryException.class })
@Override
public Content getSnapshotFile(String id, String path) throws IOException {
  StorageTx tx = UnitOfWork.currentTx();
  Bucket bucket = tx.findBucket(getRepository());
  Component component = tx.findComponentWithProperty(P_NAME, id, bucket);
  if (component == null) {
    return null;
  }

  final Asset asset = tx.findAssetWithProperty(P_NAME, createAssetPath(id, path), component);
  if (asset == null) {
    return null;
  }

  final Blob blob = tx.requireBlob(asset.requireBlobRef());
  return FacetHelper.toContent(asset, blob);
}
 
Example 2
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 3
Source File: AptProxyFacet.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Transactional(retryOn = {ONeedRetryException.class})
protected void doIndicateVerified(final Content content, final CacheInfo cacheInfo, final String assetPath) {
  StorageTx tx = UnitOfWork.currentTx();
  Bucket bucket = tx.findBucket(getRepository());

  Asset asset = Content.findAsset(tx, bucket, content);
  if (asset == null) {
    asset = tx.findAssetWithProperty(P_NAME, assetPath, bucket);
  }
  if (asset == null) {
    return;
  }
  CacheInfo.applyToAsset(asset, cacheInfo);
  tx.saveAsset(asset);
}
 
Example 4
Source File: NpmFacetUtils.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Find a tarball asset by package name and tarball filename in repository.
 */
@Nullable
static Asset findTarballAsset(final StorageTx tx,
                              final Bucket bucket,
                              final NpmPackageId packageId,
                              final String tarballName)
{
  return tx.findAssetWithProperty(P_NAME, tarballAssetName(packageId, tarballName), bucket);
}
 
Example 5
Source File: NpmFacetUtils.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Find a package root asset by package name in repository.
 */
@Nullable
public static Asset findPackageRootAsset(final StorageTx tx,
                                         final Bucket bucket,
                                         final NpmPackageId packageId)
{
  return tx.findAssetWithProperty(P_NAME, packageId.id(), bucket);
}
 
Example 6
Source File: CocoapodsFacetImpl.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Override
@TransactionalStoreBlob
public Content getOrCreateAsset(final String path, final Content content, boolean toAttachComponent)
    throws IOException
{
  StorageFacet storageFacet = facet(StorageFacet.class);
  try (final TempBlob tempBlob = storageFacet.createTempBlob(content, HASH_ALGORITHMS)) {
    StorageTx tx = UnitOfWork.currentTx();
    Bucket bucket = tx.findBucket(getRepository());

    Asset asset = tx.findAssetWithProperty(P_NAME, path, bucket);
    if (asset == null) {
      if (toAttachComponent) {
        Component component = findOrCreateComponent(tx, bucket, path);
        asset = tx.createAsset(bucket, component).name(path);
      }
      else {
        asset = tx.createAsset(bucket, getRepository().getFormat()).name(path);
      }
    }
    Content.applyToAsset(asset, content.getAttributes());
    AssetBlob blob = tx.setBlob(asset, path, tempBlob, HASH_ALGORITHMS, null, null, false);
    tx.saveAsset(asset);

    final Content updatedContent = new Content(new BlobPayload(blob.getBlob(), asset.requireContentType()));
    Content.extractFromAsset(asset, HASH_ALGORITHMS, updatedContent.getAttributes());
    return updatedContent;
  }
}
 
Example 7
Source File: AptFacetImpl.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public Asset findOrCreateDebAsset(final StorageTx tx, final String path, final PackageInfo packageInfo)
{
  Bucket bucket = tx.findBucket(getRepository());
  Asset asset = tx.findAssetWithProperty(P_NAME, path, bucket);
  if (asset == null) {
    Component component = findOrCreateComponent(
        tx,
        bucket,
        packageInfo);
    asset = tx.createAsset(bucket, component).name(path);
  }

  return asset;
}
 
Example 8
Source File: AptFacetImpl.java    From nexus-repository-apt with Eclipse Public License 1.0 5 votes vote down vote up
@Override
@Nullable
@TransactionalTouchBlob
public Content get(String path) throws IOException {
  final StorageTx tx = UnitOfWork.currentTx();
  final Asset asset = tx.findAssetWithProperty(P_NAME, path, tx.findBucket(getRepository()));
  if (asset == null) {
    return null;
  }

  return FacetHelper.toContent(asset, tx.requireBlob(asset.requireBlobRef()));
}
 
Example 9
Source File: AptFacetImpl.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Override
@TransactionalDeleteBlob
public boolean delete(final String path) throws IOException {
  StorageTx tx = UnitOfWork.currentTx();
  Bucket bucket = tx.findBucket(getRepository());
  Asset asset = tx.findAssetWithProperty(P_NAME, path, bucket);
  if (asset == null) {
    return false;
  }

  tx.deleteAsset(asset);
  return true;
}
 
Example 10
Source File: CocoapodsFacetImpl.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Override
@Nullable
@TransactionalTouchBlob
public Content get(final String path) {
  final StorageTx tx = UnitOfWork.currentTx();
  final Asset asset = tx.findAssetWithProperty(P_NAME, path, tx.findBucket(getRepository()));
  if (asset == null) {
    return null;
  }
  Content content = new Content(new BlobPayload(tx.requireBlob(asset.requireBlobRef()), asset.requireContentType()));
  Content.extractFromAsset(asset, HASH_ALGORITHMS, content.getAttributes());
  return content;
}
 
Example 11
Source File: HelmFacetImpl.java    From nexus-repository-helm with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Find an asset by its name.
 *
 * @return found Optional<Asset> or Optional.empty if not found
 */
@Override
public Optional<Asset> findAsset(final StorageTx tx, final String assetName) {
  Bucket bucket = tx.findBucket(getRepository());
  Asset asset = tx.findAssetWithProperty(P_NAME, assetName, bucket);
  return Optional.ofNullable(asset);
}
 
Example 12
Source File: AptFacetImpl.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Override
@Nullable
@TransactionalTouchBlob
public Content get(final String path) throws IOException {
  final StorageTx tx = UnitOfWork.currentTx();
  final Asset asset = tx.findAssetWithProperty(P_NAME, path, tx.findBucket(getRepository()));
  if (asset == null) {
    return null;
  }

  return FacetHelper.toContent(asset, tx.requireBlob(asset.requireBlobRef()));
}
 
Example 13
Source File: RundeckMavenResource.java    From nexus3-rundeck-plugin with MIT License 4 votes vote down vote up
@GET
@Path("content")
public Response content(
        @QueryParam("r") String repositoryName,
        @QueryParam("g") String groupId,
        @QueryParam("a") String artifactId,
        @QueryParam("v") String version,
        @QueryParam("c") String classifier,
        @QueryParam("p") @DefaultValue("jar") String extension
) {


    // default version
    if ("LATEST".equals(version)) {
        version = null;
    }
    version = Optional.ofNullable(version).orElse(latestVersion(
            repositoryName, groupId, artifactId, classifier, extension
    ));

    // valid params
    if (isBlank(repositoryName) || isBlank(groupId) || isBlank(artifactId) || isBlank(version)) {
        return NOT_FOUND;
    }

    Repository repository = repositoryManager.get(repositoryName);
    if (null == repository || !repository.getFormat().getValue().equals("maven2")) {
        return NOT_FOUND;
    }

    StorageFacet facet = repository.facet(StorageFacet.class);
    Supplier<StorageTx> storageTxSupplier = facet.txSupplier();

    log.debug("rundeck download repository: {}", repository);
    final StorageTx tx = storageTxSupplier.get();
    tx.begin();
    Bucket bucket = tx.findBucket(repository);
    log.debug("rundeck download bucket: {}", bucket);

    if (null == bucket) {
        return commitAndReturn(NOT_FOUND, tx);
    }

    String fileName = artifactId + "-" + version + (isBlank(classifier) ? "" : ("-" + classifier)) + "." + extension;
    String path = groupId.replace(".", "/") +
            "/" + artifactId +
            "/" + version +
            "/" + fileName;
    Asset asset = tx.findAssetWithProperty("name", path, bucket);
    log.debug("rundeck download asset: {}", asset);
    if (null == asset) {
        return commitAndReturn(NOT_FOUND, tx);
    }
    asset.markAsDownloaded();
    tx.saveAsset(asset);
    Blob blob = tx.requireBlob(asset.requireBlobRef());
    Response.ResponseBuilder ok = Response.ok(blob.getInputStream());
    ok.header("Content-Type", blob.getHeaders().get("BlobStore.content-type"));
    ok.header("Content-Disposition", "attachment;filename=\"" + fileName + "\"");
    return commitAndReturn(ok.build(), tx);
}
 
Example 14
Source File: ComposerContentFacetImpl.java    From nexus-repository-composer with Eclipse Public License 1.0 4 votes vote down vote up
@Nullable
private Asset findAsset(final StorageTx tx, final String path) {
  return tx.findAssetWithProperty(P_NAME, path, tx.findBucket(getRepository()));
}
 
Example 15
Source File: RRestoreFacetImpl.java    From nexus-repository-r with Eclipse Public License 1.0 4 votes vote down vote up
@Override
@TransactionalTouchBlob
public boolean assetExists(final String path) {
  final StorageTx tx = UnitOfWork.currentTx();
  return tx.findAssetWithProperty(P_NAME, path, tx.findBucket(getRepository())) != null;
}
 
Example 16
Source File: CondaFacetImpl.java    From nexus-public with Eclipse Public License 1.0 4 votes vote down vote up
@Override
@Nullable
public Asset findAsset(final StorageTx tx, final Bucket bucket, final String assetName)
{
  return tx.findAssetWithProperty(MetadataNodeEntityAdapter.P_NAME, assetName, bucket);
}
 
Example 17
Source File: RawContentFacetImpl.java    From nexus-public with Eclipse Public License 1.0 4 votes vote down vote up
private Asset findAsset(StorageTx tx, String path) {
  return tx.findAssetWithProperty(P_NAME, path, tx.findBucket(getRepository()));
}
 
Example 18
Source File: P2RestoreFacetImpl.java    From nexus-repository-p2 with Eclipse Public License 1.0 4 votes vote down vote up
@Override
@TransactionalTouchBlob
public boolean assetExists(final String path) {
  final StorageTx tx = UnitOfWork.currentTx();
  return tx.findAssetWithProperty(P_NAME, path, tx.findBucket(getRepository())) != null;
}
 
Example 19
Source File: P2FacetImpl.java    From nexus-repository-p2 with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Find an asset by its name.
 *
 * @return found asset or null if not found
 */
@Nullable
@Override
public Asset findAsset(final StorageTx tx, final Bucket bucket, final String assetName) {
  return tx.findAssetWithProperty(MetadataNodeEntityAdapter.P_NAME, assetName, bucket);
}
 
Example 20
Source File: OrientPyPiDataUtils.java    From nexus-public with Eclipse Public License 1.0 2 votes vote down vote up
/**
 * Find an asset by its name.
 *
 * @return found asset or null if not found
 */
@Nullable
static Asset findAsset(final StorageTx tx, final Bucket bucket, final String assetName) {
  return tx.findAssetWithProperty(MetadataNodeEntityAdapter.P_NAME, assetName, bucket);
}