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.duplicates.suspicions;
35
36 import fr.paris.lutece.plugins.identitystore.business.identity.Identity;
37 import fr.paris.lutece.plugins.identitystore.business.identity.IdentityHome;
38 import fr.paris.lutece.plugins.identitystore.v3.web.rs.dto.search.SearchAttribute;
39 import fr.paris.lutece.plugins.identitystore.web.exception.IdentityNotFoundException;
40 import fr.paris.lutece.plugins.identitystore.web.exception.IdentityStoreException;
41 import fr.paris.lutece.portal.service.plugin.Plugin;
42 import fr.paris.lutece.portal.service.plugin.PluginService;
43 import fr.paris.lutece.portal.service.spring.SpringContextService;
44 import fr.paris.lutece.util.ReferenceList;
45 import org.apache.commons.collections.CollectionUtils;
46
47 import java.util.List;
48 import java.util.Objects;
49 import java.util.Optional;
50
51
52
53
54 public final class SuspiciousIdentityHome
55 {
56
57 private static final ISuspiciousIdentityDAO _dao = SpringContextService.getBean( "identitystore-quality.suspiciousIdentityDAO" );
58 private static final Plugin _plugin = PluginService.getPlugin( "identitystore-quality" );
59
60
61
62
63 private SuspiciousIdentityHome( )
64 {
65 }
66
67
68
69
70
71
72
73
74 public static SuspiciousIdentity./../../../../fr/paris/lutece/plugins/identitystore/business/duplicates/suspicions/SuspiciousIdentity.html#SuspiciousIdentity">SuspiciousIdentity create( SuspiciousIdentity suspiciousIdentity )
75 {
76 _dao.insert( suspiciousIdentity, _plugin );
77
78 return suspiciousIdentity;
79 }
80
81
82
83
84
85
86
87
88 public static SuspiciousIdentity./../../../../fr/paris/lutece/plugins/identitystore/business/duplicates/suspicions/SuspiciousIdentity.html#SuspiciousIdentity">SuspiciousIdentity update( SuspiciousIdentity suspiciousIdentity )
89 {
90 _dao.store( suspiciousIdentity, _plugin );
91
92 return suspiciousIdentity;
93 }
94
95
96
97
98
99
100
101
102
103
104 public static void exclude( String firstCuid, String secondCuid, String authorType, String authorName )
105 {
106 if ( !excluded( firstCuid, secondCuid ) )
107 {
108 _dao.insertExcluded( firstCuid, secondCuid, authorType, authorName, _plugin );
109 }
110 }
111
112
113
114
115
116
117
118
119
120
121 public static boolean excluded( String firstCuid, String secondCuid )
122 {
123 return _dao.checkIfExcluded( firstCuid, secondCuid, _plugin );
124 }
125
126
127
128
129
130
131
132
133
134
135 public static boolean excluded( String firstCuid, List<String> cuids )
136 {
137 return _dao.checkIfExcluded( firstCuid, cuids, _plugin );
138 }
139
140
141
142
143
144
145
146
147 public static boolean hasSuspicious( final List<String> customerIds )
148 {
149 return CollectionUtils.isNotEmpty( customerIds ) && _dao.checkIfContainsSuspicious( customerIds, _plugin );
150 }
151
152
153
154
155
156
157
158 public static void remove( int nId )
159 {
160 _dao.delete( nId, _plugin );
161 }
162
163
164
165
166
167
168
169 public static void remove( String customerId )
170 {
171 _dao.delete( customerId, _plugin );
172 }
173
174
175
176
177
178
179
180
181 public static Optional<SuspiciousIdentity> findByPrimaryKey( int nKey )
182 {
183 return _dao.load( nKey, _plugin );
184 }
185
186
187
188
189
190
191
192
193 public static List<SuspiciousIdentity> getSuspiciousIdentitysList( final String ruleCode, final int max, final Integer priority )
194 throws IdentityStoreException
195 {
196 return _dao.selectSuspiciousIdentitysList( ruleCode, max, priority, _plugin );
197 }
198
199
200
201
202
203
204
205
206
207
208 public static List<SuspiciousIdentity> getSuspiciousIdentitysList( final String ruleCode, final List<SearchAttribute> attributes, final Integer max,
209 final Integer priority ) throws IdentityStoreException
210 {
211 return _dao.selectSuspiciousIdentitysList( ruleCode, attributes, max, priority, _plugin );
212 }
213
214
215
216
217
218
219 public static List<ExcludedIdentities> getExcludedIdentitiesList( )
220 {
221 return _dao.selectExcludedIdentitiesList( _plugin );
222 }
223
224
225
226
227
228
229 public static List<ExcludedIdentities> getExcludedIdentitiesList( final String customerId )
230 {
231 return _dao.selectExcludedIdentitiesList( customerId, _plugin );
232 }
233
234 public static void removeExcludedIdentities( final String firstCuid, final String secondCuid )
235 {
236 _dao.removeExcludedIdentities( firstCuid, secondCuid, _plugin );
237 }
238
239 public static void removeExcludedIdentities( final String cuid )
240 {
241 _dao.removeExcludedIdentities( cuid, _plugin );
242 }
243
244
245
246
247
248
249
250
251 public static List<String> getSuspiciousIdentityCuidsList( final String ruleCode )
252 {
253 return _dao.selectSuspiciousIdentityCuidsList( ruleCode, _plugin );
254 }
255
256
257
258
259
260
261 public static List<Integer> getIdSuspiciousIdentitysList( )
262 {
263 return _dao.selectIdSuspiciousIdentitysList( _plugin );
264 }
265
266
267
268
269
270
271 public static ReferenceList getSuspiciousIdentitysReferenceList( )
272 {
273 return _dao.selectSuspiciousIdentitysReferenceList( _plugin );
274 }
275
276
277
278
279
280
281
282
283 public static List<SuspiciousIdentity> getSuspiciousIdentitysListByIds( List<Integer> listIds )
284 {
285 return _dao.selectSuspiciousIdentitysListByIds( _plugin, listIds );
286 }
287
288 public static SuspiciousIdentity selectByCustomerID( String customerId )
289 {
290 return _dao.selectByCustomerID( customerId, _plugin );
291 }
292
293 public static List<SuspiciousIdentity> selectByCustomerIDs( List<String> customerIds )
294 {
295 return _dao.selectByCustomerIDs( customerIds, _plugin );
296 }
297
298 public static void purge( )
299 {
300 _dao.purge( _plugin );
301 }
302
303 public static int countSuspiciousIdentity( final int ruleId )
304 {
305 return _dao.countSuspiciousIdentities( ruleId, _plugin );
306 }
307
308 public static int countSuspiciousIdentity( )
309 {
310 return _dao.countSuspiciousIdentities( _plugin );
311 }
312
313 public static boolean manageLock( String customerId, String authorName, String authorType, boolean lock ) throws IdentityStoreException
314 {
315 final Identity identity = IdentityHome.findByCustomerId( customerId );
316 if ( identity == null )
317 {
318 throw new IdentityNotFoundException( "Could not find identity with customerId " + customerId );
319 }
320
321 final SuspiciousIdentity suspiciousIdentity = SuspiciousIdentityHome.selectByCustomerID( customerId );
322 if ( suspiciousIdentity == null )
323 {
324 throw new IdentityNotFoundException( "Could not find suspicious identity with customerId " + customerId );
325 }
326
327 final boolean isAlreadyLocked = suspiciousIdentity.getLock( ).isLocked( );
328 final boolean sameAuthorName = Objects.equals( suspiciousIdentity.getLock( ).getAuthorName( ), authorName );
329 final boolean sameAuthorType = Objects.equals( suspiciousIdentity.getLock( ).getAuthorType( ), authorType );
330 final boolean sameAuthor = sameAuthorName && sameAuthorType;
331 if ( lock && isAlreadyLocked && !sameAuthor )
332 {
333 throw new SuspiciousIdentityLockedException(
334 "Suspicious identity with customerId " + customerId + " is locked by " + suspiciousIdentity.getLock( ).getAuthorName( ) + "." );
335 }
336
337 if ( !lock && !isAlreadyLocked )
338 {
339 throw new SuspiciousIdentityLockedException( "Suspicious identity with customerId " + customerId + " is already unlocked." );
340 }
341
342 if ( !lock && isAlreadyLocked && !sameAuthor )
343 {
344 throw new SuspiciousIdentityLockedException( "Suspicious identity with customerId " + customerId + " is locked by "
345 + suspiciousIdentity.getLock( ).getAuthorName( ) + ". User" + authorName + " is not allowed to unlock." );
346 }
347
348 if ( lock && isAlreadyLocked && sameAuthor )
349 {
350
351 return true;
352 }
353
354 return _dao.manageLock( customerId, lock, authorType, authorName, _plugin );
355 }
356
357 public static void purgeLocks( )
358 {
359 _dao.purgeLocks( _plugin );
360 }
361 }