use of com.yahoo.elide.core.dictionary.Injector in project elide by yahoo.
the class MultiplexManagerTest method subordinateEntityDictionaryInheritsInjector.
@Test
public void subordinateEntityDictionaryInheritsInjector() {
final Injector injector = entity -> {
// NOOP
};
final QueryDictionaryDataStore ds1 = new QueryDictionaryDataStore();
final MultiplexManager multiplexManager = new MultiplexManager(ds1);
multiplexManager.populateEntityDictionary(EntityDictionary.builder().injector(injector).build());
assertEquals(ds1.getDictionary().getInjector(), injector);
}
use of com.yahoo.elide.core.dictionary.Injector in project elide by yahoo.
the class Elide method registerCustomSerde.
protected void registerCustomSerde() {
Injector injector = elideSettings.getDictionary().getInjector();
Set<Class<?>> classes = registerCustomSerdeScan();
for (Class<?> clazz : classes) {
if (!Serde.class.isAssignableFrom(clazz)) {
log.warn("Skipping Serde registration (not a Serde!): {}", clazz);
continue;
}
Serde serde = (Serde) injector.instantiate(clazz);
injector.inject(serde);
ElideTypeConverter converter = clazz.getAnnotation(ElideTypeConverter.class);
Class baseType = converter.type();
registerCustomSerde(baseType, serde, converter.name());
for (Class type : converter.subTypes()) {
if (!baseType.isAssignableFrom(type)) {
throw new IllegalArgumentException("Mentioned type " + type + " not subtype of " + baseType);
}
registerCustomSerde(type, serde, converter.name());
}
}
}
use of com.yahoo.elide.core.dictionary.Injector in project elide by yahoo.
the class DataStoreTransaction method createNewObject.
/**
* Create a new instance of an object.
*
* @param entityClass the class
* @param <T> the model type to create
* @return a new instance of type T
*/
default <T> T createNewObject(Type<T> entityClass, RequestScope scope) {
Injector injector = scope.getDictionary().getInjector();
T obj;
if (entityClass.getUnderlyingClass().isPresent()) {
obj = injector.instantiate(entityClass.getUnderlyingClass().get());
} else {
try {
obj = entityClass.newInstance();
} catch (java.lang.InstantiationException | IllegalAccessException e) {
obj = null;
}
}
return obj;
}
use of com.yahoo.elide.core.dictionary.Injector in project elide by yahoo.
the class ElideStandaloneSettings method getEntityDictionary.
/**
* Gets the EntityDictionary for elide.
* @param injector Service locator for web service for dependency injection.
* @param dynamicConfiguration optional dynamic config object.
* @param entitiesToExclude set of Entities to exclude from binding.
* @return EntityDictionary object initialized.
*/
default EntityDictionary getEntityDictionary(ServiceLocator injector, ClassScanner scanner, Optional<DynamicConfiguration> dynamicConfiguration, Set<Type<?>> entitiesToExclude) {
Map<String, Class<? extends Check>> checks = new HashMap<>();
if (getAnalyticProperties().enableDynamicModelConfigAPI()) {
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
new HashMap<>(), // Role Checks
new HashMap<>(), new Injector() {
@Override
public void inject(Object entity) {
injector.inject(entity);
}
@Override
public <T> T instantiate(Class<T> cls) {
return injector.create(cls);
}
}, // Serde Lookup
CoerceUtil::lookup, entitiesToExclude, scanner);
dynamicConfiguration.map(DynamicConfiguration::getRoles).orElseGet(Collections::emptySet).forEach(role -> dictionary.addRoleCheck(role, new Role.RoleMemberCheck(role)));
return dictionary;
}
use of com.yahoo.elide.core.dictionary.Injector 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;
}
Aggregations