@Nullable @Override public String getContentType() { return payload.getContentType(); }
@Nullable @Override public String getContentType() { return payload.getContentType(); } }
/** * Rewrites the provider JSON so that source entries are removed and dist entries are pointed back to Nexus. */ public Payload rewriteProviderJson(final Repository repository, final Payload payload) throws IOException { Map<String, Object> json = parseJson(payload); if (json.get(PACKAGES_KEY) instanceof Map) { Map<String, Object> packagesMap = (Map<String, Object>) json.get(PACKAGES_KEY); for (String packageName : packagesMap.keySet()) { Map<String, Object> packageVersions = (Map<String, Object>) packagesMap.get(packageName); for (String packageVersion : packageVersions.keySet()) { // TODO: Make this more robust, right now it makes a lot of assumptions and doesn't deal with bad things well Map<String, Object> versionInfo = (Map<String, Object>) packageVersions.get(packageVersion); versionInfo.remove(SOURCE_KEY); // TODO: For now don't allow sources, probably should make this configurable? Map<String, Object> distInfo = (Map<String, Object>) versionInfo.get(DIST_KEY); if (distInfo != null && ZIP_TYPE.equals(distInfo.get(TYPE_KEY))) { versionInfo.put(DIST_KEY, buildDistInfo(repository, packageName, packageVersion, (String) distInfo.get(REFERENCE_KEY), (String) distInfo.get(SHASUM_KEY), ZIP_TYPE)); } } } } return new StringPayload(mapper.writeValueAsString(json), payload.getContentType()); }
/** * Save an asset and create blob. * * @return blob content */ public Content saveAsset(final StorageTx tx, final Asset asset, final Supplier<InputStream> contentSupplier, final Payload payload) throws IOException { AttributesMap contentAttributes = null; String contentType = null; if (payload instanceof Content) { contentAttributes = ((Content) payload).getAttributes(); contentType = payload.getContentType(); } return saveAsset(tx, asset, contentSupplier, contentType, contentAttributes); }
@TransactionalStoreBlob public Asset ingestAsset(Payload body) throws IOException, PGPException { StorageFacet storageFacet = facet(StorageFacet.class); try (TempBlob tempBlob = storageFacet.createTempBlob(body, FacetHelper.hashAlgorithms)) { ControlFile control = AptPackageParser.parsePackage(tempBlob); if (control == null) { throw new IllegalOperationException("Invalid Debian package supplied"); } return ingestAsset(control, tempBlob, body.getSize(), body.getContentType()); } }
@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); }
@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()); }
tempBlob, null, payload.getContentType(), false );
@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()); } }