use of io.crnk.core.engine.information.resource.ResourceField 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.core.engine.information.resource.ResourceField 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;
}
use of io.crnk.core.engine.information.resource.ResourceField in project crnk-framework by crnk-project.
the class BraveUtil method getSpanName.
public static String getSpanName(RepositoryRequestSpec request) {
ResourceField relationshipField = request.getRelationshipField();
StringBuilder pathBuilder = new StringBuilder();
String method = request.getMethod().toString();
pathBuilder.append(BraveRepositoryFilter.COMPONENT_NAME);
pathBuilder.append(BraveRepositoryFilter.COMPONENT_NAME_SEPARATOR);
pathBuilder.append(method);
pathBuilder.append(BraveRepositoryFilter.COMPONENT_NAME_SEPARATOR);
pathBuilder.append("/");
if (relationshipField == null) {
pathBuilder.append(request.getQueryAdapter().getResourceInformation().getResourceType());
} else {
pathBuilder.append(relationshipField.getParentResourceInformation().getResourceType());
}
pathBuilder.append("/");
Iterable<Object> ids = request.getIds();
if (ids != null) {
pathBuilder.append(StringUtils.join(",", ids));
pathBuilder.append("/");
}
if (relationshipField != null) {
pathBuilder.append(relationshipField.getJsonName());
pathBuilder.append("/");
}
return pathBuilder.toString();
}
use of io.crnk.core.engine.information.resource.ResourceField in project crnk-framework by crnk-project.
the class JpaPartialEntityExposureTest method testInformationBuilder.
@Test
public void testInformationBuilder() {
EntityManager em = null;
JpaResourceInformationProvider builder = new JpaResourceInformationProvider(new NullPropertiesProvider());
ResourceInformation info = builder.build(TestEntity.class);
List<ResourceField> relationshipFields = info.getRelationshipFields();
Assert.assertEquals(0, relationshipFields.size());
}
use of io.crnk.core.engine.information.resource.ResourceField in project crnk-framework by crnk-project.
the class DefaultRegistryEntryBuilder method buildRelationships.
private Map<ResourceField, ResponseRelationshipEntry> buildRelationships(ResourceInformation resourceInformation) {
for (String relationshipName : relationshipRepositoryMap.keySet()) {
if (resourceInformation.findFieldByUnderlyingName(relationshipName) == null) {
throw new ResourceFieldNotFoundException("failed to find relationship field '" + relationshipName + "' to setup " + "registered relationship repository");
}
}
Map<ResourceField, ResponseRelationshipEntry> map = new HashMap<>();
for (ResourceField relationshipField : resourceInformation.getRelationshipFields()) {
ResponseRelationshipEntry relationshipEntry = null;
// check for local definition
DefaultRelationshipRepository repository = relationshipRepositoryMap.get(relationshipField.getUnderlyingName());
if (repository != null) {
RelationshipRepositoryInformation relationshipInformation = repository.information.build();
relationshipEntry = setupRelationship(relationshipField, relationshipInformation, repository.instance);
}
// check for match
if (relationshipEntry == null) {
relationshipEntry = findRelationshipMatch(relationshipField);
}
// check for implicit
if (relationshipEntry == null) {
relationshipEntry = setupImplicitRelationshipRepository(relationshipField);
}
if (relationshipEntry != null) {
map.put(relationshipField, relationshipEntry);
} else {
LOGGER.warn("no relationship repository found for " + resourceInformation.getResourceType() + "." + relationshipField.getUnderlyingName());
}
}
return map;
}
Aggregations