public SchemaAttributeResponse Transform(Models.SchemaAttribute record) { if (record == null) { return(null); } if (record.Type == Common.Constants.SchemaAttributeTypes.Complex) { var comlexSchemaAttr = new ComplexSchemaAttributeResponse(); comlexSchemaAttr.SetData(record); var subAttrs = new List <SchemaAttributeResponse>(); if (record.Children != null) { foreach (var child in record.Children) { var transformed = Transform(child); if (transformed == null) { continue; } subAttrs.Add(transformed); } } comlexSchemaAttr.SubAttributes = subAttrs; return(comlexSchemaAttr); } return(record.ToDomain()); }
public IEnumerable <SchemaAttributeResponse> Evaluate(IEnumerable <SchemaAttributeResponse> schemaAttrs) { var representations = schemaAttrs.Where(r => r.Name == Name); if (!representations.Any()) { var lst = new List <SchemaAttributeResponse>(); foreach (var schemaAttr in schemaAttrs) { var c = schemaAttr as ComplexSchemaAttributeResponse; if (c == null || !c.SubAttributes.Any(val => val.Name == Name)) { continue; } lst.AddRange(c.SubAttributes.Where(val => val.Name == Name)); } if (!lst.Any()) { return(new SchemaAttributeResponse[0]); } representations = lst; } if ((ValueFilter != null && representations.Any(r => !r.MultiValued)) || (Next != null && representations.Any(r => r.Type != Common.Constants.SchemaAttributeTypes.Complex))) { return(null); } if (ValueFilter != null || Next != null) { var subAttrs = new List <SchemaAttributeResponse>(); var lst = new List <SchemaAttributeResponse>(); foreach (var representation in representations) { var record = representation; var complexAttr = representation as ComplexSchemaAttributeResponse; if (complexAttr != null && complexAttr.SubAttributes != null) { if (ValueFilter != null) { record = new ComplexSchemaAttributeResponse() { SubAttributes = ValueFilter.Evaluate(complexAttr.SubAttributes) }; } if (Next != null && complexAttr.SubAttributes != null && complexAttr.SubAttributes.Any()) { subAttrs.AddRange(Next.Evaluate(((ComplexSchemaAttributeResponse)record).SubAttributes)); } } lst.Add(record); } representations = lst; if (subAttrs.Any()) { return(subAttrs); } } return(representations); }