org.sonatype.nexus.repository.transaction.TransactionalStoreBlob Java Examples
The following examples show how to use
org.sonatype.nexus.repository.transaction.TransactionalStoreBlob.
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: ConanProxyFacet.java From nexus-repository-conan with Eclipse Public License 1.0 | 6 votes |
@TransactionalStoreBlob protected Content doPutPackage(final TempBlob tempBlob, final Payload content, final ConanCoords coords, final AssetKind assetKind) throws IOException { StorageTx tx = UnitOfWork.currentTx(); Bucket bucket = tx.findBucket(getRepository()); Component component = getOrCreateComponent(tx, bucket, coords); String assetPath = getProxyAssetPath(coords, assetKind); Asset asset = findAsset(tx, bucket, assetPath); if (asset == null) { asset = tx.createAsset(bucket, component); asset.name(assetPath); asset.formatAttributes().set(P_ASSET_KIND, CONAN_PACKAGE.name()); } else if (!asset.componentId().equals(EntityHelper.id(component))) { asset.componentId(EntityHelper.id(component)); } return saveAsset(tx, asset, tempBlob, content, null); }
Example #2
Source File: OrientPyPiHostedFacetImpl.java From nexus-public with Eclipse Public License 1.0 | 6 votes |
@Override @TransactionalStoreBlob @Nullable public Content getRootIndex() { StorageTx tx = UnitOfWork.currentTx(); Bucket bucket = tx.findBucket(getRepository()); Asset asset = findAsset(tx, bucket, INDEX_PATH_PREFIX); if (asset == null) { try { return createAndSaveRootIndex(bucket); } catch (IOException e) { log.error("Unable to create root index for repository: {}", getRepository().getName(), e); return null; } } return toContent(asset, tx.requireBlob(asset.requireBlobRef())); }
Example #3
Source File: OrientPyPiHostedFacetImpl.java From nexus-public with Eclipse Public License 1.0 | 6 votes |
@Override @TransactionalStoreBlob public Content getIndex(final String name) throws IOException { checkNotNull(name); StorageTx tx = UnitOfWork.currentTx(); // If we don't even have a single component entry, then nothing has been uploaded yet if (!findComponentExists(tx, getRepository(), name)) { return null; } String indexPath = indexPath(name); Bucket bucket = tx.findBucket(getRepository()); Asset savedIndex = findAsset(tx, bucket, indexPath); if (savedIndex == null) { savedIndex = createIndexAsset(name, tx, indexPath, bucket); } return toContent(savedIndex, tx.requireBlob(savedIndex.requireBlobRef())); }
Example #4
Source File: OrientPyPiProxyFacetImpl.java From nexus-public with Eclipse Public License 1.0 | 6 votes |
@TransactionalStoreBlob protected Content doPutIndex(final String name, final TempBlob tempBlob, final Payload payload, final Map<String, Object> attributes) throws IOException { StorageTx tx = UnitOfWork.currentTx(); Bucket bucket = tx.findBucket(getRepository()); Asset asset = findAsset(tx, bucket, name); if (asset == null) { asset = tx.createAsset(bucket, getRepository().getFormat()); asset.name(name); } if (attributes != null) { for (Entry<String, Object> entry : attributes.entrySet()) { asset.formatAttributes().set(entry.getKey(), entry.getValue()); } } return saveAsset(tx, asset, tempBlob, payload); }
Example #5
Source File: OrientNpmHostedFacet.java From nexus-public with Eclipse Public License 1.0 | 6 votes |
@TransactionalStoreBlob protected void putPublishRequest(final NpmPackageId packageId, @Nullable final String revision, final NpmPublishRequest request) throws IOException { log.debug("Storing package: {}", packageId); StorageTx tx = UnitOfWork.currentTx(); NestedAttributesMap packageRoot = request.getPackageRoot(); // process attachments, if any NestedAttributesMap attachments = packageRoot.child("_attachments"); if (!attachments.isEmpty()) { for (String name : attachments.keys()) { NestedAttributesMap attachment = attachments.child(name); NestedAttributesMap packageVersion = selectVersionByTarballName(packageRoot, name); putTarball(tx, packageId, packageVersion, attachment, request); } } putPackageRoot(packageId, revision, packageRoot); }
Example #6
Source File: OrientNpmHostedFacet.java From nexus-public with Eclipse Public License 1.0 | 6 votes |
@TransactionalStoreBlob protected Asset putPackage(final NpmPackageId packageId, final NestedAttributesMap requestPackageRoot, final TempBlob tarballTempBlob) throws IOException { checkNotNull(packageId); checkNotNull(requestPackageRoot); checkNotNull(tarballTempBlob); log.debug("Storing package: {}", packageId); StorageTx tx = UnitOfWork.currentTx(); String tarballName = NpmMetadataUtils.extractTarballName(requestPackageRoot); AssetBlob assetBlob = NpmFacetUtils.createTarballAssetBlob(tx, packageId, tarballName, tarballTempBlob); NpmFacet npmFacet = facet(NpmFacet.class); Asset asset = npmFacet.putTarball(packageId.id(), tarballName, assetBlob, new AttributesMap()); putPackageRoot(packageId, null, requestPackageRoot); return asset; }
Example #7
Source File: OrientPyPiGroupFacet.java From nexus-public with Eclipse Public License 1.0 | 6 votes |
@TransactionalStoreBlob public Content saveToCache(final String name, final Content content) throws IOException { StorageTx tx = UnitOfWork.currentTx(); Asset asset = getAsset(tx, name); AttributesMap contentAttributes = Content.maintainLastModified(asset, null); contentAttributes.set(CacheInfo.class, cacheController.current()); Content.applyToAsset(asset, contentAttributes); AssetBlob blob = updateAsset(tx, asset, content); Content response = new Content(new BlobPayload(blob.getBlob(), ContentTypes.TEXT_HTML)); Content.extractFromAsset(asset, HASH_ALGORITHMS, response.getAttributes()); return response; }
Example #8
Source File: OrientPyPiGroupFacet.java From nexus-public with Eclipse Public License 1.0 | 6 votes |
@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 #9
Source File: CondaProxyFacetImpl.java From nexus-public with Eclipse Public License 1.0 | 6 votes |
@TransactionalStoreBlob protected Content findOrCreateAsset(final TempBlob tempBlob, final Content content, final AssetKind assetKind, final String assetPath, final Component component) throws IOException { StorageTx tx = UnitOfWork.currentTx(); Bucket bucket = tx.findBucket(getRepository()); Asset asset = getCondaFacet().findAsset(tx, bucket, assetPath); if (asset == null) { if (ARCH_TAR_PACKAGE.equals(assetKind) || ARCH_CONDA_PACKAGE.equals(assetKind)) { asset = tx.createAsset(bucket, component); } else { asset = tx.createAsset(bucket, getRepository().getFormat()); } asset.name(assetPath); asset.formatAttributes().set(P_ASSET_KIND, assetKind.name()); } return getCondaFacet().saveAsset(tx, asset, tempBlob, content); }
Example #10
Source File: CondaProxyFacetImpl.java From nexus-public with Eclipse Public License 1.0 | 6 votes |
@TransactionalStoreBlob protected Component findOrCreateComponent(final String arch, final String name, final String version) { StorageTx tx = UnitOfWork.currentTx(); Bucket bucket = tx.findBucket(getRepository()); Component component = getCondaFacet().findComponent(tx, getRepository(), arch, name, version); if (component == null) { component = tx.createComponent(bucket, getRepository().getFormat()) .group(arch) .name(name) .version(version); } tx.saveComponent(component); return component; }
Example #11
Source File: RawContentFacetImpl.java From nexus-public with Eclipse Public License 1.0 | 6 votes |
@TransactionalStoreBlob protected Content doPutContent(final String path, final TempBlob tempBlob, final Payload payload) throws IOException { StorageTx tx = UnitOfWork.currentTx(); Asset asset = getOrCreateAsset(getRepository(), path, RawCoordinatesHelper.getGroup(path), path); AttributesMap contentAttributes = null; if (payload instanceof Content) { contentAttributes = ((Content) payload).getAttributes(); } Content.applyToAsset(asset, Content.maintainLastModified(asset, contentAttributes)); AssetBlob assetBlob = tx.setBlob( asset, path, tempBlob, null, payload.getContentType(), false ); tx.saveAsset(asset); return toContent(asset, assetBlob.getBlob()); }
Example #12
Source File: GolangDataAccess.java From nexus-public with Eclipse Public License 1.0 | 6 votes |
/** * Save an asset and create blob. * * @return blob content */ @TransactionalStoreBlob public Content maybeCreateAndSaveAsset(final Repository repository, final String assetPath, final AssetKind assetKind, final TempBlob tempBlob, final Payload payload) throws IOException { StorageTx tx = UnitOfWork.currentTx(); Bucket bucket = tx.findBucket(repository); Asset asset = findAsset(tx, bucket, assetPath); if (asset == null) { asset = tx.createAsset(bucket, repository.getFormat()); asset.name(assetPath); asset.formatAttributes().set(P_ASSET_KIND, assetKind.name()); } return saveAsset(tx, asset, tempBlob, payload); }
Example #13
Source File: ConanProxyFacet.java From nexus-repository-conan with Eclipse Public License 1.0 | 6 votes |
@TransactionalStoreBlob protected Content doSaveMetadata(final TempBlob metadataContent, final Payload payload, final AssetKind assetKind, final ConanCoords coords) throws IOException { HashCode hash = null; StorageTx tx = UnitOfWork.currentTx(); Bucket bucket = tx.findBucket(getRepository()); Component component = getOrCreateComponent(tx, bucket, coords); String assetPath = getProxyAssetPath(coords, assetKind); Asset asset = findAsset(tx, bucket, assetPath); if (asset == null) { asset = tx.createAsset(bucket, component); asset.name(assetPath); asset.formatAttributes().set(P_ASSET_KIND, assetKind.name()); hash = hashVerifier.lookupHashFromAsset(tx, bucket, assetPath); } else if (!asset.componentId().equals(EntityHelper.id(component))) { asset.componentId(EntityHelper.id(component)); } return saveAsset(tx, asset, metadataContent, payload, hash); }
Example #14
Source File: MavenFacetImpl.java From nexus-public with Eclipse Public License 1.0 | 6 votes |
@TransactionalStoreBlob protected Content doPut(final MavenPath path, final Payload payload, final TempBlob tempBlob) throws IOException { final StorageTx tx = UnitOfWork.currentTx(); final AssetBlob assetBlob = tx.createBlob( path.getPath(), tempBlob, null, payload.getContentType(), false ); AttributesMap contentAttributes = null; if (payload instanceof Content) { contentAttributes = ((Content) payload).getAttributes(); } return doPutAssetBlob(path, contentAttributes, tx, assetBlob); }
Example #15
Source File: RHostedFacetImpl.java From nexus-repository-r with Eclipse Public License 1.0 | 6 votes |
@TransactionalStoreBlob protected Asset doPutArchive(final String path, final TempBlob archiveContent, final Payload payload) throws IOException { StorageTx tx = UnitOfWork.currentTx(); RFacet rFacet = facet(RFacet.class); Map<String, String> attributes; try (InputStream is = archiveContent.get()) { attributes = extractDescriptionFromArchive(path, is); } Component component = rFacet.findOrCreateComponent(tx, path, attributes); Asset asset = rFacet.findOrCreateAsset(tx, component, path, attributes); saveAsset(tx, asset, archiveContent, payload); return asset; }
Example #16
Source File: RProxyFacetImpl.java From nexus-repository-r with Eclipse Public License 1.0 | 6 votes |
@TransactionalStoreBlob protected Content doPutArchive(final String path, final TempBlob archiveContent, final Content content) throws IOException { RFacet rFacet = facet(RFacet.class); StorageTx tx = UnitOfWork.currentTx(); Map<String, String> attributes; try (InputStream is = archiveContent.get()) { attributes = extractDescriptionFromArchive(path, is); } Component component = rFacet.findOrCreateComponent(tx, path, attributes); Asset asset = rFacet.findOrCreateAsset(tx, component, path, attributes); return saveAsset(tx, asset, archiveContent, content); }
Example #17
Source File: MavenFacetImpl.java From nexus-public with Eclipse Public License 1.0 | 6 votes |
@TransactionalStoreBlob protected Content doPut(final MavenPath path, final Path sourceFile, final String contentType, final AttributesMap contentAttributes, final Map<HashAlgorithm, HashCode> hashes, final long size) throws IOException { final StorageTx tx = UnitOfWork.currentTx(); final AssetBlob assetBlob = tx.createBlob( path.getPath(), sourceFile, hashes, null, contentType, size ); return doPutAssetBlob(path, contentAttributes, tx, assetBlob); }
Example #18
Source File: HelmHostedFacetImpl.java From nexus-repository-helm with Eclipse Public License 1.0 | 6 votes |
@Override @TransactionalStoreBlob public Asset upload(String path, TempBlob tempBlob, Payload payload, AssetKind assetKind) throws IOException { checkNotNull(path); checkNotNull(tempBlob); if (assetKind != HELM_PACKAGE && assetKind != HELM_PROVENANCE) { throw new IllegalArgumentException("Unsupported assetKind: " + assetKind); } StorageTx tx = UnitOfWork.currentTx(); InputStream inputStream = tempBlob.get(); HelmAttributes attributes = helmAttributeParser.getAttributes(assetKind, inputStream); final Asset asset = helmFacet.findOrCreateAsset(tx, path, assetKind, attributes); helmFacet.saveAsset(tx, asset, tempBlob, payload); return asset; }
Example #19
Source File: MavenHostedFacetImpl.java From nexus-public with Eclipse Public License 1.0 | 6 votes |
@TransactionalStoreBlob protected int doRebuildArchetypeCatalog() throws IOException { final Path path = Files.createTempFile("hosted-archetype-catalog", "xml"); int count = 0; try { StorageTx tx = UnitOfWork.currentTx(); Iterable<Archetype> archetypes = getArchetypes(tx); ArchetypeCatalog hostedCatalog = new ArchetypeCatalog(); Iterables.addAll(hostedCatalog.getArchetypes(), archetypes); count = hostedCatalog.getArchetypes().size(); try (Content content = MavenFacetUtils.createTempContent( path, ContentTypes.APPLICATION_XML, (OutputStream outputStream) -> MavenModels.writeArchetypeCatalog(outputStream, hostedCatalog))) { MavenFacetUtils.putWithHashes(mavenFacet, archetypeCatalogMavenPath, content); log.trace("Rebuilt hosted archetype catalog for {} with {} archetype", getRepository().getName(), count); } } finally { Files.delete(path); } return count; }
Example #20
Source File: CreateIndexServiceImpl.java From nexus-repository-helm with Eclipse Public License 1.0 | 6 votes |
@TransactionalStoreBlob @Nullable public TempBlob buildIndexYaml(final Repository repository) { StorageFacet storageFacet = repository.facet(StorageFacet.class); HelmFacet helmFacet = repository.facet(HelmFacet.class); StorageTx tx = UnitOfWork.currentTx(); ChartIndex index = new ChartIndex(); for (Asset asset : helmFacet.browseComponentAssets(tx, AssetKind.HELM_PACKAGE)) { parseAssetIntoChartEntry(index, asset); } index.setApiVersion(API_VERSION); index.setGenerated(new DateTime()); return indexYamlBuilder.build(index, storageFacet); }
Example #21
Source File: AptRestoreFacetImpl.java From nexus-public with Eclipse Public License 1.0 | 6 votes |
@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 #22
Source File: P2FacetImpl.java From nexus-repository-p2 with Eclipse Public License 1.0 | 6 votes |
@TransactionalStoreBlob @Override public Content doCreateOrSaveComponent(final P2Attributes p2Attributes, final TempBlob componentContent, final Payload payload, final AssetKind assetKind) throws IOException { StorageTx tx = UnitOfWork.currentTx(); Bucket bucket = tx.findBucket(getRepository()); Component component = findOrCreateComponent(tx, p2Attributes); Asset asset = findAsset(tx, bucket, p2Attributes.getPath()); if (asset == null) { asset = tx.createAsset(bucket, component); asset.name(p2Attributes.getPath()); //add human readable plugin or feature name in asset attributes asset.formatAttributes().set(PLUGIN_NAME, p2Attributes.getPluginName()); asset.formatAttributes().set(P_ASSET_KIND, assetKind.name()); } return saveAsset(tx, asset, componentContent, payload); }
Example #23
Source File: OrientMetadataUpdater.java From nexus-public with Eclipse Public License 1.0 | 6 votes |
/** * Writes/overwrites metadata, replacing existing one, if any. */ @VisibleForTesting void replace(final MavenPath mavenPath, final Maven2Metadata metadata) { try { TransactionalStoreBlob.operation.throwing(IOException.class).call(() -> { checkNotNull(mavenPath); checkNotNull(metadata); final Metadata oldMetadata = OrientMetadataUtils.read(repository, mavenPath); if (oldMetadata == null) { // old does not exists, just write it write(mavenPath, toMetadata(metadata)); } else { final Metadata updated = toMetadata(metadata); writeIfUnchanged(mavenPath, oldMetadata, updated); } return null; }); } catch (IOException e) { throw new RuntimeException(e); } }
Example #24
Source File: P2ProxyFacetImpl.java From nexus-repository-p2 with Eclipse Public License 1.0 | 6 votes |
@TransactionalStoreBlob protected Content saveMetadataAsAsset(final String assetPath, final TempBlob metadataContent, final Payload payload, final AssetKind assetKind) throws IOException { StorageTx tx = UnitOfWork.currentTx(); Bucket bucket = tx.findBucket(getRepository()); Asset asset = facet(P2Facet.class).findAsset(tx, bucket, assetPath); if (asset == null) { asset = tx.createAsset(bucket, getRepository().getFormat()); asset.name(assetPath); asset.formatAttributes().set(P_ASSET_KIND, assetKind.name()); } return facet(P2Facet.class).saveAsset(tx, asset, metadataContent, payload); }
Example #25
Source File: ComposerContentFacetImpl.java From nexus-repository-composer with Eclipse Public License 1.0 | 5 votes |
@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 #26
Source File: AptHostedFacet.java From nexus-public with Eclipse Public License 1.0 | 5 votes |
@TransactionalStoreBlob protected Asset ingestAsset(final ControlFile control, final TempBlob body, final long size, final String contentType) throws IOException { AptFacet aptFacet = getRepository().facet(AptFacet.class); StorageTx tx = UnitOfWork.currentTx(); Bucket bucket = tx.findBucket(getRepository()); PackageInfo info = new PackageInfo(control); String name = info.getPackageName(); String version = info.getVersion(); String architecture = info.getArchitecture(); String assetPath = FacetHelper.buildAssetPath(name, version, architecture); Content content = aptFacet.put( assetPath, new StreamPayload(() -> body.get(), size, contentType), info); Asset asset = Content.findAsset(tx, bucket, content); String indexSection = buildIndexSection(control, asset.size(), asset.getChecksums(FacetHelper.hashAlgorithms), assetPath); asset.formatAttributes().set(P_ARCHITECTURE, architecture); asset.formatAttributes().set(P_PACKAGE_NAME, name); asset.formatAttributes().set(P_PACKAGE_VERSION, version); asset.formatAttributes().set(P_INDEX_SECTION, indexSection); asset.formatAttributes().set(P_ASSET_KIND, "DEB"); tx.saveAsset(asset); rebuildIndexes(singletonList(new AssetChange(AssetAction.ADDED, asset))); return asset; }
Example #27
Source File: OrientPyPiHostedFacetImpl.java From nexus-public with Eclipse Public License 1.0 | 5 votes |
@TransactionalStoreBlob @Override public Asset upload(final String filename, final Map<String, String> attributes, final TempBlobPartPayload payload) throws IOException { return savePyPiWheelPayload(filename, attributes, payload); }
Example #28
Source File: OrientPyPiHostedFacetImpl.java From nexus-public with Eclipse Public License 1.0 | 5 votes |
@TransactionalStoreBlob protected Asset storeWheelAndSignaturePayloads(final TempBlobPartPayload wheelPayload, final TempBlobPartPayload gpgPayload, final Map<String, String> attributes) throws IOException { Asset wheelAsset = storeWheelPayload(wheelPayload, attributes); storeGpgSignaturePayload(gpgPayload, attributes); return wheelAsset; }
Example #29
Source File: AptFacetImpl.java From nexus-public with Eclipse Public License 1.0 | 5 votes |
@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 #30
Source File: RawContentFacetImpl.java From nexus-public with Eclipse Public License 1.0 | 5 votes |
@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; }