private boolean patch(Resource resource, RequestScope requestScope) { boolean isUpdated = false; // Update attributes first Map<String, Object> attributes = resource.getAttributes(); if (attributes != null) { for (Map.Entry<String, Object> entry : attributes.entrySet()) { String fieldName = entry.getKey(); Object newVal = entry.getValue(); isUpdated |= record.updateAttribute(fieldName, newVal); } } // Relations next Map<String, Relationship> relationships = resource.getRelationships(); if (relationships != null) { for (Map.Entry<String, Relationship> entry : relationships.entrySet()) { String fieldName = entry.getKey(); Relationship relationship = entry.getValue(); Set<PersistentResource> resources = (relationship == null) ? null : relationship.toPersistentResources(requestScope); isUpdated |= record.updateRelation(fieldName, resources); } } return isUpdated; } }
private boolean patch(Resource resource, RequestScope requestScope) { boolean isUpdated = false; // Update attributes first Map<String, Object> attributes = resource.getAttributes(); if (attributes != null) { for (Map.Entry<String, Object> entry : attributes.entrySet()) { String fieldName = entry.getKey(); Object newVal = entry.getValue(); isUpdated |= record.updateAttribute(fieldName, newVal); } } // Relations next Map<String, Relationship> relationships = resource.getRelationships(); if (relationships != null) { for (Map.Entry<String, Relationship> entry : relationships.entrySet()) { String fieldName = entry.getKey(); Relationship relationship = entry.getValue(); Set<PersistentResource> resources = (relationship == null) ? null : relationship.toPersistentResources(requestScope); isUpdated |= record.updateRelation(fieldName, resources); } } return isUpdated; } }
parent.orElse(null), newObjectClass, requestScope, Optional.ofNullable(id)); Map<String, Object> attributes = resource.getAttributes(); if (attributes != null) { for (Map.Entry<String, Object> entry : attributes.entrySet()) {
parent.orElse(null), newObjectClass, requestScope, Optional.ofNullable(id)); Map<String, Object> attributes = resource.getAttributes(); if (attributes != null) { for (Map.Entry<String, Object> entry : attributes.entrySet()) {
@Test(priority = 1) public void testPatchAttrSingle() throws Exception { String request = jsonParser.getJson("/ResourceIT/testPatchAttrSingle.json"); given() .contentType(JSONAPI_CONTENT_TYPE) .accept(JSONAPI_CONTENT_TYPE) .body(request) .patch("/parent/2") .then() .statusCode(HttpStatus.SC_NO_CONTENT) .header(HttpHeaders.CONTENT_LENGTH, (String) null); String actual = given() .contentType(JSONAPI_CONTENT_TYPE) .accept(JSONAPI_CONTENT_TYPE) .get("/parent/2") .then() .statusCode(HttpStatus.SC_OK) .contentType(JSONAPI_CONTENT_TYPE) .extract().response().asString(); JsonApiDocument doc = jsonApiMapper.readJsonApiDocument(actual); Data<Resource> data = doc.getData(); Resource resource = data.getSingleValue(); assertEquals(resource.getAttributes().get("firstName"), "syzygy"); assertEquals(resource.getRelationships().size(), 2); assertEquals(resource.getRelationships().get("children").getData().get().size(), 2); }
assertEquals(resource.getAttributes().get("firstName"), "Unknown"); assertEquals(id1, "4"); assertEquals(id2, "5");