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)); }
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); }
/** * 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()); }
/** * 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()); }
@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; }
/** * Save an asset and 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()); }
@TransactionalStoreBlob protected Asset savePackageRootToCache(final NpmPackageId packageId, final NestedAttributesMap result) throws IOException { StorageTx tx = UnitOfWork.currentTx(); Asset asset = getAsset(tx, packageId); AttributesMap contentAttributes = maintainLastModified(asset, null); maintainCacheInfo(contentAttributes); applyToAsset(asset, contentAttributes); savePackageRoot(tx, asset, result); return asset; }
@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()); }
@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()); }
@TransactionalStoreBlob protected Content doPutPackageRoot(final NpmPackageId packageId, final NestedAttributesMap packageRoot, final Content content, final boolean mergePackageRoot) throws IOException { log.debug("Storing package: {}", packageId); StorageTx tx = UnitOfWork.currentTx(); Bucket bucket = tx.findBucket(getRepository()); NestedAttributesMap newPackageRoot = packageRoot; Asset asset = NpmFacetUtils.findPackageRootAsset(tx, bucket, packageId); if (asset == null) { asset = tx.createAsset(bucket, getRepository().getFormat()).name(packageId.id()); } else if (mergePackageRoot) { newPackageRoot = mergeNewRootWithExistingRoot(tx, newPackageRoot, asset); } Content.applyToAsset(asset, Content.maintainLastModified(asset, content.getAttributes())); NpmFacetUtils.savePackageRoot(tx, asset, newPackageRoot); // we must have the round-trip to equip record with _rev rewrite the URLs (ret val is served to client) NestedAttributesMap storedPackageRoot = NpmFacetUtils.loadPackageRoot(tx, asset); NpmMetadataUtils.rewriteTarballUrl(getRepository().getName(), storedPackageRoot); return NpmFacetUtils.toContent(asset, storedPackageRoot); }
Content.applyToAsset(asset, Content.maintainLastModified(asset, ((Content) payload).getAttributes()));
@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()); } }