Java Code Examples for org.sonatype.nexus.repository.storage.StorageTx#requireBlob()
The following examples show how to use
org.sonatype.nexus.repository.storage.StorageTx#requireBlob() .
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: ComposerContentFacetImpl.java From nexus-repository-composer with Eclipse Public License 1.0 | 6 votes |
@Nullable @Override @TransactionalTouchBlob public Content get(final String path) throws IOException { StorageTx tx = UnitOfWork.currentTx(); final Asset asset = findAsset(tx, path); if (asset == null) { return null; } if (asset.markAsDownloaded()) { tx.saveAsset(asset); } final Blob blob = tx.requireBlob(asset.requireBlobRef()); return toContent(asset, blob); }
Example 2
Source File: AptSnapshotFacetSupport.java From nexus-repository-apt with Eclipse Public License 1.0 | 6 votes |
@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 3
Source File: NpmFacetUtils.java From nexus-public with Eclipse Public License 1.0 | 6 votes |
/** * Returns the tarball content. */ @Nullable static Content getTarballContent(final StorageTx tx, final Bucket bucket, final NpmPackageId packageId, final String tarballName) { Asset asset = findTarballAsset(tx, bucket, packageId, tarballName); if (asset == null) { return null; } Blob blob = tx.requireBlob(asset.requireBlobRef()); Content content = new Content(new BlobPayload(blob, asset.requireContentType())); Content.extractFromAsset(asset, HASH_ALGORITHMS, content.getAttributes()); return content; }
Example 4
Source File: NpmFacetUtils.java From nexus-public with Eclipse Public License 1.0 | 5 votes |
/** * Returns the package root JSON content by reading up package root asset's blob and parsing it. It also decorates * the JSON document with some fields. */ public static NestedAttributesMap loadPackageRoot(final StorageTx tx, final Asset packageRootAsset) throws IOException { final Blob blob = tx.requireBlob(packageRootAsset.requireBlobRef()); NestedAttributesMap metadata = NpmJsonUtils.parse(() -> blob.getInputStream()); // add _id metadata.set(NpmMetadataUtils.META_ID, packageRootAsset.name()); return metadata; }
Example 5
Source File: NpmFacetImpl.java From nexus-public with Eclipse Public License 1.0 | 5 votes |
private void maybeExtractFormatAttributes(final StorageTx tx, final String packageId, final Asset asset, final AssetBlob assetBlob) { Blob blob = tx.requireBlob(assetBlob.getBlobRef()); Map<String, Object> formatAttributes = npmPackageParser.parsePackageJson(blob::getInputStream); if (formatAttributes.isEmpty()) { log.warn("No format attributes found in package.json for npm package ID {}, will not be searchable", packageId); } else { NpmFormatAttributesExtractor formatAttributesExtractor = new NpmFormatAttributesExtractor(formatAttributes); formatAttributesExtractor.copyFormatAttributes(asset); } }
Example 6
Source File: RawContentFacetImpl.java From nexus-public with Eclipse Public License 1.0 | 5 votes |
@Nullable @Override @TransactionalTouchBlob public Content get(final String path) { StorageTx tx = UnitOfWork.currentTx(); final Asset asset = findAsset(tx, path); if (asset == null) { return null; } final Blob blob = tx.requireBlob(asset.requireBlobRef()); return toContent(asset, blob); }
Example 7
Source File: MavenFacetImpl.java From nexus-public with Eclipse Public License 1.0 | 5 votes |
@Nullable @TransactionalStoreBlob protected Content doGet(MavenPath path) throws IOException { StorageTx tx = UnitOfWork.currentTx(); Bucket bucket = tx.findBucket(getRepository()); Asset asset = findAsset(tx, bucket, path); if (asset == null) { return null; } Blob blob = tx.requireBlob(asset.requireBlobRef()); if (needsRebuild(path, asset)) { try { removeRebuildFlag(asset); tx.saveAsset(asset); rebuildMetadata(blob); // locate the rebuilt asset + blob asset = findAsset(tx, bucket, path); if (asset == null) { return null; } blob = tx.requireBlob(asset.requireBlobRef()); } catch (OModificationOperationProhibitedException e) { log.debug("Cannot rebuild metadata when NXRM is read-only {} : {}", getRepository().getName(), path.getPath(), e); } } return toContent(asset, blob); }
Example 8
Source File: AptSnapshotFacetSupport.java From nexus-public with Eclipse Public License 1.0 | 5 votes |
@Transactional(retryOn = {ONeedRetryException.class}) @Override @Nullable public Content getSnapshotFile(final String id, final String path) throws IOException { StorageTx tx = UnitOfWork.currentTx(); Bucket bucket = tx.findBucket(getRepository()); final Asset asset = tx.findAssetWithProperty(P_NAME, createAssetPath(id, path), bucket); if (asset == null) { return null; } final Blob blob = tx.requireBlob(asset.requireBlobRef()); return FacetHelper.toContent(asset, blob); }
Example 9
Source File: CocoapodsFacetImpl.java From nexus-public with Eclipse Public License 1.0 | 5 votes |
@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 10
Source File: RundeckMavenResource.java From nexus3-rundeck-plugin with MIT License | 4 votes |
@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 11
Source File: GolangDataAccess.java From nexus-public with Eclipse Public License 1.0 | 4 votes |
public Payload getBlobAsPayload(final StorageTx tx, final Asset asset) { return new BlobPayload(tx.requireBlob(asset.requireBlobRef()), asset.requireContentType()); }