use of nl.knaw.huygens.timbuctoo.core.dto.UpdateRelation in project timbuctoo by HuygensING.
the class TimbuctooActionsRelationTest method replaceRelationUpdatesARelation.
@Test
public void replaceRelationUpdatesARelation() throws Exception {
UUID id = UUID.randomUUID();
UpdateRelation updateRelation = new UpdateRelation(id, 1, false);
TimbuctooActions instance = createInstance(true);
instance.replaceRelation(collection, updateRelation, userWithId(USER_ID));
verify(dataStoreOperations).replaceRelation(argThat(is(collection)), argThat(allOf(hasProperty("id", is(id)), hasProperty("modified", allOf(hasProperty("userId", is(USER_ID)), hasProperty("timeStamp", is(instant.toEpochMilli())))))));
}
use of nl.knaw.huygens.timbuctoo.core.dto.UpdateRelation in project timbuctoo by HuygensING.
the class TimbuctooActionsRelationTest method replaceRelationThrowsANotFoundExceptionWhenTheRelationCannotBeFound.
@Test(expected = NotFoundException.class)
public void replaceRelationThrowsANotFoundExceptionWhenTheRelationCannotBeFound() throws Exception {
UpdateRelation updateRelation = new UpdateRelation(null, 1, false);
doThrow(new NotFoundException()).when(dataStoreOperations).replaceRelation(collection, updateRelation);
TimbuctooActions instance = createInstance(true);
instance.replaceRelation(collection, updateRelation, userWithId(USER_ID));
}
use of nl.knaw.huygens.timbuctoo.core.dto.UpdateRelation in project timbuctoo by HuygensING.
the class JsonCrudService method replaceRelation.
private void replaceRelation(Collection collection, UUID id, ObjectNode data, User user) throws IOException, NotFoundException, PermissionFetchingException {
JsonNode accepted = data.get("accepted");
if (accepted == null || !accepted.isBoolean()) {
throw new IOException("Only the property accepted can be updated. It must be a boolean");
}
JsonNode rev = data.get("^rev");
if (rev == null || !rev.isNumber()) {
throw new IOException("^rev must be a number");
}
for (Iterator<String> fieldNames = data.fieldNames(); fieldNames.hasNext(); ) {
String name = fieldNames.next();
if (!name.startsWith("^") && !name.startsWith("@") && !name.equals("_id") && !name.equals("accepted")) {
throw new IOException("Only 'accepted' is a changeable property");
}
}
UpdateRelation updateRelation = new UpdateRelation(id, rev.asInt(), accepted.asBoolean());
timDbAccess.replaceRelation(collection, updateRelation, user);
}
Aggregations