use of io.crnk.core.engine.information.resource.ResourceField in project crnk-framework by crnk-project.
the class ResourceInformationProviderBase method getResourceFields.
protected List<ResourceField> getResourceFields(Class<?> resourceClass) {
BeanInformation beanDesc = BeanInformation.get(resourceClass);
List<String> attributeNames = beanDesc.getAttributeNames();
List<ResourceField> fields = new ArrayList<>();
Set<String> relationIdFields = new HashSet<>();
for (String attributeName : attributeNames) {
BeanAttributeInformation attributeDesc = beanDesc.getAttribute(attributeName);
if (!isIgnored(attributeDesc)) {
InformationBuilder informationBuilder = context.getInformationBuilder();
InformationBuilder.Field fieldBuilder = informationBuilder.createResourceField();
buildResourceField(beanDesc, attributeDesc, fieldBuilder);
fields.add(fieldBuilder.build());
} else if (attributeDesc.getAnnotation(JsonApiRelationId.class).isPresent()) {
relationIdFields.add(attributeDesc.getName());
}
}
verifyRelationIdFields(resourceClass, relationIdFields, fields);
return fields;
}
use of io.crnk.core.engine.information.resource.ResourceField 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.ResourceField in project crnk-framework by crnk-project.
the class DefaultResourceInformationProviderTest method checkJsonApiAttributeAnnotation.
@Test
public void checkJsonApiAttributeAnnotation() throws Exception {
ResourceInformation resourceInformation = resourceInformationProvider.build(Task.class);
ResourceField field = resourceInformation.findAttributeFieldByName("status");
Assert.assertFalse(field.getAccess().isPatchable());
Assert.assertFalse(field.getAccess().isPostable());
}
use of io.crnk.core.engine.information.resource.ResourceField in project crnk-framework by crnk-project.
the class DefaultResourceInformationProviderTest method checkJsonApiAttributeAnnotationDefaultsForIds.
@Test
public void checkJsonApiAttributeAnnotationDefaultsForIds() throws Exception {
ResourceInformation resourceInformation = resourceInformationProvider.build(Task.class);
ResourceField field = resourceInformation.getIdField();
Assert.assertFalse(field.getAccess().isPatchable());
Assert.assertTrue(field.getAccess().isPostable());
Assert.assertTrue(field.getAccess().isReadable());
}
use of io.crnk.core.engine.information.resource.ResourceField in project crnk-framework by crnk-project.
the class JsonApiRelationIdInformationProviderTest method shouldAutoDetectWithCustomName.
@Test
public void shouldAutoDetectWithCustomName() {
ResourceInformation resourceInformation = resourceInformationProvider.build(RenamedIdFieldResource.class);
ResourceField field = resourceInformation.findFieldByName("project");
Assert.assertNotNull(field);
Assert.assertNull(resourceInformation.findFieldByName("projectFk"));
Assert.assertTrue(field.hasIdField());
RenamedIdFieldResource resource = new RenamedIdFieldResource();
Assert.assertNull(field.getIdAccessor().getValue(resource));
field.getIdAccessor().setValue(resource, 13L);
Assert.assertEquals(13L, resource.getProjectFk().longValue());
Assert.assertEquals(13L, field.getIdAccessor().getValue(resource));
}
Aggregations