use of io.crnk.core.engine.information.resource.ResourceInformation 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.information.resource.ResourceInformation 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);
}
use of io.crnk.core.engine.information.resource.ResourceInformation in project crnk-framework by crnk-project.
the class DefaultResourceRegistryPart method addEntry.
@Override
public RegistryEntry addEntry(RegistryEntry entry) {
ResourceInformation resourceInformation = entry.getResourceInformation();
Class<?> resourceClass = resourceInformation.getResourceClass();
String resourceType = resourceInformation.getResourceType();
PreconditionUtil.assertNotNull("no resourceType set", resourceType);
resourcesByClass.put(resourceClass, entry);
resourcesByType.put(resourceType, entry);
logger.debug("Added resource {} to ResourceRegistry", entry.getResourceInformation().getResourceType());
notifyChange();
return entry;
}
use of io.crnk.core.engine.information.resource.ResourceInformation in project crnk-framework by crnk-project.
the class RegistryEntry method getResourceRepository.
@SuppressWarnings("unchecked")
public ResourceRepositoryAdapter getResourceRepository(RepositoryMethodParameterProvider parameterProvider) {
Object repoInstance = null;
if (resourceEntry instanceof DirectResponseResourceEntry) {
repoInstance = ((DirectResponseResourceEntry) resourceEntry).getResourceRepository();
} else if (resourceEntry instanceof AnnotatedResourceEntry) {
repoInstance = ((AnnotatedResourceEntry) resourceEntry).build(parameterProvider);
}
if (repoInstance instanceof ResourceRegistryAware) {
((ResourceRegistryAware) repoInstance).setResourceRegistry(moduleRegistry.getResourceRegistry());
}
ResourceInformation resourceInformation = getResourceInformation();
return new ResourceRepositoryAdapter(resourceInformation, moduleRegistry, repoInstance);
}
use of io.crnk.core.engine.information.resource.ResourceInformation in project crnk-framework by crnk-project.
the class DefaultResourceInformationProviderTest method shouldHaveOneIdFieldOfTypeLong.
@Test
public void shouldHaveOneIdFieldOfTypeLong() {
/*
Task has a Long getId() field and a boolean hasId() which is ignored, only the former should have survived
*/
ResourceInformation resourceInformation = resourceInformationProvider.build(Task.class);
assertThat(resourceInformation.getIdField()).isNotNull();
assertThat(resourceInformation.getIdField().getType()).isEqualTo(Long.class);
assertThat(containsFieldWithName(resourceInformation, "hasId")).isFalse();
}
Aggregations