private static void Parse(SCIMExpression expression, ICollection <SCIMSchemaAttribute> scimSchemaAttributes) { var compAttrExpression = expression as SCIMComparisonExpression; var attrExpression = expression as SCIMAttributeExpression; var logicalExpression = expression as SCIMLogicalExpression; var notExpression = expression as SCIMNotExpression; var presentExpression = expression as SCIMPresentExpression; if (compAttrExpression != null) { var schemaAttr = scimSchemaAttributes.FirstOrDefault(s => s.Name == compAttrExpression.LeftExpression.Name); if (schemaAttr != null && compAttrExpression.LeftExpression.Child != null && schemaAttr.MultiValued && schemaAttr.Type == SCIMSchemaAttributeTypes.COMPLEX && compAttrExpression.LeftExpression.Child == null) { compAttrExpression.LeftExpression.Child = new SCIMAttributeExpression("value"); } Parse(compAttrExpression.LeftExpression, scimSchemaAttributes); } else if (logicalExpression != null) { Parse(logicalExpression.LeftExpression, scimSchemaAttributes); Parse(logicalExpression.RightExpression, scimSchemaAttributes); } else if (attrExpression != null) { var schemaAttr = scimSchemaAttributes.FirstOrDefault(s => s.Name == attrExpression.Name); if (schemaAttr == null) { return; } Parse(attrExpression.Child, schemaAttr.SubAttributes); } }
public static Expression Evaluate(this SCIMExpression expression, ParameterExpression parameterExpression) { var compAttrExpression = expression as SCIMComparisonExpression; var attrExpression = expression as SCIMAttributeExpression; var logicalExpression = expression as SCIMLogicalExpression; var notExpression = expression as SCIMNotExpression; var presentExpression = expression as SCIMPresentExpression; if (compAttrExpression != null) { return(compAttrExpression.Evaluate(parameterExpression)); } if (attrExpression != null) { return(attrExpression.Evaluate(parameterExpression)); } if (logicalExpression != null) { return(logicalExpression.Evaluate(parameterExpression)); } if (notExpression != null) { return(notExpression.Evaluate(parameterExpression)); } if (presentExpression != null) { return(presentExpression.Evaluate(parameterExpression)); } return(null); }
public SearchSCIMRepresentationsParameter(string resourceType, int startIndex, int count, string sortBy, SearchSCIMRepresentationOrders?sortOrder = null, SCIMExpression filter = null) { ResourceType = resourceType; StartIndex = startIndex; Count = count; SortBy = sortBy; SortOrder = sortOrder; Filter = filter; }
public SearchSCIMRepresentationsParameter(string resourceType, int startIndex, int count, SCIMExpression sortBy, SearchSCIMRepresentationOrders?sortOrder = null, SCIMExpression filter = null, IEnumerable <string> attributes = null) { ResourceType = resourceType; StartIndex = startIndex; Count = count; SortBy = sortBy; SortOrder = sortOrder; Filter = filter; Attributes = attributes; }
public static LambdaExpression Evaluate(this SCIMExpression expression, IQueryable <SCIMRepresentationModel> representations) { var representationParameter = Expression.Parameter(typeof(SCIMRepresentationModel), "rp"); var anyLambdaExpression = expression.Evaluate(representationParameter); var enumarableType = typeof(Queryable); var whereMethod = enumarableType.GetMethods() .Where(m => m.Name == "Where" && m.IsGenericMethodDefinition) .Where(m => m.GetParameters().Count() == 2).First().MakeGenericMethod(typeof(SCIMRepresentationModel)); var equalLambda = Expression.Lambda <Func <SCIMRepresentationModel, bool> >(anyLambdaExpression, representationParameter); var whereExpr = Expression.Call(whereMethod, Expression.Constant(representations), equalLambda); var finalSelectArg = Expression.Parameter(typeof(IQueryable <SCIMRepresentationModel>), "f"); var finalSelectRequestBody = Expression.Lambda(whereExpr, new ParameterExpression[] { finalSelectArg }); return(finalSelectRequestBody); }
public static LambdaExpression EvaluateOrderBy(this SCIMExpression expression, IQueryable <SCIMRepresentation> representations, SearchSCIMRepresentationOrders order) { var attrExpression = expression as SCIMAttributeExpression; if (attrExpression == null) { return(null); } var result = EvaluateOrderByMetadata(attrExpression, representations, order); if (result == null) { result = EvaluateOrderByProperty(attrExpression, representations, order); } return(result); }
public static async Task <SearchSCIMRepresentationsResponse> EvaluateOrderBy( this SCIMExpression expression, SCIMDbContext dbContext, IQueryable <SCIMRepresentation> representations, SearchSCIMRepresentationOrders order, int startIndex, int count, IEnumerable <SCIMAttributeExpression> includedAttributes, IEnumerable <SCIMAttributeExpression> excludedAttributes) { var attrExpression = expression as SCIMAttributeExpression; if (attrExpression == null) { return(null); } var result = EvaluateOrderByMetadata(dbContext, attrExpression, representations, order, startIndex, count, includedAttributes, excludedAttributes); if (result == null) { result = EvaluateOrderByProperty( dbContext, attrExpression, representations, order, startIndex, count, includedAttributes, excludedAttributes); } return(result); }
public static async Task <SearchSCIMRepresentationsResponse> EvaluateOrderBy(this SCIMExpression expression, SCIMDbContext dbContext, IQueryable <SCIMRepresentationModel> representations, SearchSCIMRepresentationOrders order, int startIndex, int count, CancellationToken cancellationToken) { var attrExpression = expression as SCIMAttributeExpression; if (attrExpression == null) { return(null); } var result = await EvaluateOrderByMetadata(attrExpression, representations, order, startIndex, count, cancellationToken); if (result == null) { result = await EvaluateOrderByProperty(dbContext, attrExpression, representations, order, startIndex, count, cancellationToken); } return(result); }
public SCIMLogicalExpression(SCIMLogicalOperators logicalOperator, SCIMExpression leftExpression, SCIMExpression rightExpression) { LogicalOperator = logicalOperator; LeftExpression = leftExpression; RightExpression = rightExpression; }
public SCIMComplexAttributeExpression(string name, SCIMExpression groupingFilter) : base(name) { GroupingFilter = groupingFilter; }
public SCIMComplexAttributeExpression(string name, SCIMExpression groupingFilter, SCIMAttributeExpression child) : this(name, child) { }
private static IQueryable <SCIMRepresentationAttribute> GetRepresentationAttributeFromPath(IQueryable <SCIMRepresentationAttribute> representationAttributes, SCIMExpression scimExpression) { var scimAttributeExpression = scimExpression as SCIMAttributeExpression; if (scimAttributeExpression == null) { throw new SCIMAttributeException("not a valid attribute expression"); } var filteredAttributes = GetAttributes(scimAttributeExpression, representationAttributes); if (!filteredAttributes.Any()) { return((new List <SCIMRepresentationAttribute>()).AsQueryable()); } if (scimAttributeExpression.Child != null) { return(GetRepresentationAttributeFromPath(filteredAttributes.SelectMany(v => v.Values), scimAttributeExpression.Child)); } return(filteredAttributes); }
private static void IncludeAttribute(this SCIMRepresentation scimRepresentation, SCIMExpression scimExpression, JObject result) { var scimAttributeExpression = scimExpression as SCIMAttributeExpression; if (scimAttributeExpression == null) { throw new SCIMAttributeException("not a valid attribute expression"); } IncludeAttribute(scimAttributeExpression, scimRepresentation.Attributes.AsQueryable(), result); }
private static void IncludeAttribute(this SCIMRepresentation scimRepresentation, SCIMExpression scimExpression, JObject result) { var scimAttributeExpression = scimExpression as SCIMAttributeExpression; if (scimAttributeExpression == null) { throw new SCIMAttributeException(Global.InvalidAttributeExpression); } IncludeAttribute(scimAttributeExpression, scimRepresentation.Attributes.AsQueryable(), result); var fullPath = scimAttributeExpression.GetFullPath(); if (!COMMNON_PROPERTY_NAMES.Contains(fullPath)) { return; } if (fullPath == SCIMConstants.StandardSCIMRepresentationAttributes.ExternalId) { result.Add(SCIMConstants.StandardSCIMRepresentationAttributes.ExternalId, scimRepresentation.ExternalId); } else if (fullPath == $"{SCIMConstants.StandardSCIMRepresentationAttributes.Meta}.{SCIMConstants.StandardSCIMMetaAttributes.ResourceType}") { result.Add(SCIMConstants.StandardSCIMRepresentationAttributes.Meta, new JObject { { SCIMConstants.StandardSCIMMetaAttributes.ResourceType, scimRepresentation.ResourceType } }); } else if (fullPath == $"{SCIMConstants.StandardSCIMRepresentationAttributes.Meta}.{SCIMConstants.StandardSCIMMetaAttributes.Created}") { result.Add(SCIMConstants.StandardSCIMRepresentationAttributes.Meta, new JObject { { SCIMConstants.StandardSCIMMetaAttributes.Created, scimRepresentation.Created } }); } else if (fullPath == $"{SCIMConstants.StandardSCIMRepresentationAttributes.Meta}.{SCIMConstants.StandardSCIMMetaAttributes.LastModified}") { result.Add(SCIMConstants.StandardSCIMRepresentationAttributes.Meta, new JObject { { SCIMConstants.StandardSCIMMetaAttributes.LastModified, scimRepresentation.LastModified } }); } else if (fullPath == $"{SCIMConstants.StandardSCIMRepresentationAttributes.Meta}.{SCIMConstants.StandardSCIMMetaAttributes.Version}") { result.Add(SCIMConstants.StandardSCIMRepresentationAttributes.Meta, new JObject { { SCIMConstants.StandardSCIMMetaAttributes.Version, scimRepresentation.Version } }); } }
private static void Parse(SCIMExpression expression, ICollection <SCIMSchemaAttribute> scimSchemaAttributes, ICollection <SCIMSchema> schemas) { var compAttrExpression = expression as SCIMComparisonExpression; var attrExpression = expression as SCIMAttributeExpression; var logicalExpression = expression as SCIMLogicalExpression; var notExpression = expression as SCIMNotExpression; var presentExpression = expression as SCIMPresentExpression; if (compAttrExpression != null) { var schemaAttr = GetSCIMSchemaAttribute(compAttrExpression.LeftExpression.Name, scimSchemaAttributes, schemas); if (schemaAttr != null && schemaAttr.MultiValued && schemaAttr.Type == SCIMSchemaAttributeTypes.COMPLEX && compAttrExpression.LeftExpression.Child == null) { var schema = schemas.FirstOrDefault(s => s.HasAttribute(schemaAttr)); var children = schema.GetChildren(schemaAttr); compAttrExpression.LeftExpression.Child = new SCIMAttributeExpression("value") { SchemaAttribute = children.First(c => c.Name == "value") }; } Parse(compAttrExpression.LeftExpression, scimSchemaAttributes, schemas); } else if (logicalExpression != null) { Parse(logicalExpression.LeftExpression, scimSchemaAttributes, schemas); Parse(logicalExpression.RightExpression, scimSchemaAttributes, schemas); } else if (attrExpression != null) { var schemaAttr = GetSCIMSchemaAttribute(attrExpression.Name, scimSchemaAttributes, schemas); if (schemaAttr == null) { return; } attrExpression.SchemaAttribute = schemaAttr; var complex = attrExpression as SCIMComplexAttributeExpression; if (attrExpression.Child != null || complex != null) { var schema = schemas.FirstOrDefault(s => s.HasAttribute(attrExpression.SchemaAttribute)); var subAttributes = schema.GetChildren(attrExpression.SchemaAttribute).ToList(); if (attrExpression.Child != null) { Parse(attrExpression.Child, subAttributes, schemas); } if (complex != null && complex.GroupingFilter != null) { Parse(complex.GroupingFilter, subAttributes, schemas); } } } else if (presentExpression != null) { var schemaAttr = GetSCIMSchemaAttribute(presentExpression.Content.Name, scimSchemaAttributes, schemas); if (schemaAttr == null) { return; } presentExpression.Content.SchemaAttribute = schemaAttr; } else if (notExpression != null) { Parse(notExpression.Content, scimSchemaAttributes, schemas); } }
public SCIMNotExpression(SCIMExpression content) { Content = content; }