Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
National Crime Agency (c) Crown Copyright 2018
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 uk.gov.nca.graph.mapper;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal;
import org.apache.tinkerpop.gremlin.structure.Edge;
import org.apache.tinkerpop.gremlin.structure.Graph;
import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraph;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import uk.gov.nca.graph.mapper.exceptions.ParseException;
import uk.gov.nca.graph.mapper.mapping.DataType;
import uk.gov.nca.graph.mapper.mapping.DataTypeUtils;
import uk.gov.nca.graph.mapper.mapping.EdgeMap;
import uk.gov.nca.graph.mapper.mapping.Mapping;
import uk.gov.nca.graph.mapper.mapping.VertexMap;
/**
* Class for adding data to a graph based on the configuration
*/
public class Grapher {
private final Configuration configuration;
private static final Logger LOGGER = LoggerFactory.getLogger(Grapher.class);
private static final String IDENTIFIER = "identifier";
/**
* Constructor taking the configuration to use
*/
public Grapher(Configuration configuration){
this.configuration = configuration;
}
/**
* Get the configuration of this class
*/
public Configuration getConfiguration() {
return configuration;
}
/**
* Add an index to the graph on IDENTIFIER, iff the graph is a TinkerGraph
*/
public void addIndex(Graph graph){
if(graph instanceof TinkerGraph){
LOGGER.info("Creating index on field {}", IDENTIFIER);
((TinkerGraph) graph).createIndex(IDENTIFIER, Vertex.class);
LOGGER.info("Index created on field {}", IDENTIFIER);
}else{
LOGGER.warn("Unable to create index on field {} as graph type {} is not supported",
IDENTIFIER,
graph.getClass().getSimpleName());
}
}
/**
* Perform mapping and add data to graph
*/
public void addDataToGraph(Map data, Graph graph){
addDataToGraph(data, graph, Collections.emptyMap());
}
/**
* Perform mapping and add data to graph, adding the contents of auditData
* to every vertex and edge. Audit data will override any data from the
* mapping file, and any existing data in the graph.
*/
public void addDataToGraph(Map data, Graph graph, Map auditData){
Map