use of nl.knaw.huygens.timbuctoo.core.dto.UpdateEntity 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()));
}
use of nl.knaw.huygens.timbuctoo.core.dto.UpdateEntity 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);
}
use of nl.knaw.huygens.timbuctoo.core.dto.UpdateEntity in project timbuctoo by HuygensING.
the class JsonToEntityMapperTest method newUpdateEntityMapsTheJsonObjectToAnUpdateEntity.
@Test
public void newUpdateEntityMapsTheJsonObjectToAnUpdateEntity() throws Exception {
Collection collection = new VresBuilder().withVre("WomenWriters", "ww", vre -> vre.withCollection("wwpersons", c -> c.withProperty("name", localProperty("wwname")).withProperty("age", localProperty("wwage")))).build().getCollection("wwpersons").get();
int rev = 2;
ObjectNode input = JsonBuilder.jsnO("name", jsn("Hans"), "age", jsn("12"), "^rev", jsn(rev));
JsonToEntityMapper instance = new JsonToEntityMapper();
UUID id = UUID.randomUUID();
UpdateEntity updateEntity = instance.newUpdateEntity(collection, id, input);
assertThat(updateEntity.getProperties(), containsInAnyOrder(allOf(hasProperty("name", equalTo("name")), hasProperty("value", equalTo("Hans"))), allOf(hasProperty("name", equalTo("age")), hasProperty("value", equalTo("12")))));
assertThat(updateEntity.getId(), is(id));
assertThat(updateEntity.getRev(), is(rev));
}
use of nl.knaw.huygens.timbuctoo.core.dto.UpdateEntity in project timbuctoo by HuygensING.
the class ChangeListenerTest method callsOnPropertyUpdateOnReplaceEntity.
@Test
public void callsOnPropertyUpdateOnReplaceEntity() throws Exception {
ChangeListener changeListener = new ChangeListenerImpl(vertex -> {
assertThat(vertex, likeVertex().withProperty("isLatest", true).withProperty("rev", 2));
Long prevVersions = stream(vertex.vertices(Direction.BOTH, VERSION_OF)).collect(Collectors.counting());
assertThat(prevVersions, is(1L));
});
UUID id = UUID.randomUUID();
ChangeListener spy = spy(changeListener);
DataStoreOperations instance = forReplaceCall(spy, id, 1);
UpdateEntity updateEntity = new UpdateEntity(id, newArrayList(), 1);
updateEntity.setModified(new Change());
Collection collectionMock = mock(Collection.class);
instance.replaceEntity(collectionMock, updateEntity);
verify(spy).onPropertyUpdate(same(collectionMock), any(), any());
}
use of nl.knaw.huygens.timbuctoo.core.dto.UpdateEntity in project timbuctoo by HuygensING.
the class JsonCrudService method replaceEntity.
private void replaceEntity(Collection collection, UUID id, ObjectNode data, User user) throws NotFoundException, IOException, AlreadyUpdatedException, PermissionFetchingException {
UpdateEntity updateEntity = jsonToEntityMapper.newUpdateEntity(collection, id, data);
timDbAccess.replaceEntity(collection, updateEntity, user);
}
Aggregations