Search in sources :

Example 1 with DeployMetadata

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

the class PutMetadataSlice method response.

@Override
public Response response(final String line, final Iterable<Map.Entry<String, String>> headers, final Publisher<ByteBuffer> body) {
    final Response res;
    final Matcher matcher = PutMetadataSlice.PTN_META.matcher(new RequestLineFrom(line).uri().getPath());
    if (matcher.matches()) {
        final Key pkg = new KeyFromPath(matcher.group("pkg"));
        res = new AsyncResponse(new PublisherAs(body).asciiString().thenCombine(this.asto.list(new Key.From(UploadSlice.TEMP, pkg)), (xml, list) -> {
            final Optional<String> snapshot = new DeployMetadata(xml).snapshots().stream().filter(item -> list.stream().anyMatch(key -> key.string().contains(item))).findFirst();
            final Key key;
            if (snapshot.isPresent()) {
                key = new Key.From(UploadSlice.TEMP, pkg.string(), snapshot.get(), PutMetadataSlice.SUB_META, PutMetadataSlice.MAVEN_METADATA);
            } else {
                key = new Key.From(UploadSlice.TEMP, pkg.string(), new DeployMetadata(xml).release(), PutMetadataSlice.SUB_META, PutMetadataSlice.MAVEN_METADATA);
            }
            return this.asto.save(key, new Content.From(xml.getBytes(StandardCharsets.US_ASCII)));
        }).thenApply(nothing -> new RsWithStatus(RsStatus.CREATED)));
    } else {
        res = new RsWithStatus(RsStatus.BAD_REQUEST);
    }
    return res;
}
Also used : PublisherAs(com.artipie.asto.ext.PublisherAs) RequestLineFrom(com.artipie.http.rq.RequestLineFrom) RsWithStatus(com.artipie.http.rs.RsWithStatus) KeyFromPath(com.artipie.http.slice.KeyFromPath) DeployMetadata(com.artipie.maven.metadata.DeployMetadata) Slice(com.artipie.http.Slice) Publisher(org.reactivestreams.Publisher) Response(com.artipie.http.Response) RsStatus(com.artipie.http.rs.RsStatus) Content(com.artipie.asto.Content) Key(com.artipie.asto.Key) ByteBuffer(java.nio.ByteBuffer) StandardCharsets(java.nio.charset.StandardCharsets) PublisherAs(com.artipie.asto.ext.PublisherAs) Matcher(java.util.regex.Matcher) Storage(com.artipie.asto.Storage) Map(java.util.Map) AsyncResponse(com.artipie.http.async.AsyncResponse) Optional(java.util.Optional) Pattern(java.util.regex.Pattern) Optional(java.util.Optional) Matcher(java.util.regex.Matcher) RequestLineFrom(com.artipie.http.rq.RequestLineFrom) Response(com.artipie.http.Response) AsyncResponse(com.artipie.http.async.AsyncResponse) DeployMetadata(com.artipie.maven.metadata.DeployMetadata) KeyFromPath(com.artipie.http.slice.KeyFromPath) RsWithStatus(com.artipie.http.rs.RsWithStatus) RequestLineFrom(com.artipie.http.rq.RequestLineFrom) AsyncResponse(com.artipie.http.async.AsyncResponse) Key(com.artipie.asto.Key)

Aggregations

Content (com.artipie.asto.Content)1 Key (com.artipie.asto.Key)1 Storage (com.artipie.asto.Storage)1 PublisherAs (com.artipie.asto.ext.PublisherAs)1 Response (com.artipie.http.Response)1 Slice (com.artipie.http.Slice)1 AsyncResponse (com.artipie.http.async.AsyncResponse)1 RequestLineFrom (com.artipie.http.rq.RequestLineFrom)1 RsStatus (com.artipie.http.rs.RsStatus)1 RsWithStatus (com.artipie.http.rs.RsWithStatus)1 KeyFromPath (com.artipie.http.slice.KeyFromPath)1 DeployMetadata (com.artipie.maven.metadata.DeployMetadata)1 ByteBuffer (java.nio.ByteBuffer)1 StandardCharsets (java.nio.charset.StandardCharsets)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 Publisher (org.reactivestreams.Publisher)1