1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 package fr.paris.lutece.plugins.identitystore.business.identity;
35
36 import fr.paris.lutece.plugins.identitystore.service.IdentityStorePlugin;
37 import fr.paris.lutece.plugins.identitystore.v3.web.rs.dto.crud.UpdatedIdentityDto;
38 import fr.paris.lutece.plugins.identitystore.v3.web.rs.dto.history.IdentityChange;
39 import fr.paris.lutece.plugins.identitystore.v3.web.rs.dto.history.IdentityChangeType;
40 import fr.paris.lutece.plugins.identitystore.v3.web.rs.dto.search.SearchUpdatedAttribute;
41 import fr.paris.lutece.plugins.identitystore.web.exception.IdentityStoreException;
42 import fr.paris.lutece.portal.service.plugin.Plugin;
43 import fr.paris.lutece.portal.service.plugin.PluginService;
44 import fr.paris.lutece.portal.service.spring.SpringContextService;
45 import fr.paris.lutece.portal.service.util.AppPropertiesService;
46 import org.apache.commons.lang3.tuple.Pair;
47
48 import java.sql.Timestamp;
49 import java.util.Date;
50 import java.util.List;
51 import java.util.Map;
52 import java.util.Objects;
53
54
55
56
57 public final class IdentityHome
58 {
59 private static final String PROPERTY_MAX_NB_IDENTITY_RETURNED = "identitystore.search.maxNbIdentityReturned";
60
61
62 private static final IIdentityDAO _dao = SpringContextService.getBean( IIdentityDAO.BEAN_NAME );
63 private static final Plugin _plugin = PluginService.getPlugin( IdentityStorePlugin.PLUGIN_NAME );
64
65
66
67
68 private IdentityHome( )
69 {
70 }
71
72
73
74
75
76
77
78
79 public static Identitys/identitystore/business/identity/Identity.html#Identity">Identity create( final Identity identity, final int dataRetentionPeriodInMonth )
80 {
81 _dao.insert( identity, dataRetentionPeriodInMonth, _plugin );
82
83 return identity;
84 }
85
86
87
88
89
90
91
92
93 public static Identity../../../../../../../fr/paris/lutece/plugins/identitystore/business/identity/Identity.html#Identity">Identity update( Identity identity )
94 {
95 _dao.store( identity, _plugin );
96
97 return identity;
98 }
99
100
101
102
103
104
105
106 public static Identity"../../../../../../../fr/paris/lutece/plugins/identitystore/business/identity/Identity.html#Identity">Identity merge( Identity identity )
107 {
108 _dao.merge( identity, _plugin );
109
110 return identity;
111 }
112
113 public static void cancelMerge( Identity identity )
114 {
115 _dao.cancelMerge( identity, _plugin );
116 }
117
118
119
120
121
122
123
124 public static void hardRemove( int nIdentityId )
125 {
126 IdentityAttributeHome.removeAllAttributes( nIdentityId );
127 _dao.hardDelete( nIdentityId, _plugin );
128 }
129
130 public static void softRemove( String strCuid )
131 {
132 _dao.softDelete( strCuid, _plugin );
133 }
134
135
136
137
138
139
140
141
142 public static int findIdByCustomerId( String strCustomerId )
143 {
144 return _dao.selectIdByCustomerId( strCustomerId, _plugin );
145 }
146
147
148
149
150
151
152
153
154 public static Identity findByPrimaryKey( int nKey )
155 {
156 return _dao.load( nKey, _plugin );
157 }
158
159
160
161
162
163
164 public static List<Identity> findAll( )
165 {
166 final List<Identity> identities = _dao.selectAll( _plugin );
167 identities.forEach( identity -> identity.setAttributes( IdentityAttributeHome.getAttributes( identity.getId( ) ) ) );
168 return identities;
169 }
170
171
172
173
174
175
176
177
178 public static Identity findByConnectionId( String strConnectionId )
179 {
180 return _dao.selectByConnectionId( strConnectionId, _plugin );
181 }
182
183
184
185
186
187
188
189
190 public static List<IdentityChange> findHistoryByCustomerId( String strCustomerId ) throws IdentityStoreException
191 {
192 return _dao.selectIdentityHistoryByCustomerId( strCustomerId, _plugin );
193 }
194
195
196
197
198
199
200
201
202 public static List<IdentityChange> findHistoryBySearchParameters( final String strCustomerId, final String clientCode, final String authorName,
203 final IdentityChangeType changeType, final String changeStatus, final String authorType, final Date modificationDate, final Map<String, String> metadata, final Integer nbDaysFrom,
204 final Pair<Date, Date> modificationDateInterval ) throws IdentityStoreException
205 {
206 return _dao.selectIdentityHistoryBySearchParameters( strCustomerId, clientCode, authorName, changeType, changeStatus, authorType, modificationDate, metadata, nbDaysFrom,
207 modificationDateInterval, _plugin );
208 }
209
210
211
212
213
214
215
216
217 public static Identity findByCustomerId( String strCustomerId )
218 {
219 Identity identity = _dao.selectByCustomerId( strCustomerId, _plugin );
220
221 if ( identity != null )
222 {
223 identity.setAttributes( IdentityAttributeHome.getAttributes( identity.getId( ) ) );
224 }
225
226 return identity;
227 }
228
229
230
231
232
233
234
235
236 public static Identity findByCustomerIdNoAttributes( String strCustomerId )
237 {
238 return _dao.selectByCustomerId( strCustomerId, _plugin );
239 }
240
241
242
243
244
245
246
247
248 public static Identity findMasterIdentityByCustomerId( String strCustomerId )
249 {
250 Identity identity = _dao.selectNotMergedByCustomerId( strCustomerId, _plugin );
251
252 if ( identity != null )
253 {
254 identity.setAttributes( IdentityAttributeHome.getAttributes( identity.getId( ) ) );
255 }
256
257 return identity;
258 }
259
260
261
262
263
264
265
266
267 public static Timestamp getMasterIdentityLastUpdateDate( final String customerId )
268 {
269 final Identity identity = _dao.selectNotMergedByCustomerId( customerId, _plugin );
270 return identity != null ? identity.getLastUpdateDate( ) : null;
271 }
272
273
274
275
276
277
278
279
280 public static Identity findMasterIdentityByConnectionId( String strConnectionId )
281 {
282 Identity identity = _dao.selectNotMergedByConnectionId( strConnectionId, _plugin );
283
284 if ( identity != null )
285 {
286 identity.setAttributes( IdentityAttributeHome.getAttributes( identity.getId( ) ) );
287 }
288
289 return identity;
290 }
291
292
293
294
295
296
297
298
299 public static Identity getMasterIdentityNoAttributesByConnectionId( final String connectionId )
300 {
301 return _dao.selectNotMergedByConnectionId( connectionId, _plugin );
302 }
303
304
305
306
307
308
309
310
311
312 public static List<Identity> findByAttributesValueForApiSearch( Map<String, List<String>> mapAttributes, final int max )
313 {
314 int nMaxNbIdentityReturned = ( max > 0 ) ? max : AppPropertiesService.getPropertyInt( PROPERTY_MAX_NB_IDENTITY_RETURNED, 100 );
315 return _dao.selectByAttributesValueForApiSearch( mapAttributes, nMaxNbIdentityReturned, _plugin );
316 }
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332 public static List<String> findByAttributeExisting( final List<Integer> idAttributeList, final int nbFilledAttributes, final boolean notMerged,
333 final boolean notSuspicious, final int rulePriority )
334 {
335 return _dao.selectByAttributeExisting( idAttributeList, nbFilledAttributes, notMerged, notSuspicious, rulePriority, _plugin );
336 }
337
338
339
340
341
342
343
344 public static void addIdentityChangeHistory( IdentityChange identityChange ) throws IdentityStoreException
345 {
346 if ( Objects.equals( identityChange.getChangeType( ), IdentityChangeType.READ ) )
347 {
348 _dao.addOrUpdateChangeHistory( identityChange, _plugin );
349 }
350 else
351 {
352 _dao.addChangeHistory( identityChange, _plugin );
353 }
354 }
355
356
357
358
359
360
361
362
363
364
365
366
367 public static List<UpdatedIdentityDto> findUpdatedIdentities( final Integer days, final List<IdentityChangeType> identityChangeTypes,
368 final List<SearchUpdatedAttribute> updatedAttributes, final Integer max )
369 {
370 return _dao.selectUpdated( days, identityChangeTypes, updatedAttributes, max, _plugin );
371 }
372
373
374
375
376
377
378
379
380
381
382
383
384 public static List<Integer> findUpdatedIdentityIds( final Integer days, final List<IdentityChangeType> identityChangeTypes,
385 final List<SearchUpdatedAttribute> updatedAttributes, final Integer max )
386 {
387 return _dao.selectUpdatedIds( days, identityChangeTypes, updatedAttributes, max, _plugin );
388 }
389
390
391
392
393
394
395
396
397 public static List<UpdatedIdentityDto> getUpdatedIdentitiesFromIds( final List<Integer> identityIds )
398 {
399 return _dao.selectUpdatedFromIds( identityIds, _plugin );
400 }
401
402
403
404
405
406
407
408
409 public static List<Identity> findExpiredNotMergedAndNotConnectedIdentities( final int limit )
410 {
411 return _dao.selectExpiredNotMergedAndNotConnectedIdentities( limit, _plugin );
412 }
413
414
415
416
417
418
419
420
421 public static List<Identity> findMergedIdentities( final int identityId )
422 {
423 return _dao.selectMergedIdentities( identityId, _plugin );
424 }
425
426
427
428
429
430
431
432 public static void deleteAttributeHistory( final int identityId )
433 {
434 _dao.deleteAttributeHistory( identityId, _plugin );
435 }
436 }