Search in sources :

Example 36 with Key

use of com.artipie.asto.Key in project artipie by artipie.

the class ConfigFile method delete.

/**
 * Deletes value from the storage.
 * @param storage Storage where the file with different extensions is checked for existence
 * @return Result of completion.
 */
public CompletionStage<Void> delete(final Storage storage) {
    final CompletionStage<Void> res;
    if (this.isYamlOrYml() || this.extension().isEmpty()) {
        final String name = this.name();
        final Key yaml = Extension.YAML.key(name);
        res = storage.exists(yaml).thenCompose(exist -> {
            final CompletionStage<Void> result;
            if (exist) {
                result = storage.delete(yaml);
            } else {
                result = storage.delete(Extension.YML.key(name));
            }
            return result;
        });
    } else {
        res = CompletableFuture.allOf();
    }
    return res;
}
Also used : CompletionStage(java.util.concurrent.CompletionStage) Matcher(java.util.regex.Matcher) Storage(com.artipie.asto.Storage) Optional(java.util.Optional) CompletableFuture(java.util.concurrent.CompletableFuture) Pattern(java.util.regex.Pattern) Content(com.artipie.asto.Content) Key(com.artipie.asto.Key) Key(com.artipie.asto.Key) CompletionStage(java.util.concurrent.CompletionStage)

Example 37 with Key

use of com.artipie.asto.Key in project artipie by artipie.

the class ConfigFile method existsIn.

/**
 * Does config file exist in the specified storage?
 * @param storage Storage where the file with different extensions is checked for existence
 * @return True if a file with either of the two extensions exists, false otherwise.
 */
public CompletionStage<Boolean> existsIn(final Storage storage) {
    final CompletionStage<Boolean> res;
    if (this.isYamlOrYml() || this.extension().isEmpty()) {
        final String name = this.name();
        final Key yaml = Extension.YAML.key(name);
        res = storage.exists(yaml).thenCompose(exist -> {
            final CompletionStage<Boolean> result;
            if (exist) {
                result = CompletableFuture.completedFuture(true);
            } else {
                final Key yml = Extension.YML.key(name);
                result = storage.exists(yml);
            }
            return result;
        });
    } else {
        res = CompletableFuture.completedFuture(false);
    }
    return res;
}
Also used : CompletionStage(java.util.concurrent.CompletionStage) Matcher(java.util.regex.Matcher) Storage(com.artipie.asto.Storage) Optional(java.util.Optional) CompletableFuture(java.util.concurrent.CompletableFuture) Pattern(java.util.regex.Pattern) Content(com.artipie.asto.Content) Key(com.artipie.asto.Key) Key(com.artipie.asto.Key) CompletionStage(java.util.concurrent.CompletionStage)

Aggregations

Key (com.artipie.asto.Key)37 Test (org.junit.jupiter.api.Test)17 Storage (com.artipie.asto.Storage)16 BlockingStorage (com.artipie.asto.blocking.BlockingStorage)13 InMemoryStorage (com.artipie.asto.memory.InMemoryStorage)9 Content (com.artipie.asto.Content)8 Optional (java.util.Optional)8 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)7 YamlMapping (com.amihaiemil.eoyaml.YamlMapping)6 PublisherAs (com.artipie.asto.ext.PublisherAs)6 CompletableFuture (java.util.concurrent.CompletableFuture)6 Matcher (java.util.regex.Matcher)6 Pattern (java.util.regex.Pattern)6 Collectors (java.util.stream.Collectors)5 TestResource (com.artipie.asto.test.TestResource)4 Response (com.artipie.http.Response)4 Slice (com.artipie.http.Slice)4 AsyncResponse (com.artipie.http.async.AsyncResponse)4 RequestLineFrom (com.artipie.http.rq.RequestLineFrom)4 CompletionStage (java.util.concurrent.CompletionStage)4