use of org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.has in project timbuctoo by HuygensING.
the class TinkerPopOperationsTest method replaceEntityUpdatesTheKnownProperties.
@Test
public void replaceEntityUpdatesTheKnownProperties() throws Exception {
Vres vres = createConfiguration();
Collection collection = vres.getCollection("testthings").get();
UUID id = UUID.randomUUID();
TinkerPopGraphManager graphManager = newGraph().withVertex(v -> v.withTimId(id).withVre("test").withType("thing").withProperty("testthing_prop1", "oldValue").withProperty("isLatest", true).withProperty("rev", 1)).wrap();
TinkerPopOperations instance = forGraphWrapperAndMappings(graphManager, vres);
ArrayList<TimProperty<?>> properties = Lists.newArrayList(new StringProperty("prop1", "newValue"), new StringProperty("prop2", "prop2Value"));
UpdateEntity updateEntity = new UpdateEntity(id, properties, 1);
long timeStamp = Instant.now().toEpochMilli();
updateEntity.setModified(new Change(timeStamp, "userId", null));
instance.replaceEntity(collection, updateEntity);
Vertex vertex = graphManager.getGraph().traversal().V().has("tim_id", id.toString()).has("isLatest", true).next();
assertThat(vertex, is(likeVertex().withProperty("testthing_prop1", "newValue").withProperty("testthing_prop2", "prop2Value")));
}
use of org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.has in project timbuctoo by HuygensING.
the class TinkerPopOperationsTest method doQuickSearchLetsLimitTheAmountOfResults.
@Test
public void doQuickSearchLetsLimitTheAmountOfResults() {
Vres vres = createConfiguration();
GremlinEntityFetcher entityFetcher = new GremlinEntityFetcher();
UUID id1 = UUID.randomUUID();
UUID id2 = UUID.randomUUID();
UUID id3 = UUID.randomUUID();
TinkerPopGraphManager graphManager = newGraph().withVertex(v -> v.withTimId(id1).withType("thing").withVre("test").withProperty("rev", 1).withProperty("testthing_displayName", "matching").isLatest(true).withLabel("testthing")).withVertex(v -> v.withTimId(id2).withType("thing").withVre("test").withProperty("rev", 1).withProperty("testthing_displayName", "also matching").isLatest(true).withLabel("testthing")).withVertex(v -> v.withTimId(id3).withType("thing").withVre("test").withProperty("rev", 1).withProperty("testthing_displayName", "different name").isLatest(true).withLabel("testthing")).wrap();
IndexHandler indexHandler = mock(IndexHandler.class);
when(indexHandler.hasQuickSearchIndexFor(any(Collection.class))).thenReturn(true);
when(indexHandler.findByQuickSearch(any(Collection.class), any())).thenReturn(graphManager.getGraph().traversal().V().has("tim_id", within(id1.toString(), id2.toString())));
TinkerPopOperations instance = new TinkerPopOperations(graphManager, mock(ChangeListener.class), entityFetcher, vres, indexHandler);
Collection collection = vres.getCollection("testthings").get();
QuickSearch quickSearch = QuickSearch.fromQueryString("matching");
List<QuickSearchResult> result = instance.doQuickSearch(collection, quickSearch, 1);
assertThat(result, hasSize(1));
}
use of org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.has in project timbuctoo by HuygensING.
the class TinkerPopOperationsTest method getEntityByRdfUriReturnsTheLatestEntity.
@Test
public void getEntityByRdfUriReturnsTheLatestEntity() {
UUID id1 = UUID.randomUUID();
TinkerPopGraphManager graphManager = newGraph().withVertex(v -> v.withTimId(id1).withType("thing").withVre("test").withProperty("rdfUri", "http://example.com/entity").withProperty("rev", 2).isLatest(true).withLabel("testthing")).withVertex(v -> v.withTimId(id1).withType("thing").withVre("test").withProperty("rdfUri", "http://example.com/entity").isLatest(false).withProperty("rev", 1).withLabel("testthing")).wrap();
Vres vres = createConfiguration();
IndexHandler indexHandler = mock(IndexHandler.class);
Vertex vertex = graphManager.getGraph().traversal().V().has("tim_id", id1.toString()).next();
when(indexHandler.findVertexInRdfIndex(any(Vre.class), anyString())).thenReturn(Optional.of(vertex));
TinkerPopOperations instance = forGraphMappingsAndIndex(graphManager, vres, indexHandler);
Collection collection = vres.getCollection("testthings").get();
Optional<ReadEntity> readEntity = instance.getEntityByRdfUri(collection, "http://example.com/entity", false);
assertThat(readEntity, is(present()));
assertThat(readEntity.get(), hasProperty("rev", equalTo(2)));
}
use of org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.has in project timbuctoo by HuygensING.
the class TinkerPopOperationsTest method acceptRelationSetsTheCreatedInformation.
@Test
public void acceptRelationSetsTheCreatedInformation() throws Exception {
Vres vres = createConfiguration();
Collection collection = vres.getCollection("testrelations").get();
UUID typeId = UUID.randomUUID();
UUID sourceId = UUID.randomUUID();
UUID targetId = UUID.randomUUID();
TinkerPopGraphManager graphManager = newGraph().withVertex(v -> v.withTimId(typeId.toString()).withType("relationtype").withProperty("relationtype_regularName", "regularName").withProperty("rev", 1).withProperty("isLatest", true)).withVertex(v -> v.withTimId(sourceId.toString()).withProperty("rev", 1).withVre("test").withType("thing").withProperty("isLatest", true)).withVertex(v -> v.withTimId(targetId.toString()).withProperty("rev", 1).withVre("test").withType("thing").withProperty("isLatest", true)).wrap();
TinkerPopOperations instance = forGraphWrapperAndMappings(graphManager, vres);
CreateRelation createRelation = new CreateRelation(sourceId, typeId, targetId);
long timeStamp = Instant.now().toEpochMilli();
String userId = "userId";
createRelation.setCreated(new Change(timeStamp, userId, null));
UUID relId = instance.acceptRelation(collection, createRelation);
Edge newEdge = graphManager.getGraph().traversal().E().has("tim_id", relId.toString()).next();
assertThat(getModificationInfo("modified", newEdge), is(jsnO("timeStamp", jsn(timeStamp), "userId", jsn(userId))));
assertThat(getModificationInfo("created", newEdge), is(jsnO("timeStamp", jsn(timeStamp), "userId", jsn(userId))));
}
use of org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.has in project timbuctoo by HuygensING.
the class TinkerPopOperationsTest method doQuickSearchUsesTheIndexToSearchTheEntity.
@Test
public void doQuickSearchUsesTheIndexToSearchTheEntity() {
Vres vres = createConfiguration();
GremlinEntityFetcher entityFetcher = new GremlinEntityFetcher();
UUID id1 = UUID.randomUUID();
UUID id2 = UUID.randomUUID();
UUID id3 = UUID.randomUUID();
TinkerPopGraphManager graphManager = newGraph().withVertex(v -> v.withTimId(id1).withType("thing").withVre("test").withProperty("rev", 1).withProperty("testthing_displayName", "matching").isLatest(true).withLabel("testthing")).withVertex(v -> v.withTimId(id2).withType("thing").withVre("test").withProperty("rev", 1).withProperty("testthing_displayName", "also matching").isLatest(true).withLabel("testthing")).withVertex(v -> v.withTimId(id3).withType("thing").withVre("test").withProperty("rev", 1).withProperty("testthing_displayName", "different name").isLatest(true).withLabel("testthing")).wrap();
IndexHandler indexHandler = mock(IndexHandler.class);
when(indexHandler.hasQuickSearchIndexFor(any(Collection.class))).thenReturn(true);
when(indexHandler.findByQuickSearch(any(Collection.class), any())).thenReturn(graphManager.getGraph().traversal().V().has("tim_id", within(id1.toString(), id2.toString())));
TinkerPopOperations instance = new TinkerPopOperations(graphManager, mock(ChangeListener.class), entityFetcher, vres, indexHandler);
Collection collection = vres.getCollection("testthings").get();
QuickSearch quickSearch = QuickSearch.fromQueryString("matching");
List<QuickSearchResult> result = instance.doQuickSearch(collection, quickSearch, 3);
assertThat(result.stream().map(e -> e.getId()).collect(toList()), containsInAnyOrder(id1, id2));
verify(indexHandler).findByQuickSearch(collection, quickSearch);
}
Aggregations