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;
}
Aggregations