Search in sources :

Example 1 with ArtifactsMetadata

use of com.artipie.maven.metadata.ArtifactsMetadata in project maven-adapter by artipie.

the class AstoValidUpload method validateMetadata.

/**
 * Validates uploaded and existing metadata by comparing group and artifact ids.
 * @param upload Uploaded artifacts location
 * @param artifact Artifact location
 * @return Completable validation action: true if group and artifact ids are equal,
 *  false otherwise.
 */
private CompletionStage<Boolean> validateMetadata(final Key upload, final Key artifact) {
    final ArtifactsMetadata metadata = new ArtifactsMetadata(this.storage);
    final String meta = "maven-metadata.xml";
    return this.storage.exists(new Key.From(artifact, meta)).thenCompose(exists -> {
        final CompletionStage<Boolean> res;
        if (exists) {
            res = metadata.groupAndArtifact(new Key.From(upload, PutMetadataSlice.SUB_META)).thenCompose(existing -> metadata.groupAndArtifact(artifact).thenApply(uploaded -> uploaded.equals(existing)));
        } else {
            res = CompletableFuture.completedStage(true);
        }
        return res;
    }).thenCompose(same -> {
        final CompletionStage<Boolean> res;
        if (same) {
            res = this.validateArtifactChecksums(new Key.From(upload, meta)).to(SingleInterop.get());
        } else {
            res = CompletableFuture.completedStage(false);
        }
        return res;
    });
}
Also used : ContentDigest(com.artipie.asto.ext.ContentDigest) ArtifactsMetadata(com.artipie.maven.metadata.ArtifactsMetadata) PutMetadataSlice(com.artipie.maven.http.PutMetadataSlice) CompletableFuture(java.util.concurrent.CompletableFuture) Key(com.artipie.asto.Key) Single(io.reactivex.Single) Collectors(java.util.stream.Collectors) Digests(com.artipie.asto.ext.Digests) SingleInterop(hu.akarnokd.rxjava2.interop.SingleInterop) ArrayList(java.util.ArrayList) ValidUpload(com.artipie.maven.ValidUpload) CompletionStage(java.util.concurrent.CompletionStage) RxStorageWrapper(com.artipie.asto.rx.RxStorageWrapper) Storage(com.artipie.asto.Storage) Locale(java.util.Locale) Map(java.util.Map) Observable(io.reactivex.Observable) Pattern(java.util.regex.Pattern) ArtifactsMetadata(com.artipie.maven.metadata.ArtifactsMetadata) Key(com.artipie.asto.Key) CompletionStage(java.util.concurrent.CompletionStage)

Aggregations

Key (com.artipie.asto.Key)1 Storage (com.artipie.asto.Storage)1 ContentDigest (com.artipie.asto.ext.ContentDigest)1 Digests (com.artipie.asto.ext.Digests)1 RxStorageWrapper (com.artipie.asto.rx.RxStorageWrapper)1 ValidUpload (com.artipie.maven.ValidUpload)1 PutMetadataSlice (com.artipie.maven.http.PutMetadataSlice)1 ArtifactsMetadata (com.artipie.maven.metadata.ArtifactsMetadata)1 SingleInterop (hu.akarnokd.rxjava2.interop.SingleInterop)1 Observable (io.reactivex.Observable)1 Single (io.reactivex.Single)1 ArrayList (java.util.ArrayList)1 Locale (java.util.Locale)1 Map (java.util.Map)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 CompletionStage (java.util.concurrent.CompletionStage)1 Pattern (java.util.regex.Pattern)1 Collectors (java.util.stream.Collectors)1