All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.uid2.shared.store.reader.RotatingSiteStore Maven / Gradle / Ivy

package com.uid2.shared.store.reader;

import com.uid2.shared.cloud.DownloadCloudStorage;
import com.uid2.shared.model.Site;
import com.uid2.shared.store.CloudPath;
import com.uid2.shared.store.EncryptedScopedStoreReader;
import com.uid2.shared.store.ISiteStore;
import com.uid2.shared.store.ScopedStoreReader;
import com.uid2.shared.store.parser.SiteParser;
import com.uid2.shared.store.scope.EncryptedScope;
import com.uid2.shared.store.scope.StoreScope;
import io.vertx.core.json.JsonObject;

import java.util.Collection;
import java.util.Map;


public class RotatingSiteStore implements ISiteStore, StoreReader> {
    public static final String SITES_METADATA_PATH = "sites_metadata_path";
    private final ScopedStoreReader> reader;

    public RotatingSiteStore(DownloadCloudStorage fileStreamProvider, StoreScope scope) {
        this.reader = new ScopedStoreReader<>(fileStreamProvider, scope, new SiteParser(), "sites");
    }

    public RotatingSiteStore(DownloadCloudStorage fileStreamProvider, EncryptedScope scope, RotatingS3KeyProvider s3KeyProvider) {
        this.reader = new EncryptedScopedStoreReader<>(fileStreamProvider, scope, new SiteParser(), "sites", s3KeyProvider);
    }

    @Override
    public CloudPath getMetadataPath() { return reader.getMetadataPath(); }

    @Override
    public Collection getAllSites() {
        return getAll();
    }

    @Override
    public Collection getAll() {
        return reader.getSnapshot().values();
    }

    @Override
    public Site getSite(int siteId) {
        return reader.getSnapshot().get(siteId);
    }

    public JsonObject getMetadata() throws Exception {
        return reader.getMetadata();
    }

    @Override
    public long getVersion(JsonObject metadata) {
        return metadata.getLong("version");
    }

    @Override
    public long loadContent(JsonObject metadata) throws Exception {
        return reader.loadContent(metadata, "sites");
    }

    public void loadContent() throws Exception {
        this.loadContent(this.getMetadata());
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy