use of nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection 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 nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection 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));
}
use of nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection in project timbuctoo by HuygensING.
the class TinkerPopOperationsTest method acceptRelationCallTheChangeListener.
@Test
public void acceptRelationCallTheChangeListener() throws Exception {
ChangeListener changeListener = mock(ChangeListener.class);
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 = forGraphMappingsAndChangeListener(graphManager, vres, changeListener);
CreateRelation createRelation = new CreateRelation(sourceId, typeId, targetId);
createRelation.setCreated(new Change(Instant.now().toEpochMilli(), "userId", null));
instance.acceptRelation(collection, createRelation);
verify(changeListener).onCreateEdge(argThat(is(sameInstance(collection))), argThat(is(likeEdge().withSourceWithId(sourceId).withTargetWithId(targetId).withTypeId(typeId))));
}
use of nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection in project timbuctoo by HuygensING.
the class TinkerPopOperationsTest method getEntityIgnoresThePropertiesWithAWrongValue.
@Test
public void getEntityIgnoresThePropertiesWithAWrongValue() 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).withType("thing").withVre("test").withProperty("testthing_prop2", // should be a string
42)).wrap();
TinkerPopOperations instance = forGraphWrapperAndMappings(graphManager, vres);
ReadEntity entity = instance.getEntity(id, null, collection, (readEntity, vertex) -> {
}, (graphTraversalSource, vre, vertex, relationRef) -> {
});
assertThat(entity.getProperties(), emptyIterable());
}
use of nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection in project timbuctoo by HuygensING.
the class TinkerPopOperationsTest method replaceEntityUpdatesModified.
@Test
public void replaceEntityUpdatesModified() 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("isLatest", true).withProperty("rev", 1)).wrap();
TinkerPopOperations instance = forGraphWrapperAndMappings(graphManager, vres);
UpdateEntity updateEntity = new UpdateEntity(id, Lists.newArrayList(), 1);
long timeStamp = Instant.now().toEpochMilli();
updateEntity.setModified(new Change(timeStamp, "userId", null));
instance.replaceEntity(collection, updateEntity);
String modified = (String) graphManager.getGraph().traversal().V().has("tim_id", id.toString()).has("isLatest", true).properties("modified").value().next();
assertThat(modified, sameJSONAs(String.format("{\"timeStamp\": %s,\"userId\": \"%s\"}", timeStamp, "userId")));
}
Aggregations