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();
}
}
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));
}
Aggregations