summaryrefslogtreecommitdiffstats
path: root/vespaclient-container-plugin/src/main/java/com/yahoo/document/restapi/BucketSpaceEnumerator.java
blob: 24692859266a723012941dd218bd6d6912172240 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.document.restapi;

import com.yahoo.config.subscription.ConfigGetter;
import com.yahoo.vespa.config.content.core.BucketspacesConfig;

import java.util.Collections;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * TODO description
 */
class BucketSpaceEnumerator {

    private final Map<String, String> doctypeToSpace;

    private BucketSpaceEnumerator(String configId) {
        doctypeToSpace = Collections.unmodifiableMap(buildMappingFromConfig(configId));
    }

    public static BucketSpaceEnumerator fromConfig(String configId) {
        return new BucketSpaceEnumerator(configId);
    }

    public Map<String, String> getDoctypeToSpaceMapping() {
        return doctypeToSpace;
    }

    private static Map<String, String> buildMappingFromConfig(String configId) {
        BucketspacesConfig config = new ConfigGetter<>(BucketspacesConfig.class).getConfig(configId);
        return config.documenttype().stream().collect(Collectors.toMap(dt -> dt.name(), dt -> dt.bucketspace()));
    }

}