Search in sources :

Example 1 with Change

use of nl.knaw.huygens.timbuctoo.model.Change in project timbuctoo by HuygensING.

the class TinkerPopOperationsTest method deleteEntityRemovesTypeWhenOtherTypesExist.

@Test
public void deleteEntityRemovesTypeWhenOtherTypesExist() 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").withVre("other").withType("thing").withProperty("isLatest", true).withProperty("rev", 1).withLabel("testthing").withLabel("otherthing")).wrap();
    GremlinEntityFetcher entityFetcher = new GremlinEntityFetcher();
    TinkerPopOperations instance = forGraphWrapperAndMappings(graphManager, vres);
    instance.deleteEntity(collection, id, new Change(Instant.now().toEpochMilli(), "userId", null));
    String types = (String) graphManager.getGraph().traversal().V().has("tim_id", idString).has("isLatest", true).properties("types").value().next();
    assertThat(types, is("[\"otherthing\"]"));
    // Type should also be removed from the Neo4j labels
    assertThat(graphManager.getGraph().traversal().V().has("tim_id", idString).has("isLatest", true).has(T.label, LabelP.of("testthing")).hasNext(), is(false));
    // Other type should not be removed from the Neo4j labels
    assertThat(graphManager.getGraph().traversal().V().has("tim_id", idString).has("isLatest", true).has(T.label, LabelP.of("otherthing")).hasNext(), is(true));
}
Also used : ImmutableCreateProperty(nl.knaw.huygens.timbuctoo.core.dto.rdf.ImmutableCreateProperty) AlreadyUpdatedException(nl.knaw.huygens.timbuctoo.core.AlreadyUpdatedException) NodeFactory(org.apache.jena.graph.NodeFactory) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) CreateCollection(nl.knaw.huygens.timbuctoo.core.dto.CreateCollection) Matchers.not(org.hamcrest.Matchers.not) CreateEntityStubs.withProperties(nl.knaw.huygens.timbuctoo.core.dto.CreateEntityStubs.withProperties) Try(javaslang.control.Try) QuickSearch(nl.knaw.huygens.timbuctoo.core.dto.QuickSearch) RdfProperty(nl.knaw.huygens.timbuctoo.core.dto.rdf.RdfProperty) Matchers.nullValue(org.hamcrest.Matchers.nullValue) TestGraphBuilder.newGraph(nl.knaw.huygens.timbuctoo.util.TestGraphBuilder.newGraph) HAS_ENTITY_NODE_RELATION_NAME(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.HAS_ENTITY_NODE_RELATION_NAME) QuickSearchResult(nl.knaw.huygens.timbuctoo.core.dto.QuickSearchResult) Matchers.allOf(org.hamcrest.Matchers.allOf) TinkerPopGraphManager(nl.knaw.huygens.timbuctoo.server.TinkerPopGraphManager) COLLECTION_NAME_PROPERTY_NAME(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.COLLECTION_NAME_PROPERTY_NAME) ValueTypeInUse(nl.knaw.huygens.timbuctoo.core.dto.rdf.ValueTypeInUse) ChangeListener(nl.knaw.huygens.timbuctoo.database.tinkerpop.changelistener.ChangeListener) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) ReadEntity(nl.knaw.huygens.timbuctoo.core.dto.ReadEntity) Element(org.apache.tinkerpop.gremlin.structure.Element) Matchers.contains(org.hamcrest.Matchers.contains) Vre(nl.knaw.huygens.timbuctoo.model.vre.Vre) Matchers.is(org.hamcrest.Matchers.is) TinkerPopOperationsStubs.forGraphWrapperAndMappings(nl.knaw.huygens.timbuctoo.database.tinkerpop.TinkerPopOperationsStubs.forGraphWrapperAndMappings) CreateEntity(nl.knaw.huygens.timbuctoo.core.dto.CreateEntity) Matchers.containsString(org.hamcrest.Matchers.containsString) Mockito.mock(org.mockito.Mockito.mock) LabelP(org.apache.tinkerpop.gremlin.neo4j.process.traversal.LabelP) RAW_PROPERTY_EDGE_NAME(nl.knaw.huygens.timbuctoo.database.tinkerpop.TinkerpopSaver.RAW_PROPERTY_EDGE_NAME) Matchers.anyString(org.mockito.Matchers.anyString) ArrayList(java.util.ArrayList) Matchers.hasProperty(org.hamcrest.Matchers.hasProperty) CreateRelation(nl.knaw.huygens.timbuctoo.core.dto.CreateRelation) Lists(com.google.common.collect.Lists) TinkerPopOperationsStubs.forGraphMappingsAndChangeListener(nl.knaw.huygens.timbuctoo.database.tinkerpop.TinkerPopOperationsStubs.forGraphMappingsAndChangeListener) HAS_ENTITY_RELATION_NAME(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.HAS_ENTITY_RELATION_NAME) TinkerPopOperationsStubs.forGraphWrapper(nl.knaw.huygens.timbuctoo.database.tinkerpop.TinkerPopOperationsStubs.forGraphWrapper) Matchers.hasSize(org.hamcrest.Matchers.hasSize) OptionalPresentMatcher.present(nl.knaw.huygens.hamcrest.OptionalPresentMatcher.present) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) RelationType(nl.knaw.huygens.timbuctoo.core.dto.RelationType) DataStream(nl.knaw.huygens.timbuctoo.core.dto.DataStream) Test(org.junit.Test) IOException(java.io.IOException) T(org.apache.tinkerpop.gremlin.structure.T) Direction(org.apache.tinkerpop.gremlin.structure.Direction) Database(nl.knaw.huygens.timbuctoo.rdf.Database) HAS_DISPLAY_NAME_RELATION_NAME(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.HAS_DISPLAY_NAME_RELATION_NAME) Matchers.sameInstance(org.hamcrest.Matchers.sameInstance) RDF_URI_PROP(nl.knaw.huygens.timbuctoo.rdf.Database.RDF_URI_PROP) GraphReadUtils.getProp(nl.knaw.huygens.timbuctoo.model.GraphReadUtils.getProp) Change(nl.knaw.huygens.timbuctoo.model.Change) P.within(org.apache.tinkerpop.gremlin.process.traversal.P.within) SameJSONAs.sameJSONAs(uk.co.datumedge.hamcrest.json.SameJSONAs.sameJSONAs) StreamIterator.stream(nl.knaw.huygens.timbuctoo.util.StreamIterator.stream) PropertyTypes.localProperty(nl.knaw.huygens.timbuctoo.model.properties.PropertyTypes.localProperty) Graph(org.apache.tinkerpop.gremlin.structure.Graph) RDF_SYNONYM_PROP(nl.knaw.huygens.timbuctoo.rdf.Database.RDF_SYNONYM_PROP) StringProperty(nl.knaw.huygens.timbuctoo.core.dto.property.StringProperty) VertexMatcher.likeVertex(nl.knaw.huygens.timbuctoo.util.VertexMatcher.likeVertex) MockitoHamcrest.argThat(org.mockito.hamcrest.MockitoHamcrest.argThat) RelationNotPossibleException(nl.knaw.huygens.timbuctoo.core.RelationNotPossibleException) URI(java.net.URI) IS_RELATION_COLLECTION_PROPERTY_NAME(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.IS_RELATION_COLLECTION_PROPERTY_NAME) org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.has(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.has) CollectionBuilder(nl.knaw.huygens.timbuctoo.core.dto.dataset.CollectionBuilder) EntityFinisherHelper(nl.knaw.huygens.timbuctoo.core.EntityFinisherHelper) NotFoundException(nl.knaw.huygens.timbuctoo.core.NotFoundException) UUID(java.util.UUID) Instant(java.time.Instant) RAW_COLLECTION_NAME_PROPERTY_NAME(nl.knaw.huygens.timbuctoo.database.tinkerpop.TinkerpopSaver.RAW_COLLECTION_NAME_PROPERTY_NAME) UpdateEntity(nl.knaw.huygens.timbuctoo.core.dto.UpdateEntity) List(java.util.List) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) Matchers.equalTo(org.hamcrest.Matchers.equalTo) Optional(java.util.Optional) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) JsonBuilder.jsnO(nl.knaw.huygens.timbuctoo.util.JsonBuilder.jsnO) Collection(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection) TinkerPopOperationsStubs.forGraphMappingsAndIndex(nl.knaw.huygens.timbuctoo.database.tinkerpop.TinkerPopOperationsStubs.forGraphMappingsAndIndex) VERSION_OF(nl.knaw.huygens.timbuctoo.database.tinkerpop.VertexDuplicator.VERSION_OF) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) VreStubs.minimalCorrectVre(nl.knaw.huygens.timbuctoo.model.vre.VreStubs.minimalCorrectVre) CollectionNameHelper.defaultEntityTypeName(nl.knaw.huygens.timbuctoo.core.CollectionNameHelper.defaultEntityTypeName) VresBuilder(nl.knaw.huygens.timbuctoo.model.vre.vres.VresBuilder) JsonBuilder.jsn(nl.knaw.huygens.timbuctoo.util.JsonBuilder.jsn) Edge(org.apache.tinkerpop.gremlin.structure.Edge) RdfReadProperty(nl.knaw.huygens.timbuctoo.core.dto.rdf.RdfReadProperty) Matchers.empty(org.hamcrest.Matchers.empty) PredicateInUse(nl.knaw.huygens.timbuctoo.core.dto.rdf.PredicateInUse) TimProperty(nl.knaw.huygens.timbuctoo.core.dto.property.TimProperty) RAW_ITEM_EDGE_NAME(nl.knaw.huygens.timbuctoo.database.tinkerpop.TinkerpopSaver.RAW_ITEM_EDGE_NAME) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ENTITY_TYPE_NAME_PROPERTY_NAME(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.ENTITY_TYPE_NAME_PROPERTY_NAME) Mockito.when(org.mockito.Mockito.when) PropertyNameHelper.createPropName(nl.knaw.huygens.timbuctoo.database.tinkerpop.PropertyNameHelper.createPropName) Vres(nl.knaw.huygens.timbuctoo.model.vre.Vres) Entity(nl.knaw.huygens.timbuctoo.rdf.Entity) Mockito.verify(org.mockito.Mockito.verify) Collectors.toList(java.util.stream.Collectors.toList) Matchers.emptyIterable(org.hamcrest.Matchers.emptyIterable) EdgeMatcher.likeEdge(nl.knaw.huygens.timbuctoo.util.EdgeMatcher.likeEdge) HAS_COLLECTION_RELATION_NAME(nl.knaw.huygens.timbuctoo.model.vre.Vre.HAS_COLLECTION_RELATION_NAME) TinkerPopOperationsStubs.forGraphMappingsListenerAndIndex(nl.knaw.huygens.timbuctoo.database.tinkerpop.TinkerPopOperationsStubs.forGraphMappingsListenerAndIndex) HAS_PROPERTY_RELATION_NAME(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.HAS_PROPERTY_RELATION_NAME) RAW_COLLECTION_EDGE_NAME(nl.knaw.huygens.timbuctoo.database.tinkerpop.TinkerpopSaver.RAW_COLLECTION_EDGE_NAME) UpdateRelation(nl.knaw.huygens.timbuctoo.core.dto.UpdateRelation) Vres(nl.knaw.huygens.timbuctoo.model.vre.Vres) TinkerPopGraphManager(nl.knaw.huygens.timbuctoo.server.TinkerPopGraphManager) CreateCollection(nl.knaw.huygens.timbuctoo.core.dto.CreateCollection) Collection(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection) Matchers.containsString(org.hamcrest.Matchers.containsString) Matchers.anyString(org.mockito.Matchers.anyString) Change(nl.knaw.huygens.timbuctoo.model.Change) UUID(java.util.UUID) Test(org.junit.Test)

Example 2 with Change

use of nl.knaw.huygens.timbuctoo.model.Change in project timbuctoo by HuygensING.

the class TinkerPopOperationsTest method replaceEntityPreparesABackupCopyAfterMakingTheChanges.

@Test
public void replaceEntityPreparesABackupCopyAfterMakingTheChanges() 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);
    List<TimProperty<?>> properties = Lists.newArrayList(new StringProperty("prop1", "newValue"));
    UpdateEntity updateEntity = new UpdateEntity(id, properties, 1);
    long timeStamp = Instant.now().toEpochMilli();
    updateEntity.setModified(new Change(timeStamp, "userId", null));
    Vertex beforeUpdate = graphManager.getGraph().traversal().V().has("tim_id", id.toString()).has("isLatest", true).next();
    instance.replaceEntity(collection, updateEntity);
    Vertex afterUpdate = graphManager.getGraph().traversal().V().has("tim_id", id.toString()).has("isLatest", true).next();
    assertThat(afterUpdate.id(), is(not(beforeUpdate.id())));
    assertThat(afterUpdate.edges(Direction.IN).next().outVertex().id(), is(beforeUpdate.id()));
}
Also used : ImmutableCreateProperty(nl.knaw.huygens.timbuctoo.core.dto.rdf.ImmutableCreateProperty) AlreadyUpdatedException(nl.knaw.huygens.timbuctoo.core.AlreadyUpdatedException) NodeFactory(org.apache.jena.graph.NodeFactory) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) CreateCollection(nl.knaw.huygens.timbuctoo.core.dto.CreateCollection) Matchers.not(org.hamcrest.Matchers.not) CreateEntityStubs.withProperties(nl.knaw.huygens.timbuctoo.core.dto.CreateEntityStubs.withProperties) Try(javaslang.control.Try) QuickSearch(nl.knaw.huygens.timbuctoo.core.dto.QuickSearch) RdfProperty(nl.knaw.huygens.timbuctoo.core.dto.rdf.RdfProperty) Matchers.nullValue(org.hamcrest.Matchers.nullValue) TestGraphBuilder.newGraph(nl.knaw.huygens.timbuctoo.util.TestGraphBuilder.newGraph) HAS_ENTITY_NODE_RELATION_NAME(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.HAS_ENTITY_NODE_RELATION_NAME) QuickSearchResult(nl.knaw.huygens.timbuctoo.core.dto.QuickSearchResult) Matchers.allOf(org.hamcrest.Matchers.allOf) TinkerPopGraphManager(nl.knaw.huygens.timbuctoo.server.TinkerPopGraphManager) COLLECTION_NAME_PROPERTY_NAME(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.COLLECTION_NAME_PROPERTY_NAME) ValueTypeInUse(nl.knaw.huygens.timbuctoo.core.dto.rdf.ValueTypeInUse) ChangeListener(nl.knaw.huygens.timbuctoo.database.tinkerpop.changelistener.ChangeListener) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) ReadEntity(nl.knaw.huygens.timbuctoo.core.dto.ReadEntity) Element(org.apache.tinkerpop.gremlin.structure.Element) Matchers.contains(org.hamcrest.Matchers.contains) Vre(nl.knaw.huygens.timbuctoo.model.vre.Vre) Matchers.is(org.hamcrest.Matchers.is) TinkerPopOperationsStubs.forGraphWrapperAndMappings(nl.knaw.huygens.timbuctoo.database.tinkerpop.TinkerPopOperationsStubs.forGraphWrapperAndMappings) CreateEntity(nl.knaw.huygens.timbuctoo.core.dto.CreateEntity) Matchers.containsString(org.hamcrest.Matchers.containsString) Mockito.mock(org.mockito.Mockito.mock) LabelP(org.apache.tinkerpop.gremlin.neo4j.process.traversal.LabelP) RAW_PROPERTY_EDGE_NAME(nl.knaw.huygens.timbuctoo.database.tinkerpop.TinkerpopSaver.RAW_PROPERTY_EDGE_NAME) Matchers.anyString(org.mockito.Matchers.anyString) ArrayList(java.util.ArrayList) Matchers.hasProperty(org.hamcrest.Matchers.hasProperty) CreateRelation(nl.knaw.huygens.timbuctoo.core.dto.CreateRelation) Lists(com.google.common.collect.Lists) TinkerPopOperationsStubs.forGraphMappingsAndChangeListener(nl.knaw.huygens.timbuctoo.database.tinkerpop.TinkerPopOperationsStubs.forGraphMappingsAndChangeListener) HAS_ENTITY_RELATION_NAME(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.HAS_ENTITY_RELATION_NAME) TinkerPopOperationsStubs.forGraphWrapper(nl.knaw.huygens.timbuctoo.database.tinkerpop.TinkerPopOperationsStubs.forGraphWrapper) Matchers.hasSize(org.hamcrest.Matchers.hasSize) OptionalPresentMatcher.present(nl.knaw.huygens.hamcrest.OptionalPresentMatcher.present) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) RelationType(nl.knaw.huygens.timbuctoo.core.dto.RelationType) DataStream(nl.knaw.huygens.timbuctoo.core.dto.DataStream) Test(org.junit.Test) IOException(java.io.IOException) T(org.apache.tinkerpop.gremlin.structure.T) Direction(org.apache.tinkerpop.gremlin.structure.Direction) Database(nl.knaw.huygens.timbuctoo.rdf.Database) HAS_DISPLAY_NAME_RELATION_NAME(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.HAS_DISPLAY_NAME_RELATION_NAME) Matchers.sameInstance(org.hamcrest.Matchers.sameInstance) RDF_URI_PROP(nl.knaw.huygens.timbuctoo.rdf.Database.RDF_URI_PROP) GraphReadUtils.getProp(nl.knaw.huygens.timbuctoo.model.GraphReadUtils.getProp) Change(nl.knaw.huygens.timbuctoo.model.Change) P.within(org.apache.tinkerpop.gremlin.process.traversal.P.within) SameJSONAs.sameJSONAs(uk.co.datumedge.hamcrest.json.SameJSONAs.sameJSONAs) StreamIterator.stream(nl.knaw.huygens.timbuctoo.util.StreamIterator.stream) PropertyTypes.localProperty(nl.knaw.huygens.timbuctoo.model.properties.PropertyTypes.localProperty) Graph(org.apache.tinkerpop.gremlin.structure.Graph) RDF_SYNONYM_PROP(nl.knaw.huygens.timbuctoo.rdf.Database.RDF_SYNONYM_PROP) StringProperty(nl.knaw.huygens.timbuctoo.core.dto.property.StringProperty) VertexMatcher.likeVertex(nl.knaw.huygens.timbuctoo.util.VertexMatcher.likeVertex) MockitoHamcrest.argThat(org.mockito.hamcrest.MockitoHamcrest.argThat) RelationNotPossibleException(nl.knaw.huygens.timbuctoo.core.RelationNotPossibleException) URI(java.net.URI) IS_RELATION_COLLECTION_PROPERTY_NAME(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.IS_RELATION_COLLECTION_PROPERTY_NAME) org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.has(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.has) CollectionBuilder(nl.knaw.huygens.timbuctoo.core.dto.dataset.CollectionBuilder) EntityFinisherHelper(nl.knaw.huygens.timbuctoo.core.EntityFinisherHelper) NotFoundException(nl.knaw.huygens.timbuctoo.core.NotFoundException) UUID(java.util.UUID) Instant(java.time.Instant) RAW_COLLECTION_NAME_PROPERTY_NAME(nl.knaw.huygens.timbuctoo.database.tinkerpop.TinkerpopSaver.RAW_COLLECTION_NAME_PROPERTY_NAME) UpdateEntity(nl.knaw.huygens.timbuctoo.core.dto.UpdateEntity) List(java.util.List) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) Matchers.equalTo(org.hamcrest.Matchers.equalTo) Optional(java.util.Optional) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) JsonBuilder.jsnO(nl.knaw.huygens.timbuctoo.util.JsonBuilder.jsnO) Collection(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection) TinkerPopOperationsStubs.forGraphMappingsAndIndex(nl.knaw.huygens.timbuctoo.database.tinkerpop.TinkerPopOperationsStubs.forGraphMappingsAndIndex) VERSION_OF(nl.knaw.huygens.timbuctoo.database.tinkerpop.VertexDuplicator.VERSION_OF) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) VreStubs.minimalCorrectVre(nl.knaw.huygens.timbuctoo.model.vre.VreStubs.minimalCorrectVre) CollectionNameHelper.defaultEntityTypeName(nl.knaw.huygens.timbuctoo.core.CollectionNameHelper.defaultEntityTypeName) VresBuilder(nl.knaw.huygens.timbuctoo.model.vre.vres.VresBuilder) JsonBuilder.jsn(nl.knaw.huygens.timbuctoo.util.JsonBuilder.jsn) Edge(org.apache.tinkerpop.gremlin.structure.Edge) RdfReadProperty(nl.knaw.huygens.timbuctoo.core.dto.rdf.RdfReadProperty) Matchers.empty(org.hamcrest.Matchers.empty) PredicateInUse(nl.knaw.huygens.timbuctoo.core.dto.rdf.PredicateInUse) TimProperty(nl.knaw.huygens.timbuctoo.core.dto.property.TimProperty) RAW_ITEM_EDGE_NAME(nl.knaw.huygens.timbuctoo.database.tinkerpop.TinkerpopSaver.RAW_ITEM_EDGE_NAME) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ENTITY_TYPE_NAME_PROPERTY_NAME(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.ENTITY_TYPE_NAME_PROPERTY_NAME) Mockito.when(org.mockito.Mockito.when) PropertyNameHelper.createPropName(nl.knaw.huygens.timbuctoo.database.tinkerpop.PropertyNameHelper.createPropName) Vres(nl.knaw.huygens.timbuctoo.model.vre.Vres) Entity(nl.knaw.huygens.timbuctoo.rdf.Entity) Mockito.verify(org.mockito.Mockito.verify) Collectors.toList(java.util.stream.Collectors.toList) Matchers.emptyIterable(org.hamcrest.Matchers.emptyIterable) EdgeMatcher.likeEdge(nl.knaw.huygens.timbuctoo.util.EdgeMatcher.likeEdge) HAS_COLLECTION_RELATION_NAME(nl.knaw.huygens.timbuctoo.model.vre.Vre.HAS_COLLECTION_RELATION_NAME) TinkerPopOperationsStubs.forGraphMappingsListenerAndIndex(nl.knaw.huygens.timbuctoo.database.tinkerpop.TinkerPopOperationsStubs.forGraphMappingsListenerAndIndex) HAS_PROPERTY_RELATION_NAME(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.HAS_PROPERTY_RELATION_NAME) RAW_COLLECTION_EDGE_NAME(nl.knaw.huygens.timbuctoo.database.tinkerpop.TinkerpopSaver.RAW_COLLECTION_EDGE_NAME) UpdateRelation(nl.knaw.huygens.timbuctoo.core.dto.UpdateRelation) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) VertexMatcher.likeVertex(nl.knaw.huygens.timbuctoo.util.VertexMatcher.likeVertex) Vres(nl.knaw.huygens.timbuctoo.model.vre.Vres) UpdateEntity(nl.knaw.huygens.timbuctoo.core.dto.UpdateEntity) StringProperty(nl.knaw.huygens.timbuctoo.core.dto.property.StringProperty) Change(nl.knaw.huygens.timbuctoo.model.Change) TinkerPopGraphManager(nl.knaw.huygens.timbuctoo.server.TinkerPopGraphManager) TimProperty(nl.knaw.huygens.timbuctoo.core.dto.property.TimProperty) CreateCollection(nl.knaw.huygens.timbuctoo.core.dto.CreateCollection) Collection(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection) UUID(java.util.UUID) Test(org.junit.Test)

Example 3 with Change

use of nl.knaw.huygens.timbuctoo.model.Change in project timbuctoo by HuygensING.

the class TinkerPopOperationsTest method replaceEntityThrowsAnAlreadyUpdatedExceptionWhenTheRevDoesNotMatch.

@Test(expected = AlreadyUpdatedException.class)
public void replaceEntityThrowsAnAlreadyUpdatedExceptionWhenTheRevDoesNotMatch() 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", 2)).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);
}
Also used : ImmutableCreateProperty(nl.knaw.huygens.timbuctoo.core.dto.rdf.ImmutableCreateProperty) AlreadyUpdatedException(nl.knaw.huygens.timbuctoo.core.AlreadyUpdatedException) NodeFactory(org.apache.jena.graph.NodeFactory) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) CreateCollection(nl.knaw.huygens.timbuctoo.core.dto.CreateCollection) Matchers.not(org.hamcrest.Matchers.not) CreateEntityStubs.withProperties(nl.knaw.huygens.timbuctoo.core.dto.CreateEntityStubs.withProperties) Try(javaslang.control.Try) QuickSearch(nl.knaw.huygens.timbuctoo.core.dto.QuickSearch) RdfProperty(nl.knaw.huygens.timbuctoo.core.dto.rdf.RdfProperty) Matchers.nullValue(org.hamcrest.Matchers.nullValue) TestGraphBuilder.newGraph(nl.knaw.huygens.timbuctoo.util.TestGraphBuilder.newGraph) HAS_ENTITY_NODE_RELATION_NAME(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.HAS_ENTITY_NODE_RELATION_NAME) QuickSearchResult(nl.knaw.huygens.timbuctoo.core.dto.QuickSearchResult) Matchers.allOf(org.hamcrest.Matchers.allOf) TinkerPopGraphManager(nl.knaw.huygens.timbuctoo.server.TinkerPopGraphManager) COLLECTION_NAME_PROPERTY_NAME(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.COLLECTION_NAME_PROPERTY_NAME) ValueTypeInUse(nl.knaw.huygens.timbuctoo.core.dto.rdf.ValueTypeInUse) ChangeListener(nl.knaw.huygens.timbuctoo.database.tinkerpop.changelistener.ChangeListener) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) ReadEntity(nl.knaw.huygens.timbuctoo.core.dto.ReadEntity) Element(org.apache.tinkerpop.gremlin.structure.Element) Matchers.contains(org.hamcrest.Matchers.contains) Vre(nl.knaw.huygens.timbuctoo.model.vre.Vre) Matchers.is(org.hamcrest.Matchers.is) TinkerPopOperationsStubs.forGraphWrapperAndMappings(nl.knaw.huygens.timbuctoo.database.tinkerpop.TinkerPopOperationsStubs.forGraphWrapperAndMappings) CreateEntity(nl.knaw.huygens.timbuctoo.core.dto.CreateEntity) Matchers.containsString(org.hamcrest.Matchers.containsString) Mockito.mock(org.mockito.Mockito.mock) LabelP(org.apache.tinkerpop.gremlin.neo4j.process.traversal.LabelP) RAW_PROPERTY_EDGE_NAME(nl.knaw.huygens.timbuctoo.database.tinkerpop.TinkerpopSaver.RAW_PROPERTY_EDGE_NAME) Matchers.anyString(org.mockito.Matchers.anyString) ArrayList(java.util.ArrayList) Matchers.hasProperty(org.hamcrest.Matchers.hasProperty) CreateRelation(nl.knaw.huygens.timbuctoo.core.dto.CreateRelation) Lists(com.google.common.collect.Lists) TinkerPopOperationsStubs.forGraphMappingsAndChangeListener(nl.knaw.huygens.timbuctoo.database.tinkerpop.TinkerPopOperationsStubs.forGraphMappingsAndChangeListener) HAS_ENTITY_RELATION_NAME(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.HAS_ENTITY_RELATION_NAME) TinkerPopOperationsStubs.forGraphWrapper(nl.knaw.huygens.timbuctoo.database.tinkerpop.TinkerPopOperationsStubs.forGraphWrapper) Matchers.hasSize(org.hamcrest.Matchers.hasSize) OptionalPresentMatcher.present(nl.knaw.huygens.hamcrest.OptionalPresentMatcher.present) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) RelationType(nl.knaw.huygens.timbuctoo.core.dto.RelationType) DataStream(nl.knaw.huygens.timbuctoo.core.dto.DataStream) Test(org.junit.Test) IOException(java.io.IOException) T(org.apache.tinkerpop.gremlin.structure.T) Direction(org.apache.tinkerpop.gremlin.structure.Direction) Database(nl.knaw.huygens.timbuctoo.rdf.Database) HAS_DISPLAY_NAME_RELATION_NAME(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.HAS_DISPLAY_NAME_RELATION_NAME) Matchers.sameInstance(org.hamcrest.Matchers.sameInstance) RDF_URI_PROP(nl.knaw.huygens.timbuctoo.rdf.Database.RDF_URI_PROP) GraphReadUtils.getProp(nl.knaw.huygens.timbuctoo.model.GraphReadUtils.getProp) Change(nl.knaw.huygens.timbuctoo.model.Change) P.within(org.apache.tinkerpop.gremlin.process.traversal.P.within) SameJSONAs.sameJSONAs(uk.co.datumedge.hamcrest.json.SameJSONAs.sameJSONAs) StreamIterator.stream(nl.knaw.huygens.timbuctoo.util.StreamIterator.stream) PropertyTypes.localProperty(nl.knaw.huygens.timbuctoo.model.properties.PropertyTypes.localProperty) Graph(org.apache.tinkerpop.gremlin.structure.Graph) RDF_SYNONYM_PROP(nl.knaw.huygens.timbuctoo.rdf.Database.RDF_SYNONYM_PROP) StringProperty(nl.knaw.huygens.timbuctoo.core.dto.property.StringProperty) VertexMatcher.likeVertex(nl.knaw.huygens.timbuctoo.util.VertexMatcher.likeVertex) MockitoHamcrest.argThat(org.mockito.hamcrest.MockitoHamcrest.argThat) RelationNotPossibleException(nl.knaw.huygens.timbuctoo.core.RelationNotPossibleException) URI(java.net.URI) IS_RELATION_COLLECTION_PROPERTY_NAME(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.IS_RELATION_COLLECTION_PROPERTY_NAME) org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.has(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.has) CollectionBuilder(nl.knaw.huygens.timbuctoo.core.dto.dataset.CollectionBuilder) EntityFinisherHelper(nl.knaw.huygens.timbuctoo.core.EntityFinisherHelper) NotFoundException(nl.knaw.huygens.timbuctoo.core.NotFoundException) UUID(java.util.UUID) Instant(java.time.Instant) RAW_COLLECTION_NAME_PROPERTY_NAME(nl.knaw.huygens.timbuctoo.database.tinkerpop.TinkerpopSaver.RAW_COLLECTION_NAME_PROPERTY_NAME) UpdateEntity(nl.knaw.huygens.timbuctoo.core.dto.UpdateEntity) List(java.util.List) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) Matchers.equalTo(org.hamcrest.Matchers.equalTo) Optional(java.util.Optional) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) JsonBuilder.jsnO(nl.knaw.huygens.timbuctoo.util.JsonBuilder.jsnO) Collection(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection) TinkerPopOperationsStubs.forGraphMappingsAndIndex(nl.knaw.huygens.timbuctoo.database.tinkerpop.TinkerPopOperationsStubs.forGraphMappingsAndIndex) VERSION_OF(nl.knaw.huygens.timbuctoo.database.tinkerpop.VertexDuplicator.VERSION_OF) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) VreStubs.minimalCorrectVre(nl.knaw.huygens.timbuctoo.model.vre.VreStubs.minimalCorrectVre) CollectionNameHelper.defaultEntityTypeName(nl.knaw.huygens.timbuctoo.core.CollectionNameHelper.defaultEntityTypeName) VresBuilder(nl.knaw.huygens.timbuctoo.model.vre.vres.VresBuilder) JsonBuilder.jsn(nl.knaw.huygens.timbuctoo.util.JsonBuilder.jsn) Edge(org.apache.tinkerpop.gremlin.structure.Edge) RdfReadProperty(nl.knaw.huygens.timbuctoo.core.dto.rdf.RdfReadProperty) Matchers.empty(org.hamcrest.Matchers.empty) PredicateInUse(nl.knaw.huygens.timbuctoo.core.dto.rdf.PredicateInUse) TimProperty(nl.knaw.huygens.timbuctoo.core.dto.property.TimProperty) RAW_ITEM_EDGE_NAME(nl.knaw.huygens.timbuctoo.database.tinkerpop.TinkerpopSaver.RAW_ITEM_EDGE_NAME) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ENTITY_TYPE_NAME_PROPERTY_NAME(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.ENTITY_TYPE_NAME_PROPERTY_NAME) Mockito.when(org.mockito.Mockito.when) PropertyNameHelper.createPropName(nl.knaw.huygens.timbuctoo.database.tinkerpop.PropertyNameHelper.createPropName) Vres(nl.knaw.huygens.timbuctoo.model.vre.Vres) Entity(nl.knaw.huygens.timbuctoo.rdf.Entity) Mockito.verify(org.mockito.Mockito.verify) Collectors.toList(java.util.stream.Collectors.toList) Matchers.emptyIterable(org.hamcrest.Matchers.emptyIterable) EdgeMatcher.likeEdge(nl.knaw.huygens.timbuctoo.util.EdgeMatcher.likeEdge) HAS_COLLECTION_RELATION_NAME(nl.knaw.huygens.timbuctoo.model.vre.Vre.HAS_COLLECTION_RELATION_NAME) TinkerPopOperationsStubs.forGraphMappingsListenerAndIndex(nl.knaw.huygens.timbuctoo.database.tinkerpop.TinkerPopOperationsStubs.forGraphMappingsListenerAndIndex) HAS_PROPERTY_RELATION_NAME(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.HAS_PROPERTY_RELATION_NAME) RAW_COLLECTION_EDGE_NAME(nl.knaw.huygens.timbuctoo.database.tinkerpop.TinkerpopSaver.RAW_COLLECTION_EDGE_NAME) UpdateRelation(nl.knaw.huygens.timbuctoo.core.dto.UpdateRelation) Vres(nl.knaw.huygens.timbuctoo.model.vre.Vres) TinkerPopGraphManager(nl.knaw.huygens.timbuctoo.server.TinkerPopGraphManager) UpdateEntity(nl.knaw.huygens.timbuctoo.core.dto.UpdateEntity) CreateCollection(nl.knaw.huygens.timbuctoo.core.dto.CreateCollection) Collection(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection) Change(nl.knaw.huygens.timbuctoo.model.Change) UUID(java.util.UUID) Test(org.junit.Test)

Example 4 with Change

use of nl.knaw.huygens.timbuctoo.model.Change in project timbuctoo by HuygensING.

the class TinkerPopOperationsTest method replaceRelationUpdatesTheModifiedInformation.

@Test
public void replaceRelationUpdatesTheModifiedInformation() throws Exception {
    Vres vres = createConfiguration();
    Collection collection = vres.getCollection("testrelations").get();
    UUID typeId = UUID.randomUUID();
    UUID sourceId = UUID.randomUUID();
    UUID targetId = UUID.randomUUID();
    UUID relId = 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).withOutgoingRelation("regularName", "otherVertex", r -> r.withTim_id(relId).withAccepted("testrelation", true).withTypeId(typeId).withRev(1).addType("testrelation"))).withVertex("otherVertex", v -> v.withTimId(targetId.toString()).withProperty("rev", 1).withVre("test").withType("thing").withProperty("isLatest", true)).wrap();
    IndexHandler indexHandler = mock(IndexHandler.class);
    when(indexHandler.findEdgeById(relId)).thenReturn(Optional.of(graphManager.getGraph().traversal().E().has("tim_id", relId.toString()).next()));
    TinkerPopOperations instance = forGraphMappingsAndIndex(graphManager, vres, indexHandler);
    UpdateRelation updateRelation = new UpdateRelation(relId, 1, false);
    long timeStamp = Instant.now().toEpochMilli();
    String userId = "userId";
    updateRelation.setModified(new Change(timeStamp, userId, null));
    instance.replaceRelation(collection, updateRelation);
    Edge newEdge = graphManager.getGraph().traversal().E().has("tim_id", relId.toString()).has("isLatest", true).next();
    assertThat(getModificationInfo("modified", newEdge), is(jsnO("timeStamp", jsn(timeStamp), "userId", jsn(userId))));
}
Also used : ImmutableCreateProperty(nl.knaw.huygens.timbuctoo.core.dto.rdf.ImmutableCreateProperty) AlreadyUpdatedException(nl.knaw.huygens.timbuctoo.core.AlreadyUpdatedException) NodeFactory(org.apache.jena.graph.NodeFactory) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) CreateCollection(nl.knaw.huygens.timbuctoo.core.dto.CreateCollection) Matchers.not(org.hamcrest.Matchers.not) CreateEntityStubs.withProperties(nl.knaw.huygens.timbuctoo.core.dto.CreateEntityStubs.withProperties) Try(javaslang.control.Try) QuickSearch(nl.knaw.huygens.timbuctoo.core.dto.QuickSearch) RdfProperty(nl.knaw.huygens.timbuctoo.core.dto.rdf.RdfProperty) Matchers.nullValue(org.hamcrest.Matchers.nullValue) TestGraphBuilder.newGraph(nl.knaw.huygens.timbuctoo.util.TestGraphBuilder.newGraph) HAS_ENTITY_NODE_RELATION_NAME(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.HAS_ENTITY_NODE_RELATION_NAME) QuickSearchResult(nl.knaw.huygens.timbuctoo.core.dto.QuickSearchResult) Matchers.allOf(org.hamcrest.Matchers.allOf) TinkerPopGraphManager(nl.knaw.huygens.timbuctoo.server.TinkerPopGraphManager) COLLECTION_NAME_PROPERTY_NAME(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.COLLECTION_NAME_PROPERTY_NAME) ValueTypeInUse(nl.knaw.huygens.timbuctoo.core.dto.rdf.ValueTypeInUse) ChangeListener(nl.knaw.huygens.timbuctoo.database.tinkerpop.changelistener.ChangeListener) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) ReadEntity(nl.knaw.huygens.timbuctoo.core.dto.ReadEntity) Element(org.apache.tinkerpop.gremlin.structure.Element) Matchers.contains(org.hamcrest.Matchers.contains) Vre(nl.knaw.huygens.timbuctoo.model.vre.Vre) Matchers.is(org.hamcrest.Matchers.is) TinkerPopOperationsStubs.forGraphWrapperAndMappings(nl.knaw.huygens.timbuctoo.database.tinkerpop.TinkerPopOperationsStubs.forGraphWrapperAndMappings) CreateEntity(nl.knaw.huygens.timbuctoo.core.dto.CreateEntity) Matchers.containsString(org.hamcrest.Matchers.containsString) Mockito.mock(org.mockito.Mockito.mock) LabelP(org.apache.tinkerpop.gremlin.neo4j.process.traversal.LabelP) RAW_PROPERTY_EDGE_NAME(nl.knaw.huygens.timbuctoo.database.tinkerpop.TinkerpopSaver.RAW_PROPERTY_EDGE_NAME) Matchers.anyString(org.mockito.Matchers.anyString) ArrayList(java.util.ArrayList) Matchers.hasProperty(org.hamcrest.Matchers.hasProperty) CreateRelation(nl.knaw.huygens.timbuctoo.core.dto.CreateRelation) Lists(com.google.common.collect.Lists) TinkerPopOperationsStubs.forGraphMappingsAndChangeListener(nl.knaw.huygens.timbuctoo.database.tinkerpop.TinkerPopOperationsStubs.forGraphMappingsAndChangeListener) HAS_ENTITY_RELATION_NAME(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.HAS_ENTITY_RELATION_NAME) TinkerPopOperationsStubs.forGraphWrapper(nl.knaw.huygens.timbuctoo.database.tinkerpop.TinkerPopOperationsStubs.forGraphWrapper) Matchers.hasSize(org.hamcrest.Matchers.hasSize) OptionalPresentMatcher.present(nl.knaw.huygens.hamcrest.OptionalPresentMatcher.present) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) RelationType(nl.knaw.huygens.timbuctoo.core.dto.RelationType) DataStream(nl.knaw.huygens.timbuctoo.core.dto.DataStream) Test(org.junit.Test) IOException(java.io.IOException) T(org.apache.tinkerpop.gremlin.structure.T) Direction(org.apache.tinkerpop.gremlin.structure.Direction) Database(nl.knaw.huygens.timbuctoo.rdf.Database) HAS_DISPLAY_NAME_RELATION_NAME(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.HAS_DISPLAY_NAME_RELATION_NAME) Matchers.sameInstance(org.hamcrest.Matchers.sameInstance) RDF_URI_PROP(nl.knaw.huygens.timbuctoo.rdf.Database.RDF_URI_PROP) GraphReadUtils.getProp(nl.knaw.huygens.timbuctoo.model.GraphReadUtils.getProp) Change(nl.knaw.huygens.timbuctoo.model.Change) P.within(org.apache.tinkerpop.gremlin.process.traversal.P.within) SameJSONAs.sameJSONAs(uk.co.datumedge.hamcrest.json.SameJSONAs.sameJSONAs) StreamIterator.stream(nl.knaw.huygens.timbuctoo.util.StreamIterator.stream) PropertyTypes.localProperty(nl.knaw.huygens.timbuctoo.model.properties.PropertyTypes.localProperty) Graph(org.apache.tinkerpop.gremlin.structure.Graph) RDF_SYNONYM_PROP(nl.knaw.huygens.timbuctoo.rdf.Database.RDF_SYNONYM_PROP) StringProperty(nl.knaw.huygens.timbuctoo.core.dto.property.StringProperty) VertexMatcher.likeVertex(nl.knaw.huygens.timbuctoo.util.VertexMatcher.likeVertex) MockitoHamcrest.argThat(org.mockito.hamcrest.MockitoHamcrest.argThat) RelationNotPossibleException(nl.knaw.huygens.timbuctoo.core.RelationNotPossibleException) URI(java.net.URI) IS_RELATION_COLLECTION_PROPERTY_NAME(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.IS_RELATION_COLLECTION_PROPERTY_NAME) org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.has(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.has) CollectionBuilder(nl.knaw.huygens.timbuctoo.core.dto.dataset.CollectionBuilder) EntityFinisherHelper(nl.knaw.huygens.timbuctoo.core.EntityFinisherHelper) NotFoundException(nl.knaw.huygens.timbuctoo.core.NotFoundException) UUID(java.util.UUID) Instant(java.time.Instant) RAW_COLLECTION_NAME_PROPERTY_NAME(nl.knaw.huygens.timbuctoo.database.tinkerpop.TinkerpopSaver.RAW_COLLECTION_NAME_PROPERTY_NAME) UpdateEntity(nl.knaw.huygens.timbuctoo.core.dto.UpdateEntity) List(java.util.List) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) Matchers.equalTo(org.hamcrest.Matchers.equalTo) Optional(java.util.Optional) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) JsonBuilder.jsnO(nl.knaw.huygens.timbuctoo.util.JsonBuilder.jsnO) Collection(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection) TinkerPopOperationsStubs.forGraphMappingsAndIndex(nl.knaw.huygens.timbuctoo.database.tinkerpop.TinkerPopOperationsStubs.forGraphMappingsAndIndex) VERSION_OF(nl.knaw.huygens.timbuctoo.database.tinkerpop.VertexDuplicator.VERSION_OF) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) VreStubs.minimalCorrectVre(nl.knaw.huygens.timbuctoo.model.vre.VreStubs.minimalCorrectVre) CollectionNameHelper.defaultEntityTypeName(nl.knaw.huygens.timbuctoo.core.CollectionNameHelper.defaultEntityTypeName) VresBuilder(nl.knaw.huygens.timbuctoo.model.vre.vres.VresBuilder) JsonBuilder.jsn(nl.knaw.huygens.timbuctoo.util.JsonBuilder.jsn) Edge(org.apache.tinkerpop.gremlin.structure.Edge) RdfReadProperty(nl.knaw.huygens.timbuctoo.core.dto.rdf.RdfReadProperty) Matchers.empty(org.hamcrest.Matchers.empty) PredicateInUse(nl.knaw.huygens.timbuctoo.core.dto.rdf.PredicateInUse) TimProperty(nl.knaw.huygens.timbuctoo.core.dto.property.TimProperty) RAW_ITEM_EDGE_NAME(nl.knaw.huygens.timbuctoo.database.tinkerpop.TinkerpopSaver.RAW_ITEM_EDGE_NAME) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ENTITY_TYPE_NAME_PROPERTY_NAME(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.ENTITY_TYPE_NAME_PROPERTY_NAME) Mockito.when(org.mockito.Mockito.when) PropertyNameHelper.createPropName(nl.knaw.huygens.timbuctoo.database.tinkerpop.PropertyNameHelper.createPropName) Vres(nl.knaw.huygens.timbuctoo.model.vre.Vres) Entity(nl.knaw.huygens.timbuctoo.rdf.Entity) Mockito.verify(org.mockito.Mockito.verify) Collectors.toList(java.util.stream.Collectors.toList) Matchers.emptyIterable(org.hamcrest.Matchers.emptyIterable) EdgeMatcher.likeEdge(nl.knaw.huygens.timbuctoo.util.EdgeMatcher.likeEdge) HAS_COLLECTION_RELATION_NAME(nl.knaw.huygens.timbuctoo.model.vre.Vre.HAS_COLLECTION_RELATION_NAME) TinkerPopOperationsStubs.forGraphMappingsListenerAndIndex(nl.knaw.huygens.timbuctoo.database.tinkerpop.TinkerPopOperationsStubs.forGraphMappingsListenerAndIndex) HAS_PROPERTY_RELATION_NAME(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.HAS_PROPERTY_RELATION_NAME) RAW_COLLECTION_EDGE_NAME(nl.knaw.huygens.timbuctoo.database.tinkerpop.TinkerpopSaver.RAW_COLLECTION_EDGE_NAME) UpdateRelation(nl.knaw.huygens.timbuctoo.core.dto.UpdateRelation) Vres(nl.knaw.huygens.timbuctoo.model.vre.Vres) TinkerPopGraphManager(nl.knaw.huygens.timbuctoo.server.TinkerPopGraphManager) CreateCollection(nl.knaw.huygens.timbuctoo.core.dto.CreateCollection) Collection(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection) Matchers.containsString(org.hamcrest.Matchers.containsString) Matchers.anyString(org.mockito.Matchers.anyString) Change(nl.knaw.huygens.timbuctoo.model.Change) UUID(java.util.UUID) UpdateRelation(nl.knaw.huygens.timbuctoo.core.dto.UpdateRelation) Edge(org.apache.tinkerpop.gremlin.structure.Edge) EdgeMatcher.likeEdge(nl.knaw.huygens.timbuctoo.util.EdgeMatcher.likeEdge) Test(org.junit.Test)

Example 5 with Change

use of nl.knaw.huygens.timbuctoo.model.Change in project timbuctoo by HuygensING.

the class TinkerPopOperationsTest method deleteEntityMovesRelationsToNewestVertex.

@Test
public void deleteEntityMovesRelationsToNewestVertex() 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).withOutgoingRelation("hasWritten", "stuff").withIncomingRelation("isFriendOf", "friend")).withVertex("stuff", v -> v.withVre("test").withType("stuff").withProperty("isLatest", true).withProperty("rev", 1)).withVertex("friend", v -> v.withVre("test").withType("thing").withProperty("isLatest", true).withProperty("rev", 1)).wrap();
    TinkerPopOperations instance = forGraphWrapperAndMappings(graphManager, vres);
    Vertex orig = graphManager.getGraph().traversal().V().has("tim_id", idString).has("isLatest", true).next();
    assertThat(stream(orig.edges(Direction.BOTH, "hasWritten", "isFriendOf")).count(), is(2L));
    instance.deleteEntity(collection, id, new Change(Instant.now().toEpochMilli(), "userId", null));
    Vertex replacement = graphManager.getGraph().traversal().V().has("tim_id", idString).has("isLatest", true).next();
    assertThat(stream(orig.edges(Direction.BOTH, "hasWritten", "isFriendOf")).count(), is(0L));
    assertThat(stream(replacement.edges(Direction.BOTH, "hasWritten", "isFriendOf")).count(), is(2L));
}
Also used : ImmutableCreateProperty(nl.knaw.huygens.timbuctoo.core.dto.rdf.ImmutableCreateProperty) AlreadyUpdatedException(nl.knaw.huygens.timbuctoo.core.AlreadyUpdatedException) NodeFactory(org.apache.jena.graph.NodeFactory) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) CreateCollection(nl.knaw.huygens.timbuctoo.core.dto.CreateCollection) Matchers.not(org.hamcrest.Matchers.not) CreateEntityStubs.withProperties(nl.knaw.huygens.timbuctoo.core.dto.CreateEntityStubs.withProperties) Try(javaslang.control.Try) QuickSearch(nl.knaw.huygens.timbuctoo.core.dto.QuickSearch) RdfProperty(nl.knaw.huygens.timbuctoo.core.dto.rdf.RdfProperty) Matchers.nullValue(org.hamcrest.Matchers.nullValue) TestGraphBuilder.newGraph(nl.knaw.huygens.timbuctoo.util.TestGraphBuilder.newGraph) HAS_ENTITY_NODE_RELATION_NAME(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.HAS_ENTITY_NODE_RELATION_NAME) QuickSearchResult(nl.knaw.huygens.timbuctoo.core.dto.QuickSearchResult) Matchers.allOf(org.hamcrest.Matchers.allOf) TinkerPopGraphManager(nl.knaw.huygens.timbuctoo.server.TinkerPopGraphManager) COLLECTION_NAME_PROPERTY_NAME(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.COLLECTION_NAME_PROPERTY_NAME) ValueTypeInUse(nl.knaw.huygens.timbuctoo.core.dto.rdf.ValueTypeInUse) ChangeListener(nl.knaw.huygens.timbuctoo.database.tinkerpop.changelistener.ChangeListener) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) ReadEntity(nl.knaw.huygens.timbuctoo.core.dto.ReadEntity) Element(org.apache.tinkerpop.gremlin.structure.Element) Matchers.contains(org.hamcrest.Matchers.contains) Vre(nl.knaw.huygens.timbuctoo.model.vre.Vre) Matchers.is(org.hamcrest.Matchers.is) TinkerPopOperationsStubs.forGraphWrapperAndMappings(nl.knaw.huygens.timbuctoo.database.tinkerpop.TinkerPopOperationsStubs.forGraphWrapperAndMappings) CreateEntity(nl.knaw.huygens.timbuctoo.core.dto.CreateEntity) Matchers.containsString(org.hamcrest.Matchers.containsString) Mockito.mock(org.mockito.Mockito.mock) LabelP(org.apache.tinkerpop.gremlin.neo4j.process.traversal.LabelP) RAW_PROPERTY_EDGE_NAME(nl.knaw.huygens.timbuctoo.database.tinkerpop.TinkerpopSaver.RAW_PROPERTY_EDGE_NAME) Matchers.anyString(org.mockito.Matchers.anyString) ArrayList(java.util.ArrayList) Matchers.hasProperty(org.hamcrest.Matchers.hasProperty) CreateRelation(nl.knaw.huygens.timbuctoo.core.dto.CreateRelation) Lists(com.google.common.collect.Lists) TinkerPopOperationsStubs.forGraphMappingsAndChangeListener(nl.knaw.huygens.timbuctoo.database.tinkerpop.TinkerPopOperationsStubs.forGraphMappingsAndChangeListener) HAS_ENTITY_RELATION_NAME(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.HAS_ENTITY_RELATION_NAME) TinkerPopOperationsStubs.forGraphWrapper(nl.knaw.huygens.timbuctoo.database.tinkerpop.TinkerPopOperationsStubs.forGraphWrapper) Matchers.hasSize(org.hamcrest.Matchers.hasSize) OptionalPresentMatcher.present(nl.knaw.huygens.hamcrest.OptionalPresentMatcher.present) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) RelationType(nl.knaw.huygens.timbuctoo.core.dto.RelationType) DataStream(nl.knaw.huygens.timbuctoo.core.dto.DataStream) Test(org.junit.Test) IOException(java.io.IOException) T(org.apache.tinkerpop.gremlin.structure.T) Direction(org.apache.tinkerpop.gremlin.structure.Direction) Database(nl.knaw.huygens.timbuctoo.rdf.Database) HAS_DISPLAY_NAME_RELATION_NAME(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.HAS_DISPLAY_NAME_RELATION_NAME) Matchers.sameInstance(org.hamcrest.Matchers.sameInstance) RDF_URI_PROP(nl.knaw.huygens.timbuctoo.rdf.Database.RDF_URI_PROP) GraphReadUtils.getProp(nl.knaw.huygens.timbuctoo.model.GraphReadUtils.getProp) Change(nl.knaw.huygens.timbuctoo.model.Change) P.within(org.apache.tinkerpop.gremlin.process.traversal.P.within) SameJSONAs.sameJSONAs(uk.co.datumedge.hamcrest.json.SameJSONAs.sameJSONAs) StreamIterator.stream(nl.knaw.huygens.timbuctoo.util.StreamIterator.stream) PropertyTypes.localProperty(nl.knaw.huygens.timbuctoo.model.properties.PropertyTypes.localProperty) Graph(org.apache.tinkerpop.gremlin.structure.Graph) RDF_SYNONYM_PROP(nl.knaw.huygens.timbuctoo.rdf.Database.RDF_SYNONYM_PROP) StringProperty(nl.knaw.huygens.timbuctoo.core.dto.property.StringProperty) VertexMatcher.likeVertex(nl.knaw.huygens.timbuctoo.util.VertexMatcher.likeVertex) MockitoHamcrest.argThat(org.mockito.hamcrest.MockitoHamcrest.argThat) RelationNotPossibleException(nl.knaw.huygens.timbuctoo.core.RelationNotPossibleException) URI(java.net.URI) IS_RELATION_COLLECTION_PROPERTY_NAME(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.IS_RELATION_COLLECTION_PROPERTY_NAME) org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.has(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.has) CollectionBuilder(nl.knaw.huygens.timbuctoo.core.dto.dataset.CollectionBuilder) EntityFinisherHelper(nl.knaw.huygens.timbuctoo.core.EntityFinisherHelper) NotFoundException(nl.knaw.huygens.timbuctoo.core.NotFoundException) UUID(java.util.UUID) Instant(java.time.Instant) RAW_COLLECTION_NAME_PROPERTY_NAME(nl.knaw.huygens.timbuctoo.database.tinkerpop.TinkerpopSaver.RAW_COLLECTION_NAME_PROPERTY_NAME) UpdateEntity(nl.knaw.huygens.timbuctoo.core.dto.UpdateEntity) List(java.util.List) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) Matchers.equalTo(org.hamcrest.Matchers.equalTo) Optional(java.util.Optional) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) JsonBuilder.jsnO(nl.knaw.huygens.timbuctoo.util.JsonBuilder.jsnO) Collection(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection) TinkerPopOperationsStubs.forGraphMappingsAndIndex(nl.knaw.huygens.timbuctoo.database.tinkerpop.TinkerPopOperationsStubs.forGraphMappingsAndIndex) VERSION_OF(nl.knaw.huygens.timbuctoo.database.tinkerpop.VertexDuplicator.VERSION_OF) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) VreStubs.minimalCorrectVre(nl.knaw.huygens.timbuctoo.model.vre.VreStubs.minimalCorrectVre) CollectionNameHelper.defaultEntityTypeName(nl.knaw.huygens.timbuctoo.core.CollectionNameHelper.defaultEntityTypeName) VresBuilder(nl.knaw.huygens.timbuctoo.model.vre.vres.VresBuilder) JsonBuilder.jsn(nl.knaw.huygens.timbuctoo.util.JsonBuilder.jsn) Edge(org.apache.tinkerpop.gremlin.structure.Edge) RdfReadProperty(nl.knaw.huygens.timbuctoo.core.dto.rdf.RdfReadProperty) Matchers.empty(org.hamcrest.Matchers.empty) PredicateInUse(nl.knaw.huygens.timbuctoo.core.dto.rdf.PredicateInUse) TimProperty(nl.knaw.huygens.timbuctoo.core.dto.property.TimProperty) RAW_ITEM_EDGE_NAME(nl.knaw.huygens.timbuctoo.database.tinkerpop.TinkerpopSaver.RAW_ITEM_EDGE_NAME) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ENTITY_TYPE_NAME_PROPERTY_NAME(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.ENTITY_TYPE_NAME_PROPERTY_NAME) Mockito.when(org.mockito.Mockito.when) PropertyNameHelper.createPropName(nl.knaw.huygens.timbuctoo.database.tinkerpop.PropertyNameHelper.createPropName) Vres(nl.knaw.huygens.timbuctoo.model.vre.Vres) Entity(nl.knaw.huygens.timbuctoo.rdf.Entity) Mockito.verify(org.mockito.Mockito.verify) Collectors.toList(java.util.stream.Collectors.toList) Matchers.emptyIterable(org.hamcrest.Matchers.emptyIterable) EdgeMatcher.likeEdge(nl.knaw.huygens.timbuctoo.util.EdgeMatcher.likeEdge) HAS_COLLECTION_RELATION_NAME(nl.knaw.huygens.timbuctoo.model.vre.Vre.HAS_COLLECTION_RELATION_NAME) TinkerPopOperationsStubs.forGraphMappingsListenerAndIndex(nl.knaw.huygens.timbuctoo.database.tinkerpop.TinkerPopOperationsStubs.forGraphMappingsListenerAndIndex) HAS_PROPERTY_RELATION_NAME(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection.HAS_PROPERTY_RELATION_NAME) RAW_COLLECTION_EDGE_NAME(nl.knaw.huygens.timbuctoo.database.tinkerpop.TinkerpopSaver.RAW_COLLECTION_EDGE_NAME) UpdateRelation(nl.knaw.huygens.timbuctoo.core.dto.UpdateRelation) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) VertexMatcher.likeVertex(nl.knaw.huygens.timbuctoo.util.VertexMatcher.likeVertex) Vres(nl.knaw.huygens.timbuctoo.model.vre.Vres) TinkerPopGraphManager(nl.knaw.huygens.timbuctoo.server.TinkerPopGraphManager) CreateCollection(nl.knaw.huygens.timbuctoo.core.dto.CreateCollection) Collection(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection) Matchers.containsString(org.hamcrest.Matchers.containsString) Matchers.anyString(org.mockito.Matchers.anyString) Change(nl.knaw.huygens.timbuctoo.model.Change) UUID(java.util.UUID) Test(org.junit.Test)

Aggregations

Change (nl.knaw.huygens.timbuctoo.model.Change)52 Collection (nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection)40 Test (org.junit.Test)40 UUID (java.util.UUID)39 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)34 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)33 IOException (java.io.IOException)33 TimProperty (nl.knaw.huygens.timbuctoo.core.dto.property.TimProperty)31 UpdateEntity (nl.knaw.huygens.timbuctoo.core.dto.UpdateEntity)30 Instant (java.time.Instant)29 List (java.util.List)29 ReadEntity (nl.knaw.huygens.timbuctoo.core.dto.ReadEntity)29 Vres (nl.knaw.huygens.timbuctoo.model.vre.Vres)29 Lists (com.google.common.collect.Lists)28 URI (java.net.URI)28 Optional (java.util.Optional)28 Collectors.toList (java.util.stream.Collectors.toList)28 CreateCollection (nl.knaw.huygens.timbuctoo.core.dto.CreateCollection)28 CreateEntity (nl.knaw.huygens.timbuctoo.core.dto.CreateEntity)28 ArrayList (java.util.ArrayList)27