diff --git a/crnk-core/src/main/java/io/crnk/core/boot/CrnkBoot.java b/crnk-core/src/main/java/io/crnk/core/boot/CrnkBoot.java index 7b1ff3c97..a35f069d5 100644 --- a/crnk-core/src/main/java/io/crnk/core/boot/CrnkBoot.java +++ b/crnk-core/src/main/java/io/crnk/core/boot/CrnkBoot.java @@ -240,6 +240,7 @@ private List toSimpleNames(List implementations) { private void setupRepositories(ResourceRegistryPart rootPart) { for (RegistryEntry entry : moduleRegistry.getRegistryEntries()) { rootPart.addEntry(entry); + entry.getResourceInformation().initNesting(); } } diff --git a/crnk-core/src/main/java/io/crnk/core/engine/information/resource/ResourceInformation.java b/crnk-core/src/main/java/io/crnk/core/engine/information/resource/ResourceInformation.java index ec8e78d55..0353bc59b 100644 --- a/crnk-core/src/main/java/io/crnk/core/engine/information/resource/ResourceInformation.java +++ b/crnk-core/src/main/java/io/crnk/core/engine/information/resource/ResourceInformation.java @@ -273,6 +273,9 @@ private boolean setupManyNesting() { parentAttribute.getName(), implementationClass); ((ResourceFieldImpl) parentField).setIdField(parentAttribute.getName(), parentAttribute.getImplementationClass(), parentIdAccessor); + if(null == ((ResourceFieldImpl)parentField).getOppositeName() && shouldBeNested()) { + ((ResourceFieldImpl)parentField).setOppositeName(resourcePath); + } } return true; diff --git a/crnk-core/src/main/java/io/crnk/core/engine/internal/dispatcher/controller/FieldResourcePost.java b/crnk-core/src/main/java/io/crnk/core/engine/internal/dispatcher/controller/FieldResourcePost.java index b1912c4fb..2ebe8dda4 100644 --- a/crnk-core/src/main/java/io/crnk/core/engine/internal/dispatcher/controller/FieldResourcePost.java +++ b/crnk-core/src/main/java/io/crnk/core/engine/internal/dispatcher/controller/FieldResourcePost.java @@ -56,7 +56,6 @@ public Result handleAsync(JsonPath jsonPath, QueryAdapter queryAdapter RegistryEntry bodyRegistryEntry = resourceRegistry.getEntry(resourceBody.getType()); ResourceInformation bodyResourceInformation = bodyRegistryEntry.getResourceInformation(); - Serializable id = jsonPath.getId(); ResourceField relationshipField = fieldPath.getField(); @@ -69,13 +68,13 @@ public Result handleAsync(JsonPath jsonPath, QueryAdapter queryAdapter DocumentMapper documentMapper = context.getDocumentMapper(); QueryContext queryContext = queryAdapter.getQueryContext(); - Object entity = buildNewResource(relationshipRegistryEntry, resourceBody, relationshipResourceType); + Object entity = buildNewResource(bodyRegistryEntry, resourceBody, relationshipResourceType); - setId(resourceBody, entity, relationshipResourceInformation); + setId(resourceBody, entity, bodyResourceInformation); setType(resourceBody, entity); - setAttributes(resourceBody, entity, relationshipResourceInformation, queryContext); - setMeta(resourceBody, entity, relationshipResourceInformation); - setLinks(resourceBody, entity, relationshipResourceInformation); + setAttributes(resourceBody, entity, bodyResourceInformation, queryContext); + setMeta(resourceBody, entity, bodyResourceInformation); + setLinks(resourceBody, entity, bodyResourceInformation); Result createdResource = setRelationsAsync(entity, bodyRegistryEntry, resourceBody, queryAdapter, false) .merge(it -> resourceRepository.create(entity, queryAdapter)); diff --git a/crnk-core/src/main/java/io/crnk/core/engine/internal/dispatcher/controller/ResourceUpsert.java b/crnk-core/src/main/java/io/crnk/core/engine/internal/dispatcher/controller/ResourceUpsert.java index 41865e53e..2a8606317 100644 --- a/crnk-core/src/main/java/io/crnk/core/engine/internal/dispatcher/controller/ResourceUpsert.java +++ b/crnk-core/src/main/java/io/crnk/core/engine/internal/dispatcher/controller/ResourceUpsert.java @@ -210,12 +210,10 @@ protected boolean checkAccess() { Object buildNewResource(RegistryEntry registryEntry, Resource dataBody, String resourceName) { + RegistryEntry relationshipRegistryEntry = context.getResourceRegistry().getEntry(resourceName); + PreconditionUtil.verify(dataBody != null, "No data field in the body."); - PreconditionUtil.verify(resourceName.equals(dataBody.getType()), - "Inconsistent type definition between path and body: body type: " + - "%s, request type: %s", - dataBody.getType(), - resourceName); + verifyTypes(HttpMethod.POST, relationshipRegistryEntry, registryEntry); ResourceInstanceBuilder instanceBuilder = registryEntry.getResourceInformation().getInstanceBuilder(); Object entity = instanceBuilder.buildResource(dataBody);