Search in sources :

Example 6 with UpdateRelation

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())))))));
}
Also used : UUID(java.util.UUID) UpdateRelation(nl.knaw.huygens.timbuctoo.core.dto.UpdateRelation) Test(org.junit.Test)

Example 7 with UpdateRelation

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));
}
Also used : UpdateRelation(nl.knaw.huygens.timbuctoo.core.dto.UpdateRelation) Test(org.junit.Test)

Example 8 with UpdateRelation

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);
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) IOException(java.io.IOException) UpdateRelation(nl.knaw.huygens.timbuctoo.core.dto.UpdateRelation)

Aggregations

UpdateRelation (nl.knaw.huygens.timbuctoo.core.dto.UpdateRelation)8 IOException (java.io.IOException)6 UUID (java.util.UUID)6 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)5 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)5 Lists (com.google.common.collect.Lists)5 URI (java.net.URI)5 Instant (java.time.Instant)5 ArrayList (java.util.ArrayList)5 List (java.util.List)5 Optional (java.util.Optional)5 Collectors.toList (java.util.stream.Collectors.toList)5 Try (javaslang.control.Try)5 OptionalPresentMatcher.present (nl.knaw.huygens.hamcrest.OptionalPresentMatcher.present)5 AlreadyUpdatedException (nl.knaw.huygens.timbuctoo.core.AlreadyUpdatedException)5 CollectionNameHelper.defaultEntityTypeName (nl.knaw.huygens.timbuctoo.core.CollectionNameHelper.defaultEntityTypeName)5 EntityFinisherHelper (nl.knaw.huygens.timbuctoo.core.EntityFinisherHelper)5 NotFoundException (nl.knaw.huygens.timbuctoo.core.NotFoundException)5 RelationNotPossibleException (nl.knaw.huygens.timbuctoo.core.RelationNotPossibleException)5 CreateCollection (nl.knaw.huygens.timbuctoo.core.dto.CreateCollection)5