private Asset getAssetFromPayload(final Payload payload) { if (payload instanceof Content) { return ((Content) payload).getAttributes().get(Asset.class); } return null; } }
@Nullable private static EntityId extractComponentId(final Content content) { Optional<Asset> asset = Optional.ofNullable(content.getAttributes().get(Asset.class)); return asset.map(Asset::componentId).orElse(null); } }
@Nullable private NestedAttributesMap getNestedAttributesMap(final Payload payload) { return nonNull(payload) ? ((Content) payload).getAttributes().get(NestedAttributesMap.class) : null; }
public TempContent(final Content remote) throws IOException { super(cachePayload(remote), remote.getAttributes()); }
private void addSignatureItem(StringBuilder builder, HashAlgorithm algo, Content content, String filename) { Map<HashAlgorithm, HashCode> hashMap = content.getAttributes().get(Content.CONTENT_HASH_CODES_MAP, Content.T_CONTENT_HASH_CODES_MAP); builder.append("\n "); builder.append(hashMap.get(algo).toString()); builder.append(" "); builder.append(content.getSize()); builder.append(" "); builder.append(filename); }
private void putChecksumFiles(final MavenFacet facet, final MavenPath path, final Content content) throws IOException { DateTime dateTime = content.getAttributes().require(Content.CONTENT_LAST_MODIFIED, DateTime.class); Map<HashAlgorithm, HashCode> hashes = MavenFacetUtils.getHashAlgorithmFromContent(content.getAttributes()); MavenFacetUtils.addHashes(facet, path, hashes, dateTime); }
/** * Returns {@code true} if the content is considered stale; otherwise {@code false}. */ protected boolean isStale(@Nullable final Content content) { return content == null || cacheController.isStale(content.getAttributes().require(CacheInfo.class)); }
/** * Performs a {@link MavenFacet#put(MavenPath, Payload)} for passed in {@link Content} and it's hashes too. Returns * the put content. */ public static void putWithHashes(final MavenFacet mavenFacet, final MavenPath mavenPath, final Content content) throws IOException { final Map<HashAlgorithm, HashCode> hashCodes = getHashAlgorithmFromContent(content.getAttributes()); final DateTime now = content.getAttributes().require(Content.CONTENT_LAST_MODIFIED, DateTime.class); mavenFacet.put(mavenPath, content); addHashes(mavenFacet, mavenPath, hashCodes, now); }
/** * Creates a {@link Content} out of passed in package metadata. */ @Nonnull static Content toContent(final Asset packageRootAsset, final NestedAttributesMap packageRoot) { Content content = new Content(new BytesPayload(NpmJsonUtils.bytes(packageRoot), ContentTypes.APPLICATION_JSON)); Content.extractFromAsset(packageRootAsset, HASH_ALGORITHMS, content.getAttributes()); content.getAttributes().set(NestedAttributesMap.class, packageRoot); return content; }
private boolean isStale(final Context context, final Content content) { if (content == null) { // not in cache, consider it stale return true; } final CacheInfo cacheInfo = content.getAttributes().get(CacheInfo.class); return cacheInfo == null || getCacheController(context).isStale(cacheInfo); }
/** * Convert an asset blob to {@link Content}. * * @return content of asset blob */ @Nonnull public static Content toContent(final Asset asset, final Blob blob) { Content content = new Content(new BlobPayload(blob, asset.requireContentType())); Content.extractFromAsset(asset, HASH_ALGORITHMS, content.getAttributes()); return content; }
private Content toContent(final Asset asset, final Blob blob) { final Content content = new Content(new BlobPayload(blob, asset.requireContentType())); Content.extractFromAsset(asset, hashAlgorithms, content.getAttributes()); return content; } }
@TransactionalTouchMetadata public void setCacheInfo(final Content content, final CacheInfo cacheInfo) throws IOException { StorageTx tx = UnitOfWork.currentTx(); Asset asset = Content.findAsset(tx, tx.findBucket(getRepository()), content); if (asset == null) { log.debug( "Attempting to set cache info for non-existent npm asset {}", content.getAttributes().require(Asset.class) ); return; } log.debug("Updating cacheInfo of {} to {}", asset, cacheInfo); CacheInfo.applyToAsset(asset, cacheInfo); tx.saveAsset(asset); }
private Content toContent(final Asset asset, final Blob blob) { final String contentType = asset.contentType(); final Content content = new Content(new BlobPayload(blob, contentType)); Content.extractFromAsset(asset, HashType.ALGORITHMS, content.getAttributes()); return content; }
@TransactionalTouchMetadata public void setCacheInfo(final Content content, final CacheInfo cacheInfo) throws IOException { StorageTx tx = UnitOfWork.currentTx(); Asset asset = Content.findAsset(tx, tx.findBucket(getRepository()), content); if (asset == null) { log.debug( "Attempting to set cache info for non-existent Helm asset {}", content.getAttributes().require(Asset.class) ); return; } log.debug("Updating cacheInfo of {} to {}", asset, cacheInfo); CacheInfo.applyToAsset(asset, cacheInfo); tx.saveAsset(asset); }
public static Content toContent(final Asset asset, final Blob blob) { final Content content = new Content(new BlobPayload(blob, asset.requireContentType())); Content.extractFromAsset(asset, hashAlgorithms, content.getAttributes()); return content; }
private Content toContent(final Asset asset, final Blob blob) { final Content content = new Content(new BlobPayload(blob, asset.requireContentType())); Content.extractFromAsset(asset, hashAlgorithms, content.getAttributes()); return content; } }
/** * Convert an asset blob to {@link Content}. * * @return content of asset blob */ public Content toContent(final Asset asset, final Blob blob) { Content content = new Content(new BlobPayload(blob, asset.requireContentType())); Content.extractFromAsset(asset, HASH_ALGORITHMS, content.getAttributes()); return content; } }
private Response doGet(final MavenPath path, final MavenFacet mavenFacet) throws IOException { Content content = mavenFacet.get(path); if (content == null) { return HttpResponses.notFound(path.getPath()); } AttributesMap attributesMap = content.getAttributes(); MavenFacetUtils.mayAddETag(attributesMap, getHashAlgorithmFromContent(attributesMap)); return HttpResponses.ok(content); }
@TransactionalStoreBlob protected Content doPutTarball(final NpmPackageId packageId, final String tarballName, final TempBlob tempBlob, final Content content) throws IOException { StorageTx tx = UnitOfWork.currentTx(); AssetBlob assetBlob = NpmFacetUtils.createTarballAssetBlob(tx, packageId, tarballName, tempBlob); NpmFacet npmFacet = facet(NpmFacet.class); npmFacet.putTarball(packageId.id(), tarballName, assetBlob, content.getAttributes()); return NpmFacetUtils.getTarballContent(tx, tx.findBucket(getRepository()), packageId, tarballName); }