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;
}
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();
}
}
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);
}
Aggregations