Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move Include to package-info #1852

Open
wants to merge 6 commits into
base: elide-4.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 11 additions & 0 deletions elide-core/src/main/java/com/yahoo/elide/core/EntityBinding.java
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,17 @@ public static Class<?> getFieldType(Class<?> parentClass,
type = ((ParameterizedType) type).getActualTypeArguments()[index.get().intValue()];
}

Class<?> cls = TypeUtils.getRawType(type, parentClass);
if (cls != null) {
return cls;
}

if (fieldOrMethod instanceof Field) {
type = ((Field) fieldOrMethod).getType();
} else {
type = ((Method) fieldOrMethod).getReturnType();
}

return TypeUtils.getRawType(type, parentClass);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/
package com.yahoo.elide.core.datastore.inmemory;

import com.yahoo.elide.annotation.Exclude;
import com.yahoo.elide.annotation.Include;
import com.yahoo.elide.core.DataStore;
import com.yahoo.elide.core.DataStoreTransaction;
Expand All @@ -15,6 +16,7 @@
import com.google.common.collect.Sets;
import lombok.Getter;

import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashMap;
Expand All @@ -40,9 +42,11 @@ public HashMapDataStore(Set<Package> beanPackages) {
this.beanPackages = beanPackages;

for (Package beanPackage : beanPackages) {
ClassScanner.getAnnotatedClasses(beanPackage, Include.class).stream()
.filter(modelClass -> modelClass.getName().startsWith(beanPackage.getName()))
.forEach(modelClass -> dataStore.put(modelClass, Collections.synchronizedMap(new LinkedHashMap<>())));
ClassScanner.getAllClasses(beanPackage.getName()).stream()
.filter(modelClass -> dictionary.getFirstAnnotation(modelClass,
Arrays.asList(Include.class, Exclude.class)) instanceof Include)
.forEach(modelClass -> dataStore.put(modelClass,
Collections.synchronizedMap(new LinkedHashMap<>())));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@
import com.yahoo.elide.core.filter.expression.FilterExpression;
import com.yahoo.elide.core.pagination.Pagination;
import com.yahoo.elide.core.sort.Sorting;
import com.yahoo.elide.models.generics.Manager;

import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import example.Author;
Expand Down Expand Up @@ -518,42 +520,56 @@ public void testSortingRequiresInMemoryPagination() {

@Test
public void testInMemoryDataStore() {
HashMapDataStore wrapped = new HashMapDataStore(Book.class.getPackage());
HashMapDataStore wrapped = new HashMapDataStore(Sets.newHashSet(
Book.class.getPackage(), Manager.class.getPackage()));
InMemoryDataStore store = new InMemoryDataStore(wrapped);
DataStoreTransaction tx = store.beginReadTransaction();
assertEquals(InMemoryStoreTransaction.class, tx.getClass());

assertEquals(wrapped, wrapped.getDataStore());

String tos = store.toString();
assertTrue(tos.contains("Data store contents"));
assertTrue(tos.contains("Table class example.NoReadEntity contents"));
assertTrue(tos.contains("Table class example.Author contents"));
assertTrue(tos.contains("Table class example.Book contents"));
assertTrue(tos.contains("Table class example.Child contents"));
assertTrue(tos.contains("Table class example.ComputedBean contents"));
assertTrue(tos.contains("Table class example.Editor contents"));
assertTrue(tos.contains("Table class example.FieldAnnotations contents"));
assertTrue(tos.contains("Table class example.FirstClassFields contents"));
assertTrue(tos.contains("Table class example.FunWithPermissions contents"));
assertTrue(tos.contains("Table class example.Invoice contents"));
assertTrue(tos.contains("Table class example.Job contents"));
assertTrue(tos.contains("Table class example.Left contents"));
assertTrue(tos.contains("Table class example.LineItem contents"));
assertTrue(tos.contains("Table class example.MapColorShape contents"));
assertTrue(tos.contains("Table class example.NoDeleteEntity contents"));
assertTrue(tos.contains("Table class example.NoShareEntity contents"));
assertTrue(tos.contains("Table class example.NoUpdateEntity contents"));
assertTrue(tos.contains("Table class example.Parent contents"));
assertTrue(tos.contains("Table class example.Post contents"));
assertTrue(tos.contains("Table class example.PrimitiveId contents"));
assertTrue(tos.contains("Table class example.Publisher contents"));
assertTrue(tos.contains("Table class example.Right contents"));
assertTrue(tos.contains("Table class example.StringId contents"));
assertTrue(tos.contains("Table class example.UpdateAndCreate contents"));
assertTrue(tos.contains("Table class example.User contents"));
assertTrue(tos.contains("Table class example.packageshareable.ContainerWithPackageShare contents"));
assertTrue(tos.contains("Table class example.packageshareable.ShareableWithPackageShare contents"));
assertTrue(tos.contains("Table class example.packageshareable.UnshareableWithEntityUnshare contents"));
// extract class names from DataStore string
String tos = store.toString()
.replace("Data store contents", "")
.replace("Table class ", "").replace(" contents", "")
.replace("Wrapped:[", "").replace("]", "")
.replace("\n\n", ",")
.replace(" ", "").replace("\n", "");

// make sure count is correct
assertEquals(ImmutableSet.copyOf(new String[] {
"example.Author",
"example.Book",
"example.Child",
"example.ComputedBean",
"example.Editor",
"example.FieldAnnotations",
"example.FirstClassFields",
"example.FunWithPermissions",
"example.Invoice",
"example.Job",
"example.Left",
"example.LineItem",
"example.MapColorShape",
"example.NoDeleteEntity",
"example.NoReadEntity",
"example.NoShareEntity",
"example.NoUpdateEntity",
"example.Parent",
"example.Post",
"example.PrimitiveId",
"example.Publisher",
"example.Right",
"example.StringId",
"example.UpdateAndCreate",
"example.User",
"example.packageshareable.ContainerWithPackageShare",
"example.packageshareable.ShareableWithPackageShare",
"example.packageshareable.UnshareableWithEntityUnshare",
"com.yahoo.elide.models.generics.Employee",
"com.yahoo.elide.models.generics.Manager",
"com.yahoo.elide.models.generics.Overlord",
"com.yahoo.elide.models.generics.Peon"
}), ImmutableSet.copyOf(tos.split(",")), String.join("\n", tos.split(",")));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
*/
package example.packageshareable;

import com.yahoo.elide.annotation.Include;

import java.util.Collection;

import javax.persistence.Entity;
Expand All @@ -20,7 +18,6 @@
* Container for ShareableWithPackageShare and UnshareableWithEntityUnshare.
*/
@Entity
@Include(rootLevel = true)
public class ContainerWithPackageShare {
private long id;
private Collection<UnshareableWithEntityUnshare> unshareableWithEntityUnshares;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
*/
package example.packageshareable;

import com.yahoo.elide.annotation.Include;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
Expand All @@ -18,7 +16,6 @@
* Package level shareable bean.
*/
@Entity
@Include(rootLevel = true)
public class ShareableWithPackageShare {
private long id;
private ContainerWithPackageShare container;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
*/
package example.packageshareable;

import com.yahoo.elide.annotation.Include;
import com.yahoo.elide.annotation.SharePermission;

import javax.persistence.Entity;
Expand All @@ -20,7 +19,6 @@
*/
@Entity
@SharePermission(sharable = false)
@Include(rootLevel = true)
public class UnshareableWithEntityUnshare {
private long id;
private ContainerWithPackageShare container;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
* See LICENSE file in project root for terms.
*/
@SharePermission
@Include(rootLevel = true)
package example.packageshareable;

import com.yahoo.elide.annotation.Include;
import com.yahoo.elide.annotation.SharePermission;
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,11 @@

package com.yahoo.elide.models.generics;

import com.yahoo.elide.annotation.Include;

import javax.persistence.Entity;

/**
* Helper class to test parameterized subclass/superclass hierarchies.
*/
@Include(rootLevel = true)
@Entity
public class Employee extends Peon<Manager> {
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,11 @@

package com.yahoo.elide.models.generics;

import com.yahoo.elide.annotation.Include;

import javax.persistence.Entity;

/**
* Tests a parameterized superclass.
*/
@Include(rootLevel = true)
@Entity
public class Manager extends Overlord<Employee> {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Copyright 2021, Yahoo Inc.
* Licensed under the Apache License, Version 2.0
* See LICENSE file in project root for terms.
*/

package com.yahoo.elide.models.generics;

import com.yahoo.elide.annotation.Exclude;

import javax.persistence.Entity;

/**
* Helper class to test parameterized subclass/superclass hierarchies.
*/
@Entity
@Exclude
public class Other extends Peon<Manager> {
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
* See LICENSE file in project root for terms.
*/

@Include(rootLevel = true)
@SharePermission
package com.yahoo.elide.models.generics;

import com.yahoo.elide.annotation.Include;
import com.yahoo.elide.annotation.SharePermission;