Search in sources :

Example 61 with ResourceField

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;
}
Also used : BeanInformation(io.crnk.core.engine.information.bean.BeanInformation) InformationBuilder(io.crnk.core.engine.information.InformationBuilder) ResourceField(io.crnk.core.engine.information.resource.ResourceField) ArrayList(java.util.ArrayList) BeanAttributeInformation(io.crnk.core.engine.information.bean.BeanAttributeInformation) HashSet(java.util.HashSet)

Example 62 with ResourceField

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);
}
Also used : ResourceField(io.crnk.core.engine.information.resource.ResourceField) ResourceInformation(io.crnk.core.engine.information.resource.ResourceInformation) RegistryEntry(io.crnk.core.engine.registry.RegistryEntry)

Example 63 with ResourceField

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());
}
Also used : ResourceField(io.crnk.core.engine.information.resource.ResourceField) ResourceInformation(io.crnk.core.engine.information.resource.ResourceInformation) Test(org.junit.Test)

Example 64 with ResourceField

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());
}
Also used : ResourceField(io.crnk.core.engine.information.resource.ResourceField) ResourceInformation(io.crnk.core.engine.information.resource.ResourceInformation) Test(org.junit.Test)

Example 65 with ResourceField

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));
}
Also used : ResourceField(io.crnk.core.engine.information.resource.ResourceField) ResourceInformation(io.crnk.core.engine.information.resource.ResourceInformation) Test(org.junit.Test)

Aggregations

ResourceField (io.crnk.core.engine.information.resource.ResourceField)109 ResourceInformation (io.crnk.core.engine.information.resource.ResourceInformation)75 Test (org.junit.Test)41 RegistryEntry (io.crnk.core.engine.registry.RegistryEntry)36 JsonApiResponse (io.crnk.core.repository.response.JsonApiResponse)14 QueryAdapter (io.crnk.core.engine.query.QueryAdapter)13 QuerySpec (io.crnk.core.queryspec.QuerySpec)11 ArrayList (java.util.ArrayList)9 RepositoryRequestSpec (io.crnk.core.engine.dispatcher.RepositoryRequestSpec)8 Response (io.crnk.core.engine.dispatcher.Response)8 Resource (io.crnk.core.engine.document.Resource)8 RepositoryFilterContext (io.crnk.core.engine.filter.RepositoryFilterContext)8 BulkRelationshipRepositoryV2 (io.crnk.core.repository.BulkRelationshipRepositoryV2)8 HashSet (java.util.HashSet)8 Document (io.crnk.core.engine.document.Document)7 Task (io.crnk.core.mock.models.Task)7 Serializable (java.io.Serializable)7 RelationshipRepositoryAdapter (io.crnk.core.engine.internal.repository.RelationshipRepositoryAdapter)6 ResourceRepositoryAdapter (io.crnk.core.engine.internal.repository.ResourceRepositoryAdapter)6 MultivaluedMap (io.crnk.core.engine.internal.utils.MultivaluedMap)6