use of com.yahoo.elide.core.dictionary.EntityDictionary in project elide by yahoo.
the class TestBinder method configure.
@Override
protected void configure() {
EntityDictionary dictionary = EntityDictionary.builder().injector(injector::inject).build();
dictionary.scanForSecurityChecks();
bind(dictionary).to(EntityDictionary.class);
ConnectionFactory connectionFactory = new ActiveMQConnectionFactory(EMBEDDED_JMS_URL);
bind(connectionFactory).to(ConnectionFactory.class);
// Primary Elide instance for CRUD endpoints.
bindFactory(new Factory<Elide>() {
@Override
public Elide provide() {
HashMapDataStore inMemoryStore = new HashMapDataStore(Set.of(Book.class, Author.class, Publisher.class, ChatBot.class));
Elide elide = buildElide(inMemoryStore, dictionary);
elide.doScans();
SubscriptionScanner subscriptionScanner = SubscriptionScanner.builder().connectionFactory(connectionFactory).dictionary(elide.getElideSettings().getDictionary()).scanner(elide.getScanner()).build();
subscriptionScanner.bindLifecycleHooks();
return elide;
}
@Override
public void dispose(Elide elide) {
}
}).to(Elide.class).named("elide");
}
use of com.yahoo.elide.core.dictionary.EntityDictionary in project elide by yahoo.
the class HashMapDataStoreTest method checkLoading.
@Test
public void checkLoading() {
final EntityDictionary entityDictionary = inMemoryDataStore.getDictionary();
assertNotNull(entityDictionary.getJsonAliasFor(ClassType.of(FirstBean.class)));
assertNotNull(entityDictionary.getJsonAliasFor(ClassType.of(SecondBean.class)));
assertThrows(IllegalArgumentException.class, () -> entityDictionary.getJsonAliasFor(ClassType.of(NonEntity.class)));
assertThrows(IllegalArgumentException.class, () -> entityDictionary.getJsonAliasFor(ClassType.of(ExcludedBean.class)));
}
use of com.yahoo.elide.core.dictionary.EntityDictionary in project elide by yahoo.
the class ElideAutoConfiguration method buildSwagger.
/**
* Creates a singular swagger document for JSON-API.
* @param elide Singleton elide instance.
* @param settings Elide configuration settings.
* @return An instance of a JPA DataStore.
*/
@Bean
@ConditionalOnMissingBean
@ConditionalOnProperty(name = "elide.swagger.enabled", havingValue = "true")
@RefreshScope
public SwaggerController.SwaggerRegistrations buildSwagger(RefreshableElide elide, ElideConfigProperties settings) {
EntityDictionary dictionary = elide.getElide().getElideSettings().getDictionary();
Info info = new Info().title(settings.getSwagger().getName()).version(settings.getSwagger().getVersion());
SwaggerBuilder builder = new SwaggerBuilder(dictionary, info).withLegacyFilterDialect(false);
return new SwaggerController.SwaggerRegistrations(builder.build().basePath(settings.getJsonApi().getPath()));
}
use of com.yahoo.elide.core.dictionary.EntityDictionary 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.EntityDictionary in project elide by yahoo.
the class ElideAsyncConfiguration method buildAsyncExecutorService.
/**
* Configure the AsyncExecutorService used for submitting async query requests.
* @param elide elideObject.
* @param settings Elide settings.
* @param asyncQueryDao AsyncDao object.
* @return a AsyncExecutorService.
*/
@Bean
@ConditionalOnMissingBean
public AsyncExecutorService buildAsyncExecutorService(RefreshableElide elide, ElideConfigProperties settings, AsyncAPIDAO asyncQueryDao, @Autowired(required = false) ResultStorageEngine resultStorageEngine) {
AsyncProperties asyncProperties = settings.getAsync();
ExecutorService executor = Executors.newFixedThreadPool(asyncProperties.getThreadPoolSize());
ExecutorService updater = Executors.newFixedThreadPool(asyncProperties.getThreadPoolSize());
AsyncExecutorService asyncExecutorService = new AsyncExecutorService(elide.getElide(), executor, updater, asyncQueryDao);
// Binding AsyncQuery LifeCycleHook
AsyncQueryHook asyncQueryHook = new AsyncQueryHook(asyncExecutorService, asyncProperties.getMaxAsyncAfterSeconds());
EntityDictionary dictionary = elide.getElide().getElideSettings().getDictionary();
dictionary.bindTrigger(AsyncQuery.class, CREATE, PREFLUSH, asyncQueryHook, false);
dictionary.bindTrigger(AsyncQuery.class, CREATE, POSTCOMMIT, asyncQueryHook, false);
dictionary.bindTrigger(AsyncQuery.class, CREATE, PRESECURITY, asyncQueryHook, false);
boolean exportEnabled = ElideAutoConfiguration.isExportEnabled(asyncProperties);
if (exportEnabled) {
// Initialize the Formatters.
boolean skipCSVHeader = asyncProperties.getExport() != null && asyncProperties.getExport().isSkipCSVHeader();
Map<ResultType, TableExportFormatter> supportedFormatters = new HashMap<>();
supportedFormatters.put(ResultType.CSV, new CSVExportFormatter(elide.getElide(), skipCSVHeader));
supportedFormatters.put(ResultType.JSON, new JSONExportFormatter(elide.getElide()));
// Binding TableExport LifeCycleHook
TableExportHook tableExportHook = getTableExportHook(asyncExecutorService, settings, supportedFormatters, resultStorageEngine);
dictionary.bindTrigger(TableExport.class, CREATE, PREFLUSH, tableExportHook, false);
dictionary.bindTrigger(TableExport.class, CREATE, POSTCOMMIT, tableExportHook, false);
dictionary.bindTrigger(TableExport.class, CREATE, PRESECURITY, tableExportHook, false);
}
return asyncExecutorService;
}
Aggregations