use of com.yahoo.elide.core.type.Type in project elide by yahoo.
the class AggregationDataStore method validateModelExpressionChecks.
/**
* Validates The security Check expression type for both Table and all its fields.
* Table Security Check Condition - User Checks and Filter Expression Checks
* Field Security Check Condition - User Checks
* @param dictionary - Entity Dictionary
* @param clz - Model Type.
*/
private void validateModelExpressionChecks(EntityDictionary dictionary, Type<?> clz) {
PermissionExpressionVisitor visitor = new PermissionExpressionVisitor();
ParseTree parseTree = dictionary.getPermissionsForClass(clz, ReadPermission.class);
if (parseTree != null) {
validateExpression(dictionary, visitor.visit(parseTree), (checkClass) -> UserCheck.class.isAssignableFrom(checkClass) || FilterExpressionCheck.class.isAssignableFrom(checkClass), "Table Can only have User Check and Filter Expression Check." + "Operation Checks Not allowed. given - %s");
}
dictionary.getAllExposedFields(clz).stream().map(field -> dictionary.getPermissionsForField(clz, field, ReadPermission.class)).filter(Objects::nonNull).forEach(tree -> validateExpression(dictionary, visitor.visit(tree), (checkClass) -> UserCheck.class.isAssignableFrom(checkClass), "Fields Can only have User checks. Given - %s"));
}
use of com.yahoo.elide.core.type.Type in project elide by yahoo.
the class MetaDataStore method getMetaData.
/**
* Get all metadata of a specific metadata class.
*
* @param cls metadata class
* @param <T> metadata class
* @return all metadata of given class
*/
public <T> Set<T> getMetaData(Type<T> cls) {
String version = EntityDictionary.getModelVersion(cls);
HashMapDataStore hashMapDataStore = hashMapDataStores.computeIfAbsent(version, SERVER_ERROR);
return hashMapDataStore.get(cls).values().stream().map(obj -> (T) obj).collect(Collectors.toSet());
}
use of com.yahoo.elide.core.type.Type in project elide by yahoo.
the class OperatorTest method constructPath.
private Path constructPath(Class<?> rootEntity, String pathString) {
List<Path.PathElement> pathElementsList = new ArrayList<>();
Type prevEntity = ClassType.of(rootEntity);
for (String field : pathString.split("\\.")) {
Type<?> fieldType = ("id".equals(field.toLowerCase(Locale.ENGLISH))) ? dictionary.getIdType(prevEntity) : dictionary.getParameterizedType(prevEntity, field);
Path.PathElement pathElement = new Path.PathElement(prevEntity, fieldType, field);
pathElementsList.add(pathElement);
prevEntity = fieldType;
}
return new Path(pathElementsList);
}
use of com.yahoo.elide.core.type.Type in project elide by yahoo.
the class Entity method setRelationships.
/**
* Extract the relationships of the entity.
*/
private void setRelationships() {
if (this.data != null) {
this.relationships = new LinkedHashSet<>();
EntityDictionary dictionary = this.requestScope.getDictionary();
this.data.entrySet().stream().filter(entry -> dictionary.isRelation(this.entityClass, entry.getKey())).forEach(entry -> {
String relationshipName = entry.getKey();
Type<?> relationshipClass = dictionary.getParameterizedType(this.entityClass, relationshipName);
Set<Entity> relationshipEntities = new LinkedHashSet<>();
// if the relationship is ToOne, entry.getValue() should be a single map
if (dictionary.getRelationshipType(this.entityClass, relationshipName).isToOne()) {
relationshipEntities.add(new Entity(Optional.of(this), ((Map<String, Object>) entry.getValue()), relationshipClass, this.requestScope));
} else {
for (Map<String, Object> row : (List<Map<String, Object>>) entry.getValue()) {
relationshipEntities.add(new Entity(Optional.of(this), row, relationshipClass, this.requestScope));
}
}
this.relationships.add(new Relationship(relationshipName, relationshipEntities));
});
}
}
use of com.yahoo.elide.core.type.Type in project elide by yahoo.
the class GraphQLConversionUtils method attributeToInputObject.
/**
* Helper function which converts an attribute of an entity to a GraphQL Input Type.
* @param parentClass The parent entity class (Can either be an elide entity or not).
* @param attributeClass The attribute class.
* @param attribute The name of the attribute.
* @param dictionary The dictionary that contains the runtime type information for the parent class.
*
* @return A newly created GraphQL Input Type or null if the underlying type cannot be converted.
*/
protected GraphQLInputType attributeToInputObject(Type<?> parentClass, Type<?> attributeClass, String attribute, EntityDictionary dictionary) {
/* Determine if we've already processed this attribute */
if (inputConversions.containsKey(attributeClass)) {
return inputConversions.get(attributeClass);
}
if (enumConversions.containsKey(attributeClass)) {
return enumConversions.get(attributeClass);
}
/* We don't support Class */
if (ClassType.CLASS_TYPE.isAssignableFrom(attributeClass)) {
return null;
}
/* If the attribute is a map */
if (ClassType.MAP_TYPE.isAssignableFrom(attributeClass)) {
/* Extract the key and value types */
Type<?> keyType = dictionary.getParameterizedType(parentClass, attribute, 0);
Type<?> valueType = dictionary.getParameterizedType(parentClass, attribute, 1);
return classToInputMap(keyType, valueType);
/* If the attribute is a collection */
} else if (ClassType.COLLECTION_TYPE.isAssignableFrom(attributeClass)) {
/* Extract the collection type */
Type<?> listType = dictionary.getParameterizedType(parentClass, attribute, 0);
return new GraphQLList(fetchScalarOrObjectInput(listType));
}
return fetchScalarOrObjectInput(attributeClass);
}
Aggregations