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.SearchAttribute;
41  import fr.paris.lutece.plugins.identitystore.v3.web.rs.dto.search.SearchUpdatedAttribute;
42  import fr.paris.lutece.plugins.identitystore.web.exception.IdentityStoreException;
43  import fr.paris.lutece.portal.service.plugin.Plugin;
44  import fr.paris.lutece.portal.service.plugin.PluginService;
45  import fr.paris.lutece.portal.service.spring.SpringContextService;
46  import fr.paris.lutece.portal.service.util.AppPropertiesService;
47  import org.apache.commons.lang3.tuple.Pair;
48  
49  import java.sql.Timestamp;
50  import java.util.Date;
51  import java.util.List;
52  import java.util.Map;
53  import java.util.Objects;
54  
55  
56  
57  
58  public final class IdentityHome
59  {
60      private static final int PROPERTY_MAX_NB_IDENTITY_RETURNED = AppPropertiesService.getPropertyInt("identitystore.search.maxNbIdentityReturned", 0);
61  
62      
63      private static final IIdentityDAO _dao = SpringContextService.getBean( IIdentityDAO.BEAN_NAME );
64      private static final Plugin _plugin = PluginService.getPlugin( IdentityStorePlugin.PLUGIN_NAME );
65  
66      
67  
68  
69      private IdentityHome( )
70      {
71      }
72  
73      
74  
75  
76  
77  
78  
79  
80      public static Identitys/identitystore/business/identity/Identity.html#Identity">Identity create( final Identity identity, final int dataRetentionPeriodInMonth )
81      {
82          _dao.insert( identity, dataRetentionPeriodInMonth, _plugin );
83  
84          return identity;
85      }
86  
87      
88  
89  
90  
91  
92  
93  
94      public static Identity../../../../../../../fr/paris/lutece/plugins/identitystore/business/identity/Identity.html#Identity">Identity update( Identity identity )
95      {
96          _dao.store( identity, _plugin );
97  
98          return identity;
99      }
100 
101     
102 
103 
104 
105 
106 
107     public static Identity"../../../../../../../fr/paris/lutece/plugins/identitystore/business/identity/Identity.html#Identity">Identity merge( Identity identity )
108     {
109         _dao.merge( identity, _plugin );
110         IdentityAttributeHome.removeAllAttributes( identity.getId() );
111 
112         return identity;
113     }
114 
115     public static void cancelMerge( Identity identity )
116     {
117         _dao.cancelMerge( identity, _plugin );
118     }
119 
120     
121 
122 
123 
124 
125 
126     public static void hardRemove( int nIdentityId )
127     {
128         IdentityAttributeHome.removeAllAttributes( nIdentityId );
129         _dao.hardDelete( nIdentityId, _plugin );
130     }
131 
132     public static void softRemove( String strCuid )
133     {
134         _dao.softDelete( strCuid, _plugin );
135     }
136 
137     
138 
139 
140 
141 
142 
143 
144     public static int findIdByCustomerId( String strCustomerId )
145     {
146         return _dao.selectIdByCustomerId( strCustomerId, _plugin );
147     }
148 
149     
150 
151 
152 
153 
154 
155 
156     public static Identity findByPrimaryKey( int nKey )
157     {
158         return _dao.load( nKey, _plugin );
159     }
160 
161     
162 
163 
164 
165 
166     public static List<Identity> findAll( )
167     {
168         final List<Identity> identities = _dao.selectAll( _plugin );
169         identities.forEach( identity -> identity.setAttributes( IdentityAttributeHome.getAttributes( identity.getId( ) ) ) );
170         return identities;
171     }
172 
173     
174 
175 
176 
177 
178 
179 
180     public static Identity findByConnectionId( String strConnectionId )
181     {
182         return _dao.selectByConnectionId( strConnectionId, _plugin );
183     }
184 
185     
186 
187 
188 
189 
190 
191 
192     public static List<IdentityChange> findHistoryByCustomerId( String strCustomerId ) throws IdentityStoreException
193     {
194         return _dao.selectIdentityHistoryByCustomerId( strCustomerId, _plugin );
195     }
196 
197     
198 
199 
200 
201 
202 
203 
204     public static List<IdentityChange> findHistoryBySearchParameters( final String strCustomerId, final String clientCode, final String authorName,
205             final IdentityChangeType changeType, final String changeStatus, final String authorType, final Date modificationDate, final Map<String, String> metadata, final Integer nbDaysFrom,
206             final Pair<Date, Date> modificationDateInterval, final int max ) throws IdentityStoreException
207     {
208         int nMaxNbIdentityReturned = ( max > 0 ) ? max : PROPERTY_MAX_NB_IDENTITY_RETURNED;
209         return _dao.selectIdentityHistoryBySearchParameters( strCustomerId, clientCode, authorName, changeType, changeStatus, authorType, modificationDate, metadata, nbDaysFrom,
210                 modificationDateInterval, _plugin, nMaxNbIdentityReturned );
211     }
212 
213     
214 
215 
216 
217 
218 
219 
220     public static Identity findByCustomerId( String strCustomerId )
221     {
222         Identity identity = _dao.selectByCustomerId( strCustomerId, _plugin );
223 
224         if ( identity != null )
225         {
226             identity.setAttributes( IdentityAttributeHome.getAttributes( identity.getId( ) ) );
227         }
228 
229         return identity;
230     }
231 
232     
233 
234 
235 
236 
237 
238 
239     public static Identity findByCustomerIdNoAttributes( String strCustomerId )
240     {
241         return _dao.selectByCustomerId( strCustomerId, _plugin );
242     }
243 
244     
245 
246 
247 
248 
249 
250 
251     public static Identity findMasterIdentityByCustomerId( String strCustomerId )
252     {
253         Identity identity = _dao.selectNotMergedByCustomerId( strCustomerId, _plugin );
254 
255         if ( identity != null )
256         {
257             identity.setAttributes( IdentityAttributeHome.getAttributes( identity.getId( ) ) );
258         }
259 
260         return identity;
261     }
262 
263     
264 
265 
266 
267 
268 
269 
270     public static Timestamp getMasterIdentityLastUpdateDate( final String customerId )
271     {
272         final Identity identity = _dao.selectNotMergedByCustomerId( customerId, _plugin );
273         return identity != null ? identity.getLastUpdateDate( ) : null;
274     }
275 
276     
277 
278 
279 
280 
281 
282 
283     public static Identity findMasterIdentityByConnectionId( String strConnectionId )
284     {
285         Identity identity = _dao.selectNotMergedByConnectionId( strConnectionId, _plugin );
286 
287         if ( identity != null )
288         {
289             identity.setAttributes( IdentityAttributeHome.getAttributes( identity.getId( ) ) );
290         }
291 
292         return identity;
293     }
294 
295     
296 
297 
298 
299 
300 
301 
302     public static Identity getMasterIdentityNoAttributesByConnectionId( final String connectionId )
303     {
304         return _dao.selectNotMergedByConnectionId( connectionId, _plugin );
305     }
306 
307     
308 
309 
310 
311 
312 
313 
314 
315     public static List<Identity> findByAttributesValueForApiSearch(final List<SearchAttribute> searchAttributes, final int max )
316     {
317         int nMaxNbIdentityReturned = ( max > 0 ) ? max : PROPERTY_MAX_NB_IDENTITY_RETURNED;
318         return _dao.selectByAttributesValueForApiSearch( searchAttributes, nMaxNbIdentityReturned, _plugin );
319     }
320 
321     
322 
323 
324 
325 
326 
327 
328 
329 
330 
331 
332 
333 
334 
335     public static List<String> findByAttributeExisting( final List<Integer> idAttributeList, final int nbFilledAttributes, final boolean notMerged,
336             final boolean notSuspicious, final int rulePriority )
337     {
338         return _dao.selectByAttributeExisting( idAttributeList, nbFilledAttributes, notMerged, notSuspicious, rulePriority, _plugin );
339     }
340 
341     
342 
343 
344 
345 
346 
347     public static void addIdentityChangeHistory( IdentityChange identityChange ) throws IdentityStoreException
348     {
349         if ( Objects.equals( identityChange.getChangeType( ), IdentityChangeType.READ ) )
350         {
351             _dao.addOrUpdateChangeHistory( identityChange, _plugin );
352         }
353         else
354         {
355             _dao.addChangeHistory( identityChange, _plugin );
356         }
357     }
358 
359     
360 
361 
362 
363 
364 
365 
366 
367 
368 
369 
370     public static List<UpdatedIdentityDto> findUpdatedIdentities( final Integer days, final List<IdentityChangeType> identityChangeTypes,
371             final List<SearchUpdatedAttribute> updatedAttributes, final Integer max )
372     {
373         int nMaxNbIdentityReturned = ( max > 0 ) ? max : PROPERTY_MAX_NB_IDENTITY_RETURNED;
374         return _dao.selectUpdated( days, identityChangeTypes, updatedAttributes, nMaxNbIdentityReturned, _plugin );
375     }
376 
377     
378 
379 
380 
381 
382 
383 
384 
385 
386 
387 
388     public static List<Integer> findUpdatedIdentityIds( final Integer days, final List<IdentityChangeType> identityChangeTypes,
389             final List<SearchUpdatedAttribute> updatedAttributes, final Integer max )
390     {
391         int nMaxNbIdentityReturned = ( max > 0 ) ? max : PROPERTY_MAX_NB_IDENTITY_RETURNED;
392         return _dao.selectUpdatedIds( days, identityChangeTypes, updatedAttributes, nMaxNbIdentityReturned, _plugin );
393     }
394 
395     
396 
397 
398 
399 
400 
401 
402     public static List<UpdatedIdentityDto> getUpdatedIdentitiesFromIds( final List<Integer> identityIds )
403     {
404         return _dao.selectUpdatedFromIds( identityIds, _plugin );
405     }
406 
407     
408 
409 
410 
411 
412 
413 
414     public static List<Identity> findExpiredNotMergedAndNotConnectedIdentities( final int limit, boolean withGuidOnly )
415     {
416         return _dao.selectExpiredNotMergedAndNotConnectedIdentities( limit, withGuidOnly, _plugin );
417     }
418 
419     
420 
421 
422 
423 
424 
425 
426 
427 
428     public static List<String> findNotMergedNotConnectedWithNonCertifiedAttributeCustomerIds( final String attributeKey, String certProcess, final int limit )
429     {
430         return _dao.selectNotMergedNotConnectedWithNonCertifiedAttributeCustomerIds( attributeKey, certProcess, limit, _plugin );
431     }
432 
433     
434 
435 
436 
437 
438 
439 
440     public static List<Identity> findMergedIdentities( final int identityId )
441     {
442         return _dao.selectMergedIdentities( identityId, _plugin );
443     }
444 
445     
446 
447 
448 
449 
450 
451     public static void deleteAttributeHistory( final int identityId )
452     {
453         _dao.deleteAttributeHistory( identityId, _plugin );
454     }
455 
456     
457 
458 
459     public static Integer getCountIdentities( )
460     {
461         return _dao.getCountIdentities( _plugin );
462     }
463 
464     
465 
466 
467 
468 
469 
470     public static Integer getCountDeletedIdentities( final boolean deleted )
471     {
472         return _dao.getCountDeletedIdentities( deleted, _plugin) ;
473     }
474 
475     
476 
477 
478 
479 
480 
481     public static Integer getCountMergedIdentities( final boolean merged )
482     {
483         return _dao.getCountMergedIdentities( merged, _plugin );
484     }
485 
486     
487 
488 
489 
490 
491 
492     public static Integer getCountActiveMonParisdentities( final boolean monParisActive )
493     {
494         return _dao.getCountActiveMonParisdentities( monParisActive, _plugin );
495     }
496 
497     
498 
499 
500     public static Map<Integer, Integer> getCountAttributesByIdentities( )
501     {
502         return _dao.getCountAttributesByIdentities( _plugin );
503     }
504 
505     
506 
507 
508     public static Integer getCountUnmergedIdentitiesWithoutAttributes( )
509     {
510         return _dao.getCountUnmergedIdentitiesWithoutAttributes( _plugin );
511     }
512 
513     public static Integer getCountIndexEligibleIdentities( )
514     {
515         return _dao.getCountIndexEligibleIdentities( _plugin );
516     }
517 
518     public static Integer getCountIndexNotEligibleIdentities( )
519     {
520         return _dao.getCountIndexNotEligibleIdentities( _plugin );
521     }
522 
523     public static List<IndicatorsActionsType> getActionsTypesDuringInterval(int interval)
524     {
525         return _dao.getActionsTypesDuringInterval(interval, _plugin);
526     }
527 
528     public static List<String> getHistoryStatusList( )
529     {
530         return _dao.getHistoryStatusList( _plugin );
531     }
532 }