Search in sources :

Example 6 with Type

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"));
}
Also used : ColumnMeta(com.yahoo.elide.datastores.aggregation.annotation.ColumnMeta) Arrays(java.util.Arrays) ArgumentType(com.yahoo.elide.core.dictionary.ArgumentType) Join(com.yahoo.elide.datastores.aggregation.annotation.Join) AccessibleObject(com.yahoo.elide.core.type.AccessibleObject) TableMeta(com.yahoo.elide.datastores.aggregation.annotation.TableMeta) UserCheck(com.yahoo.elide.core.security.checks.UserCheck) PermissionExecutor(com.yahoo.elide.core.security.PermissionExecutor) Function(java.util.function.Function) ClassType(com.yahoo.elide.core.type.ClassType) Column(com.yahoo.elide.datastores.aggregation.metadata.models.Column) ToString(lombok.ToString) ParseTree(org.antlr.v4.runtime.tree.ParseTree) FilterExpressionCheck(com.yahoo.elide.core.security.checks.FilterExpressionCheck) RequestScope(com.yahoo.elide.core.RequestScope) DataStoreTransaction(com.yahoo.elide.core.datastore.DataStoreTransaction) Check(com.yahoo.elide.core.security.checks.Check) Cache(com.yahoo.elide.datastores.aggregation.cache.Cache) FromSubquery(com.yahoo.elide.datastores.aggregation.queryengines.sql.annotation.FromSubquery) PermissionExpressionVisitor(com.yahoo.elide.modelconfig.validator.PermissionExpressionVisitor) NonNull(lombok.NonNull) Predicate(java.util.function.Predicate) ValueType(com.yahoo.elide.datastores.aggregation.metadata.enums.ValueType) ArgumentDefinition(com.yahoo.elide.datastores.aggregation.metadata.models.ArgumentDefinition) Set(java.util.Set) FromTable(com.yahoo.elide.datastores.aggregation.queryengines.sql.annotation.FromTable) AggregationStorePermissionExecutor(com.yahoo.elide.core.security.executors.AggregationStorePermissionExecutor) EntityDictionary(com.yahoo.elide.core.dictionary.EntityDictionary) Objects(java.util.Objects) List(java.util.List) ReadPermission(com.yahoo.elide.annotation.ReadPermission) Builder(lombok.Builder) DataStore(com.yahoo.elide.core.datastore.DataStore) Type(com.yahoo.elide.core.type.Type) TimeDimension(com.yahoo.elide.datastores.aggregation.metadata.models.TimeDimension) Annotation(java.lang.annotation.Annotation) Table(com.yahoo.elide.datastores.aggregation.metadata.models.Table) QueryLogger(com.yahoo.elide.datastores.aggregation.core.QueryLogger) PermissionExpressionVisitor(com.yahoo.elide.modelconfig.validator.PermissionExpressionVisitor) ReadPermission(com.yahoo.elide.annotation.ReadPermission) ParseTree(org.antlr.v4.runtime.tree.ParseTree)

Example 7 with Type

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());
}
Also used : HashMapDataStore(com.yahoo.elide.core.datastore.inmemory.HashMapDataStore) Arrays(java.util.Arrays) Path(com.yahoo.elide.core.Path) Getter(lombok.Getter) IS_FIELD_HIDDEN(com.yahoo.elide.datastores.aggregation.AggregationDataStore.IS_FIELD_HIDDEN) Include(com.yahoo.elide.annotation.Include) Dimension(com.yahoo.elide.datastores.aggregation.metadata.models.Dimension) HashMap(java.util.HashMap) Function(java.util.function.Function) HashSet(java.util.HashSet) DuplicateMappingException(com.yahoo.elide.core.exceptions.DuplicateMappingException) NamespacePackage(com.yahoo.elide.datastores.aggregation.dynamic.NamespacePackage) Pair(org.apache.commons.lang3.tuple.Pair) DEFAULT_NAMESPACE(com.yahoo.elide.datastores.aggregation.dynamic.NamespacePackage.DEFAULT_NAMESPACE) TableType(com.yahoo.elide.datastores.aggregation.dynamic.TableType) Namespace(com.yahoo.elide.datastores.aggregation.metadata.models.Namespace) ClassScanner(com.yahoo.elide.core.utils.ClassScanner) Map(java.util.Map) Column(com.yahoo.elide.datastores.aggregation.metadata.models.Column) NO_VERSION(com.yahoo.elide.core.dictionary.EntityDictionary.NO_VERSION) InternalServerErrorException(com.yahoo.elide.core.exceptions.InternalServerErrorException) AggregationDataStore(com.yahoo.elide.datastores.aggregation.AggregationDataStore) Entity(javax.persistence.Entity) ApiVersion(com.yahoo.elide.annotation.ApiVersion) DataStoreTransaction(com.yahoo.elide.core.datastore.DataStoreTransaction) TableSource(com.yahoo.elide.datastores.aggregation.metadata.models.TableSource) DEFAULT(com.yahoo.elide.datastores.aggregation.dynamic.NamespacePackage.DEFAULT) FromSubquery(com.yahoo.elide.datastores.aggregation.queryengines.sql.annotation.FromSubquery) Collection(java.util.Collection) ArgumentDefinition(com.yahoo.elide.datastores.aggregation.metadata.models.ArgumentDefinition) TimeDimensionGrain(com.yahoo.elide.datastores.aggregation.metadata.models.TimeDimensionGrain) Set(java.util.Set) FromTable(com.yahoo.elide.datastores.aggregation.queryengines.sql.annotation.FromTable) Subselect(org.hibernate.annotations.Subselect) Collectors(java.util.stream.Collectors) EntityDictionary(com.yahoo.elide.core.dictionary.EntityDictionary) List(java.util.List) Versioned(com.yahoo.elide.datastores.aggregation.metadata.models.Versioned) TypeHelper.getClassType(com.yahoo.elide.core.utils.TypeHelper.getClassType) DataStore(com.yahoo.elide.core.datastore.DataStore) Type(com.yahoo.elide.core.type.Type) TimeDimension(com.yahoo.elide.datastores.aggregation.metadata.models.TimeDimension) Annotation(java.lang.annotation.Annotation) Table(com.yahoo.elide.datastores.aggregation.metadata.models.Table) EMPTY(com.yahoo.elide.datastores.aggregation.dynamic.NamespacePackage.EMPTY) MetricFormula(com.yahoo.elide.datastores.aggregation.annotation.MetricFormula) Metric(com.yahoo.elide.datastores.aggregation.metadata.models.Metric) DEFAULT(com.yahoo.elide.datastores.aggregation.dynamic.NamespacePackage.DEFAULT) HashMapDataStore(com.yahoo.elide.core.datastore.inmemory.HashMapDataStore)

Example 8 with Type

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);
}
Also used : Path(com.yahoo.elide.core.Path) ClassType(com.yahoo.elide.core.type.ClassType) Type(com.yahoo.elide.core.type.Type) ArrayList(java.util.ArrayList)

Example 9 with Type

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));
        });
    }
}
Also used : Getter(lombok.Getter) Iterator(java.util.Iterator) Set(java.util.Set) EntityProjection(com.yahoo.elide.core.request.EntityProjection) UUID(java.util.UUID) EntityDictionary(com.yahoo.elide.core.dictionary.EntityDictionary) Objects(java.util.Objects) List(java.util.List) Type(com.yahoo.elide.core.type.Type) Map(java.util.Map) PersistentResource(com.yahoo.elide.core.PersistentResource) Optional(java.util.Optional) AllArgsConstructor(lombok.AllArgsConstructor) LinkedHashSet(java.util.LinkedHashSet) RequestScope(com.yahoo.elide.core.RequestScope) LinkedHashSet(java.util.LinkedHashSet) List(java.util.List) EntityDictionary(com.yahoo.elide.core.dictionary.EntityDictionary)

Example 10 with Type

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);
}
Also used : GraphQLList(graphql.schema.GraphQLList) GraphQLInputObjectType(graphql.schema.GraphQLInputObjectType) GraphQLScalarType(graphql.schema.GraphQLScalarType) ClassType(com.yahoo.elide.core.type.ClassType) GraphQLObjectType(graphql.schema.GraphQLObjectType) GraphQLInputType(graphql.schema.GraphQLInputType) GraphQLOutputType(graphql.schema.GraphQLOutputType) Type(com.yahoo.elide.core.type.Type) GraphQLEnumType(graphql.schema.GraphQLEnumType)

Aggregations

Type (com.yahoo.elide.core.type.Type)35 EntityDictionary (com.yahoo.elide.core.dictionary.EntityDictionary)22 Set (java.util.Set)17 List (java.util.List)16 Map (java.util.Map)16 ClassType (com.yahoo.elide.core.type.ClassType)15 Function (java.util.function.Function)14 FilterExpression (com.yahoo.elide.core.filter.expression.FilterExpression)13 Annotation (java.lang.annotation.Annotation)12 Collectors (java.util.stream.Collectors)12 Collection (java.util.Collection)11 ReadPermission (com.yahoo.elide.annotation.ReadPermission)10 ArrayList (java.util.ArrayList)10 HashSet (java.util.HashSet)10 DataStoreTransaction (com.yahoo.elide.core.datastore.DataStoreTransaction)9 Optional (java.util.Optional)9 RequestScope (com.yahoo.elide.core.RequestScope)8 Objects (java.util.Objects)8 Path (com.yahoo.elide.core.Path)7 RelationshipType (com.yahoo.elide.core.dictionary.RelationshipType)7