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.util;
35
36 import fr.paris.lutece.plugins.identitystore.web.rs.dto.AttributeDto;
37 import fr.paris.lutece.plugins.identitystore.web.rs.dto.CertificateDto;
38 import fr.paris.lutece.plugins.identitystore.web.rs.dto.IdentityDto;
39 import fr.paris.lutece.plugins.mydashboard.modules.identity.business.DashboardAttribute;
40 import fr.paris.lutece.plugins.mydashboard.modules.identity.business.DashboardIdentity;
41
42 import org.apache.commons.lang.StringUtils;
43
44 import java.util.HashMap;
45 import java.util.Map;
46 import javax.servlet.http.HttpServletRequest;
47
48
49
50
51
52
53
54 public class DashboardIdentityUtils
55 {
56 private static DashboardIdentityUtils _instance;
57
58
59 private static Map<String,String> _mapAttributeKeyMatch;
60
61
62
63
64 private DashboardIdentityUtils( )
65 {
66 _mapAttributeKeyMatch = new HashMap<String,String>( );
67 _mapAttributeKeyMatch.put(Constants.ATTRIBUTE_DB_IDENTITY_LAST_NAME, Constants.PROPERTY_KEY_NAME );
68 _mapAttributeKeyMatch.put(Constants.ATTRIBUTE_DB_IDENTITY_PREFERRED_USER_NAME, Constants.PROPERTY_KEY_PREFERREDUSERNAME );
69 _mapAttributeKeyMatch.put(Constants.ATTRIBUTE_DB_IDENTITY_FIRSTNAME, Constants.PROPERTY_KEY_FIRSTNAME );
70 _mapAttributeKeyMatch.put(Constants.ATTRIBUTE_DB_IDENTITY_GENDER, Constants.PROPERTY_KEY_GENDER );
71 _mapAttributeKeyMatch.put(Constants.ATTRIBUTE_DB_IDENTITY_BIRTHDATE, Constants.PROPERTY_KEY_BIRTHDATE );
72 _mapAttributeKeyMatch.put(Constants.ATTRIBUTE_DB_IDENTITY_BIRTHPLACE, Constants.PROPERTY_KEY_BIRTHPLACE );
73 _mapAttributeKeyMatch.put(Constants.ATTRIBUTE_DB_IDENTITY_BIRTHCOUNTRY, Constants.PROPERTY_KEY_BIRTHCOUNTRY );
74 _mapAttributeKeyMatch.put(Constants.ATTRIBUTE_DB_IDENTITY_ADDRESS, Constants.PROPERTY_KEY_ADDRESS );
75 _mapAttributeKeyMatch.put(Constants.ATTRIBUTE_DB_IDENTITY_ADDRESS_DETAIL, Constants.PROPERTY_KEY_ADDRESSDETAIL );
76 _mapAttributeKeyMatch.put(Constants.ATTRIBUTE_DB_IDENTITY_ADDRESS_POSTAL_CODE, Constants.PROPERTY_KEY_ADDRESS_POSTAL_CODE );
77 _mapAttributeKeyMatch.put(Constants.ATTRIBUTE_DB_IDENTITY_ADDRESS_CITY, Constants.PROPERTY_KEY_ADDRESS_CITY );
78 _mapAttributeKeyMatch.put(Constants.ATTRIBUTE_DB_IDENTITY_BILLING_ADDRESS, Constants.PROPERTY_KEY_BILLING_ADDRESS );
79 _mapAttributeKeyMatch.put(Constants.ATTRIBUTE_DB_IDENTITY_BILLING_ADDRESS_DETAIL, Constants.PROPERTY_KEY_BILLING_ADDRESSDETAIL );
80 _mapAttributeKeyMatch.put(Constants.ATTRIBUTE_DB_IDENTITY_BILLING_ADDRESS_POSTAL_CODE, Constants.PROPERTY_KEY_BILLING_ADDRESS_POSTAL_CODE );
81 _mapAttributeKeyMatch.put(Constants.ATTRIBUTE_DB_IDENTITY_BILLING_ADDRESS_CITY, Constants.PROPERTY_KEY_BILLING_ADDRESS_CITY );
82 _mapAttributeKeyMatch.put(Constants.ATTRIBUTE_DB_IDENTITY_EMAIL, Constants.PROPERTY_KEY_EMAIL );
83 _mapAttributeKeyMatch.put(Constants.ATTRIBUTE_DB_IDENTITY_PHONE, Constants.PROPERTY_KEY_PHONE );
84 _mapAttributeKeyMatch.put(Constants.ATTRIBUTE_DB_IDENTITY_PREFERRED_CONTACT_MODE, Constants.PROPERTY_KEY_PREFERRED_CONTACT );
85 _mapAttributeKeyMatch.put(Constants.ATTRIBUTE_DB_IDENTITY_MOBILE_PHONE, Constants.PROPERTY_KEY_MOBILE_PHONE );
86 _mapAttributeKeyMatch.put(Constants.ATTRIBUTE_DB_IDENTITY_ACCEPT_NEWS, Constants.PROPERTY_KEY_ACCEPT_NEWS );
87 _mapAttributeKeyMatch.put(Constants.ATTRIBUTE_DB_IDENTITY_ACCEPT_SURVEY, Constants.PROPERTY_KEY_ACCEPT_SURVEY );
88 _mapAttributeKeyMatch.put(Constants.ATTRIBUTE_DB_IDENTITY_DIRECTION, Constants.PROPERTY_KEY_DIRECTION );
89 _mapAttributeKeyMatch.put(Constants.ATTRIBUTE_DB_IDENTITY_SOI, Constants.PROPERTY_KEY_SOI );
90 _mapAttributeKeyMatch.put(Constants.ATTRIBUTE_DB_IDENTITY_NUM_BUREAU, Constants.PROPERTY_KEY_NUM_BUREAU);
91 _mapAttributeKeyMatch.put(Constants.ATTRIBUTE_DB_IDENTITY_TEL_PRO, Constants.PROPERTY_KEY_TEL_PRO );
92 _mapAttributeKeyMatch.put(Constants.ATTRIBUTE_DB_IDENTITY_CATEGORIE, Constants.PROPERTY_KEY_CATEGORIE );
93 _mapAttributeKeyMatch.put(Constants.ATTRIBUTE_DB_IDENTITY_CORPS, Constants.PROPERTY_KEY_CORPS);
94 _mapAttributeKeyMatch.put(Constants.ATTRIBUTE_DB_IDENTITY_GRADE, Constants.PROPERTY_KEY_GRADE );
95 _mapAttributeKeyMatch.put(Constants.ATTRIBUTE_DB_IDENTITY_POSITION_ADMINISTRATIVE, Constants.PROPERTY_KEY_POSITION_ADMINISTRATIVE );
96 _mapAttributeKeyMatch.put(Constants.ATTRIBUTE_DB_IDENTITY_AFFECTION_DATE, Constants.PROPERTY_KEY_AFFECTECTATION_DATE );
97 _mapAttributeKeyMatch.put(Constants.ATTRIBUTE_DB_IDENTITY_ENTITE_JURIDIQUE, Constants.PROPERTY_KEY_ENTITE_JURIDIQUE);
98 _mapAttributeKeyMatch.put(Constants.ATTRIBUTE_DB_IDENTITY_SERVICE_CENTRAUX, Constants.PROPERTY_KEY_SERVICE_CENTRAUX);
99 _mapAttributeKeyMatch.put(Constants.ATTRIBUTE_DB_IDENTITY_NIVEAU, Constants.PROPERTY_KEY_NIVEAU );
100 _mapAttributeKeyMatch.put(Constants.ATTRIBUTE_DB_IDENTITY_ENCADRANT, Constants.PROPERTY_KEY_ENCADRANT );
101 _mapAttributeKeyMatch.put(Constants.ATTRIBUTE_DB_IDENTITY_RH_NOM_USAGE, Constants.PROPERTY_KEY_RH_NOM_USAGE);
102 _mapAttributeKeyMatch.put(Constants.ATTRIBUTE_DB_IDENTITY_RH_PRENOM, Constants.PROPERTY_KEY_RH_PRENOM );
103 _mapAttributeKeyMatch.put(Constants.ATTRIBUTE_DB_IDENTITY_RH_TEL, Constants.PROPERTY_KEY_RH_TEL );
104 _mapAttributeKeyMatch.put(Constants.ATTRIBUTE_DB_IDENTITY_UGD_SOI, Constants.PROPERTY_KEY_UGD_SOI);
105 _mapAttributeKeyMatch.put(Constants.ATTRIBUTE_DB_IDENTITY_UGD_UNITE, Constants.PROPERTY_KEY_UGD_UNITE);
106 _mapAttributeKeyMatch.put(Constants.ATTRIBUTE_DB_IDENTITY_UGD_UNITE_SOI, Constants.ATTRIBUTE_DB_IDENTITY_UGD_UNITE_SOI );
107 _mapAttributeKeyMatch.put(Constants.ATTRIBUTE_DB_IDENTITY_IS_ENCADRANT, Constants.PROPERTY_KEY_IS_ENCADRANT );
108 }
109
110 public static DashboardIdentityUtils getInstance( )
111 {
112 if ( _instance == null )
113 {
114 _instance = new DashboardIdentityUtils( );
115 }
116 return _instance;
117 }
118
119
120
121
122
123
124
125
126
127 public DashboardIdentity convertToDashboardIdentity( IdentityDto identity )
128 {
129 DashboardIdentity dashboardIdentity = new DashboardIdentity( );
130
131 dashboardIdentity.setConnectionId( new DashboardAttribute(
132 Constants.ATTRIBUTE_DB_IDENTITY_CONNECTION_ID,
133 identity.getConnectionId( ) ) );
134
135
136 dashboardIdentity.setCustomerId( new DashboardAttribute(
137 Constants.ATTRIBUTE_DB_IDENTITY_CUSTOMER_ID,
138 identity.getCustomerId( ) ) );
139
140 for ( Map.Entry<String,String> attributeMatch : _mapAttributeKeyMatch.entrySet( ) )
141 {
142 dashboardIdentity.setAttribute(
143 attributeMatch.getKey( ),
144 getDashboardAttributeFromAttributeDtoKey (
145 identity,
146 attributeMatch.getValue( ),
147 attributeMatch.getKey( )
148 ) );
149 }
150
151 return dashboardIdentity;
152 }
153
154
155
156
157
158
159
160
161 public IdentityDto convertToIdentityDto( DashboardIdentity dashboardIdentity )
162 {
163 IdentityDto identityDto = new IdentityDto( );
164 identityDto.setConnectionId( dashboardIdentity.getConnectionId( ).getValue( ) );
165 identityDto.setCustomerId( dashboardIdentity.getCustomerId( ).getValue( ) );
166
167 Map<String, AttributeDto> mapAttributes = new HashMap<String, AttributeDto>( );
168
169 for ( Map.Entry<String,String> attributeMatch : _mapAttributeKeyMatch.entrySet( ) )
170 {
171 DashboardAttribute dashboardAttribute = dashboardIdentity.getAttribute( attributeMatch.getKey( ) );
172 AttributeDto attribute = new AttributeDto( );
173 attribute.setKey( attributeMatch.getValue( ) );
174 attribute.setValue( dashboardAttribute.getValue( ) );
175 attribute.setCertified( dashboardAttribute.getCertifierCode( ) != null );
176
177 if ( attribute.getCertified( ) )
178 {
179 CertificateDto certificate = new CertificateDto( );
180 certificate.setCertificateExpirationDate( dashboardAttribute.getExpirationDate( ) );
181 certificate.setCertifierCode( dashboardAttribute.getCertifierCode( ) );
182 certificate.setCertifierLevel( dashboardAttribute.getCertifierLevel( ) );
183 certificate.setCertifierName( dashboardAttribute.getCertifierName( ) );
184 attribute.setCertificate( certificate );
185 }
186 mapAttributes.put( attribute.getKey( ), attribute );
187 }
188
189 identityDto.setAttributes( mapAttributes );
190
191 return identityDto;
192 }
193
194
195
196
197
198
199
200
201 private DashboardAttribute getDashboardAttributeFromAttributeDtoKey ( IdentityDto identity, String identityDtoAttributeKey, String dashboardAttributeKey )
202 {
203 AttributeDto attribute = identity.getAttributes( ).get( identityDtoAttributeKey );
204 if ( attribute != null )
205 {
206 if ( attribute.getCertificate( ) != null )
207 {
208 return new DashboardAttribute(
209 dashboardAttributeKey,
210 attribute.getValue( ),
211 attribute.getCertificate( ).getCertifierCode( ),
212 attribute.getCertificate( ).getCertifierName( ),
213 attribute.getCertificate( ).getCertifierLevel( ),
214 attribute.getCertificate( ).getCertificateExpirationDate( ) );
215 }
216 else
217 {
218 return new DashboardAttribute(
219 dashboardAttributeKey,
220 attribute.getValue( ) );
221 }
222
223 }
224 return new DashboardAttribute(
225 dashboardAttributeKey,
226 StringUtils.EMPTY
227 );
228 }
229
230
231
232
233
234
235 public void populateDashboardIdentity ( DashboardIdentity identity, HttpServletRequest request )
236 {
237 String connectionId = request.getParameter( Constants.ATTRIBUTE_DB_IDENTITY_CONNECTION_ID );
238 String customerId = request.getParameter( Constants.ATTRIBUTE_DB_IDENTITY_CUSTOMER_ID );
239
240 if ( connectionId != null )
241 {
242 identity.setAttributeValue( Constants.ATTRIBUTE_DB_IDENTITY_CONNECTION_ID, connectionId );
243 }
244 if ( customerId != null )
245 {
246 identity.setAttributeValue( Constants.ATTRIBUTE_DB_IDENTITY_CUSTOMER_ID, customerId );
247 }
248
249 for ( String strAttributeKey : _mapAttributeKeyMatch.keySet( ) )
250 {
251 String attributeValue = request.getParameter( strAttributeKey );
252 if ( attributeValue != null )
253 {
254 identity.setAttributeValue( strAttributeKey, attributeValue );
255 }
256 }
257 }
258 }