use of org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.has in project timbuctoo by HuygensING.
the class TinkerPopOperationsTest method addPidAddsAPidToEachVertexInTheCollectionWithTheIdAndRev.
@Test
public void addPidAddsAPidToEachVertexInTheCollectionWithTheIdAndRev() throws Exception {
Vres vres = createConfiguration();
UUID id = UUID.randomUUID();
int rev = 1;
TinkerPopGraphManager graphManager = newGraph().withVertex(v -> v.withTimId(id.toString()).withType("relationtype").withProperty("relationtype_regularName", "regularName").withProperty("rev", rev).withProperty("isLatest", true).withIncomingRelation("VERSION_OF", "version")).withVertex("version", v -> v.withTimId(id.toString()).withType("relationtype").withProperty("relationtype_regularName", "regularName").withProperty("rev", rev).withProperty("isLatest", false)).wrap();
TinkerPopOperations instance = forGraphWrapperAndMappings(graphManager, vres);
URI pidUri = new URI("http://example.com/pid");
instance.addPid(id, rev, pidUri);
assertThat(graphManager.getGraph().traversal().V().has("pid", pidUri.toString()).count().next(), is(2L));
}
use of org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.has in project timbuctoo by HuygensING.
the class TinkerPopOperationsTest method replaceEntityUpdatesTheRevisionByOne.
@Test
public void replaceEntityUpdatesTheRevisionByOne() throws Exception {
Vres vres = createConfiguration();
Collection collection = vres.getCollection("testthings").get();
UUID id = UUID.randomUUID();
TinkerPopGraphManager graphManager = newGraph().withVertex(v -> v.withTimId(id.toString()).withProperty("isLatest", true).withProperty("rev", 1).withIncomingRelation("VERSION_OF", "orig")).withVertex("orig", v -> v.withTimId(id.toString()).withProperty("isLatest", false).withProperty("rev", 1)).wrap();
TinkerPopOperations instance = forGraphWrapperAndMappings(graphManager, vres);
UpdateEntity updateEntity = new UpdateEntity(id, Lists.newArrayList(), 1);
updateEntity.setModified(new Change(Instant.now().toEpochMilli(), "userId", null));
instance.replaceEntity(collection, updateEntity);
int rev = (int) graphManager.getGraph().traversal().V().has("tim_id", id.toString()).has("isLatest", true).values("rev").next();
assertThat(rev, is(2));
}
use of org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.has in project timbuctoo by HuygensING.
the class TinkerPopOperationsTest method deleteEntityPreparesBackupCopyAfterMakingChanges.
@Test
public void deleteEntityPreparesBackupCopyAfterMakingChanges() 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).withVre("test").withType("thing").withProperty("isLatest", true).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);
Vertex beforeUpdate = graphManager.getGraph().traversal().V().has("tim_id", idString).has("isLatest", true).next();
instance.deleteEntity(collection, id, new Change(Instant.now().toEpochMilli(), "userId", null));
Vertex afterUpdate = graphManager.getGraph().traversal().V().has("tim_id", idString).has("isLatest", true).next();
assertThat(afterUpdate.id(), is(not(beforeUpdate.id())));
// single edge, containing the VERSION_OF pointer
assertThat(afterUpdate.edges(Direction.IN).next().outVertex().id(), is(beforeUpdate.id()));
}
use of org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.has in project timbuctoo by HuygensING.
the class TinkerPopOperationsTest method deletesAllRelationsOfCurrentVre.
@Test
public void deletesAllRelationsOfCurrentVre() throws Exception {
Vres vres = createConfiguration();
Collection collection = vres.getCollection("testthings").get();
UUID id = UUID.randomUUID();
String idString = id.toString();
final String testOnlyId = "10000000-0000-0000-0000-000000000000";
final String otherOnlyId = "20000000-0000-0000-0000-000000000000";
final String inBothId = "30000000-0000-0000-0000-000000000000";
TinkerPopGraphManager graphManager = newGraph().withVertex(v -> v.withTimId(idString).withVre("test").withType("thing").withProperty("isLatest", true).withProperty("rev", 1).withOutgoingRelation("hasWritten", "stuff", rel -> rel.withTim_id(UUID.fromString(testOnlyId)).removeType("other").withAccepted("testrelation", true)).withIncomingRelation("isFriendOf", "friend", rel -> rel.withTim_id(UUID.fromString(inBothId)).withAccepted("testrelation", true).withAccepted("otherrelation", true)).withIncomingRelation("isFriendOf", "friend", rel -> rel.withTim_id(UUID.fromString(otherOnlyId)).removeType("test").withAccepted("otherrelation", true))).withVertex("stuff", v -> v.withVre("test").withType("stuff").withProperty("isLatest", true).withProperty("rev", 1)).withVertex("friend", v -> v.withVre("test").withVre("other").withType("thing").withProperty("isLatest", true).withProperty("rev", 1)).wrap();
TinkerPopOperations instance = forGraphWrapperAndMappings(graphManager, vres);
instance.deleteEntity(collection, id, new Change(Instant.now().toEpochMilli(), "userId", null));
assertThat(graphManager.getGraph().traversal().E().has("tim_id", testOnlyId).has("isLatest", true).has("testrelation_accepted", false).not(has("otherrelation_accepted")).hasNext(), is(true));
assertThat(graphManager.getGraph().traversal().E().has("tim_id", inBothId).has("isLatest", true).has("testrelation_accepted", false).has("otherrelation_accepted", true).hasNext(), is(true));
assertThat(graphManager.getGraph().traversal().E().has("tim_id", otherOnlyId).has("isLatest", true).not(has("testrelation_accepted")).has("otherrelation_accepted", true).hasNext(), is(true));
}
use of org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.has in project timbuctoo by HuygensING.
the class TinkerPopOperationsTest method doKeywordQuickSearchLetsLimitLimitTheAmountOfResults.
@Test
public void doKeywordQuickSearchLetsLimitLimitTheAmountOfResults() {
Vres vres = createConfiguration();
GremlinEntityFetcher entityFetcher = new GremlinEntityFetcher();
UUID id1 = UUID.randomUUID();
UUID id2 = UUID.randomUUID();
UUID id3 = UUID.randomUUID();
String keywordType = "keywordType";
TinkerPopGraphManager graphManager = newGraph().withVertex(v -> v.withTimId(id1).withType("keyword").withVre("test").withProperty("rev", 1).withProperty("testkeyword_displayName", "matching").isLatest(true).withProperty("keyword_type", keywordType).withLabel("testkeyword")).withVertex(v -> v.withTimId(id2).withType("keyword").withVre("test").withProperty("rev", 1).withProperty("testkeyword_displayName", "also matching").isLatest(true).withProperty("keyword_type", keywordType).withLabel("testkeyword")).withVertex(v -> v.withTimId(id3).withType("keyword").withVre("test").withProperty("rev", 1).withProperty("testkeyword_displayName", "different name").isLatest(true).withProperty("keyword_type", keywordType).withLabel("testkeyword")).wrap();
IndexHandler indexHandler = mock(IndexHandler.class);
when(indexHandler.hasQuickSearchIndexFor(any(Collection.class))).thenReturn(true);
when(indexHandler.findKeywordsByQuickSearch(any(Collection.class), any(), anyString())).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("testkeywords").get();
QuickSearch quickSearch = QuickSearch.fromQueryString("matching");
List<QuickSearchResult> result = instance.doKeywordQuickSearch(collection, keywordType, quickSearch, 1);
assertThat(result, hasSize(1));
}
Aggregations