use of com.yahoo.elide.annotation.Include in project elide by yahoo.
the class EntityDictionary method bindEntity.
/**
* Add an EntityBinding instance to dictionary.
*
* @param entityBinding EntityBinding instance
*/
public void bindEntity(EntityBinding entityBinding) {
Type<?> declaredClass = entityBinding.entityClass;
if (entitiesToExclude.contains(declaredClass)) {
// Exclude Entity
return;
}
if (isClassBound(declaredClass)) {
// Ignore duplicate bindings.
return;
}
Include include = (Include) getFirstAnnotation(declaredClass, Collections.singletonList(Include.class));
String version = getModelVersion(declaredClass);
bindJsonApiToEntity.put(Pair.of(entityBinding.jsonApiType, version), declaredClass);
entityBindings.put(declaredClass, entityBinding);
apiVersions.add(version);
if (include != null && include.rootLevel()) {
bindEntityRoots.add(declaredClass);
}
}
use of com.yahoo.elide.annotation.Include in project elide by yahoo.
the class EntityDictionary method getEntityName.
/**
* Looks up the API model name for a given class.
* @param modelClass The model class to lookup.
* @return the API name for the model class.
*/
public static String getEntityName(Type<?> modelClass) {
Type<?> declaringClass = lookupAnnotationDeclarationClass(modelClass, Include.class);
if (declaringClass == null) {
declaringClass = lookupAnnotationDeclarationClass(modelClass, Entity.class);
}
String entityPrefix = getEntityPrefix(modelClass);
Preconditions.checkNotNull(declaringClass);
Include include = declaringClass.getAnnotation(Include.class);
if (include != null && !"".equals(include.name())) {
return entityPrefix + include.name();
}
Entity entity = (Entity) getFirstAnnotation(declaringClass, Arrays.asList(Entity.class));
if (entity == null || "".equals(entity.name())) {
return entityPrefix + StringUtils.uncapitalize(declaringClass.getSimpleName());
}
return entityPrefix + entity.name();
}
use of com.yahoo.elide.annotation.Include in project elide by yahoo.
the class MetaDataStore method getNamespace.
/**
* Get a namespace object.
*
* @param modelType the model type
* @return the namespace
*/
public Namespace getNamespace(Type<?> modelType) {
String apiVersionName = EntityDictionary.getModelVersion(modelType);
Include include = (Include) EntityDictionary.getFirstPackageAnnotation(modelType, Arrays.asList(Include.class));
String namespaceName;
if (include != null && !include.name().isEmpty()) {
namespaceName = include.name();
} else {
namespaceName = DEFAULT;
}
return namespaces.stream().filter(namespace -> namespace.getName().equals(namespaceName)).filter(namespace -> namespace.getVersion().equals(apiVersionName)).findFirst().orElse(null);
}
use of com.yahoo.elide.annotation.Include in project elide by yahoo.
the class NamespacePackage method buildAnnotations.
private static Map<Class<? extends Annotation>, Annotation> buildAnnotations(NamespaceConfig namespace) {
Map<Class<? extends Annotation>, Annotation> annotations = new HashMap<>();
annotations.put(ReadPermission.class, new ReadPermission() {
@Override
public Class<? extends Annotation> annotationType() {
return ReadPermission.class;
}
@Override
public String expression() {
return namespace.getReadAccess();
}
});
annotations.put(Include.class, new Include() {
@Override
public Class<? extends Annotation> annotationType() {
return Include.class;
}
@Override
public boolean rootLevel() {
return true;
}
@Override
public String description() {
return namespace.getDescription();
}
@Override
public String friendlyName() {
return namespace.getFriendlyName();
}
@Override
public String name() {
return namespace.getName();
}
});
annotations.put(ApiVersion.class, new ApiVersion() {
@Override
public String version() {
return namespace.getApiVersion();
}
@Override
public Class<? extends Annotation> annotationType() {
return ApiVersion.class;
}
});
return annotations;
}
use of com.yahoo.elide.annotation.Include in project elide by yahoo.
the class JpaDataStoreTest method verifyManualEntityBinding.
@Test
public void verifyManualEntityBinding() {
@Include(rootLevel = false)
@Entity
class Test {
@Id
private long id;
private String name;
}
Metamodel mockModel = mock(Metamodel.class);
when(mockModel.getEntities()).thenReturn(Sets.newHashSet());
EntityManager managerMock = mock(EntityManager.class);
when(managerMock.getMetamodel()).thenReturn(mockModel);
JpaDataStore store = new JpaDataStore(() -> managerMock, unused -> null, ClassType.of(Test.class));
EntityDictionary dictionary = EntityDictionary.builder().build();
store.populateEntityDictionary(dictionary);
assertNotNull(dictionary.lookupBoundClass(ClassType.of(Test.class)));
}
Aggregations