Search in sources :

Example 1 with ConcurrentUpdateException

use of nl.knaw.huygens.timbuctoo.v5.jsonldimport.ConcurrentUpdateException in project timbuctoo by HuygensING.

the class JsonLdEditEndpoint method submitChanges.

@PUT
public Response submitChanges(String jsonLdImport, @PathParam("user") String ownerId, @PathParam("dataset") String dataSetId, @HeaderParam("authorization") String authHeader) throws LogStorageFailedException {
    Optional<User> user;
    try {
        user = userValidator.getUserFromAccessToken(authHeader);
    } catch (UserValidationException e) {
        user = Optional.empty();
    }
    Optional<DataSet> dataSetOpt = dataSetRepository.getDataSet(user.get(), ownerId, dataSetId);
    if (!dataSetOpt.isPresent()) {
        return Response.status(Response.Status.NOT_FOUND).build();
    }
    final DataSet dataSet = dataSetOpt.get();
    final QuadStore quadStore = dataSet.getQuadStore();
    final ImportManager importManager = dataSet.getImportManager();
    final Response response = checkWriteAccess(dataSet, user, permissionFetcher);
    if (response != null) {
        return response;
    }
    try {
        final Future<ImportStatus> promise = importManager.generateLog(dataSet.getMetadata().getBaseUri(), dataSet.getMetadata().getBaseUri(), fromCurrentState(documentLoader, jsonLdImport, quadStore, TIM_USERS + user.get().getPersistentId(), UUID.randomUUID().toString(), Clock.systemUTC()));
        return handleImportManagerResult(promise);
    } catch (IOException e) {
        return Response.status(Response.Status.BAD_REQUEST).entity(e.getMessage()).build();
    } catch (ConcurrentUpdateException e) {
        return Response.status(Response.Status.CONFLICT).entity(e.getMessage()).build();
    }
}
Also used : Response(javax.ws.rs.core.Response) UserValidationException(nl.knaw.huygens.timbuctoo.v5.security.exceptions.UserValidationException) ImportManager(nl.knaw.huygens.timbuctoo.v5.dataset.ImportManager) User(nl.knaw.huygens.timbuctoo.v5.security.dto.User) QuadStore(nl.knaw.huygens.timbuctoo.v5.datastores.quadstore.QuadStore) DataSet(nl.knaw.huygens.timbuctoo.v5.dataset.dto.DataSet) ImportStatus(nl.knaw.huygens.timbuctoo.v5.dataset.ImportStatus) IOException(java.io.IOException) ConcurrentUpdateException(nl.knaw.huygens.timbuctoo.v5.jsonldimport.ConcurrentUpdateException) PUT(javax.ws.rs.PUT)

Example 2 with ConcurrentUpdateException

use of nl.knaw.huygens.timbuctoo.v5.jsonldimport.ConcurrentUpdateException in project timbuctoo by HuygensING.

the class JsonProvenanceToRdfPatchTest method doesOptimisticLocking.

@Test
public void doesOptimisticLocking() throws Exception {
    String examplePatch = "{\n" + "   \"@type\":\"prov:Activity\",\n" + "   \"http://www.w3.org/ns/prov#generates\":[\n" + "      {\n" + "         \"@type\":\"prov:Entity\",\n" + "         \"specializationOf\":{\n" + "            \"@id\":\"http://example.com/the/actual/entity1\"\n" + "         },\n" + "        \"wasRevisionOf\":{\n" + "            \"@id\":\"http://example.org/revision1\"\n" + "         },\n" + "         \"additions\":[\n" + "            {\n" + "               \"@type\":\"http://timbuctoo.huygens.knaw.nl/v5/vocabulary#mutation\",\n" + "               \"predicate\":\"http://example.org/pred1\",\n" + "               \"value\":\"value1\"\n" + "            }\n" + "         ]\n" + "      }\n" + "   ],\n" + context + "}";
    QuadStore testQuadStore = new DummyQuadStore().with("http://example.org/entity1", RdfConstants.TIM_LATEST_REVISION, "http://example.org/revision2", null);
    boolean exceptionWasThrown = false;
    try {
        fromCurrentState(new DocumentLoader(), examplePatch, testQuadStore, "http://example.org/users/myUser", UUID.randomUUID().toString(), CLOCK);
    } catch (ConcurrentUpdateException e) {
        exceptionWasThrown = true;
    }
    assertThat(exceptionWasThrown, is(true));
}
Also used : QuadStore(nl.knaw.huygens.timbuctoo.v5.datastores.quadstore.QuadStore) DocumentLoader(com.github.jsonldjava.core.DocumentLoader) Test(org.junit.Test)

Aggregations

QuadStore (nl.knaw.huygens.timbuctoo.v5.datastores.quadstore.QuadStore)2 DocumentLoader (com.github.jsonldjava.core.DocumentLoader)1 IOException (java.io.IOException)1 PUT (javax.ws.rs.PUT)1 Response (javax.ws.rs.core.Response)1 ImportManager (nl.knaw.huygens.timbuctoo.v5.dataset.ImportManager)1 ImportStatus (nl.knaw.huygens.timbuctoo.v5.dataset.ImportStatus)1 DataSet (nl.knaw.huygens.timbuctoo.v5.dataset.dto.DataSet)1 ConcurrentUpdateException (nl.knaw.huygens.timbuctoo.v5.jsonldimport.ConcurrentUpdateException)1 User (nl.knaw.huygens.timbuctoo.v5.security.dto.User)1 UserValidationException (nl.knaw.huygens.timbuctoo.v5.security.exceptions.UserValidationException)1 Test (org.junit.Test)1