@@ -5,11 +5,11 @@ namespace Microsoft.SCIM.WebHostSample.Provider
5
5
using System ;
6
6
using System . Collections . Generic ;
7
7
using System . Linq ;
8
+ using System . Linq . Expressions ;
8
9
using System . Net ;
9
10
using System . Threading . Tasks ;
10
11
using System . Web . Http ;
11
12
using Microsoft . SCIM ;
12
- using Microsoft . SCIM . WebHostSample . Resources ;
13
13
14
14
public class InMemoryGroupProvider : ProviderBase
15
15
{
@@ -44,6 +44,10 @@ public override Task<Resource> CreateAsync(Resource resource, string correlation
44
44
{
45
45
throw new HttpResponseException ( HttpStatusCode . Conflict ) ;
46
46
}
47
+ //Update Metadata
48
+ DateTime created = DateTime . UtcNow ;
49
+ group . Metadata . Created = created ;
50
+ group . Metadata . LastModified = created ;
47
51
48
52
string resourceIdentifier = Guid . NewGuid ( ) . ToString ( ) ;
49
53
resource . Identifier = resourceIdentifier ;
@@ -83,83 +87,61 @@ public override Task<Resource[]> QueryAsync(IQueryParameters parameters, string
83
87
84
88
if ( null == parameters . AlternateFilters )
85
89
{
86
- throw new ArgumentException ( SampleServiceResources . ExceptionInvalidParameters ) ;
90
+ throw new ArgumentException ( SystemForCrossDomainIdentityManagementServiceResources . ExceptionInvalidParameters ) ;
87
91
}
88
92
89
93
if ( string . IsNullOrWhiteSpace ( parameters . SchemaIdentifier ) )
90
94
{
91
- throw new ArgumentException ( SampleServiceResources . ExceptionInvalidParameters ) ;
95
+ throw new ArgumentException ( SystemForCrossDomainIdentityManagementServiceResources . ExceptionInvalidParameters ) ;
92
96
}
93
97
94
- Resource [ ] results ;
98
+ IEnumerable < Resource > results ;
95
99
IFilter queryFilter = parameters . AlternateFilters . SingleOrDefault ( ) ;
96
- IEnumerable < Core2Group > buffer = Enumerable . Empty < Core2Group > ( ) ;
100
+
101
+ var predicate = PredicateBuilder . False < Core2Group > ( ) ;
102
+ Expression < Func < Core2Group , bool > > predicateAnd ;
103
+ predicateAnd = PredicateBuilder . True < Core2Group > ( ) ;
104
+
97
105
if ( queryFilter == null )
98
106
{
99
- buffer = this . storage . Groups . Values ;
107
+ results = this . storage . Groups . Values . Select (
108
+ ( Core2Group user ) => user as Resource ) ;
100
109
}
101
110
else
102
111
{
103
112
if ( string . IsNullOrWhiteSpace ( queryFilter . AttributePath ) )
104
113
{
105
- throw new ArgumentException ( SampleServiceResources . ExceptionInvalidParameters ) ;
114
+ throw new ArgumentException ( SystemForCrossDomainIdentityManagementServiceResources . ExceptionInvalidParameters ) ;
106
115
}
107
116
108
117
if ( string . IsNullOrWhiteSpace ( queryFilter . ComparisonValue ) )
109
118
{
110
- throw new ArgumentException ( SampleServiceResources . ExceptionInvalidParameters ) ;
119
+ throw new ArgumentException ( SystemForCrossDomainIdentityManagementServiceResources . ExceptionInvalidParameters ) ;
111
120
}
112
121
113
122
if ( queryFilter . FilterOperator != ComparisonOperator . Equals )
114
123
{
115
- throw new NotSupportedException ( SampleServiceResources . UnsupportedComparisonOperator ) ;
124
+ throw new NotSupportedException ( string . Format ( SystemForCrossDomainIdentityManagementServiceResources . ExceptionFilterOperatorNotSupportedTemplate , queryFilter . FilterOperator ) ) ;
116
125
}
117
126
127
+
118
128
if ( queryFilter . AttributePath . Equals ( AttributeNames . DisplayName ) )
119
129
{
120
- buffer =
121
- this . storage . Groups . Values
122
- . Where (
123
- ( Core2Group item ) =>
124
- string . Equals (
125
- item . DisplayName ,
126
- parameters . AlternateFilters . Single ( ) . ComparisonValue ,
127
- StringComparison . OrdinalIgnoreCase ) ) ;
130
+
131
+ string displayName = queryFilter . ComparisonValue ;
132
+ predicateAnd = predicateAnd . And ( p => string . Equals ( p . DisplayName , displayName , StringComparison . OrdinalIgnoreCase ) ) ;
133
+
128
134
}
129
135
else
130
136
{
131
- throw new NotSupportedException ( SampleServiceResources . UnsupportedFilterAttributeGroup ) ;
137
+ throw new NotSupportedException ( string . Format ( SystemForCrossDomainIdentityManagementServiceResources . ExceptionFilterAttributePathNotSupportedTemplate , queryFilter . AttributePath ) ) ;
132
138
}
133
139
}
140
+
141
+ predicate = predicate . Or ( predicateAnd ) ;
142
+ results = this . storage . Groups . Values . Where ( predicate . Compile ( ) ) ;
134
143
135
- results =
136
- buffer
137
- . Select ( ( Core2Group item ) =>
138
- {
139
- Core2Group bufferItem =
140
- new Core2Group
141
- {
142
- DisplayName = item . DisplayName ,
143
- ExternalIdentifier = item . ExternalIdentifier ,
144
- Identifier = item . Identifier ,
145
- Members = item . Members ,
146
- Metadata = item . Metadata
147
- } ;
148
-
149
- if ( parameters ? . ExcludedAttributePaths ? . Any (
150
- ( string excludedAttributes ) =>
151
- excludedAttributes . Equals ( AttributeNames . Members , StringComparison . OrdinalIgnoreCase ) )
152
- == true )
153
- {
154
- bufferItem . Members = null ;
155
- }
156
-
157
- return bufferItem ;
158
- } )
159
- . Select ( ( Core2Group item ) => item as Resource )
160
- . ToArray ( ) ;
161
-
162
- return Task . FromResult ( results ) ;
144
+ return Task . FromResult ( results . ToArray ( ) ) ;
163
145
}
164
146
165
147
public override Task < Resource > ReplaceAsync ( Resource resource , string correlationIdentifier )
@@ -176,10 +158,10 @@ public override Task<Resource> ReplaceAsync(Resource resource, string correlatio
176
158
throw new HttpResponseException ( HttpStatusCode . BadRequest ) ;
177
159
}
178
160
179
- IEnumerable < Core2Group > exisitingGroups = this . storage . Groups . Values ;
161
+ Core2Group exisitingGroups = resource as Core2Group ;
180
162
if
181
163
(
182
- exisitingGroups . Any (
164
+ this . storage . Groups . Values . Any (
183
165
( Core2Group exisitingUser ) =>
184
166
string . Equals ( exisitingUser . DisplayName , group . DisplayName , StringComparison . Ordinal ) &&
185
167
! string . Equals ( exisitingUser . Identifier , group . Identifier , StringComparison . OrdinalIgnoreCase ) )
@@ -193,6 +175,10 @@ public override Task<Resource> ReplaceAsync(Resource resource, string correlatio
193
175
throw new HttpResponseException ( HttpStatusCode . NotFound ) ;
194
176
}
195
177
178
+ // Update metadata
179
+ group . Metadata . Created = exisitingGroups . Metadata . Created ;
180
+ group . Metadata . LastModified = DateTime . UtcNow ;
181
+
196
182
this . storage . Groups [ group . Identifier ] = group ;
197
183
Resource result = group as Resource ;
198
184
return Task . FromResult ( result ) ;
@@ -238,17 +224,17 @@ public override Task UpdateAsync(IPatch patch, string correlationIdentifier)
238
224
239
225
if ( null == patch . ResourceIdentifier )
240
226
{
241
- throw new ArgumentException ( SampleServiceResources . ExceptionInvalidPatch ) ;
227
+ throw new ArgumentException ( SystemForCrossDomainIdentityManagementServiceResources . ExceptionInvalidOperation ) ;
242
228
}
243
229
244
230
if ( string . IsNullOrWhiteSpace ( patch . ResourceIdentifier . Identifier ) )
245
231
{
246
- throw new ArgumentException ( SampleServiceResources . ExceptionInvalidPatch ) ;
232
+ throw new ArgumentException ( SystemForCrossDomainIdentityManagementServiceResources . ExceptionInvalidOperation ) ;
247
233
}
248
234
249
235
if ( null == patch . PatchRequest )
250
236
{
251
- throw new ArgumentException ( SampleServiceResources . ExceptionInvalidPatch ) ;
237
+ throw new ArgumentException ( SystemForCrossDomainIdentityManagementServiceResources . ExceptionInvalidOperation ) ;
252
238
}
253
239
254
240
PatchRequest2 patchRequest =
@@ -263,6 +249,8 @@ public override Task UpdateAsync(IPatch patch, string correlationIdentifier)
263
249
if ( this . storage . Groups . TryGetValue ( patch . ResourceIdentifier . Identifier , out Core2Group group ) )
264
250
{
265
251
group . Apply ( patchRequest ) ;
252
+ // Update metadata
253
+ group . Metadata . LastModified = DateTime . UtcNow ;
266
254
}
267
255
else
268
256
{
0 commit comments