use of io.crnk.core.engine.information.resource.ResourceInformation 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.core.engine.information.resource.ResourceInformation 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.ResourceInformation 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.ResourceInformation in project crnk-framework by crnk-project.
the class DefaultRegistryEntryBuilder method setupImplicitRelationshipRepository.
private ResponseRelationshipEntry setupImplicitRelationshipRepository(ResourceField relationshipField) {
RelationshipRepositoryBehavior behavior = relationshipField.getRelationshipRepositoryBehavior();
if (behavior == RelationshipRepositoryBehavior.DEFAULT) {
if (relationshipField.hasIdField() || relationshipField.getLookupIncludeAutomatically() == LookupIncludeBehavior.NONE) {
behavior = RelationshipRepositoryBehavior.FORWARD_OWNER;
} else {
behavior = RelationshipRepositoryBehavior.CUSTOM;
}
}
if (behavior == RelationshipRepositoryBehavior.IMPLICIT_FROM_OWNER) {
behavior = RelationshipRepositoryBehavior.FORWARD_OWNER;
}
if (behavior == RelationshipRepositoryBehavior.IMPLICIT_GET_OPPOSITE_MODIFY_OWNER) {
behavior = RelationshipRepositoryBehavior.FORWARD_GET_OPPOSITE_SET_OWNER;
}
if (behavior != RelationshipRepositoryBehavior.CUSTOM) {
ResourceInformation sourceInformation = relationshipField.getParentResourceInformation();
ResourceFieldAccess fieldAccess = relationshipField.getAccess();
RepositoryMethodAccess access = new RepositoryMethodAccess(fieldAccess.isPostable(), fieldAccess.isPatchable(), fieldAccess.isReadable(), fieldAccess.isPatchable());
RelationshipMatcher matcher = new RelationshipMatcher().rule().field(relationshipField).add();
RelationshipRepositoryInformationImpl implicitRepoInformation = new RelationshipRepositoryInformationImpl(matcher, access);
ForwardingRelationshipRepository repository;
if (behavior == RelationshipRepositoryBehavior.FORWARD_OWNER) {
repository = new ForwardingRelationshipRepository(sourceInformation.getResourceType(), matcher, ForwardingDirection.OWNER, ForwardingDirection.OWNER);
} else if (behavior == RelationshipRepositoryBehavior.FORWARD_GET_OPPOSITE_SET_OWNER) {
repository = new ForwardingRelationshipRepository(sourceInformation.getResourceType(), matcher, ForwardingDirection.OPPOSITE, ForwardingDirection.OWNER);
} else {
PreconditionUtil.assertEquals("unknown behavior", RelationshipRepositoryBehavior.FORWARD_OPPOSITE, behavior);
repository = new ForwardingRelationshipRepository(sourceInformation.getResourceType(), matcher, ForwardingDirection.OPPOSITE, ForwardingDirection.OPPOSITE);
}
repository.setResourceRegistry(moduleRegistry.getResourceRegistry());
return setupRelationship(relationshipField, implicitRepoInformation, repository);
} else {
return null;
}
}
use of io.crnk.core.engine.information.resource.ResourceInformation in project crnk-framework by crnk-project.
the class DefaultRegistryEntryBuilder method fromImplementation.
@Override
public void fromImplementation(Object repository) {
RepositoryInformationProvider repositoryInformationBuilder = moduleRegistry.getRepositoryInformationBuilder();
RepositoryInformationProviderContext builderContext = new DefaultRepositoryInformationProviderContext(moduleRegistry);
ResourceRepositoryInformation repositoryInformation = (ResourceRepositoryInformation) repositoryInformationBuilder.build(repository, builderContext);
ResourceInformation resourceInformation = repositoryInformation.getResourceInformation().get();
resource().from(resourceInformation);
resourceRepository().information().from(repositoryInformation);
resourceRepository().instance(repository);
}
Aggregations