public IEnumerable <SCIMRepresentationAttribute> GetFlatHierarchicalChildren(SCIMRepresentationAttribute attr)
        {
            var result = new List <SCIMRepresentationAttribute>();

            result.Add(attr);
            foreach (var child in GetChildren(attr))
            {
                result.AddRange(GetFlatHierarchicalChildren(child));
            }

            return(result);
        }
        public void UpdateAttribute(SCIMRepresentationAttribute attribute)
        {
            var attr = FlatAttributes.First(a => a.Id == attribute.Id);

            attr.ValueBinary    = attribute.ValueBinary;
            attr.ValueBoolean   = attribute.ValueBoolean;
            attr.ValueDateTime  = attribute.ValueDateTime;
            attr.ValueDecimal   = attribute.ValueDecimal;
            attr.ValueInteger   = attribute.ValueInteger;
            attr.ValueReference = attribute.ValueReference;
            attr.ValueString    = attribute.ValueString;
        }
        private static void EnrichAttributesHiearchy(SCIMRepresentationAttribute childAttribute, List <SCIMRepresentationAttribute> flatAttrsHiearchy, IEnumerable <SCIMRepresentationAttribute> allAttributes)
        {
            if (string.IsNullOrWhiteSpace(childAttribute.ParentAttributeId))
            {
                return;
            }

            var parents = allAttributes.Where(a => a.Id == childAttribute.ParentAttributeId);

            flatAttrsHiearchy.AddRange(parents);
            foreach (var parent in parents)
            {
                EnrichAttributesHiearchy(parent, flatAttrsHiearchy, allAttributes);
            }
        }
 public SCIMSchema GetSchema(SCIMRepresentationAttribute attribute)
 {
     return(GetSchema(attribute.SchemaAttribute));
 }
        public void AddStandardAttributes(string location, IEnumerable <string> attributes, bool isIncluded = true, bool ignore = true)
        {
            var metadata      = new SCIMRepresentationAttribute(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), StandardSchemas.StandardResponseSchemas.GetAttribute(StandardSCIMRepresentationAttributes.Meta), StandardSchemas.ResourceTypeSchema.Id);
            var startWithMeta = attributes.Any(a => a.StartsWith(StandardSCIMRepresentationAttributes.Meta) && a.Split('.').Count() > 1);
            var containsMeta  = attributes.Contains(StandardSCIMRepresentationAttributes.Meta);

            if (startWithMeta || ignore || !(containsMeta && !isIncluded))
            {
                AddAttribute(metadata);
                var includeAll           = containsMeta && isIncluded;
                var containsResourceType = attributes.Contains($"{StandardSCIMRepresentationAttributes.Meta}.{StandardSCIMMetaAttributes.ResourceType}");
                var containsCreated      = attributes.Contains($"{StandardSCIMRepresentationAttributes.Meta}.{StandardSCIMMetaAttributes.Created}");
                var containsLastModified = attributes.Contains($"{StandardSCIMRepresentationAttributes.Meta}.{StandardSCIMMetaAttributes.LastModified}");
                var containsVersion      = attributes.Contains($"{StandardSCIMRepresentationAttributes.Meta}.{StandardSCIMMetaAttributes.Version}");
                var containsLocation     = attributes.Contains($"{StandardSCIMRepresentationAttributes.Meta}.{StandardSCIMRepresentationAttributes.Location}");
                if (containsResourceType && isIncluded || !containsResourceType && !isIncluded || ignore || includeAll)
                {
                    AddAttribute(metadata, new SCIMRepresentationAttribute(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), StandardSchemas.StandardResponseSchemas.GetAttribute($"{StandardSCIMRepresentationAttributes.Meta}.{StandardSCIMMetaAttributes.ResourceType}"), StandardSchemas.ResourceTypeSchema.Id)
                    {
                        ValueString = ResourceType
                    });
                }

                if (containsCreated && isIncluded || !containsCreated && !isIncluded || ignore || includeAll)
                {
                    AddAttribute(metadata, new SCIMRepresentationAttribute(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), StandardSchemas.StandardResponseSchemas.GetAttribute($"{StandardSCIMRepresentationAttributes.Meta}.{StandardSCIMMetaAttributes.Created}"), StandardSchemas.ResourceTypeSchema.Id)
                    {
                        ValueDateTime = Created
                    });
                }

                if (containsLastModified && isIncluded || !containsLastModified && !isIncluded || ignore || includeAll)
                {
                    AddAttribute(metadata, new SCIMRepresentationAttribute(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), StandardSchemas.StandardResponseSchemas.GetAttribute($"{StandardSCIMRepresentationAttributes.Meta}.{StandardSCIMMetaAttributes.LastModified}"), StandardSchemas.ResourceTypeSchema.Id)
                    {
                        ValueDateTime = LastModified
                    });
                }

                if (containsVersion && isIncluded || !containsVersion && !isIncluded || ignore || includeAll)
                {
                    AddAttribute(metadata, new SCIMRepresentationAttribute(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), StandardSchemas.StandardResponseSchemas.GetAttribute($"{StandardSCIMRepresentationAttributes.Meta}.{StandardSCIMMetaAttributes.Version}"), StandardSchemas.ResourceTypeSchema.Id)
                    {
                        ValueInteger = Version
                    });
                }

                if ((containsLocation && isIncluded || !containsLocation && !isIncluded || ignore || includeAll) && !string.IsNullOrWhiteSpace(location))
                {
                    AddAttribute(metadata, new SCIMRepresentationAttribute(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), StandardSchemas.StandardResponseSchemas.GetAttribute($"{StandardSCIMRepresentationAttributes.Meta}.{StandardSCIMMetaAttributes.Location}"), StandardSchemas.ResourceTypeSchema.Id)
                    {
                        ValueString = location
                    });
                }
            }

            var containsExternalId = attributes.Contains(StandardSCIMRepresentationAttributes.ExternalId);
            var containsSchemas    = attributes.Contains(StandardSCIMRepresentationAttributes.Schemas);

            if (containsExternalId && isIncluded || !containsExternalId && !isIncluded || ignore)
            {
                if (!string.IsNullOrWhiteSpace(ExternalId))
                {
                    AddAttribute(new SCIMRepresentationAttribute(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), StandardSchemas.StandardResponseSchemas.GetAttribute(StandardSCIMRepresentationAttributes.ExternalId), StandardSchemas.ResourceTypeSchema.Id)
                    {
                        ValueString = ExternalId
                    });
                }
            }

            if (containsSchemas && isIncluded || !containsSchemas && !isIncluded || ignore)
            {
                foreach (var schemaId in Schemas.Select(s => s.Id))
                {
                    AddAttribute(new SCIMRepresentationAttribute(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), StandardSchemas.StandardResponseSchemas.GetAttribute(StandardSCIMRepresentationAttributes.Schemas), StandardSchemas.ResourceTypeSchema.Id)
                    {
                        ValueString = schemaId
                    });
                }
            }
        }
 public bool ContainsAttribute(SCIMRepresentationAttribute attr)
 {
     return(FlatAttributes.Any(a => a.IsSimilar(attr)));
 }
 public IEnumerable <SCIMRepresentationAttribute> GetChildren(SCIMRepresentationAttribute attr)
 {
     return(FlatAttributes.Where(a => a.ParentAttributeId == attr.Id));
 }
 public IEnumerable <SCIMRepresentationAttribute> GetParentAttributesByPath(SCIMRepresentationAttribute attr)
 {
     return(GetParentAttributesByPath(attr.FullPath));
 }
 public SCIMRepresentationAttribute GetParentAttribute(SCIMRepresentationAttribute attr)
 {
     return(GetParentAttributeById(attr.ParentAttributeId));
 }
 public ICollection <SCIMRepresentationAttribute> RemoveAttributeById(SCIMRepresentationAttribute attribute)
 {
     return(RemoveAttributesById(new[] { attribute.Id }));
 }
 public void AddAttribute(SCIMRepresentationAttribute parentAttribute, SCIMRepresentationAttribute childAttribute)
 {
     childAttribute.ParentAttributeId = parentAttribute.Id;
     FlatAttributes.Add(childAttribute);
 }
 public void AddAttribute(SCIMRepresentationAttribute attribute)
 {
     FlatAttributes.Add(attribute);
 }