Search in sources :

Example 16 with Include

use of com.yahoo.elide.annotation.Include in project elide by yahoo.

the class NamespacePackageTest method testAnnotations.

@Test
void testAnnotations() throws Exception {
    NamespaceConfig testNamespace = NamespaceConfig.builder().description("A test Namespace").name("Test").build();
    NamespacePackage namespace = new NamespacePackage(testNamespace);
    ReadPermission readPermission = namespace.getDeclaredAnnotation(ReadPermission.class);
    assertEquals("Prefab.Role.All", readPermission.expression());
    Include meta = namespace.getDeclaredAnnotation(Include.class);
    assertEquals("A test Namespace", meta.description());
    assertNull(meta.friendlyName());
    ApiVersion apiVersion = namespace.getDeclaredAnnotation(ApiVersion.class);
    assertEquals("", apiVersion.version());
}
Also used : NamespaceConfig(com.yahoo.elide.modelconfig.model.NamespaceConfig) ApiVersion(com.yahoo.elide.annotation.ApiVersion) Include(com.yahoo.elide.annotation.Include) ReadPermission(com.yahoo.elide.annotation.ReadPermission) Test(org.junit.jupiter.api.Test)

Example 17 with Include

use of com.yahoo.elide.annotation.Include 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 18 with Include

use of com.yahoo.elide.annotation.Include in project elide by yahoo.

the class EntityDictionaryTest method testGetFirstAnnotation.

@Test
public void testGetFirstAnnotation() {
    @Exclude
    class Foo {
    }
    @Include(rootLevel = false)
    class Bar extends Foo {
    }
    class Baz extends Bar {
    }
    Annotation first = getFirstAnnotation(ClassType.of(Baz.class), Arrays.asList(Exclude.class, Include.class));
    assertTrue(first instanceof Include);
}
Also used : Exclude(com.yahoo.elide.annotation.Exclude) Include(com.yahoo.elide.annotation.Include) Annotation(java.lang.annotation.Annotation) Test(org.junit.jupiter.api.Test)

Example 19 with Include

use of com.yahoo.elide.annotation.Include in project elide by yahoo.

the class EntityDictionaryTest method testSerdeId.

@Test
public void testSerdeId() {
    @Include(rootLevel = false)
    class EntityWithDateId {

        @Id
        private Date id;
    }
    EntityDictionary testDictionary = new EntityDictionary(new HashMap<>(), null, DEFAULT_INJECTOR, unused -> new ISO8601DateSerde(), Collections.emptySet(), DefaultClassScanner.getInstance());
    testDictionary.bindEntity(EntityWithDateId.class);
    EntityWithDateId testModel = new EntityWithDateId();
    testModel.id = new Date(0);
    assertEquals("1970-01-01T00:00Z", testDictionary.getId(testModel));
}
Also used : ISO8601DateSerde(com.yahoo.elide.core.utils.coerce.converters.ISO8601DateSerde) Include(com.yahoo.elide.annotation.Include) Date(java.util.Date) Test(org.junit.jupiter.api.Test)

Example 20 with Include

use of com.yahoo.elide.annotation.Include in project elide by yahoo.

the class EntityDictionary method bindEntity.

/**
 * Add given Entity bean to dictionary.
 *
 * @param cls Entity bean class
 * @param isFieldHidden Function which determines if a given field should be in the dictionary but not exposed.
 */
public void bindEntity(Type<?> cls, Predicate<AccessibleObject> isFieldHidden) {
    Type<?> declaredClass = lookupIncludeClass(cls);
    if (entitiesToExclude.contains(declaredClass)) {
        // Exclude Entity
        return;
    }
    if (declaredClass == null) {
        log.trace("Missing include or excluded class {}", cls.getName());
        return;
    }
    if (isClassBound(declaredClass)) {
        // Ignore duplicate bindings.
        return;
    }
    String type = getEntityName(declaredClass);
    String version = getModelVersion(declaredClass);
    bindJsonApiToEntity.put(Pair.of(type, version), declaredClass);
    apiVersions.add(version);
    EntityBinding binding = new EntityBinding(injector, declaredClass, type, version, isFieldHidden);
    entityBindings.put(declaredClass, binding);
    Include include = (Include) getFirstAnnotation(declaredClass, Arrays.asList(Include.class));
    if (include != null && include.rootLevel()) {
        bindEntityRoots.add(declaredClass);
    }
    bindLegacyHooks(binding);
    discoverEmbeddedTypeBindings(declaredClass);
}
Also used : Include(com.yahoo.elide.annotation.Include)

Aggregations

Include (com.yahoo.elide.annotation.Include)46 Test (org.junit.jupiter.api.Test)41 Entity (javax.persistence.Entity)37 RequestScope (com.yahoo.elide.core.RequestScope)26 EntityDictionary (com.yahoo.elide.core.dictionary.EntityDictionary)19 HashSet (java.util.HashSet)17 PersistentResource (com.yahoo.elide.core.PersistentResource)16 UpdatePermission (com.yahoo.elide.annotation.UpdatePermission)12 ReadPermission (com.yahoo.elide.annotation.ReadPermission)11 Annotation (java.lang.annotation.Annotation)4 Date (java.util.Date)4 ApiVersion (com.yahoo.elide.annotation.ApiVersion)3 NO_VERSION (com.yahoo.elide.core.dictionary.EntityDictionary.NO_VERSION)3 FromTable (com.yahoo.elide.datastores.aggregation.queryengines.sql.annotation.FromTable)3 Arrays (java.util.Arrays)3 HashMap (java.util.HashMap)3 Exclude (com.yahoo.elide.annotation.Exclude)2 AggregationStorePermissionExecutor (com.yahoo.elide.core.security.executors.AggregationStorePermissionExecutor)2 Expression (com.yahoo.elide.core.security.permissions.expressions.Expression)2 TableMeta (com.yahoo.elide.datastores.aggregation.annotation.TableMeta)2