use of io.crnk.meta.model.resource.MetaResourceField 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.meta.model.resource.MetaResourceField in project crnk-framework by crnk-project.
the class TSMetaDataObjectTransformation method generateResourceField.
private static void generateResourceField(MetaAttribute attr, TSMetaTransformationContext context, TSInterfaceType interfaceType, TSInterfaceType attributesType, TSInterfaceType relationshipsType) {
MetaType metaElementType = attr.getType().getElementType();
TSType elementType = (TSType) context.transform(metaElementType, TSMetaTransformationOptions.EMPTY);
TSField field = new TSField();
field.setName(attr.getName());
field.setType(elementType);
field.setNullable(true);
if (attr.isAssociation()) {
TSType relationshipType = attr.getType().isCollection() ? NgrxJsonApiLibrary.TYPED_MANY_RESOURCE_RELATIONSHIP : NgrxJsonApiLibrary.TYPED_ONE_RESOURCE_RELATIONSHIP;
field.setType(new TSParameterizedType(relationshipType, elementType));
relationshipsType.getDeclaredMembers().add(field);
field.setParent(relationshipsType);
} else if (attr instanceof MetaResourceField && ((MetaResourceField) attr).isMeta()) {
field.setName("meta");
interfaceType.getDeclaredMembers().add(field);
field.setParent(interfaceType);
} else if (attr instanceof MetaResourceField && ((MetaResourceField) attr).isLinks()) {
field.setName("links");
interfaceType.getDeclaredMembers().add(field);
field.setParent(interfaceType);
} else {
attributesType.getDeclaredMembers().add(field);
field.setParent(attributesType);
}
}
Aggregations