use of nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection in project timbuctoo by HuygensING.
the class TinkerPopOperationsTest method deleteEntityIncreasesTheRevision.
// TODO move increase of the rev to TimbuctooActions
@Test
public void deleteEntityIncreasesTheRevision() 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);
int rev = instance.deleteEntity(collection, id, new Change(Instant.now().toEpochMilli(), "userId", null));
assertThat(rev, is(2));
}
use of nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection in project timbuctoo by HuygensING.
the class TinkerPopOperationsTest method addPropertiesToCollectionsAddsPropertyDescriptionsToTheCollection.
@Test
public void addPropertiesToCollectionsAddsPropertyDescriptionsToTheCollection() {
TinkerPopGraphManager graphManager = newGraph().wrap();
TinkerPopOperations instance = forGraphWrapper(graphManager);
Vre vre = instance.ensureVreExists("vre");
instance.addCollectionToVre(vre, CreateCollection.defaultCollection("vre"));
vre = instance.loadVres().getVre("vre");
Collection collection = vre.getCollectionForTypeName(defaultEntityTypeName(vre));
ImmutableCreateProperty prop1 = ImmutableCreateProperty.builder().clientName("clientName1").propertyType("string").rdfUri("http://example.org/pred1").typeUri("http://example.org/string").build();
ImmutableCreateProperty prop2 = ImmutableCreateProperty.builder().clientName("clientName2").propertyType("string").rdfUri("http://example.org/pred2").typeUri("http://example.org/string").build();
instance.addPropertiesToCollection(collection, Lists.newArrayList(prop1, prop2));
collection = instance.loadVres().getCollectionForType(defaultEntityTypeName(vre)).get();
assertThat(collection.getReadableProperties().values(), hasSize(2));
List<Vertex> properties = graphManager.getGraph().traversal().V().hasLabel("property").toList();
assertThat(properties, containsInAnyOrder(likeVertex().withProperty("clientName", "@displayName"), likeVertex().withProperty("clientName", "clientName1").withProperty("dbName", collection.getEntityTypeName() + "_" + "http://example.org/pred1").withProperty("propertyType", "string").withProperty("rdfUri", "http://example.org/pred1").withProperty("typeUri", "http://example.org/string"), likeVertex().withProperty("clientName", "clientName2").withProperty("dbName", collection.getEntityTypeName() + "_" + "http://example.org/pred2").withProperty("propertyType", "string").withProperty("rdfUri", "http://example.org/pred2").withProperty("typeUri", "http://example.org/string")));
}
use of nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection in project timbuctoo by HuygensING.
the class TinkerPopOperationsTest method createEntitySetsCreatedAndModified.
@Test
public void createEntitySetsCreatedAndModified() throws Exception {
TinkerPopGraphManager graphManager = newGraph().wrap();
Vres vres = createConfiguration();
Collection collection = vres.getCollection("testthings").get();
TinkerPopOperations instance = forGraphWrapperAndMappings(graphManager, vres);
List<TimProperty<?>> properties = Lists.newArrayList();
String userId = "userId";
long timeStamp = Instant.now().toEpochMilli();
CreateEntity createEntity = withProperties(properties, userId, timeStamp);
instance.createEntity(collection, Optional.empty(), createEntity);
assertThat(graphManager.getGraph().traversal().V().has("tim_id", createEntity.getId().toString()).next().value("created"), sameJSONAs(String.format("{\"timeStamp\": %s,\"userId\": \"%s\"}", timeStamp, userId)));
assertThat(graphManager.getGraph().traversal().V().has("tim_id", createEntity.getId().toString()).next().value("modified"), sameJSONAs(String.format("{\"timeStamp\": %s,\"userId\": \"%s\"}", timeStamp, userId)));
}
use of nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection in project timbuctoo by HuygensING.
the class TinkerPopOperationsTest method getEntityAlwaysReturnsTheDeletedProperty.
@Test
public void getEntityAlwaysReturnsTheDeletedProperty() throws Exception {
Vres vres = createConfiguration();
Collection collection = vres.getCollection("testthings").get();
UUID id = UUID.randomUUID();
TinkerPopGraphManager graphManager = newGraph().withVertex(v -> v.withTimId(id.toString()).withType("thing").withVre("test").withProperty("isLatest", true).withProperty("rev", 1)).wrap();
TinkerPopOperations instance = forGraphWrapperAndMappings(graphManager, vres);
ReadEntity entity = instance.getEntity(id, null, collection, (readEntity, vertex) -> {
}, (graphTraversalSource, vre, vertex, relationRef) -> {
});
assertThat(entity.getDeleted(), is(false));
}
use of nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection in project timbuctoo by HuygensING.
the class TinkerPopOperationsTest method getEntityReturnsTheSpecifiedRevision.
@Test
public void getEntityReturnsTheSpecifiedRevision() throws Exception {
Vres vres = createConfiguration();
Collection collection = vres.getCollection("testthings").get();
UUID id = UUID.randomUUID();
TinkerPopGraphManager graphManager = newGraph().withVertex(v -> v.withTimId(id.toString()).withType("thing").withVre("test").withProperty("testthing_prop1", "old").withProperty("rev", 1).withProperty("isLatest", false).withOutgoingRelation("VERSION_OF", "replacement")).withVertex("replacement", v -> v.withTimId(id.toString()).withType("thing").withVre("test").withProperty("testthing_prop1", "new").withProperty("rev", 2).withProperty("isLatest", false).withOutgoingRelation("VERSION_OF", "dangling")).withVertex("dangling", v -> v.withTimId(id.toString()).withType("thing").withVre("test").withProperty("testthing_prop1", "new").withProperty("rev", 2).withProperty("isLatest", true)).wrap();
TinkerPopOperations instance = forGraphWrapperAndMappings(graphManager, vres);
ReadEntity entity = instance.getEntity(id, 1, collection, (readEntity, vertex) -> {
}, (graphTraversalSource, vre, vertex, relationRef) -> {
});
assertThat(entity.getRev(), is(1));
assertThat(entity.getProperties(), contains(allOf(hasProperty("name", equalTo("prop1")), hasProperty("value", equalTo("old")))));
}
Aggregations