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.mydashboard.modules.identity.service;
35
36 import java.util.HashMap;
37 import java.util.List;
38 import java.util.Locale;
39 import java.util.Map;
40
41 import javax.servlet.http.HttpServletRequest;
42
43 import org.apache.commons.collections.CollectionUtils;
44 import org.apache.commons.lang3.StringUtils;
45 import org.apache.commons.validator.routines.EmailValidator;
46
47 import fr.paris.lutece.plugins.identityquality.v3.web.service.IdentityQualityService;
48 import fr.paris.lutece.plugins.identitystore.v3.web.rs.dto.common.IdentityDto;
49 import fr.paris.lutece.plugins.identitystore.v3.web.rs.dto.common.ResponseStatusType;
50 import fr.paris.lutece.plugins.identitystore.v3.web.rs.dto.contract.AttributeDefinitionDto;
51 import fr.paris.lutece.plugins.identitystore.v3.web.rs.dto.contract.ServiceContractSearchResponse;
52 import fr.paris.lutece.plugins.identitystore.v3.web.rs.dto.search.DuplicateSearchRequest;
53 import fr.paris.lutece.plugins.identitystore.v3.web.rs.dto.search.DuplicateSearchResponse;
54 import fr.paris.lutece.plugins.identitystore.v3.web.service.ServiceContractService;
55 import fr.paris.lutece.plugins.identitystore.web.exception.IdentityStoreException;
56 import fr.paris.lutece.plugins.mydashboard.modules.identity.business.AttributeCategory;
57 import fr.paris.lutece.plugins.mydashboard.modules.identity.business.DashboardAttribute;
58 import fr.paris.lutece.plugins.mydashboard.modules.identity.business.DashboardIdentity;
59 import fr.paris.lutece.plugins.mydashboard.modules.identity.util.Constants;
60 import fr.paris.lutece.plugins.mydashboard.modules.identity.util.DashboardIdentityUtils;
61 import fr.paris.lutece.portal.service.i18n.I18nService;
62 import fr.paris.lutece.portal.service.spring.SpringContextService;
63 import fr.paris.lutece.portal.service.util.AppException;
64 import fr.paris.lutece.portal.service.util.AppLogService;
65 import fr.paris.lutece.util.ReferenceItem;
66 import fr.paris.lutece.util.ReferenceList;
67
68
69
70
71
72
73 public class DashboardIdentityService implements IDashBoardIdentityService
74 {
75
76
77 private static DashboardIdentityService _instance;
78
79
80 private static final String BEAN_SERVICE_CONTRACT_SERVICE = "mydashboard-identity.serviceContract.service";
81 private static final String BEAN_SERVICE_IDENTITY_QUALITYSERVICE = "mydashboard-identity.identityQualityService";
82 private static final String DEFAULT_ERROR="error";
83
84
85 private ServiceContractService _serviceContractService;
86 private IdentityQualityService _identityQualityService ;
87
88
89
90 private static ReferenceList _lstContactModeList;
91
92
93 private static ReferenceList _lstGenderList;
94
95
96 private static final String SPLIT_PATTERN = ";";
97
98
99
100
101 private DashboardIdentityService( )
102 {
103 }
104
105
106
107
108
109
110
111 public static IDashBoardIdentityService getInstance( )
112 {
113 if ( _instance == null )
114 {
115 _instance = new DashboardIdentityService( );
116 _instance._serviceContractService = SpringContextService.getBean( BEAN_SERVICE_CONTRACT_SERVICE );
117 _instance._identityQualityService = SpringContextService.getBean( BEAN_SERVICE_IDENTITY_QUALITYSERVICE );
118 _lstGenderList = new ReferenceList( );
119
120 int i = 0;
121
122 for ( String sItem : Constants.PROPERTY_KEY_GENDER_LIST.split( SPLIT_PATTERN ) )
123 {
124 ReferenceItem refItm = new ReferenceItem( );
125 refItm.setName( sItem );
126 refItm.setCode( String.valueOf( i ) );
127 _lstGenderList.add( refItm );
128 i++;
129 }
130
131 _lstContactModeList = new ReferenceList( );
132
133 for ( String sItem : Constants.PROPERTY_KEY_CONTACT_MODE_LIST.split( SPLIT_PATTERN ) )
134 {
135 ReferenceItem refItm = new ReferenceItem( );
136 refItm.setName( sItem );
137 refItm.setCode( sItem );
138 _lstContactModeList.add( refItm );
139 }
140 }
141 return _instance;
142 }
143
144
145
146
147
148
149
150
151
152 @Override
153
154 public DashboardIdentity getDashBoardIdentity(String strApplicationCode)throws AppException
155 {
156 return getDashBoardIdentity(strApplicationCode,null);
157
158 }
159
160
161
162
163
164 @Override
165 public DashboardIdentity getDashBoardIdentity(String strApplicationCode,String strGuid)throws AppException
166 {
167 IdentityDto identity = null;
168 DashboardIdentity dashboardIdentity = null;
169
170 ServiceContractSearchResponse serviceContractSearchResponse = getActiveServiceContract( strApplicationCode );
171
172 if( !StringUtils.isEmpty( strGuid ))
173 {
174 identity = DashboardIdentityUtils.getInstance( ).getIdentity( strGuid );
175 }
176
177 dashboardIdentity = DashboardIdentityUtils.getInstance( ).convertToDashboardIdentity( identity, serviceContractSearchResponse );
178 return dashboardIdentity;
179 }
180
181
182
183
184 @Override
185 public boolean needCertification( String strApplicationCode, String strGuid, DashboardIdentity dashboardIdentity, List<String> listAttributesNeedFC, int nLevelMin )
186 {
187 ServiceContractSearchResponse serviceContractSearchResponse = getActiveServiceContract( strApplicationCode );
188 return DashboardIdentityUtils.getInstance( ).needCertification( dashboardIdentity, serviceContractSearchResponse, listAttributesNeedFC, nLevelMin );
189 }
190
191 @Override
192 public ServiceContractSearchResponse getActiveServiceContract( String strApplicationCode )
193 {
194 ServiceContractSearchResponse serviceContractSearchResponse = null;
195 try
196 {
197 serviceContractSearchResponse = _serviceContractService.getActiveServiceContract( strApplicationCode, DashboardIdentityUtils.DASHBOARD_APP_CODE, DashboardIdentityUtils.getInstance( ).getOwnerRequestAuthor( ) );
198 }
199 catch ( IdentityStoreException e )
200 {
201 AppLogService.error( "Error ServiceContract for application {}", e.getMessage( ), strApplicationCode );
202 }
203
204 return serviceContractSearchResponse;
205 }
206
207
208
209
210 @Override
211 public Map<String,String> checkDashboardIdentityFields( DashboardIdentity dashboardIdentity, HttpServletRequest request,boolean bOnlyCheckMandatory )
212 {
213
214 return checkDashboardIdentityFields(dashboardIdentity, request, bOnlyCheckMandatory, null);
215
216 }
217
218
219
220
221
222
223 @Override
224 public Map<String,String> checkDashboardIdentityFields( DashboardIdentity dashboardIdentity, HttpServletRequest request,boolean bOnlyCheckMandatory,AttributeCategory attributeCategory )
225 {
226
227 Map<String,String> hashErrors=new HashMap<String,String>();
228
229
230 String strValidateLastName = getErrorValidation(request, Constants.ATTRIBUTE_DB_IDENTITY_LAST_NAME, Constants.PROPERTY_KEY_VALIDATION_REGEXP_LAST_NAME, I18nService.getLocalizedString( Constants.MESSAGE_ERROR_VALIDATION_LASTNAME, request.getLocale( ) ), dashboardIdentity.getLastName().isMandatory(),attributeCategory);
231
232 if ( !strValidateLastName.isEmpty( ) && !DashboardIdentityUtils.isDashboardAttributeCertified(dashboardIdentity.getLastName()) && ( ! bOnlyCheckMandatory || dashboardIdentity.getLastName().isMandatory()))
233 {
234 hashErrors.put( Constants.ATTRIBUTE_DB_IDENTITY_LAST_NAME,strValidateLastName );
235 }
236
237 String strValidatePreferredUsername = getErrorValidation(request, Constants.ATTRIBUTE_DB_IDENTITY_PREFERRED_USER_NAME, Constants.PROPERTY_KEY_VALIDATION_REGEXP_PREFERREDUSERNAME, I18nService.getLocalizedString( Constants.MESSAGE_ERROR_VALIDATION_PREFFEREDUSERNAME, request.getLocale( ) ), dashboardIdentity.getPreferredUsername().isMandatory(),attributeCategory);
238
239 if ( !strValidatePreferredUsername.isEmpty( ) && !DashboardIdentityUtils.isDashboardAttributeCertified(dashboardIdentity.getPreferredUsername()) && (! bOnlyCheckMandatory || dashboardIdentity.getPreferredUsername().isMandatory()) )
240 {
241 hashErrors.put( Constants.ATTRIBUTE_DB_IDENTITY_PREFERRED_USER_NAME,strValidatePreferredUsername );
242 }
243
244 String strValidateFirstname = getErrorValidation(request, Constants.ATTRIBUTE_DB_IDENTITY_FIRSTNAME, Constants.PROPERTY_KEY_VALIDATION_REGEXP_FIRSTNAME, I18nService.getLocalizedString( Constants.MESSAGE_ERROR_VALIDATION_FIRSTNAME, request.getLocale( ) ), dashboardIdentity.getFirstname().isMandatory() ,attributeCategory);
245
246 if ( !strValidateFirstname.isEmpty( ) && !DashboardIdentityUtils.isDashboardAttributeCertified(dashboardIdentity.getFirstname()) && (! bOnlyCheckMandatory || dashboardIdentity.getFirstname().isMandatory()) )
247 {
248 hashErrors.put(Constants.ATTRIBUTE_DB_IDENTITY_FIRSTNAME,strValidateFirstname );
249 }
250
251 if ( StringUtils.isBlank( request.getParameter( Constants.ATTRIBUTE_DB_IDENTITY_BIRTHPLACE_CODE ) ) )
252 {
253 String strValidateBirthplace = getErrorValidation(request, Constants.ATTRIBUTE_DB_IDENTITY_BIRTHPLACE, Constants.PROPERTY_KEY_VALIDATION_REGEXP_BIRTHPLACE, I18nService.getLocalizedString( Constants.MESSAGE_ERROR_VALIDATION_BIRTHPLACE, request.getLocale( ) ), dashboardIdentity.getBirthplace().isMandatory() ,attributeCategory);
254
255 if ( !strValidateBirthplace.isEmpty( ) && !DashboardIdentityUtils.isDashboardAttributeCertified(dashboardIdentity.getBirthplace()) && (! bOnlyCheckMandatory || dashboardIdentity.getBirthplace().isMandatory()) )
256 {
257 hashErrors.put(Constants.ATTRIBUTE_DB_IDENTITY_BIRTHPLACE,strValidateBirthplace );
258 }
259 }
260
261 String strValidateBirthDate = getErrorValidation(request, Constants.ATTRIBUTE_DB_IDENTITY_BIRTHDATE, Constants.PROPERTY_KEY_VALIDATION_REGEXP_BIRTHDATE, I18nService.getLocalizedString( Constants.MESSAGE_ERROR_VALIDATION_BIRTHDATE, request.getLocale( ) ), dashboardIdentity.getBirthdate().isMandatory(),attributeCategory);
262
263 if ( !strValidateBirthDate.isEmpty( ) && !DashboardIdentityUtils.isDashboardAttributeCertified(dashboardIdentity.getBirthdate()) && (! bOnlyCheckMandatory || dashboardIdentity.getBirthdate().isMandatory()) )
264 {
265 hashErrors.put(Constants.ATTRIBUTE_DB_IDENTITY_BIRTHDATE, strValidateBirthDate );
266 }
267
268 if ( StringUtils.isBlank( request.getParameter( Constants.ATTRIBUTE_DB_IDENTITY_BIRTHCOUNTRY_CODE )) )
269 {
270 String strValidateBirthCountry = getErrorValidation(request, Constants.ATTRIBUTE_DB_IDENTITY_BIRTHCOUNTRY , Constants.PROPERTY_KEY_VALIDATION_REGEXP_BIRTHCOUNTRY, I18nService.getLocalizedString( Constants.MESSAGE_ERROR_VALIDATION_BIRTHCOUNTRY, request.getLocale( ) ), dashboardIdentity.getBirthcountry().isMandatory(),attributeCategory);
271
272 if ( !strValidateBirthCountry.isEmpty( ) && !DashboardIdentityUtils.isDashboardAttributeCertified(dashboardIdentity.getBirthcountry()) && (! bOnlyCheckMandatory || dashboardIdentity.getBirthcountry().isMandatory()))
273 {
274 hashErrors.put(Constants.ATTRIBUTE_DB_IDENTITY_BIRTHCOUNTRY, strValidateBirthCountry );
275 }
276 }
277
278 String strValidateEmail = getErrorValidation(request, Constants.ATTRIBUTE_DB_IDENTITY_EMAIL , null, I18nService.getLocalizedString( Constants.MESSAGE_ERROR_VALIDATION_EMAIL, request.getLocale( ) ), dashboardIdentity.getEmail().isMandatory(),attributeCategory );
279
280 if ( !strValidateEmail.isEmpty( ) && !DashboardIdentityUtils.isDashboardAttributeCertified(dashboardIdentity.getEmail( )) && (! bOnlyCheckMandatory || dashboardIdentity.getEmail( ).isMandatory()) )
281 {
282 hashErrors.put(Constants.ATTRIBUTE_DB_IDENTITY_EMAIL,strValidateEmail );
283 }
284
285 String strValidatePhone = getErrorValidation(request, Constants.ATTRIBUTE_DB_IDENTITY_PHONE , Constants.PROPERTY_KEY_VALIDATION_REGEXP_PHONE, I18nService.getLocalizedString( Constants.MESSAGE_ERROR_VALIDATION_PHONE, request.getLocale( ) ), dashboardIdentity.getPhone().isMandatory(),attributeCategory );
286
287 if ( !strValidatePhone.isEmpty( ) && !DashboardIdentityUtils.isDashboardAttributeCertified(dashboardIdentity.getPhone( )) && (! bOnlyCheckMandatory || dashboardIdentity.getPhone( ).isMandatory()))
288 {
289 hashErrors.put(Constants.ATTRIBUTE_DB_IDENTITY_PHONE, strValidatePhone );
290 }
291
292 String strValidateMobilePhone = getErrorValidation(request, Constants.ATTRIBUTE_DB_IDENTITY_MOBILE_PHONE , Constants.PROPERTY_KEY_VALIDATION_REGEXP_MOBILEPHONE, I18nService.getLocalizedString( Constants.MESSAGE_ERROR_VALIDATION_MOBILEPHONE, request.getLocale( ) ), dashboardIdentity.getMobilePhone().isMandatory(),attributeCategory);
293
294 if ( !strValidateMobilePhone.isEmpty( ) && !DashboardIdentityUtils.isDashboardAttributeCertified( dashboardIdentity.getMobilePhone( )) && (! bOnlyCheckMandatory ||dashboardIdentity.getMobilePhone( ).isMandatory()))
295 {
296 hashErrors.put(Constants.ATTRIBUTE_DB_IDENTITY_MOBILE_PHONE , strValidateMobilePhone );
297 }
298
299 String strValidateAdresse = getErrorValidation(request, Constants.ATTRIBUTE_DB_IDENTITY_ADDRESS , Constants.PROPERTY_KEY_VALIDATION_REGEXP_ADDRESS, I18nService.getLocalizedString( Constants.MESSAGE_ERROR_VALIDATION_ADDRESS, request.getLocale( ) ), dashboardIdentity.getAddress().isMandatory(),attributeCategory);
300
301 if ( !strValidateAdresse.isEmpty( ) && !DashboardIdentityUtils.isDashboardAttributeCertified(dashboardIdentity.getAddress( ))&& (! bOnlyCheckMandatory || (dashboardIdentity.getAddress( ).isMandatory())))
302 {
303 hashErrors.put( Constants.ATTRIBUTE_DB_IDENTITY_ADDRESS,strValidateAdresse );
304 }
305
306
307 String strValidateAdresseDetail = getErrorValidation(request, Constants.ATTRIBUTE_DB_IDENTITY_ADDRESS_DETAIL , Constants.PROPERTY_KEY_VALIDATION_REGEXP_ADDRESS_DETAIL, I18nService.getLocalizedString( Constants.MESSAGE_ERROR_VALIDATION_ADDRESS_DETAIL, request.getLocale( ) ), false,attributeCategory );
308
309 if ( !strValidateAdresseDetail.isEmpty( ) && !DashboardIdentityUtils.isDashboardAttributeCertified(dashboardIdentity.getAddressDetail( ))&& (! bOnlyCheckMandatory ||( dashboardIdentity.getAddressDetail( ).isMandatory())) )
310 {
311 hashErrors.put( Constants.ATTRIBUTE_DB_IDENTITY_ADDRESS_DETAIL,strValidateAdresseDetail );
312 }
313
314
315
316 String strValidateAdressePostalcode = getErrorValidation(request, Constants.ATTRIBUTE_DB_IDENTITY_ADDRESS_POSTAL_CODE , Constants.PROPERTY_KEY_VALIDATION_REGEXP_ADDRESS_POSTALCODE, I18nService.getLocalizedString( Constants.MESSAGE_ERROR_VALIDATION_ADDRESS_POSTALCODE, request.getLocale( ) ), dashboardIdentity.getAddressPostalcode().isMandatory(),attributeCategory );
317
318 if ( !strValidateAdressePostalcode.isEmpty( ) &&!DashboardIdentityUtils.isDashboardAttributeCertified(dashboardIdentity.getAddressPostalcode( ))&& (! bOnlyCheckMandatory || (dashboardIdentity.getAddressPostalcode( ).isMandatory()) ))
319 {
320 hashErrors.put( Constants.ATTRIBUTE_DB_IDENTITY_ADDRESS_POSTAL_CODE,strValidateAdressePostalcode );
321 }
322
323 String strValidateCity = getErrorValidation(request, Constants.ATTRIBUTE_DB_IDENTITY_ADDRESS_CITY , Constants.PROPERTY_KEY_VALIDATION_REGEXP_ADDRESS_CITY, I18nService.getLocalizedString( Constants.MESSAGE_ERROR_VALIDATION_ADDRESS_CITY, request.getLocale( ) ), dashboardIdentity.getAddressCity().isMandatory(),attributeCategory );
324
325 if ( !strValidateCity.isEmpty( ) && !DashboardIdentityUtils.isDashboardAttributeCertified( dashboardIdentity.getAddressCity( ))&& (! bOnlyCheckMandatory ||(dashboardIdentity.getAddressCity( ).isMandatory()) ))
326 {
327 hashErrors.put( Constants.ATTRIBUTE_DB_IDENTITY_ADDRESS_CITY,strValidateCity );
328 }
329
330 String strValidateBirthplaceCode = getErrorValidation(request, Constants.ATTRIBUTE_DB_IDENTITY_BIRTHPLACE_CODE, Constants.PROPERTY_KEY_VALIDATION_REGEXP_BIRTHPLACE_CODE, I18nService.getLocalizedString( Constants.MESSAGE_ERROR_VALIDATION_BIRTHPLACE_CODE, request.getLocale( ) ), dashboardIdentity.getBirthplaceCode().isMandatory() ,attributeCategory);
331
332 if ( !strValidateBirthplaceCode.isEmpty( ) && !DashboardIdentityUtils.isDashboardAttributeCertified(dashboardIdentity.getBirthplaceCode())&& (! bOnlyCheckMandatory || (dashboardIdentity.getBirthplaceCode().isMandatory()) ) )
333 {
334 hashErrors.put(Constants.ATTRIBUTE_DB_IDENTITY_BIRTHPLACE_CODE,strValidateBirthplaceCode );
335 }
336
337 String strValidateBirthCountryCode = getErrorValidation(request, Constants.ATTRIBUTE_DB_IDENTITY_BIRTHCOUNTRY_CODE , Constants.PROPERTY_KEY_VALIDATION_REGEXP_BIRTHCOUNTRY_CODE, I18nService.getLocalizedString( Constants.MESSAGE_ERROR_VALIDATION_BIRTHCOUNTRY_CODE, request.getLocale( ) ), dashboardIdentity.getBirthcountryCode().isMandatory(),attributeCategory);
338
339 if ( !strValidateBirthCountryCode.isEmpty( ) && !DashboardIdentityUtils.isDashboardAttributeCertified( dashboardIdentity.getBirthcountryCode()) && (! bOnlyCheckMandatory || dashboardIdentity.getBirthcountryCode().isMandatory()))
340 {
341 hashErrors.put(Constants.ATTRIBUTE_DB_IDENTITY_BIRTHCOUNTRY_CODE, strValidateBirthCountryCode );
342 }
343
344
345 String strGender = dashboardIdentity.getGender( ).getValue( );
346
347 if( StringUtils.isNotEmpty( strGender ) )
348 {
349 for ( ReferenceItem rItem : _lstGenderList )
350 {
351 if ( strGender.compareTo( rItem.getName( ) ) == 0 )
352 {
353 dashboardIdentity.setGender( new DashboardAttribute(
354 Constants.ATTRIBUTE_DB_IDENTITY_GENDER,
355 rItem.getCode( ) ) );
356 }
357 }
358 }
359
360 return hashErrors;
361 }
362
363
364
365
366 @Override
367 public Map<String,String> checkDashboardIdentityFieldsFromServiceContract( DashboardIdentity dashboardIdentity, HttpServletRequest request, boolean bOnlyCheckMandatory, String strAppCode )
368 {
369 Map<String,String> hashErrors = new HashMap<String,String>();
370
371 ServiceContractSearchResponse contractSearchResponse = getActiveServiceContract( strAppCode );
372 if ( contractSearchResponse != null )
373 {
374 List<AttributeDefinitionDto> attributeDefinitionDtoList = contractSearchResponse.getServiceContract( ).getAttributeDefinitions( );
375
376 for ( AttributeDefinitionDto attributeDefinitionDto : attributeDefinitionDtoList )
377 {
378 for ( Map.Entry<String,String> attributeMatch : DashboardIdentityUtils.getInstance( ).getMapAttributeKeyMatch( ).entrySet( ) )
379 {
380 if ( attributeMatch.getKey( ).equals( attributeDefinitionDto.getKeyName( ) ) )
381 {
382 boolean isMandatory = false;
383
384 if ( !attributeMatch.getKey( ).equals( Constants.ATTRIBUTE_DB_IDENTITY_ADDRESS_DETAIL )
385 && !( attributeMatch.getKey( ).equals( Constants.ATTRIBUTE_DB_IDENTITY_BIRTHCOUNTRY ) && StringUtils.isNotBlank( request.getParameter( Constants.ATTRIBUTE_DB_IDENTITY_BIRTHCOUNTRY_CODE ) ) )
386 && !( attributeMatch.getKey( ).equals( Constants.ATTRIBUTE_DB_IDENTITY_BIRTHPLACE ) && StringUtils.isNotBlank( request.getParameter( Constants.ATTRIBUTE_DB_IDENTITY_BIRTHPLACE_CODE ) ) ))
387 {
388 isMandatory = dashboardIdentity.getAttribute( attributeMatch.getValue( ) ).isMandatory( );
389 }
390
391
392 String strValidate = getErrorValidation( dashboardIdentity.getAttribute( attributeMatch.getValue( ) ), attributeDefinitionDto.getValidationRegex( ), attributeDefinitionDto.getValidationErrorMessage( ) );
393
394 if ( !strValidate.isEmpty( ) && ( !bOnlyCheckMandatory || isMandatory ) )
395 {
396 hashErrors.put( attributeMatch.getKey( ), strValidate );
397 }
398 }
399 }
400 }
401 }
402
403 return hashErrors;
404 }
405
406
407
408
409 @Override
410 public void updateDashboardIdentity(DashboardIdentity dashboardIdentity,boolean bUpdateOnlyManadtory) throws AppException
411 {
412 updateDashboardIdentity(dashboardIdentity, bUpdateOnlyManadtory, null);
413
414 }
415
416
417
418
419 @Override
420 public void updateDashboardIdentity(DashboardIdentity dashboardIdentity,boolean bUpdateOnlyManadtory,AttributeCategory attributeCategory) throws AppException
421 {
422 IdentityDto identity = DashboardIdentityUtils.getInstance( ).convertToIdentityDto( dashboardIdentity,bUpdateOnlyManadtory,attributeCategory );
423
424 DashboardIdentityUtils.getInstance( ).filterByCertifier ( identity );
425 DashboardIdentityUtils.getInstance().updateIdentity( identity );
426
427 }
428
429
430
431
432
433 @Override
434 public IdentityDto getIdentityToUpdate(DashboardIdentity dashboardIdentity,boolean bUpdateOnlyManadtory)
435 {
436
437 IdentityDto identity = DashboardIdentityUtils.getInstance( ).convertToIdentityDto( dashboardIdentity,bUpdateOnlyManadtory );
438
439 DashboardIdentityUtils.getInstance( ).filterByCertifier ( identity );
440
441 return identity;
442
443 }
444
445
446
447
448
449
450
451
452 @Override
453 public void populateDashboardIdentity ( DashboardIdentity identity, HttpServletRequest request )
454 {
455
456 populateDashboardIdentity(identity, request, null);
457
458 }
459
460
461
462
463
464
465 @Override
466 public void populateDashboardIdentity ( DashboardIdentity identity, HttpServletRequest request,AttributeCategory attributeCategory )
467 {
468
469 DashboardIdentityUtils.getInstance().populateDashboardIdentity(identity, request,attributeCategory);
470
471 }
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488 private String getErrorValidation(HttpServletRequest request,String strAttributeKey,String strRegExp, String errorMessage,boolean bCheckMandatory,AttributeCategory attributeCategory)
489 {
490 String strError= StringUtils.EMPTY;
491
492 boolean bError=false;
493
494
495
496 if(DashboardIdentityUtils.getInstance().getMapAttributeKey(attributeCategory).containsKey(strAttributeKey))
497 {
498 if(strAttributeKey.equals( Constants.ATTRIBUTE_DB_IDENTITY_EMAIL )
499 && !StringUtils.isBlank(request.getParameter( strAttributeKey ))
500 && !EmailValidator.getInstance( ).isValid( request.getParameter( strAttributeKey )))
501 {
502
503 strError = errorMessage;
504 bError=true;
505
506 }
507 else if(bCheckMandatory && StringUtils.isBlank(request.getParameter( strAttributeKey )) && StringUtils.isBlank( strError ))
508 {
509
510 strError= I18nService.getLocalizedString( Constants.MESSAGE_ERROR_EMPTY_ERROR_PREFIX+strAttributeKey, request.getLocale( ) );
511 bError=true;
512
513 }
514
515 else if ( strRegExp != null && !strAttributeKey.equals( Constants.ATTRIBUTE_DB_IDENTITY_EMAIL ) && (request.getParameter( strAttributeKey ) != null && !request.getParameter( strAttributeKey ).matches( strRegExp )) )
516 {
517 strError = errorMessage;
518 bError=true;
519 }
520
521
522 if(bError && StringUtils.isEmpty(strError))
523 {
524 strError=DEFAULT_ERROR;
525 }
526 }
527 return strError;
528
529 }
530
531
532
533
534
535
536
537
538
539 private String getErrorValidation( DashboardAttribute attribute ,String strRegExp, String errorMessage )
540 {
541 String strError = StringUtils.EMPTY;
542
543 String strValueAttribute = attribute.getValue( );
544 String strKeyAttribute = attribute.getKey( );
545
546 boolean bError = false;
547 if ( strKeyAttribute.equals( Constants.ATTRIBUTE_DB_IDENTITY_EMAIL )
548 && !StringUtils.isBlank( strValueAttribute ) && !EmailValidator.getInstance( ).isValid( strValueAttribute ) )
549 {
550 strError = errorMessage;
551 bError = true;
552 }
553 else if ( attribute.isMandatory( ) && StringUtils.isBlank( strValueAttribute )
554 && StringUtils.isBlank( strError ) )
555 {
556 strError = I18nService.getLocalizedString( Constants.MESSAGE_ERROR_EMPTY_ERROR_PREFIX + strKeyAttribute, Locale.getDefault( ) );
557 bError = true;
558
559 }
560 else if ( strRegExp != null && !strKeyAttribute.equals( Constants.ATTRIBUTE_DB_IDENTITY_EMAIL )
561 && ( strValueAttribute != null && !strValueAttribute.matches( strRegExp ) ) )
562 {
563 strError = errorMessage;
564 bError = true;
565 }
566
567 if ( bError && StringUtils.isEmpty( strError ) )
568 {
569 strError = DEFAULT_ERROR;
570 }
571 return strError;
572
573 }
574
575 @Override
576 public DuplicateSearchResponse getSuspiciousIdentities( DashboardIdentity dashboardIdentity, List<String> listRules )
577 {
578 if( Constants.PROPERTY_SUSPICIOUS_IDENTITY_ACTIVATION_INDICATEUR )
579 {
580 DuplicateSearchRequest duplicateSearchRequest = new DuplicateSearchRequest( );
581 duplicateSearchRequest.setRuleCodes( listRules );
582
583 initAttributeSuspiciousSearchRequest( duplicateSearchRequest, dashboardIdentity );
584
585 try
586 {
587 return _identityQualityService.searchDuplicates( duplicateSearchRequest, DashboardIdentityUtils.DASHBOARD_APP_CODE, DashboardIdentityUtils.getInstance( ).getOwnerRequestAuthor( ) );
588 }
589 catch ( IdentityStoreException | AppException ex )
590 {
591 AppLogService.info( "Error getting Search duplicate identities ", ex );
592 }
593 }
594 return null;
595 }
596
597
598
599
600
601
602
603 private void initAttributeSuspiciousSearchRequest ( DuplicateSearchRequest duplicateSearchRequest, DashboardIdentity dashboardIdentity )
604 {
605 Map<String, String> mapAttributes = new HashMap<>( );
606
607 for ( Map.Entry<String,String> attribute : DashboardIdentityUtils.getInstance( ).getMapAttributeKeyMatch( ).entrySet( ) )
608 {
609 DashboardAttribute dashboardAttribute = dashboardIdentity.getAttribute( attribute.getKey( ) );
610 if( dashboardAttribute != null )
611 {
612 mapAttributes.put( attribute.getValue( ), dashboardAttribute.getValue( ) );
613 }
614 }
615
616 duplicateSearchRequest.setAttributes( mapAttributes );
617 }
618
619 @Override
620 public boolean existSuspiciousIdentities( DashboardIdentity dashboardIdentity, List<String> listRules )
621 {
622 DuplicateSearchResponse suspiciousSearchResponse = DashboardIdentityService.getInstance( ).getSuspiciousIdentities( dashboardIdentity, listRules ) ;
623
624 if( suspiciousSearchResponse != null && suspiciousSearchResponse.getStatus( ).getType( ).equals( ResponseStatusType.OK ) &&
625 CollectionUtils.isNotEmpty( suspiciousSearchResponse.getIdentities( ) ) )
626 {
627 for( IdentityDto identity : suspiciousSearchResponse.getIdentities( ) )
628 {
629 if( StringUtils.isEmpty( identity.getConnectionId( ) ) || dashboardIdentity.getConnectionId( ) == null
630 || !identity.getConnectionId( ).equalsIgnoreCase( dashboardIdentity.getConnectionId( ).getValue( ) ) )
631 {
632 return true;
633 }
634 }
635 return false;
636 }
637 return false;
638 }
639 }