apoc.refactor.util.PropertiesManager Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of apoc-core Show documentation
Show all versions of apoc-core Show documentation
Core package for Neo4j Procedures
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.refactor.util;
import apoc.util.ArrayBackedList;
import java.lang.reflect.Array;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;
import org.neo4j.graphdb.Entity;
import org.neo4j.graphdb.Relationship;
/**
* @author AgileLARUS
* @since 3.0.0
*/
public class PropertiesManager {
private PropertiesManager() {}
public static void mergeProperties(Map properties, Entity target, RefactorConfig refactorConfig) {
for (Map.Entry prop : properties.entrySet()) {
String key = prop.getKey();
String mergeMode = refactorConfig.getMergeMode(key, target instanceof Relationship);
mergeProperty(target, refactorConfig, prop, key, mergeMode);
}
}
private static void mergeProperty(
Entity target,
RefactorConfig refactorConfig,
Map.Entry prop,
String key,
String mergeMode) {
switch (mergeMode) {
case RefactorConfig.OVERWRITE:
case RefactorConfig.OVERRIDE:
target.setProperty(key, prop.getValue());
break;
case RefactorConfig.DISCARD:
if (!target.hasProperty(key)) {
target.setProperty(key, prop.getValue());
}
break;
case RefactorConfig.COMBINE:
combineProperties(prop, target, refactorConfig);
break;
}
}
public static void combineProperties(Map.Entry prop, Entity target, RefactorConfig refactorConfig) {
if (!target.hasProperty(prop.getKey())) target.setProperty(prop.getKey(), prop.getValue());
else {
Set