use of io.crnk.core.engine.registry.RegistryEntry in project crnk-framework by crnk-project.
the class ConstraintViolationExceptionMapper method getResourceType.
protected String getResourceType(Object resource) {
ResourceRegistry resourceRegistry = context.getResourceRegistry();
RegistryEntry entry = resourceRegistry.findEntry(resource.getClass());
ResourceInformation resourceInformation = entry.getResourceInformation();
return resourceInformation.getResourceType();
}
use of io.crnk.core.engine.registry.RegistryEntry in project crnk-framework by crnk-project.
the class DefaultRegistryEntryBuilder method build.
@Override
public RegistryEntry build() {
ResourceInformation resourceInformation = buildResource();
ResourceEntry resourceEntry = buildResourceRepository(resourceInformation);
Map<ResourceField, ResponseRelationshipEntry> relationshipEntries = buildRelationships(resourceInformation);
RegistryEntry entry = new RegistryEntry(resourceEntry, relationshipEntries);
entry.initialize(moduleRegistry);
return entry;
}
use of io.crnk.core.engine.registry.RegistryEntry in project crnk-framework by crnk-project.
the class ResourceRegistryImpl method getResourceUrl.
@Override
public String getResourceUrl(final Class<?> clazz, final String id) {
RegistryEntry registryEntry = findEntry(clazz);
String typeUrl = getResourceUrl(registryEntry.getResourceInformation());
return typeUrl != null ? String.format("%s/%s", typeUrl, id) : null;
}
use of io.crnk.core.engine.registry.RegistryEntry in project crnk-framework by crnk-project.
the class ResourceFilterDirectoryImpl method get.
@Override
public FilterBehavior get(ResourceField field, HttpMethod method) {
Map<Object, FilterBehavior> map = getCache(method);
FilterBehavior behavior = map.get(field);
if (behavior != null) {
return behavior;
}
behavior = FilterBehavior.NONE;
for (ResourceFilter filter : filters) {
behavior = behavior.merge(filter.filterField(field, method));
if (behavior == FilterBehavior.FORBIDDEN) {
break;
}
}
if (field.getResourceFieldType() == ResourceFieldType.RELATIONSHIP) {
// for relationships opposite site must also be accessible (at least with GET)
String oppositeResourceType = field.getOppositeResourceType();
RegistryEntry oppositeRegistryEntry = resourceRegistry.getEntry(oppositeResourceType);
if (oppositeRegistryEntry != null) {
PreconditionUtil.assertNotNull(oppositeResourceType, oppositeRegistryEntry);
ResourceInformation oppositeResourceInformation = oppositeRegistryEntry.getResourceInformation();
// consider checking more than GET? intersection/union of multiple?
behavior = behavior.merge(get(oppositeResourceInformation, HttpMethod.GET));
} else {
LOGGER.warn("opposite side {} not found", oppositeResourceType);
}
}
map.put(field, behavior);
return behavior;
}
use of io.crnk.core.engine.registry.RegistryEntry in project crnk-framework by crnk-project.
the class DefaultQuerySpecDeserializer method getAttributeType.
protected Class<?> getAttributeType(Class<?> clazz, String propertyName) {
if (resourceRegistry.hasEntry(clazz)) {
RegistryEntry entry = resourceRegistry.getEntryForClass(clazz);
ResourceInformation resourceInformation = entry.getResourceInformation();
ResourceField field = resourceInformation.findFieldByName(propertyName);
if (field != null) {
return field.getType();
}
}
return PropertyUtils.getPropertyClass(clazz, propertyName);
}
Aggregations