Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into gh-3256-dependency…
Browse files Browse the repository at this point in the history
…-updates
  • Loading branch information
tb06904 committed Jul 26, 2024
2 parents d7c5d8e + f4d3738 commit 832d64c
Show file tree
Hide file tree
Showing 21 changed files with 447 additions and 220 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
import uk.gov.gchq.gaffer.tinkerpop.generator.GafferPopElementGenerator;
import uk.gov.gchq.gaffer.tinkerpop.process.traversal.strategy.optimisation.GafferPopGraphStepStrategy;
import uk.gov.gchq.gaffer.tinkerpop.process.traversal.strategy.optimisation.GafferPopHasStepStrategy;
import uk.gov.gchq.gaffer.tinkerpop.process.traversal.util.TypeSubTypeValueFactory;
import uk.gov.gchq.gaffer.tinkerpop.process.traversal.util.GafferCustomTypeFactory;
import uk.gov.gchq.gaffer.tinkerpop.service.GafferPopNamedOperationServiceFactory;
import uk.gov.gchq.gaffer.user.User;
import uk.gov.gchq.koryphe.iterable.MappedIterable;
Expand Down Expand Up @@ -728,6 +728,32 @@ public <T> T execute(final OperationChain<T> opChain) {
}
}

/**
* Sets the {@link GafferPopGraphVariables} to default values for this
* graph
*
* @param variables The variables
*/
public void setDefaultVariables(final GafferPopGraphVariables variables) {
LOGGER.debug("Resetting graph variables to defaults");
variables.set(GafferPopGraphVariables.OP_OPTIONS, Collections.unmodifiableMap(opOptions));
variables.set(GafferPopGraphVariables.USER, defaultUser);
variables.set(GafferPopGraphVariables.GET_ALL_ELEMENTS_LIMIT,
configuration().getInteger(GET_ALL_ELEMENTS_LIMIT, DEFAULT_GET_ALL_ELEMENTS_LIMIT));
variables.set(GafferPopGraphVariables.HAS_STEP_FILTER_STAGE,
configuration().getString(HAS_STEP_FILTER_STAGE, DEFAULT_HAS_STEP_FILTER_STAGE.toString()));
variables.set(GafferPopGraphVariables.LAST_OPERATION_CHAIN, new OperationChain<Object>());
}

/**
* Get the underlying Gaffer graph this GafferPop graph is connected to.
*
* @return The Gaffer Graph.
*/
public Graph getGafferGraph() {
return graph;
}

private Iterator<GafferPopVertex> verticesWithSeedsAndView(final List<ElementSeed> seeds, final View view) {
final boolean getAll = null == seeds || seeds.isEmpty();
final LinkedList<GafferPopVertex> idVertices = new LinkedList<>();
Expand Down Expand Up @@ -933,9 +959,9 @@ private List<ElementSeed> getElementSeeds(final Iterable<Object> ids) {
// Check if contains label in edge ID
if (edgeIDMatcher.matches()) {
seeds.add(new EdgeSeed(edgeIDMatcher.group("src"), edgeIDMatcher.group("dest")));
// If not then check if a custom type e.g. TSTV
} else {
// If not then check if a TSTV ID
seeds.add(new EntitySeed(TypeSubTypeValueFactory.parseAsTstvIfValid(id)));
seeds.add(new EntitySeed(GafferCustomTypeFactory.parseAsCustomTypeIfValid(id)));
}
// Assume entity ID as a fallback
} else {
Expand Down Expand Up @@ -988,23 +1014,6 @@ private IncludeIncomingOutgoingType getInOutType(final Direction direction) {
return inOutType;
}

/**
* Sets the {@link GafferPopGraphVariables} to default values for this
* graph
*
* @param variables The variables
*/
public void setDefaultVariables(final GafferPopGraphVariables variables) {
LOGGER.info("Resetting graph variables to defaults");
variables.set(GafferPopGraphVariables.OP_OPTIONS, Collections.unmodifiableMap(opOptions));
variables.set(GafferPopGraphVariables.USER, defaultUser);
variables.set(GafferPopGraphVariables.GET_ALL_ELEMENTS_LIMIT,
configuration().getInteger(GET_ALL_ELEMENTS_LIMIT, DEFAULT_GET_ALL_ELEMENTS_LIMIT));
variables.set(GafferPopGraphVariables.HAS_STEP_FILTER_STAGE,
configuration().getString(HAS_STEP_FILTER_STAGE, DEFAULT_HAS_STEP_FILTER_STAGE.toString()));
variables.set(GafferPopGraphVariables.LAST_OPERATION_CHAIN, new OperationChain());
}

/**
* Gets the next ID to assign to a supplied vertex based on the currently configured ID manager.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2023 Crown Copyright
* Copyright 2016-2024 Crown Copyright
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -16,26 +16,27 @@

package uk.gov.gchq.gaffer.tinkerpop.generator;

import org.apache.tinkerpop.gremlin.structure.Property;

import uk.gov.gchq.gaffer.data.element.Edge;
import uk.gov.gchq.gaffer.data.generator.OneToOneElementGenerator;
import uk.gov.gchq.gaffer.tinkerpop.GafferPopEdge;

import java.util.Iterator;
import uk.gov.gchq.gaffer.tinkerpop.process.traversal.util.GafferCustomTypeFactory;

public class GafferEdgeGenerator implements OneToOneElementGenerator<GafferPopEdge> {
@Override
public Edge _apply(final GafferPopEdge gafferPopEdge) {
final Edge edge = new Edge(gafferPopEdge.label(), gafferPopEdge.outVertex().id(),
gafferPopEdge.inVertex().id(), true);
final Iterator<Property<Object>> propItr = gafferPopEdge.properties();
while (propItr.hasNext()) {
final Property<Object> prop = propItr.next();
if (null != prop.key()) {
edge.putProperty(prop.key(), prop.value());
// Add edge
final Edge edge = new Edge(
gafferPopEdge.label(),
GafferCustomTypeFactory.parseAsCustomTypeIfValid(gafferPopEdge.outVertex().id()),
GafferCustomTypeFactory.parseAsCustomTypeIfValid(gafferPopEdge.inVertex().id()),
true);

// Add properties
gafferPopEdge.properties().forEachRemaining(prop -> {
if (prop.key() != null) {
edge.putProperty(prop.key(), GafferCustomTypeFactory.parseAsCustomTypeIfValid(prop.value()));
}
}
});
return edge;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2023 Crown Copyright
* Copyright 2016-2024 Crown Copyright
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -19,6 +19,7 @@
import uk.gov.gchq.gaffer.data.element.Entity;
import uk.gov.gchq.gaffer.data.generator.OneToOneElementGenerator;
import uk.gov.gchq.gaffer.tinkerpop.GafferPopVertex;
import uk.gov.gchq.gaffer.tinkerpop.process.traversal.util.GafferCustomTypeFactory;

public class GafferEntityGenerator implements OneToOneElementGenerator<GafferPopVertex> {
@Override
Expand All @@ -27,12 +28,13 @@ public Entity _apply(final GafferPopVertex vertex) {
throw new IllegalArgumentException("Unable to convert a null GafferPopVertex Object");
}

final Entity entity = new Entity(vertex.label(), vertex.id());
final Entity entity = new Entity(vertex.label(), GafferCustomTypeFactory.parseAsCustomTypeIfValid(vertex.id()));

// Tinkerpop allows nested properties under a key for Gaffer we need to flatten these so only one property per key
vertex.properties().forEachRemaining(vertProp -> {
entity.putProperty(vertProp.key(), vertProp.value());
vertProp.properties().forEachRemaining(prop -> entity.putProperty(prop.key(), prop.value()));
entity.putProperty(vertProp.key(), GafferCustomTypeFactory.parseAsCustomTypeIfValid(vertProp.value()));
vertProp.properties().forEachRemaining(
prop -> entity.putProperty(prop.key(), GafferCustomTypeFactory.parseAsCustomTypeIfValid(prop.value())));
});

return entity;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2023 Crown Copyright
* Copyright 2016-2024 Crown Copyright
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -24,8 +24,7 @@
import uk.gov.gchq.gaffer.data.generator.OneToOneObjectGenerator;
import uk.gov.gchq.gaffer.tinkerpop.GafferPopEdge;
import uk.gov.gchq.gaffer.tinkerpop.GafferPopGraph;

import java.util.Map.Entry;
import uk.gov.gchq.gaffer.tinkerpop.process.traversal.util.GafferCustomTypeFactory;

public class GafferPopEdgeGenerator implements OneToOneObjectGenerator<GafferPopEdge> {
private final GafferPopGraph graph;
Expand All @@ -48,14 +47,19 @@ public GafferPopEdge _apply(final Element element) {
}

final Edge edge = ((Edge) element);
final GafferPopEdge gafferPopEdge = new GafferPopEdge(edge.getGroup(),
edge.getSource(), edge.getDestination(), graph);
final GafferPopEdge gafferPopEdge = new GafferPopEdge(
edge.getGroup(),
GafferCustomTypeFactory.parseForGraphSONv3(edge.getSource()),
GafferCustomTypeFactory.parseForGraphSONv3(edge.getDestination()),
graph);

for (final Entry<String, Object> entry : edge.getProperties().entrySet()) {
if (null != entry.getValue()) {
gafferPopEdge.propertyWithoutUpdate(entry.getKey(), entry.getValue());
// Add the properties
edge.getProperties().forEach((k, v) -> {
if (v != null) {
gafferPopEdge.propertyWithoutUpdate(k, GafferCustomTypeFactory.parseForGraphSONv3(v));
}
}
});

if (gafferPopReadOnly) {
gafferPopEdge.setReadOnly();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2023 Crown Copyright
* Copyright 2016-2024 Crown Copyright
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -25,8 +25,8 @@
import uk.gov.gchq.gaffer.data.generator.OneToOneObjectGenerator;
import uk.gov.gchq.gaffer.tinkerpop.GafferPopGraph;
import uk.gov.gchq.gaffer.tinkerpop.GafferPopVertex;
import uk.gov.gchq.gaffer.tinkerpop.process.traversal.util.GafferCustomTypeFactory;

import java.util.Map.Entry;

public class GafferPopVertexGenerator implements OneToOneObjectGenerator<GafferPopVertex> {
private final GafferPopGraph graph;
Expand All @@ -49,12 +49,18 @@ public GafferPopVertex _apply(final Element element) {
}

final Entity entity = ((Entity) element);
final GafferPopVertex vertex = new GafferPopVertex(entity.getGroup(), entity.getVertex(), graph);
for (final Entry<String, Object> entry : entity.getProperties().entrySet()) {
if (null != entry.getValue()) {
vertex.propertyWithoutUpdate(Cardinality.list, entry.getKey(), entry.getValue());
final GafferPopVertex vertex = new GafferPopVertex(
entity.getGroup(),
GafferCustomTypeFactory.parseForGraphSONv3(entity.getVertex()),
graph);

// Add the properties
entity.getProperties().forEach((k, v) -> {
if (v != null) {
vertex.propertyWithoutUpdate(Cardinality.list, k, GafferCustomTypeFactory.parseForGraphSONv3(v));
}
}
});

if (gafferPopReadOnly) {
vertex.setReadOnly();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.apache.tinkerpop.gremlin.structure.Element;
import org.apache.tinkerpop.gremlin.structure.Property;

import uk.gov.gchq.gaffer.tinkerpop.process.traversal.util.GafferCustomTypeFactory;
import uk.gov.gchq.gaffer.tinkerpop.process.traversal.util.GafferPredicateFactory;

import java.util.function.Predicate;
Expand All @@ -45,7 +46,7 @@ public Predicate getGafferPredicate() {

@Override
protected boolean testId(final Element element) {
return gafferPredicate.test(element.id());
return gafferPredicate.test(GafferCustomTypeFactory.parseAsCustomTypeIfValid(element.id()));
}

@Override
Expand All @@ -60,7 +61,7 @@ protected boolean testLabel(final Element element) {

@Override
protected boolean testValue(final Property property) {
return gafferPredicate.test(property.value());
return gafferPredicate.test(GafferCustomTypeFactory.parseAsCustomTypeIfValid(property.value()));
}

@Override
Expand Down
Loading

0 comments on commit 832d64c

Please sign in to comment.