Search in sources :

Example 1 with ResourceFieldNotFoundException

use of io.crnk.core.exception.ResourceFieldNotFoundException in project crnk-framework by crnk-project.

the class DefaultRegistryEntryBuilder method buildRelationships.

private Map<ResourceField, ResponseRelationshipEntry> buildRelationships(ResourceInformation resourceInformation) {
    for (String relationshipName : relationshipRepositoryMap.keySet()) {
        if (resourceInformation.findFieldByUnderlyingName(relationshipName) == null) {
            throw new ResourceFieldNotFoundException("failed to find relationship field '" + relationshipName + "' to setup " + "registered relationship repository");
        }
    }
    Map<ResourceField, ResponseRelationshipEntry> map = new HashMap<>();
    for (ResourceField relationshipField : resourceInformation.getRelationshipFields()) {
        ResponseRelationshipEntry relationshipEntry = null;
        // check for local definition
        DefaultRelationshipRepository repository = relationshipRepositoryMap.get(relationshipField.getUnderlyingName());
        if (repository != null) {
            RelationshipRepositoryInformation relationshipInformation = repository.information.build();
            relationshipEntry = setupRelationship(relationshipField, relationshipInformation, repository.instance);
        }
        // check for match
        if (relationshipEntry == null) {
            relationshipEntry = findRelationshipMatch(relationshipField);
        }
        // check for implicit
        if (relationshipEntry == null) {
            relationshipEntry = setupImplicitRelationshipRepository(relationshipField);
        }
        if (relationshipEntry != null) {
            map.put(relationshipField, relationshipEntry);
        } else {
            LOGGER.warn("no relationship repository found for " + resourceInformation.getResourceType() + "." + relationshipField.getUnderlyingName());
        }
    }
    return map;
}
Also used : ResourceField(io.crnk.core.engine.information.resource.ResourceField) RelationshipRepositoryInformation(io.crnk.core.engine.information.repository.RelationshipRepositoryInformation) ResourceFieldNotFoundException(io.crnk.core.exception.ResourceFieldNotFoundException) ResponseRelationshipEntry(io.crnk.core.engine.registry.ResponseRelationshipEntry) DirectResponseRelationshipEntry(io.crnk.legacy.internal.DirectResponseRelationshipEntry) HashMap(java.util.HashMap)

Example 2 with ResourceFieldNotFoundException

use of io.crnk.core.exception.ResourceFieldNotFoundException in project crnk-framework by crnk-project.

the class HttpRequestProcessorImpl method getRequestedResource.

private ResourceInformation getRequestedResource(JsonPath jsonPath) {
    ResourceRegistry resourceRegistry = moduleRegistry.getResourceRegistry();
    RegistryEntry registryEntry = resourceRegistry.getEntry(jsonPath.getResourceType());
    PreconditionUtil.assertNotNull("repository not found, that should have been catched earlier", registryEntry);
    String elementName = jsonPath.getElementName();
    if (elementName != null && !elementName.equals(jsonPath.getResourceType())) {
        ResourceField relationshipField = registryEntry.getResourceInformation().findRelationshipFieldByName(elementName);
        if (relationshipField == null) {
            throw new ResourceFieldNotFoundException(elementName);
        }
        String oppositeResourceType = relationshipField.getOppositeResourceType();
        return resourceRegistry.getEntry(oppositeResourceType).getResourceInformation();
    } else {
        return registryEntry.getResourceInformation();
    }
}
Also used : ResourceField(io.crnk.core.engine.information.resource.ResourceField) ResourceFieldNotFoundException(io.crnk.core.exception.ResourceFieldNotFoundException) ResourceRegistry(io.crnk.core.engine.registry.ResourceRegistry) RegistryEntry(io.crnk.core.engine.registry.RegistryEntry)

Example 3 with ResourceFieldNotFoundException

use of io.crnk.core.exception.ResourceFieldNotFoundException in project crnk-framework by crnk-project.

the class PathBuilder method getNonResourcePath.

private JsonPath getNonResourcePath(JsonPath previousJsonPath, String elementName, boolean relationshipMark) {
    String previousElementName = previousJsonPath.getElementName();
    RegistryEntry previousEntry = resourceRegistry.getEntry(previousElementName);
    ResourceInformation resourceInformation = previousEntry.getResourceInformation();
    List<ResourceField> resourceFields = resourceInformation.getRelationshipFields();
    for (ResourceField field : resourceFields) {
        if (field.getJsonName().equals(elementName)) {
            if (relationshipMark) {
                return new RelationshipsPath(elementName);
            } else {
                return new FieldPath(elementName);
            }
        }
    }
    // TODO: Throw different exception? element name can be null..
    throw new ResourceFieldNotFoundException(elementName);
}
Also used : ResourceField(io.crnk.core.engine.information.resource.ResourceField) ResourceInformation(io.crnk.core.engine.information.resource.ResourceInformation) ResourceFieldNotFoundException(io.crnk.core.exception.ResourceFieldNotFoundException) RegistryEntry(io.crnk.core.engine.registry.RegistryEntry)

Aggregations

ResourceField (io.crnk.core.engine.information.resource.ResourceField)3 ResourceFieldNotFoundException (io.crnk.core.exception.ResourceFieldNotFoundException)3 RegistryEntry (io.crnk.core.engine.registry.RegistryEntry)2 RelationshipRepositoryInformation (io.crnk.core.engine.information.repository.RelationshipRepositoryInformation)1 ResourceInformation (io.crnk.core.engine.information.resource.ResourceInformation)1 ResourceRegistry (io.crnk.core.engine.registry.ResourceRegistry)1 ResponseRelationshipEntry (io.crnk.core.engine.registry.ResponseRelationshipEntry)1 DirectResponseRelationshipEntry (io.crnk.legacy.internal.DirectResponseRelationshipEntry)1 HashMap (java.util.HashMap)1