Search in sources :

Example 31 with EntityDictionary

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");
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory) ActiveMQConnectionFactory(org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory) ConnectionFactory(javax.jms.ConnectionFactory) HashMapDataStore(com.yahoo.elide.core.datastore.inmemory.HashMapDataStore) SubscriptionScanner(com.yahoo.elide.graphql.subscriptions.hooks.SubscriptionScanner) Elide(com.yahoo.elide.Elide) EntityDictionary(com.yahoo.elide.core.dictionary.EntityDictionary)

Example 32 with EntityDictionary

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)));
}
Also used : EntityDictionary(com.yahoo.elide.core.dictionary.EntityDictionary) Test(org.junit.jupiter.api.Test)

Example 33 with EntityDictionary

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()));
}
Also used : SwaggerBuilder(com.yahoo.elide.swagger.SwaggerBuilder) Info(io.swagger.models.Info) EntityDictionary(com.yahoo.elide.core.dictionary.EntityDictionary) RefreshScope(org.springframework.cloud.context.config.annotation.RefreshScope) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean) ConditionalOnProperty(org.springframework.boot.autoconfigure.condition.ConditionalOnProperty)

Example 34 with EntityDictionary

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;
}
Also used : HashMap(java.util.HashMap) Check(com.yahoo.elide.core.security.checks.Check) CoerceUtil(com.yahoo.elide.core.utils.coerce.CoerceUtil) DynamicConfiguration(com.yahoo.elide.modelconfig.DynamicConfiguration) Injector(com.yahoo.elide.core.dictionary.Injector) ConfigChecks(com.yahoo.elide.modelconfig.store.models.ConfigChecks) EntityDictionary(com.yahoo.elide.core.dictionary.EntityDictionary)

Example 35 with EntityDictionary

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;
}
Also used : TableExportHook(com.yahoo.elide.async.hooks.TableExportHook) HashMap(java.util.HashMap) AsyncQueryHook(com.yahoo.elide.async.hooks.AsyncQueryHook) JSONExportFormatter(com.yahoo.elide.async.export.formatter.JSONExportFormatter) ResultType(com.yahoo.elide.async.models.ResultType) CSVExportFormatter(com.yahoo.elide.async.export.formatter.CSVExportFormatter) AsyncExecutorService(com.yahoo.elide.async.service.AsyncExecutorService) ExecutorService(java.util.concurrent.ExecutorService) AsyncExecutorService(com.yahoo.elide.async.service.AsyncExecutorService) EntityDictionary(com.yahoo.elide.core.dictionary.EntityDictionary) TableExportFormatter(com.yahoo.elide.async.export.formatter.TableExportFormatter) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Aggregations

EntityDictionary (com.yahoo.elide.core.dictionary.EntityDictionary)87 Test (org.junit.jupiter.api.Test)31 RequestScope (com.yahoo.elide.core.RequestScope)27 Include (com.yahoo.elide.annotation.Include)17 Entity (javax.persistence.Entity)17 HashSet (java.util.HashSet)16 Type (com.yahoo.elide.core.type.Type)13 FilterExpression (com.yahoo.elide.core.filter.expression.FilterExpression)12 DataStoreTransaction (com.yahoo.elide.core.datastore.DataStoreTransaction)10 Map (java.util.Map)10 BeforeAll (org.junit.jupiter.api.BeforeAll)10 PersistentResource (com.yahoo.elide.core.PersistentResource)9 Set (java.util.Set)9 ReadPermission (com.yahoo.elide.annotation.ReadPermission)8 ClassType (com.yahoo.elide.core.type.ClassType)8 List (java.util.List)8 ElideSettingsBuilder (com.yahoo.elide.ElideSettingsBuilder)7 DataStore (com.yahoo.elide.core.datastore.DataStore)7 InvalidObjectIdentifierException (com.yahoo.elide.core.exceptions.InvalidObjectIdentifierException)7 Check (com.yahoo.elide.core.security.checks.Check)7