use of io.crnk.meta.model.resource.MetaResource in project crnk-framework by crnk-project.
the class MetaRelationshipRepositoryImplTest method findManyTargetCannotBeUsedForSingeValuesRelations.
@Test(expected = ClassCastException.class)
public void findManyTargetCannotBeUsedForSingeValuesRelations() {
MetaResource resource = resourceProvider.getMeta(Task.class);
repo.findManyTargets(resource.getId(), "primaryKey", new QuerySpec(MetaElement.class));
}
use of io.crnk.meta.model.resource.MetaResource in project crnk-framework by crnk-project.
the class MetaFilteringTest method checkReadOnlyAttribute.
@Test
public void checkReadOnlyAttribute() throws IOException {
RegistryEntry entry = boot.getResourceRegistry().getEntry(Task.class);
ResourceInformation resourceInformation = entry.getResourceInformation();
ResourceField projectField = resourceInformation.findFieldByUnderlyingName("project");
Mockito.when(filter.filterField(Mockito.eq(projectField), Mockito.eq(HttpMethod.POST))).thenReturn(FilterBehavior.FORBIDDEN);
Mockito.when(filter.filterField(Mockito.eq(projectField), Mockito.eq(HttpMethod.PATCH))).thenReturn(FilterBehavior.FORBIDDEN);
QuerySpec querySpec = new QuerySpec(MetaResource.class);
querySpec.addFilter(new FilterSpec(Arrays.asList("name"), FilterOperator.EQ, "Tasks"));
ResourceList<MetaResource> list = repository.findAll(querySpec);
Assert.assertEquals(1, list.size());
MetaResource taskMeta = list.get(0);
Assert.assertTrue(taskMeta.hasAttribute("project"));
MetaAttribute projectAttr = taskMeta.getAttribute("project");
Assert.assertFalse(projectAttr.isInsertable());
Assert.assertFalse(projectAttr.isUpdatable());
}
use of io.crnk.meta.model.resource.MetaResource in project crnk-framework by crnk-project.
the class ResourceMetaFilter method getResourceInformation.
private ResourceInformation getResourceInformation(MetaResourceBase meta, boolean allowNull) {
ResourceRegistry resourceRegistry = context.getModuleContext().getResourceRegistry();
if (meta instanceof MetaResource) {
RegistryEntry entry = resourceRegistry.getEntry(((MetaResource) meta).getResourceType());
if (entry != null) {
return entry.getResourceInformation();
}
}
Class<?> resourceClass = meta.getImplementationClass();
ResourceInformationProvider infoBuilder = context.getModuleContext().getResourceInformationBuilder();
if (infoBuilder.accept(resourceClass)) {
return infoBuilder.build(resourceClass);
}
if (allowNull) {
return null;
}
throw new IllegalStateException("failed to get information for " + resourceClass.getName());
}
use of io.crnk.meta.model.resource.MetaResource 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;
}
use of io.crnk.meta.model.resource.MetaResource 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;
}
Aggregations