use of com.yahoo.elide.core.dictionary.EntityDictionary in project elide by yahoo.
the class FilteredIteratorTest method testEmptyResult.
@Test
public void testEmptyResult() throws Exception {
EntityDictionary dictionary = EntityDictionary.builder().build();
dictionary.bindEntity(Book.class);
List<Book> books = List.of();
RSQLFilterDialect filterDialect = RSQLFilterDialect.builder().dictionary(dictionary).build();
FilterExpression expression = filterDialect.parse(ClassType.of(Book.class), new HashSet<>(), "title==*bar", NO_VERSION);
RequestScope scope = new TestRequestScope(null, null, dictionary);
Iterator<Book> bookIterator = new FilteredIterator<>(expression, scope, books.iterator());
assertFalse(bookIterator.hasNext());
assertThrows(NoSuchElementException.class, () -> bookIterator.next());
}
use of com.yahoo.elide.core.dictionary.EntityDictionary in project elide by yahoo.
the class FilterPredicateTest method setup.
@BeforeAll
static void setup() {
EntityDictionary entityDictionary = EntityDictionary.builder().build();
entityDictionary.bindEntity(Book.class);
entityDictionary.bindEntity(Author.class);
strategy = new DefaultFilterDialect(entityDictionary);
}
use of com.yahoo.elide.core.dictionary.EntityDictionary in project elide by yahoo.
the class DefaultFilterDialectTest method init.
@BeforeAll
public static void init() {
EntityDictionary dictionary = EntityDictionary.builder().build();
dictionary.bindEntity(Author.class);
dictionary.bindEntity(Book.class);
dialect = new DefaultFilterDialect(dictionary);
}
use of com.yahoo.elide.core.dictionary.EntityDictionary in project elide by yahoo.
the class ElideAutoConfiguration method buildDictionary.
/**
* Creates the entity dictionary for Elide which contains static metadata about Elide models.
* Override to load check classes or life cycle hooks.
* @param beanFactory Injector to inject Elide models.
* @param dynamicConfig An instance of DynamicConfiguration.
* @param settings Elide configuration settings.
* @param entitiesToExclude set of Entities to exclude from binding.
* @return a newly configured EntityDictionary.
*/
@Bean
@ConditionalOnMissingBean
@Scope(SCOPE_PROTOTYPE)
public EntityDictionary buildDictionary(AutowireCapableBeanFactory beanFactory, ClassScanner scanner, @Autowired(required = false) DynamicConfiguration dynamicConfig, ElideConfigProperties settings, @Qualifier("entitiesToExclude") Set<Type<?>> entitiesToExclude) {
Map<String, Class<? extends Check>> checks = new HashMap<>();
if (settings.getDynamicConfig().isConfigApiEnabled()) {
checks.put(ConfigChecks.CAN_CREATE_CONFIG, ConfigChecks.CanNotCreate.class);
checks.put(ConfigChecks.CAN_READ_CONFIG, ConfigChecks.CanNotRead.class);
checks.put(ConfigChecks.CAN_DELETE_CONFIG, ConfigChecks.CanNotDelete.class);
checks.put(ConfigChecks.CAN_UPDATE_CONFIG, ConfigChecks.CanNotUpdate.class);
}
EntityDictionary dictionary = new EntityDictionary(// Checks
checks, // Role Checks
new HashMap<>(), new Injector() {
@Override
public void inject(Object entity) {
beanFactory.autowireBean(entity);
}
@Override
public <T> T instantiate(Class<T> cls) {
return beanFactory.createBean(cls);
}
}, // Serde Lookup
CoerceUtil::lookup, entitiesToExclude, scanner);
if (isAggregationStoreEnabled(settings) && isDynamicConfigEnabled(settings)) {
dynamicConfig.getRoles().forEach(role -> {
dictionary.addRoleCheck(role, new Role.RoleMemberCheck(role));
});
}
return dictionary;
}
use of com.yahoo.elide.core.dictionary.EntityDictionary in project elide by yahoo.
the class DataStoreTransaction method loadObject.
/**
* Loads an object by ID. The reason we support both load by ID and load by filter is that
* some legacy stores are optimized to load by ID.
*
* @param entityProjection the collection to load.
* @param id - the ID of the object to load.
* @param scope - the current request scope
* @param <T> The model type being loaded.
* It is optional for the data store to attempt evaluation.
* @return the loaded object if it exists AND any provided security filters pass.
*/
default <T> T loadObject(EntityProjection entityProjection, Serializable id, RequestScope scope) {
Type<?> entityClass = entityProjection.getType();
FilterExpression filterExpression = entityProjection.getFilterExpression();
EntityDictionary dictionary = scope.getDictionary();
Type idType = dictionary.getIdType(entityClass);
String idField = dictionary.getIdFieldName(entityClass);
FilterExpression idFilter = new InPredicate(new Path.PathElement(entityClass, idType, idField), id);
FilterExpression joinedFilterExpression = (filterExpression != null) ? new AndFilterExpression(idFilter, filterExpression) : idFilter;
Iterable<T> results = loadObjects(entityProjection.copyOf().filterExpression(joinedFilterExpression).build(), scope);
Iterator<T> it = results == null ? null : results.iterator();
if (it != null && it.hasNext()) {
T obj = it.next();
if (!it.hasNext()) {
return obj;
}
// Multiple objects with the same ID.
throw new InvalidObjectIdentifierException(id.toString(), dictionary.getJsonAliasFor(entityClass));
}
return null;
}
Aggregations