Search in sources :

Example 1 with MetaResourceField

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;
}
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 2 with MetaResourceField

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);
    }
}
Also used : MetaResourceField(io.crnk.meta.model.resource.MetaResourceField) TSField(io.crnk.gen.typescript.model.TSField) TSParameterizedType(io.crnk.gen.typescript.model.TSParameterizedType) TSType(io.crnk.gen.typescript.model.TSType) MetaType(io.crnk.meta.model.MetaType)

Aggregations

MetaResourceField (io.crnk.meta.model.resource.MetaResourceField)2 ResourceFilterDirectory (io.crnk.core.engine.filter.ResourceFilterDirectory)1 ResourceField (io.crnk.core.engine.information.resource.ResourceField)1 ResourceInformation (io.crnk.core.engine.information.resource.ResourceInformation)1 RegistryEntry (io.crnk.core.engine.registry.RegistryEntry)1 Module (io.crnk.core.module.Module)1 TSField (io.crnk.gen.typescript.model.TSField)1 TSParameterizedType (io.crnk.gen.typescript.model.TSParameterizedType)1 TSType (io.crnk.gen.typescript.model.TSType)1 MetaType (io.crnk.meta.model.MetaType)1 MetaResource (io.crnk.meta.model.resource.MetaResource)1