Search in sources :

Example 11 with ElideSettingsBuilder

use of com.yahoo.elide.ElideSettingsBuilder 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 12 with ElideSettingsBuilder

use of com.yahoo.elide.ElideSettingsBuilder in project faf-java-api by FAForever.

the class ElideConfig method elide.

@Bean
public Elide elide(SpringHibernateDataStore springHibernateDataStore, ObjectMapper objectMapper, EntityDictionary entityDictionary, ExtendedAuditLogger extendedAuditLogger) {
    RSQLFilterDialect rsqlFilterDialect = new RSQLFilterDialect(entityDictionary);
    registerAdditionalConverters();
    return new Elide(new ElideSettingsBuilder(springHibernateDataStore).withJsonApiMapper(new JsonApiMapper(entityDictionary, objectMapper)).withAuditLogger(extendedAuditLogger).withEntityDictionary(entityDictionary).withJoinFilterDialect(rsqlFilterDialect).withSubqueryFilterDialect(rsqlFilterDialect).build());
}
Also used : ElideSettingsBuilder(com.yahoo.elide.ElideSettingsBuilder) JsonApiMapper(com.yahoo.elide.jsonapi.JsonApiMapper) Elide(com.yahoo.elide.Elide) RSQLFilterDialect(com.yahoo.elide.core.filter.dialect.RSQLFilterDialect) Bean(org.springframework.context.annotation.Bean)

Example 13 with ElideSettingsBuilder

use of com.yahoo.elide.ElideSettingsBuilder in project elide by yahoo.

the class RequestScopeTest method testNewObjectsForInheritedTypes.

@Test
public void testNewObjectsForInheritedTypes() throws Exception {
    @Entity
    @Include(rootLevel = false)
    class MyBaseClass {

        @Id
        public long id;
    }
    @Entity
    @Include(rootLevel = false)
    class MyInheritedClass extends MyBaseClass {

        public String myField;
    }
    EntityDictionary dictionary = EntityDictionary.builder().build();
    dictionary.bindEntity(MyBaseClass.class);
    dictionary.bindEntity(MyInheritedClass.class);
    RequestScope requestScope = new RequestScope(null, "/", NO_VERSION, null, null, null, null, null, UUID.randomUUID(), new ElideSettingsBuilder(null).withEntityDictionary(dictionary).build());
    String myId = "myId";
    // Test that a new inherited class is counted for base type
    requestScope.setUUIDForObject(ClassType.of(MyInheritedClass.class), myId, new MyInheritedClass());
    assertNotNull(requestScope.getObjectById(ClassType.of(MyBaseClass.class), myId));
}
Also used : Entity(javax.persistence.Entity) ElideSettingsBuilder(com.yahoo.elide.ElideSettingsBuilder) Include(com.yahoo.elide.annotation.Include) EntityDictionary(com.yahoo.elide.core.dictionary.EntityDictionary) Test(org.junit.jupiter.api.Test)

Example 14 with ElideSettingsBuilder

use of com.yahoo.elide.ElideSettingsBuilder in project elide by yahoo.

the class LogMessageImplTest method init.

@BeforeAll
public static void init() {
    final EntityDictionary dictionary = EntityDictionary.builder().build();
    dictionary.bindEntity(Child.class);
    dictionary.bindEntity(Parent.class);
    final Child child = new Child();
    child.setId(5);
    final Parent parent = new Parent();
    parent.setId(7);
    final Child friend = new Child();
    friend.setId(9);
    child.setFriends(Sets.newHashSet(friend));
    final RequestScope requestScope = new RequestScope(null, null, NO_VERSION, null, null, new TestUser("aaron"), null, null, UUID.randomUUID(), new ElideSettingsBuilder(null).withAuditLogger(new TestAuditLogger()).withEntityDictionary(dictionary).build());
    final PersistentResource<Parent> parentRecord = new PersistentResource<>(parent, requestScope.getUUIDFor(parent), requestScope);
    childRecord = new PersistentResource<>(child, parentRecord, "children", requestScope.getUUIDFor(child), requestScope);
    friendRecord = new PersistentResource<>(friend, childRecord, "friends", requestScope.getUUIDFor(friend), requestScope);
}
Also used : PersistentResource(com.yahoo.elide.core.PersistentResource) ElideSettingsBuilder(com.yahoo.elide.ElideSettingsBuilder) Parent(example.Parent) EntityDictionary(com.yahoo.elide.core.dictionary.EntityDictionary) Child(example.Child) RequestScope(com.yahoo.elide.core.RequestScope) TestUser(com.yahoo.elide.core.security.TestUser) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 15 with ElideSettingsBuilder

use of com.yahoo.elide.ElideSettingsBuilder in project elide by yahoo.

the class PermissionToFilterExpressionVisitorTest method setupEntityDictionary.

@BeforeEach
public void setupEntityDictionary() {
    Map<String, Class<? extends Check>> checks = new HashMap<>();
    checks.put(AT_OP_ALLOW, Permissions.Succeeds.class);
    checks.put(AT_OP_DENY, Permissions.Fails.class);
    checks.put(USER_ALLOW, Role.ALL.class);
    checks.put(USER_DENY, Role.NONE.class);
    checks.put(IN_FILTER, Permissions.InFilterExpression.class);
    checks.put(NOT_IN_FILTER, Permissions.NotInFilterExpression.class);
    checks.put(LT_FILTER, Permissions.LessThanFilterExpression.class);
    checks.put(GE_FILTER, Permissions.GreaterThanOrEqualFilterExpression.class);
    dictionary = TestDictionary.getTestDictionary(checks);
    elideSettings = new ElideSettingsBuilder(null).withEntityDictionary(dictionary).build();
    requestScope = newRequestScope();
    cache = new ExpressionResultCache();
}
Also used : Role(com.yahoo.elide.core.security.checks.prefab.Role) ElideSettingsBuilder(com.yahoo.elide.ElideSettingsBuilder) HashMap(java.util.HashMap) OperationCheck(com.yahoo.elide.core.security.checks.OperationCheck) FilterExpressionCheck(com.yahoo.elide.core.security.checks.FilterExpressionCheck) Check(com.yahoo.elide.core.security.checks.Check) EntityPermissions(com.yahoo.elide.core.dictionary.EntityPermissions) ExpressionResultCache(com.yahoo.elide.core.security.permissions.ExpressionResultCache) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

ElideSettingsBuilder (com.yahoo.elide.ElideSettingsBuilder)30 Elide (com.yahoo.elide.Elide)20 Check (com.yahoo.elide.core.security.checks.Check)12 HashMap (java.util.HashMap)12 HashMapDataStore (com.yahoo.elide.core.datastore.inmemory.HashMapDataStore)10 BeforeEach (org.junit.jupiter.api.BeforeEach)10 RequestScope (com.yahoo.elide.core.RequestScope)9 EntityDictionary (com.yahoo.elide.core.dictionary.EntityDictionary)7 Test (org.junit.jupiter.api.Test)7 DataStoreTransaction (com.yahoo.elide.core.datastore.DataStoreTransaction)5 RSQLFilterDialect (com.yahoo.elide.core.filter.dialect.RSQLFilterDialect)5 User (com.yahoo.elide.core.security.User)5 BeforeAll (org.junit.jupiter.api.BeforeAll)5 ElideSettings (com.yahoo.elide.ElideSettings)4 AsyncQuery (com.yahoo.elide.async.models.AsyncQuery)4 Slf4jLogger (com.yahoo.elide.core.audit.Slf4jLogger)4 TestAuditLogger (com.yahoo.elide.core.audit.TestAuditLogger)4 ElideResponse (com.yahoo.elide.ElideResponse)3 DefaultAsyncAPIDAO (com.yahoo.elide.async.service.dao.DefaultAsyncAPIDAO)3 FileResultStorageEngine (com.yahoo.elide.async.service.storageengine.FileResultStorageEngine)3