Search in sources :

Example 1 with ResourceFilterDirectory

use of io.crnk.core.engine.filter.ResourceFilterDirectory in project crnk-framework by crnk-project.

the class ResourceMetaFilter method adjustResourceForRequest.

private MetaElement adjustResourceForRequest(MetaResource metaResource) {
    Module.ModuleContext moduleContext = context.getModuleContext();
    RegistryEntry entry = moduleContext.getResourceRegistry().getEntry(metaResource.getResourceType());
    ResourceInformation resourceInformation = entry.getResourceInformation();
    ResourceFilterDirectory filterBehaviorProvider = moduleContext.getResourceFilterDirectory();
    boolean readable = metaResource.isReadable() && filterBehaviorProvider.get(resourceInformation, HttpMethod.GET) == FilterBehavior.NONE;
    boolean insertable = metaResource.isInsertable() && filterBehaviorProvider.get(resourceInformation, HttpMethod.POST) == FilterBehavior.NONE;
    boolean updatable = metaResource.isUpdatable() && filterBehaviorProvider.get(resourceInformation, HttpMethod.PATCH) == FilterBehavior.NONE;
    boolean deletable = metaResource.isDeletable() && filterBehaviorProvider.get(resourceInformation, HttpMethod.DELETE) == FilterBehavior.NONE;
    // hide element if no permission
    if (!readable && !insertable && !updatable && !deletable) {
        return null;
    }
    // update element if necessary
    if (metaResource.isReadable() != readable || metaResource.isUpdatable() != updatable || metaResource.isInsertable() != insertable || metaResource.isDeletable() != deletable) {
        MetaResource clone = (MetaResource) metaResource.duplicate();
        clone.setReadable(readable);
        clone.setInsertable(insertable);
        clone.setUpdatable(updatable);
        clone.setDeletable(deletable);
        return clone;
    }
    return metaResource;
}
Also used : ResourceInformation(io.crnk.core.engine.information.resource.ResourceInformation) MetaResource(io.crnk.meta.model.resource.MetaResource) Module(io.crnk.core.module.Module) RegistryEntry(io.crnk.core.engine.registry.RegistryEntry) ResourceFilterDirectory(io.crnk.core.engine.filter.ResourceFilterDirectory)

Example 2 with ResourceFilterDirectory

use of io.crnk.core.engine.filter.ResourceFilterDirectory in project crnk-framework by crnk-project.

the class ResourceMetaFilter method adjustFieldForRequest.

private MetaElement adjustFieldForRequest(MetaResourceField field) {
    MetaResource metaResource = (MetaResource) field.getParent();
    Module.ModuleContext moduleContext = context.getModuleContext();
    RegistryEntry entry = moduleContext.getResourceRegistry().getEntry(metaResource.getResourceType());
    ResourceInformation resourceInformation = entry.getResourceInformation();
    ResourceField fieldInformation = resourceInformation.findFieldByUnderlyingName(field.getName());
    ResourceFilterDirectory filterBehaviorProvider = moduleContext.getResourceFilterDirectory();
    boolean readable = metaResource.isReadable() && filterBehaviorProvider.get(fieldInformation, HttpMethod.GET) == FilterBehavior.NONE;
    boolean insertable = metaResource.isInsertable() && filterBehaviorProvider.get(fieldInformation, HttpMethod.POST) == FilterBehavior.NONE;
    boolean updatable = metaResource.isUpdatable() && filterBehaviorProvider.get(fieldInformation, HttpMethod.PATCH) == FilterBehavior.NONE;
    // hide element if no permission
    if (!readable && !insertable && !updatable) {
        return null;
    }
    if (field.isUpdatable() != updatable || field.isInsertable() != insertable) {
        MetaResourceField clone = (MetaResourceField) field.duplicate();
        clone.setInsertable(insertable);
        clone.setUpdatable(updatable);
        return clone;
    }
    return field;
}
Also used : MetaResourceField(io.crnk.meta.model.resource.MetaResourceField) ResourceField(io.crnk.core.engine.information.resource.ResourceField) MetaResourceField(io.crnk.meta.model.resource.MetaResourceField) ResourceInformation(io.crnk.core.engine.information.resource.ResourceInformation) MetaResource(io.crnk.meta.model.resource.MetaResource) Module(io.crnk.core.module.Module) RegistryEntry(io.crnk.core.engine.registry.RegistryEntry) ResourceFilterDirectory(io.crnk.core.engine.filter.ResourceFilterDirectory)

Example 3 with ResourceFilterDirectory

use of io.crnk.core.engine.filter.ResourceFilterDirectory in project crnk-framework by crnk-project.

the class ControllerRegistryBuilderTest method onBuildShouldAddAllControllers.

@Test
public void onBuildShouldAddAllControllers() throws Exception {
    // GIVEN
    PropertiesProvider propertiesProvider = Mockito.mock(PropertiesProvider.class);
    ResourceFilterDirectory resourceFilterDirectory = Mockito.mock(ResourceFilterDirectory.class);
    ControllerRegistryBuilder sut = new ControllerRegistryBuilder(null, null, null, propertiesProvider, resourceFilterDirectory, (List) Collections.emptyList());
    // WHEN
    ControllerRegistry result = sut.build();
    // THEN
    result.getController(new ResourcePath("path"), "GET");
}
Also used : PropertiesProvider(io.crnk.core.engine.properties.PropertiesProvider) ControllerRegistry(io.crnk.core.engine.internal.dispatcher.ControllerRegistry) ResourcePath(io.crnk.core.engine.internal.dispatcher.path.ResourcePath) ResourceFilterDirectory(io.crnk.core.engine.filter.ResourceFilterDirectory) ControllerRegistryBuilder(io.crnk.core.engine.internal.dispatcher.ControllerRegistryBuilder) Test(org.junit.Test)

Aggregations

ResourceFilterDirectory (io.crnk.core.engine.filter.ResourceFilterDirectory)3 ResourceInformation (io.crnk.core.engine.information.resource.ResourceInformation)2 RegistryEntry (io.crnk.core.engine.registry.RegistryEntry)2 Module (io.crnk.core.module.Module)2 MetaResource (io.crnk.meta.model.resource.MetaResource)2 ResourceField (io.crnk.core.engine.information.resource.ResourceField)1 ControllerRegistry (io.crnk.core.engine.internal.dispatcher.ControllerRegistry)1 ControllerRegistryBuilder (io.crnk.core.engine.internal.dispatcher.ControllerRegistryBuilder)1 ResourcePath (io.crnk.core.engine.internal.dispatcher.path.ResourcePath)1 PropertiesProvider (io.crnk.core.engine.properties.PropertiesProvider)1 MetaResourceField (io.crnk.meta.model.resource.MetaResourceField)1 Test (org.junit.Test)1