Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,19 @@
import org.glassfish.hk2.api.MultiException;
import org.glassfish.jersey.server.spi.ResponseErrorMapper;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import uk.co.amrc.factoryplus.metadb.db.Err;

public class ErrorMapper
{
public static final Logger log = LoggerFactory.getLogger(ErrorMapper.class);

public static Response clientError (Err.ClientError err)
{
/* XXX we should allow the error to include more fields here */
log.info("Returning error: {}", err);
var json = Json.createValue(err.getMessage());
return Response.status(err.statusCode())
.entity(json)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ private static record QueryHandler (
@Consumes("application/sparql-update")
public void update (String update)
{
store.executeWrite(() ->
store.requestExecute(req ->
UpdateAction.parseExecute(update, store.dataset()));
}

Expand All @@ -143,7 +143,7 @@ public StreamingOutput sparql (String queryString) throws WebApplicationExceptio

var lang = handler.content().acceptLang(req);

return store.calculateRead(() -> {
return store.requestRead(req -> {
try (var qexec = QueryExecutionFactory.create(query, store.dataset())) {
return handler.handle().apply(qexec, lang);
}
Expand Down Expand Up @@ -226,7 +226,7 @@ public void graphPost (
var lang = RDF_HANDLER.contentLang(type);
var graph = resolveGraph(true);

store.executeWrite(() -> {
store.requestExecute(req -> {
readToGraph(graph, rdf, lang);
/* This refreshes the inferences because we have been poking
* around behind its back. Strictly this is only needed when
Expand All @@ -244,7 +244,7 @@ public void graphPut (
var lang = RDF_HANDLER.contentLang(type);
var graph = resolveGraph(true);

store.executeWrite(() -> {
store.requestExecute(req -> {
graph.removeAll();
readToGraph(graph, rdf, lang);
store.derived().rebind();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,23 +35,21 @@ public class V2Config {
@PathParam("app") UUID app;
@PathParam("object") UUID obj;

private ConfigEntry configEntry ()
{
return store.configEntry(app, obj);
}

@GET
public Response get ()
{
log.info("Get config for {}/{}", app, obj);
var entry = store.calculateRead(() -> {
return configEntry().getValue();
var entry = store.requestRead(req -> {
return req.configEntry(app, obj).getValue();
});
return entry
.map(e -> Response.ok(e.value())
.tag(e.etag())
.lastModified(Date.from(e.mtime()))
.build())
.map(e -> {
var res = Response.ok(e.value())
.tag(e.etag());
e.mtime().ifPresent(t ->
res.lastModified(Date.from(t)));
return res.build();
})
.orElseThrow(() -> new WebApplicationException(404));
}

Expand All @@ -63,26 +61,26 @@ public Response get ()
public void put (JsonValue config)
{
log.info("Put config for {}/{}", app, obj);
store.executeWrite(() -> {
configEntry().putValue(config);
store.requestExecute(req -> {
req.configEntry(app, obj).putValue(config);
});
}

@DELETE
public void delete ()
{
log.info("Delete config for {}/{}", app, obj);
store.executeWrite(() -> {
configEntry().removeValue();
store.requestExecute(req -> {
req.configEntry(app, obj).removeValue();
});
}

@PATCH @Consumes("application/merge-patch+json")
public void mergePatch (JsonValue json)
{
var patch = Json.createMergePatch(json);
store.executeWrite(() -> {
var entry = configEntry();
store.requestExecute(req -> {
var entry = req.configEntry(app, obj);

var o_conf = entry.getValue()
.map(e -> e.value())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ public class V2Objects {
@GET @Path("object")
public JsonArray listObjects ()
{
var objs = db.objectStructure().listObjects();
var objs = db.requestRead(req ->
req.objectStructure().listObjects());
return Json.createArrayBuilder(objs).build();
}

Expand All @@ -56,26 +57,28 @@ public JsonValue createObject (JsonObject spec)
/* We don't accept any other parameters. The ServiceClient
* doesn't pass any anyway. */

return db.objectStructure().createObject(klass, uuid);
return db.requestWrite(req ->
req.objectStructure().createObject(klass, uuid));
}

@DELETE @Path("object/{object}")
public void deleteObject (@PathParam("object") UUID uuid)
{
db.objectStructure().deleteObject(uuid);
db.requestExecute(req -> req.objectStructure().deleteObject(uuid));
}

@GET @Path("object/rank")
public JsonArray listRanks ()
{
var ranks = db.objectStructure().listRanks();
var ranks = db.requestRead(req -> req.objectStructure().listRanks());
return Json.createArrayBuilder(ranks).build();
}

private JsonArray listRelation (String graph, UUID uuid, String relation)
{
var members = db.objectStructure()
.listRelation(graph, uuid, relation);
var members = db.requestRead(req ->
req.objectStructure()
.listRelation(graph, uuid, relation));

return Json.createArrayBuilder(members).build();
}
Expand All @@ -101,8 +104,9 @@ public JsonArray listDirectRelation (

private Response testRelation (String graph, UUID klass, String relation, UUID object)
{
var rv = db.objectStructure()
.testRelation(graph, klass, relation, object);
var rv = db.requestRead(req ->
req.objectStructure()
.testRelation(graph, klass, relation, object));

return Response.status(rv ? 204 : 404).build();
}
Expand Down Expand Up @@ -131,7 +135,8 @@ public void putRelation (
@PathParam("relation") String relation,
@PathParam("object") UUID object)
{
db.objectStructure().putRelation(klass, relation, object);
db.requestExecute(req ->
req.objectStructure().putRelation(klass, relation, object));
}

@DELETE @Path("class/{class}/direct/{relation}/{object}")
Expand All @@ -140,8 +145,8 @@ public void delRelation (
@PathParam("relation") String relation,
@PathParam("object") UUID object)
{
db.objectStructure().delRelation(klass, relation, object);
db.requestExecute(req ->
req.objectStructure().delRelation(klass, relation, object));
}

}

Loading
Loading