String id = resource.getId(); Class<?> newObjectClass = requestScope.getDictionary().getEntityClass(resource.getType());
String id = resource.getId(); Class<?> newObjectClass = requestScope.getDictionary().getEntityClass(resource.getType());
/** * Remove data via patch extension. */ private Supplier<Pair<Integer, JsonNode>> handleRemoveOp(String path, JsonNode patchValue, PatchRequestScope requestScope) { try { JsonApiDocument value = requestScope.getMapper().readJsonApiPatchExtValue(patchValue); String fullPath; if (path.contains("relationships")) { // Reserved keyword for relationships fullPath = path; } else { Data<Resource> data = value.getData(); if (data == null || data.get() == null) { fullPath = path; } else { Collection<Resource> resources = data.get(); String id = getSingleResource(resources).getId(); fullPath = path + "/" + id; } } DeleteVisitor visitor = new DeleteVisitor( new PatchRequestScope(path, value, requestScope)); return visitor.visit(JsonApiParser.parse(fullPath)); } catch (IOException e) { throw new InvalidEntityBodyException("Could not parse patch extension value: " + patchValue); } }
/** * Remove data via patch extension. */ private Supplier<Pair<Integer, JsonNode>> handleRemoveOp(String path, JsonNode patchValue, PatchRequestScope requestScope) { try { JsonApiDocument value = requestScope.getMapper().readJsonApiPatchExtValue(patchValue); String fullPath; if (path.contains("relationships")) { // Reserved keyword for relationships fullPath = path; } else { Data<Resource> data = value.getData(); if (data == null || data.get() == null) { fullPath = path; } else { Collection<Resource> resources = data.get(); String id = getSingleResource(resources).getId(); fullPath = path + "/" + id; } } DeleteVisitor visitor = new DeleteVisitor( new PatchRequestScope(path, value, requestScope)); return visitor.visit(JsonApiParser.parse(fullPath)); } catch (IOException e) { throw new InvalidEntityBodyException("Could not parse patch extension value: " + patchValue); } }
@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); }
String id = getSingleResource(resources).getId(); String fullPath = path + "/" + id;
String id = getSingleResource(resources).getId(); String fullPath = path + "/" + id;
Collection<ResourceIdentifier> resourceIdentifiers = resource.getRelationships().get("parents").getResourceIdentifierData().get(); ResourceIdentifier rId1 = resourceIdentifiers.iterator().next(); assertEquals(resource.getId(), "6"); assertEquals(resource.getType(), "child"); assertEquals(resource.getRelationships().size(), 2);