@Override public void handle(StateContext state, RootCollectionLoadEntityContext ctx) { PersistentResource record = entityRecord(state, ctx.entity()); state.setState(new RecordTerminalState(record)); }
@Override public Supplier<Pair<Integer, JsonNode>> handleGet(StateContext state) { ObjectMapper mapper = state.getRequestScope().getMapper().getObjectMapper(); return () -> Pair.of(HttpStatus.SC_OK, getResponseBody(record, state.getRequestScope())); }
@Override public Supplier<Pair<Integer, JsonNode>> handlePatch(StateContext state) { JsonApiDocument jsonApiDocument = state.getJsonApiDocument(); Data<Resource> data = jsonApiDocument.getData(); if (data == null) { throw new InvalidEntityBodyException("Expected data but found null"); } if (!data.isToOne()) { throw new InvalidEntityBodyException("Expected single element but found list"); } Resource resource = data.getSingleValue(); if (!record.matchesId(resource.getId())) { throw new InvalidEntityBodyException("Id in response body does not match requested id to update from path"); } patch(resource, state.getRequestScope()); return constructPatchResponse(record, state); }
@Override public Supplier<Pair<Integer, JsonNode>> handlePatch(StateContext state) { JsonApiDocument jsonApiDocument = state.getJsonApiDocument(); Data<Resource> data = jsonApiDocument.getData(); if (data == null) { throw new InvalidEntityBodyException("Expected data but found null"); } if (!data.isToOne()) { throw new InvalidEntityBodyException("Expected single element but found list"); } Resource resource = data.getSingleValue(); if (!record.matchesId(resource.getId())) { throw new InvalidEntityBodyException("Id in response body does not match requested id to update from path"); } patch(resource, state.getRequestScope()); return constructPatchResponse(record, state); }
@Override public void handle(StateContext state, RootCollectionLoadEntityContext ctx) { PersistentResource record = entityRecord(state, ctx.entity()); state.setState(new RecordTerminalState(record)); }
@Override public Supplier<Pair<Integer, JsonNode>> handleGet(StateContext state) { ObjectMapper mapper = state.getRequestScope().getMapper().getObjectMapper(); return () -> Pair.of(HttpStatus.SC_OK, getResponseBody(record, state.getRequestScope())); }
@Override public void handle(StateContext state, SubCollectionReadEntityContext ctx) { String id = ctx.entity().id().getText(); String subCollection = ctx.entity().term().getText(); try { PersistentResource nextRecord = resource.getRelation(subCollection, id); state.setState(new RecordTerminalState(nextRecord)); } catch (InvalidAttributeException e) { throw new InvalidCollectionException(subCollection); } }
@Override public void handle(StateContext state, SubCollectionReadEntityContext ctx) { String id = ctx.entity().id().getText(); String subCollection = ctx.entity().term().getText(); try { PersistentResource nextRecord = resource.getRelation(subCollection, id); state.setState(new RecordTerminalState(nextRecord)); } catch (InvalidAttributeException e) { throw new InvalidCollectionException(subCollection); } }
nextState = new RecordTerminalState(record, collectionTerminalState); } else { nextState = collectionTerminalState;
nextState = new RecordTerminalState(record, collectionTerminalState); } else { nextState = collectionTerminalState;