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

apoc.hashing.FingerprintingConfig Maven / Gradle / Ivy

The newest version!
/*
 * Copyright (c) "Neo4j"
 * Neo4j Sweden AB [http://neo4j.com]
 *
 * This file is part of Neo4j.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package apoc.hashing;

import apoc.util.Util;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

public class FingerprintingConfig {

    enum FingerprintStrategy {
        EAGER,
        LAZY
    }

    private final String digestAlgorithm;
    private final Map> nodeAllowMap;
    private final Map> relAllowMap;

    private final Map> nodeDisallowMap;
    private final Map> relDisallowMap;

    private final List mapAllowList;
    private final List mapDisallowList;
    private final List allNodesAllowList;
    private final List allRelsAllowList;
    private final List allNodesDisallowList;
    private final List allRelsDisallowList;
    private final FingerprintStrategy strategy;
    private final Set allLabels;
    private final Set allTypes;

    public FingerprintingConfig(Map config) {
        if (config == null) config = Collections.emptyMap();
        this.digestAlgorithm = (String) config.getOrDefault("digestAlgorithm", "MD5");

        this.nodeAllowMap = (Map>) config.getOrDefault("nodeAllowMap", Collections.emptyMap());
        this.relAllowMap = (Map>) config.getOrDefault("relAllowMap", Collections.emptyMap());
        this.nodeDisallowMap =
                (Map>) config.getOrDefault("nodeDisallowMap", Collections.emptyMap());
        this.relDisallowMap = (Map>) config.getOrDefault("relDisallowMap", Collections.emptyMap());
        this.mapAllowList = (List) config.getOrDefault("mapAllowList", Collections.emptyList());
        this.mapDisallowList = (List) config.getOrDefault("mapDisallowList", Collections.emptyList());
        this.allNodesAllowList = (List) config.getOrDefault("allNodesAllowList", Collections.emptyList());
        this.allRelsAllowList = (List) config.getOrDefault("allRelsAllowList", Collections.emptyList());
        this.allNodesDisallowList = (List) config.getOrDefault("allNodesDisallowList", Collections.emptyList());
        this.allRelsDisallowList = (List) config.getOrDefault("allRelsDisallowList", Collections.emptyList());
        this.strategy = FingerprintStrategy.valueOf(
                (String) config.getOrDefault("strategy", FingerprintStrategy.LAZY.toString()));

        validateConfig();

        allLabels = new HashSet<>(nodeAllowMap.keySet());
        allLabels.addAll(nodeDisallowMap.keySet());
        allTypes = new HashSet<>(relAllowMap.keySet());
        allTypes.addAll(relDisallowMap.keySet());
    }

    private void validateConfig() {
        final String message = "You can't set the same %s for allow and disallow lists for %s";
        if (!Util.intersection(nodeAllowMap.keySet(), nodeDisallowMap.keySet()).isEmpty()) {
            throw new RuntimeException(String.format(message, "labels", "nodes"));
        }
        if (!Util.intersection(relAllowMap.keySet(), relDisallowMap.keySet()).isEmpty()) {
            throw new RuntimeException(String.format(message, "types", "rels"));
        }
        if (!Util.intersection(mapAllowList, mapDisallowList).isEmpty()) {
            throw new RuntimeException(String.format(message, "properties", "maps"));
        }
        if (!Util.intersection(allNodesAllowList, allNodesDisallowList).isEmpty()) {
            throw new RuntimeException(String.format(message, "properties", "all nodes"));
        }
        if (!Util.intersection(allRelsAllowList, allRelsDisallowList).isEmpty()) {
            throw new RuntimeException(String.format(message, "properties", "all rels"));
        }
    }

    public String getDigestAlgorithm() {
        return digestAlgorithm;
    }

    public Map> getNodeAllowMap() {
        return nodeAllowMap;
    }

    public Map> getRelAllowMap() {
        return relAllowMap;
    }

    public Map> getNodeDisallowMap() {
        return nodeDisallowMap;
    }

    public Map> getRelDisallowMap() {
        return relDisallowMap;
    }

    public List getMapAllowList() {
        return mapAllowList;
    }

    public List getMapDisallowList() {
        return mapDisallowList;
    }

    public List getAllNodesAllowList() {
        return allNodesAllowList;
    }

    public List getAllRelsAllowList() {
        return allRelsAllowList;
    }

    public List getAllNodesDisallowList() {
        return allNodesDisallowList;
    }

    public List getAllRelsDisallowList() {
        return allRelsDisallowList;
    }

    public FingerprintStrategy getStrategy() {
        return strategy;
    }

    public Set getAllLabels() {
        return allLabels;
    }

    public Set getAllTypes() {
        return allTypes;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy