Search in sources :

Example 1 with Slf4jLogger

use of com.yahoo.elide.core.audit.Slf4jLogger in project elide by yahoo.

the class ElideAutoConfiguration method getRefreshableElide.

/**
 * Creates the Elide instance with standard settings.
 * @param dictionary Stores the static metadata about Elide models.
 * @param dataStore The persistence store.
 * @param transactionRegistry Global transaction registry.
 * @param settings Elide settings.
 * @return A new elide instance.
 */
@Bean
@RefreshScope
@ConditionalOnMissingBean
public RefreshableElide getRefreshableElide(EntityDictionary dictionary, DataStore dataStore, TransactionRegistry transactionRegistry, ElideConfigProperties settings, JsonApiMapper mapper, ErrorMapper errorMapper) {
    ElideSettingsBuilder builder = new ElideSettingsBuilder(dataStore).withEntityDictionary(dictionary).withErrorMapper(errorMapper).withJsonApiMapper(mapper).withDefaultMaxPageSize(settings.getMaxPageSize()).withDefaultPageSize(settings.getPageSize()).withJoinFilterDialect(RSQLFilterDialect.builder().dictionary(dictionary).build()).withSubqueryFilterDialect(RSQLFilterDialect.builder().dictionary(dictionary).build()).withAuditLogger(new Slf4jLogger()).withBaseUrl(settings.getBaseUrl()).withISO8601Dates("yyyy-MM-dd'T'HH:mm'Z'", TimeZone.getTimeZone("UTC")).withJsonApiPath(settings.getJsonApi().getPath()).withGraphQLApiPath(settings.getGraphql().getPath());
    if (settings.isVerboseErrors()) {
        builder.withVerboseErrors();
    }
    if (settings.getAsync() != null && settings.getAsync().getExport() != null && settings.getAsync().getExport().isEnabled()) {
        builder.withExportApiPath(settings.getAsync().getExport().getPath());
    }
    if (settings.getJsonApi() != null && settings.getJsonApi().isEnabled() && settings.getJsonApi().isEnableLinks()) {
        String baseUrl = settings.getBaseUrl();
        if (StringUtils.isEmpty(baseUrl)) {
            builder.withJSONApiLinks(new DefaultJSONApiLinks());
        } else {
            String jsonApiBaseUrl = baseUrl + settings.getJsonApi().getPath() + "/";
            builder.withJSONApiLinks(new DefaultJSONApiLinks(jsonApiBaseUrl));
        }
    }
    Elide elide = new Elide(builder.build(), transactionRegistry, dictionary.getScanner(), true);
    return new RefreshableElide(elide);
}
Also used : ElideSettingsBuilder(com.yahoo.elide.ElideSettingsBuilder) Slf4jLogger(com.yahoo.elide.core.audit.Slf4jLogger) DefaultJSONApiLinks(com.yahoo.elide.jsonapi.links.DefaultJSONApiLinks) RefreshableElide(com.yahoo.elide.RefreshableElide) Elide(com.yahoo.elide.Elide) RefreshableElide(com.yahoo.elide.RefreshableElide) 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)

Example 2 with Slf4jLogger

use of com.yahoo.elide.core.audit.Slf4jLogger in project elide by yahoo.

the class IntegrationTestSetup method initializeElide.

// Initialize beans here if needed.
// We recreate the Elide bean here without @RefreshScope so that it can be used With @SpyBean.
@Bean
public RefreshableElide initializeElide(EntityDictionary dictionary, DataStore dataStore, ElideConfigProperties settings, JsonApiMapper mapper, ErrorMapper errorMapper) {
    ElideSettingsBuilder builder = new ElideSettingsBuilder(dataStore).withEntityDictionary(dictionary).withErrorMapper(errorMapper).withJsonApiMapper(mapper).withDefaultMaxPageSize(settings.getMaxPageSize()).withDefaultPageSize(settings.getPageSize()).withJoinFilterDialect(RSQLFilterDialect.builder().dictionary(dictionary).build()).withSubqueryFilterDialect(RSQLFilterDialect.builder().dictionary(dictionary).build()).withAuditLogger(new Slf4jLogger()).withBaseUrl(settings.getBaseUrl()).withISO8601Dates("yyyy-MM-dd'T'HH:mm'Z'", TimeZone.getTimeZone("UTC")).withJsonApiPath(settings.getJsonApi().getPath()).withGraphQLApiPath(settings.getGraphql().getPath());
    if (settings.isVerboseErrors()) {
        builder.withVerboseErrors();
    }
    if (settings.getAsync() != null && settings.getAsync().getExport() != null && settings.getAsync().getExport().isEnabled()) {
        builder.withExportApiPath(settings.getAsync().getExport().getPath());
    }
    if (settings.getJsonApi() != null && settings.getJsonApi().isEnabled() && settings.getJsonApi().isEnableLinks()) {
        String baseUrl = settings.getBaseUrl();
        if (StringUtils.isEmpty(baseUrl)) {
            builder.withJSONApiLinks(new DefaultJSONApiLinks());
        } else {
            String jsonApiBaseUrl = baseUrl + settings.getJsonApi().getPath() + "/";
            builder.withJSONApiLinks(new DefaultJSONApiLinks(jsonApiBaseUrl));
        }
    }
    Elide elide = new Elide(builder.build(), new TransactionRegistry(), dictionary.getScanner(), true);
    return new RefreshableElide(spy(elide));
}
Also used : ElideSettingsBuilder(com.yahoo.elide.ElideSettingsBuilder) Slf4jLogger(com.yahoo.elide.core.audit.Slf4jLogger) DefaultJSONApiLinks(com.yahoo.elide.jsonapi.links.DefaultJSONApiLinks) TransactionRegistry(com.yahoo.elide.core.TransactionRegistry) RefreshableElide(com.yahoo.elide.RefreshableElide) Elide(com.yahoo.elide.Elide) RefreshableElide(com.yahoo.elide.RefreshableElide) Bean(org.springframework.context.annotation.Bean)

Example 3 with Slf4jLogger

use of com.yahoo.elide.core.audit.Slf4jLogger in project elide by yahoo.

the class GraphQLTableExportOperationTest method setupMocks.

@BeforeEach
public void setupMocks(@TempDir Path tempDir) {
    dataStore = new HashMapDataStore(DefaultClassScanner.getInstance(), new HashSet<>(Arrays.asList(TableExport.class.getPackage(), ArtifactGroup.class.getPackage())));
    Map<String, Class<? extends Check>> map = new HashMap<>();
    map.put(AsyncAPIInlineChecks.AsyncAPIOwner.PRINCIPAL_IS_OWNER, AsyncAPIInlineChecks.AsyncAPIOwner.class);
    map.put(AsyncAPIInlineChecks.AsyncAPIAdmin.PRINCIPAL_IS_ADMIN, AsyncAPIInlineChecks.AsyncAPIAdmin.class);
    map.put(AsyncAPIInlineChecks.AsyncAPIStatusValue.VALUE_IS_CANCELLED, AsyncAPIInlineChecks.AsyncAPIStatusValue.class);
    map.put(AsyncAPIInlineChecks.AsyncAPIStatusQueuedValue.VALUE_IS_QUEUED, AsyncAPIInlineChecks.AsyncAPIStatusQueuedValue.class);
    elide = new Elide(new ElideSettingsBuilder(dataStore).withEntityDictionary(EntityDictionary.builder().checks(map).build()).withAuditLogger(new Slf4jLogger()).withExportApiPath("/export").build());
    elide.doScans();
    user = mock(User.class);
    requestScope = mock(RequestScope.class);
    asyncExecutorService = mock(AsyncExecutorService.class);
    engine = new FileResultStorageEngine(tempDir.toString(), false);
    when(asyncExecutorService.getElide()).thenReturn(elide);
    when(requestScope.getApiVersion()).thenReturn(NO_VERSION);
    when(requestScope.getUser()).thenReturn(user);
    when(requestScope.getElideSettings()).thenReturn(elide.getElideSettings());
    when(requestScope.getBaseUrlEndPoint()).thenReturn("https://elide.io");
}
Also used : FileResultStorageEngine(com.yahoo.elide.async.service.storageengine.FileResultStorageEngine) User(com.yahoo.elide.core.security.User) HashMap(java.util.HashMap) Slf4jLogger(com.yahoo.elide.core.audit.Slf4jLogger) Check(com.yahoo.elide.core.security.checks.Check) AsyncAPIInlineChecks(com.yahoo.elide.async.models.security.AsyncAPIInlineChecks) RequestScope(com.yahoo.elide.core.RequestScope) ElideSettingsBuilder(com.yahoo.elide.ElideSettingsBuilder) AsyncExecutorService(com.yahoo.elide.async.service.AsyncExecutorService) HashMapDataStore(com.yahoo.elide.core.datastore.inmemory.HashMapDataStore) Elide(com.yahoo.elide.Elide) HashSet(java.util.HashSet) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 4 with Slf4jLogger

use of com.yahoo.elide.core.audit.Slf4jLogger in project elide by yahoo.

the class JsonAPITableExportOperationTest method setupMocks.

@BeforeEach
public void setupMocks(@TempDir Path tempDir) {
    dataStore = new HashMapDataStore(DefaultClassScanner.getInstance(), new HashSet<>(Arrays.asList(TableExport.class.getPackage(), ArtifactGroup.class.getPackage())));
    Map<String, Class<? extends Check>> map = new HashMap<>();
    map.put(AsyncAPIInlineChecks.AsyncAPIOwner.PRINCIPAL_IS_OWNER, AsyncAPIInlineChecks.AsyncAPIOwner.class);
    map.put(AsyncAPIInlineChecks.AsyncAPIAdmin.PRINCIPAL_IS_ADMIN, AsyncAPIInlineChecks.AsyncAPIAdmin.class);
    map.put(AsyncAPIInlineChecks.AsyncAPIStatusValue.VALUE_IS_CANCELLED, AsyncAPIInlineChecks.AsyncAPIStatusValue.class);
    map.put(AsyncAPIInlineChecks.AsyncAPIStatusQueuedValue.VALUE_IS_QUEUED, AsyncAPIInlineChecks.AsyncAPIStatusQueuedValue.class);
    elide = new Elide(new ElideSettingsBuilder(dataStore).withEntityDictionary(EntityDictionary.builder().checks(map).build()).withAuditLogger(new Slf4jLogger()).withExportApiPath("/export").build());
    elide.doScans();
    user = mock(User.class);
    requestScope = mock(RequestScope.class);
    asyncExecutorService = mock(AsyncExecutorService.class);
    engine = new FileResultStorageEngine(tempDir.toString(), true);
    when(asyncExecutorService.getElide()).thenReturn(elide);
    when(requestScope.getApiVersion()).thenReturn(NO_VERSION);
    when(requestScope.getUser()).thenReturn(user);
    when(requestScope.getElideSettings()).thenReturn(elide.getElideSettings());
    when(requestScope.getBaseUrlEndPoint()).thenReturn("https://elide.io");
}
Also used : FileResultStorageEngine(com.yahoo.elide.async.service.storageengine.FileResultStorageEngine) User(com.yahoo.elide.core.security.User) HashMap(java.util.HashMap) Slf4jLogger(com.yahoo.elide.core.audit.Slf4jLogger) Check(com.yahoo.elide.core.security.checks.Check) AsyncAPIInlineChecks(com.yahoo.elide.async.models.security.AsyncAPIInlineChecks) RequestScope(com.yahoo.elide.core.RequestScope) ElideSettingsBuilder(com.yahoo.elide.ElideSettingsBuilder) AsyncExecutorService(com.yahoo.elide.async.service.AsyncExecutorService) HashMapDataStore(com.yahoo.elide.core.datastore.inmemory.HashMapDataStore) Elide(com.yahoo.elide.Elide) HashSet(java.util.HashSet) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

Elide (com.yahoo.elide.Elide)4 ElideSettingsBuilder (com.yahoo.elide.ElideSettingsBuilder)4 Slf4jLogger (com.yahoo.elide.core.audit.Slf4jLogger)4 RefreshableElide (com.yahoo.elide.RefreshableElide)2 AsyncAPIInlineChecks (com.yahoo.elide.async.models.security.AsyncAPIInlineChecks)2 AsyncExecutorService (com.yahoo.elide.async.service.AsyncExecutorService)2 FileResultStorageEngine (com.yahoo.elide.async.service.storageengine.FileResultStorageEngine)2 RequestScope (com.yahoo.elide.core.RequestScope)2 HashMapDataStore (com.yahoo.elide.core.datastore.inmemory.HashMapDataStore)2 User (com.yahoo.elide.core.security.User)2 Check (com.yahoo.elide.core.security.checks.Check)2 DefaultJSONApiLinks (com.yahoo.elide.jsonapi.links.DefaultJSONApiLinks)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 BeforeEach (org.junit.jupiter.api.BeforeEach)2 Bean (org.springframework.context.annotation.Bean)2 TransactionRegistry (com.yahoo.elide.core.TransactionRegistry)1 ConditionalOnMissingBean (org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean)1 RefreshScope (org.springframework.cloud.context.config.annotation.RefreshScope)1