use of org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.has in project timbuctoo by HuygensING.
the class TinkerPopOperationsTest method deleteVreRemovesAllTheVresCollectionsFromDatabase.
@Test
public void deleteVreRemovesAllTheVresCollectionsFromDatabase() {
TinkerPopGraphManager graphManager = newGraph().withVertex("vreName", v -> v.withLabel("VRE").withProperty(Vre.VRE_NAME_PROPERTY_NAME, "vreName").withOutgoingRelation(HAS_COLLECTION_RELATION_NAME, "collection1").withOutgoingRelation(HAS_COLLECTION_RELATION_NAME, "collection2")).withVertex("collection1", v -> v.withProperty(COLLECTION_NAME_PROPERTY_NAME, "collection1").withProperty(ENTITY_TYPE_NAME_PROPERTY_NAME, "entityType1").withProperty(IS_RELATION_COLLECTION_PROPERTY_NAME, true).withOutgoingRelation(HAS_DISPLAY_NAME_RELATION_NAME, "displayName").withOutgoingRelation(HAS_PROPERTY_RELATION_NAME, "property").withOutgoingRelation(HAS_ENTITY_NODE_RELATION_NAME, "entityNode")).withVertex("displayName", v -> v.withProperty("displayName", true).withProperty("propertyType", "string")).withVertex("property", v -> v.withProperty("property", true).withProperty("propertyType", "string")).withVertex("entityNode", v -> v.withOutgoingRelation(HAS_ENTITY_RELATION_NAME, "entity")).withVertex("entity", v -> v.withProperty("entity", true)).withVertex("collection2", v -> v.withProperty(COLLECTION_NAME_PROPERTY_NAME, "collection2").withProperty(ENTITY_TYPE_NAME_PROPERTY_NAME, "entityType2").withProperty(IS_RELATION_COLLECTION_PROPERTY_NAME, false)).withVertex("otherVreCollection", v -> v.withProperty(COLLECTION_NAME_PROPERTY_NAME, "otherVreCollection").withProperty(ENTITY_TYPE_NAME_PROPERTY_NAME, "entityType3").withProperty(IS_RELATION_COLLECTION_PROPERTY_NAME, false)).wrap();
TinkerPopOperations instance = forGraphWrapper(graphManager);
instance.deleteVre("vreName");
Graph graph = graphManager.getGraph();
assertThat(graph.traversal().V().has(Vre.VRE_NAME_PROPERTY_NAME, "vreName").hasNext(), equalTo(false));
assertThat(graph.traversal().V().has(COLLECTION_NAME_PROPERTY_NAME, "collection1").hasNext(), equalTo(false));
assertThat(graph.traversal().V().has(COLLECTION_NAME_PROPERTY_NAME, "collection2").hasNext(), equalTo(false));
assertThat(graph.traversal().V().has(COLLECTION_NAME_PROPERTY_NAME, "otherVreCollection").hasNext(), equalTo(true));
assertThat(graph.traversal().V().has("entity").hasNext(), equalTo(false));
assertThat(graph.traversal().V().has("displayName").hasNext(), equalTo(false));
}
use of org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.has in project timbuctoo by HuygensING.
the class TinkerPopOperationsTest method deleteEntitySetsDeletedToTrueWhenLastTypeIsRemoved.
@Test
public void deleteEntitySetsDeletedToTrueWhenLastTypeIsRemoved() throws Exception {
Vres vres = createConfiguration();
Collection collection = vres.getCollection("testthings").get();
UUID id = UUID.randomUUID();
String idString = id.toString();
TinkerPopGraphManager graphManager = newGraph().withVertex(v -> v.withTimId(idString).withProperty("isLatest", true).withVre("test").withType("thing").withProperty("rev", 1).withIncomingRelation("VERSION_OF", "orig")).withVertex("orig", v -> v.withTimId(idString).withVre("test").withType("thing").withProperty("isLatest", false).withProperty("rev", 1)).wrap();
TinkerPopOperations instance = forGraphWrapperAndMappings(graphManager, vres);
instance.deleteEntity(collection, id, new Change(Instant.now().toEpochMilli(), "userId", null));
assertThat(graphManager.getGraph().traversal().V().has("tim_id", idString).has("deleted", true).hasNext(), is(true));
}
use of org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.has in project timbuctoo by HuygensING.
the class ChangeRangeFacetDescription method filter.
@Override
@SuppressWarnings("unchecked")
public void filter(GraphTraversal<Vertex, Vertex> graphTraversal, List<FacetValue> facets) {
Optional<FacetValue> first = facets.stream().filter(facetValue -> Objects.equals(facetValue.getName(), facetName)).findFirst();
if (!first.isPresent()) {
return;
}
FacetValue facetValue = first.get();
if (!(facetValue instanceof DateRangeFacetValue)) {
return;
}
long lowerLimit = ((DateRangeFacetValue) facetValue).getLowerLimit();
LocalDate lowerLimitDate = LocalDate.parse("" + lowerLimit, FORMATTER);
long upperLimit = ((DateRangeFacetValue) facetValue).getUpperLimit();
LocalDate upperLimitDate = LocalDate.parse(("" + upperLimit), FORMATTER);
// Use range because the java.time.Period has no way to determine if a date falls in that Period.
Range<LocalDate> period = Range.closed(lowerLimitDate, upperLimitDate);
graphTraversal.where(__.has(propertyName, P.test((o1, o2) -> {
try {
LocalDate localDate = getChangeLocalDate(o1);
return ((Range<LocalDate>) o2).contains(localDate);
} catch (IOException e) {
LOG.error("Date {} cannot be parsed.", o1);
}
return false;
}, period)));
}
use of org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.has in project timbuctoo by HuygensING.
the class CharterPortaalFondsFacetDescription method filter.
@Override
public void filter(GraphTraversal<Vertex, Vertex> graphTraversal, List<FacetValue> facets) {
Optional<FacetValue> first = facets.stream().filter(facetValue -> Objects.equals(facetValue.getName(), getName())).findFirst();
if (first.isPresent()) {
FacetValue facetValue = first.get();
if (facetValue instanceof ListFacetValue) {
ListFacetValue listFacetValue = (ListFacetValue) facetValue;
List<String> values = listFacetValue.getValues();
if (values.isEmpty()) {
return;
}
List<String> formattedVals = values.stream().map(val -> val.substring(val.indexOf("(") + 1, val.length() - 1)).collect(toList());
graphTraversal.where(__.has(FONDS, P.within(formattedVals)));
} else {
LOG.error("Facet with name '{}' is not a ListFacet", getName());
}
}
}
use of org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.has in project timbuctoo by HuygensING.
the class MultiValueListFacetDescription method filter.
@Override
public void filter(GraphTraversal<Vertex, Vertex> graphTraversal, List<FacetValue> facetValues) {
Optional<FacetValue> first = facetValues.stream().filter(facetValue -> Objects.equals(facetValue.getName(), facetName)).findFirst();
if (!first.isPresent()) {
return;
}
FacetValue facetValue = first.get();
if (!(facetValue instanceof ListFacetValue)) {
return;
}
List<String> values = ((ListFacetValue) facetValue).getValues();
if (values.isEmpty()) {
return;
}
graphTraversal.where(__.<String>has(propertyName, P.test((o1, o2) -> o1 instanceof String && o2 instanceof List && ((List<?>) o2).stream().anyMatch(value -> ((String) o1).contains("\"" + value + "\"")), values)));
}
Aggregations