private boolean post(Data<Resource> data, RequestScope requestScope) { if (data == null) { throw new InvalidEntityBodyException("Expected data but received null"); } Collection<Resource> resources = data.get(); if (resources == null) { return false; } resources.stream().forEachOrdered(resource -> record.addRelation(relationshipName, resource.toPersistentResource(requestScope))); return true; }
private boolean post(Data<Resource> data, RequestScope requestScope) { if (data == null) { throw new InvalidEntityBodyException("Expected data but received null"); } Collection<Resource> resources = data.get(); if (resources == null) { return false; } resources.stream().forEachOrdered(resource -> record.addRelation(relationshipName, resource.toPersistentResource(requestScope))); return true; }
@Override public Supplier<Pair<Integer, JsonNode>> handlePost(StateContext state) { RequestScope requestScope = state.getRequestScope(); JsonApiMapper mapper = requestScope.getMapper(); newObject = createObject(requestScope); parent.ifPresent(persistentResource -> persistentResource.addRelation(relationName.get(), newObject)); return () -> { JsonApiDocument returnDoc = new JsonApiDocument(); returnDoc.setData(new Data(newObject.toResource())); JsonNode responseBody = mapper.getObjectMapper().convertValue(returnDoc, JsonNode.class); return Pair.of(HttpStatus.SC_CREATED, responseBody); }; }
@Override public Supplier<Pair<Integer, JsonNode>> handlePost(StateContext state) { RequestScope requestScope = state.getRequestScope(); JsonApiMapper mapper = requestScope.getMapper(); newObject = createObject(requestScope); parent.ifPresent(persistentResource -> persistentResource.addRelation(relationName.get(), newObject)); return () -> { JsonApiDocument returnDoc = new JsonApiDocument(); returnDoc.setData(new Data(newObject.toResource())); JsonNode responseBody = mapper.getObjectMapper().convertValue(returnDoc, JsonNode.class); return Pair.of(HttpStatus.SC_CREATED, responseBody); }; }
graphWalker(entity, this::updateRelationship); if (!context.isRoot()) { /* add relation between parent and nested entity */ context.parentResource.addRelation(context.field.getName(), entity.toPersistentResource());
graphWalker(entity, this::updateRelationship); if (!context.isRoot()) { /* add relation between parent and nested entity */ context.parentResource.addRelation(context.field.getName(), entity.toPersistentResource());