private Resource[] Query(IQueryParameters parameters) { if (null == parameters) { throw new ArgumentNullException(nameof(parameters)); } if (parameters.AlternateFilters.Count != 1) { throw new NotSupportedException(SystemForCrossDomainIdentityManagementServiceResources.ExceptionFilterCount); } if (parameters.PaginationParameters != null) { string exceptionMessage = string.Format( CultureInfo.InvariantCulture, SystemForCrossDomainIdentityManagementServiceResources.ExceptionPaginationIsNotSupportedTemplate, parameters.SchemaIdentifier); throw new NotSupportedException(exceptionMessage); } IFilter filter = parameters.AlternateFilters.Single(); if (filter.AdditionalFilter != null) { Resource[] result = SampleProvider.QueryMember(parameters, filter); return(result); } else if (string.Equals(parameters.SchemaIdentifier, SchemaIdentifiers.Core2EnterpriseUser, StringComparison.OrdinalIgnoreCase)) { Resource[] result = this.QueryUsers(parameters, filter); return(result); } else if (string.Equals(parameters.SchemaIdentifier, SchemaIdentifiers.Core2Group, StringComparison.OrdinalIgnoreCase)) { Resource[] result = this.QueryGroups(parameters, filter); return(result); } else { string exceptionMessage = string.Format( CultureInfo.InvariantCulture, SystemForCrossDomainIdentityManagementServiceResources.ExceptionFilterAttributePathNotSupportedTemplate, filter.AttributePath); throw new NotSupportedException(exceptionMessage); } }
private static Resource[] QueryMember(IQueryParameters parameters, IFilter filter) { if (null == parameters) { throw new ArgumentNullException(nameof(parameters)); } if (null == filter) { throw new ArgumentNullException(nameof(filter)); } if (null == filter.AdditionalFilter) { throw new ArgumentException(SystemForCrossDomainIdentityManagementServiceResources.ExceptionQueryNotSupported); } Resource[] results = null; if (parameters.ExcludedAttributePaths != null && parameters.ExcludedAttributePaths.Any()) { throw new ArgumentException(SystemForCrossDomainIdentityManagementServiceResources.ExceptionQueryNotSupported); } if (!string.Equals(parameters.SchemaIdentifier, SchemaIdentifiers.Core2Group, StringComparison.Ordinal)) { throw new NotSupportedException(SystemForCrossDomainIdentityManagementServiceResources.ExceptionQueryNotSupported); } if (null == parameters.RequestedAttributePaths || !parameters.RequestedAttributePaths.Any()) { throw new NotSupportedException(SystemForCrossDomainIdentityManagementServiceResources.ExceptionQueryNotSupported); } if (filter.AdditionalFilter.AdditionalFilter != null) { throw new NotSupportedException(SystemForCrossDomainIdentityManagementServiceResources.ExceptionQueryNotSupported); } string selectedAttribute = parameters.RequestedAttributePaths.SingleOrDefault(); if (string.IsNullOrWhiteSpace(selectedAttribute)) { throw new NotSupportedException(SystemForCrossDomainIdentityManagementServiceResources.ExceptionQueryNotSupported); } if (!string.Equals(selectedAttribute, AttributeNames.Identifier, StringComparison.OrdinalIgnoreCase)) { throw new NotSupportedException(SystemForCrossDomainIdentityManagementServiceResources.ExceptionQueryNotSupported); } IReadOnlyCollection <IFilter> filters = new IFilter[] { filter, filter.AdditionalFilter }; IFilter filterIdentifier = filters .SingleOrDefault( (IFilter item) => item.AttributePath.Equals(AttributeNames.Identifier, StringComparison.OrdinalIgnoreCase)); if (null == filterIdentifier) { throw new NotSupportedException(SystemForCrossDomainIdentityManagementServiceResources.ExceptionQueryNotSupported); } IFilter filterMembers = filters .SingleOrDefault( (IFilter item) => item.AttributePath.Equals(AttributeNames.Members, StringComparison.OrdinalIgnoreCase)); if (null == filterMembers) { throw new NotSupportedException(SystemForCrossDomainIdentityManagementServiceResources.ExceptionQueryNotSupported); } IResourceIdentifier containerIdentifier = new ResourceIdentifier() { SchemaIdentifier = parameters.SchemaIdentifier, Identifier = filterIdentifier.ComparisonValue }; if (!SampleProvider.HasMember(containerIdentifier, filterMembers.AttributePath, filterMembers.ComparisonValue)) { results = Array.Empty <Resource>(); } else { Resource container = new Core2Group() { Identifier = containerIdentifier.Identifier }; results = container.ToCollection().ToArray(); } return(results); }