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.customerprovisioning.services;
35
36 import fr.paris.lutece.plugins.customerprovisioning.business.UserDTO;
37 import fr.paris.lutece.plugins.grubusiness.business.customer.Customer;
38 import fr.paris.lutece.portal.service.util.AppLogService;
39
40 import org.apache.commons.lang.StringUtils;
41
42
43
44
45
46 public final class ProvisioningService
47 {
48
49
50
51 private ProvisioningService( )
52 {
53 }
54
55
56
57
58
59
60
61
62
63
64
65
66 public static Customer processGuidCuid( String strGuid, String strCuid, UserDTO userDto )
67 {
68 if ( AppLogService.isDebugEnabled( ) )
69 {
70 AppLogService.debug( "\n" + "Provisionning - Info : GUID : " + strGuid + "\n" );
71 AppLogService.debug( "Provisionning - Info : CID : " + strCuid + "\n" );
72 AppLogService.debug( "Provisionning - Info : user : " + userDto + "\n" );
73 }
74
75 Customer gruCustomer = null;
76
77
78 if ( ( strCuid == null ) || StringUtils.isEmpty( strCuid ) || !StringUtils.isNumeric( strCuid ) )
79 {
80
81
82 if ( ( ( strCuid == null ) || !StringUtils.isNumeric( strCuid ) ) &&
83 ( ( strGuid == null ) || StringUtils.isEmpty( strGuid ) ) && ( userDto == null ) )
84 {
85 AppLogService.error( "Provisionning - Error : JSON doesnot contains any GUID nor Customer ID : " +
86 strCuid );
87 }
88
89
90 else if ( ( strGuid != null ) && !StringUtils.isEmpty( strGuid ) )
91 {
92 gruCustomer = getCustomerByGuid( strGuid );
93
94 if ( gruCustomer == null )
95 {
96 gruCustomer = createCustomerByGuid( strGuid );
97
98 if ( AppLogService.isDebugEnabled( ) )
99 {
100 AppLogService.debug( "Provisionning - New user created into the GRU for the guid : " + strGuid +
101 " its customer id is : " + gruCustomer.getId( ) );
102 }
103 }
104 }
105 else if ( userDto != null )
106 {
107 gruCustomer = createCustomerByGuid( userDto, strGuid );
108 }
109 }
110
111
112 else if ( StringUtils.isNumeric( strCuid ) )
113 {
114
115
116 gruCustomer = getCustomerByCuid( strCuid );
117
118 if ( gruCustomer == null )
119 {
120 AppLogService.error( "Provisionning - Error : No user found with the customer ID : " + strCuid );
121 }
122 }
123
124 return gruCustomer;
125 }
126
127
128
129
130
131
132
133
134 public static Customer getCustomerByGuid( String strGuid )
135 {
136 Customer grusupplyCustomer = CustomerService.instance( ).getCustomerByGuid( strGuid );
137
138 return grusupplyCustomer;
139 }
140
141
142
143
144
145
146
147
148 public static Customer createCustomerByGuid( String strGuid )
149 {
150 UserDTO user = UserInfoService.instance( ).getUserInfo( strGuid );
151 Customer costumer = CustomerService.instance( ).createCustomer( buildCustomer( user, strGuid ) );
152
153 return costumer;
154 }
155
156
157
158
159
160
161
162
163
164
165 public static Customer createCustomerByGuid( UserDTO userDto, String strGuidFromTicket )
166 {
167 Customer costumer = CustomerService.instance( ).createCustomer( buildCustomer( userDto, strGuidFromTicket ) );
168
169 return costumer;
170 }
171
172
173
174
175
176
177
178
179 public static Customer getCustomerByCuid( String strCuid )
180 {
181 Customer grusupplyCustomer = CustomerService.instance( ).getCustomerByCid( strCuid );
182
183 return grusupplyCustomer;
184 }
185
186
187
188
189
190
191
192
193
194
195 private static Customer buildCustomer( UserDTO user, String strUserId )
196 {
197 Customer gruCustomer = new Customer( );
198 gruCustomer.setFirstname( setEmptyValueWhenNullValue( user.getFirstname( ) ) );
199 gruCustomer.setLastname( setEmptyValueWhenNullValue( user.getLastname( ) ) );
200 gruCustomer.setEmail( setEmptyValueWhenNullValue( user.getEmail( ) ) );
201 gruCustomer.setAccountGuid( setEmptyValueWhenNullValue( strUserId ) );
202 gruCustomer.setAccountLogin( setEmptyValueWhenNullValue( user.getEmail( ) ) );
203 gruCustomer.setMobilePhone( setEmptyValueWhenNullValue( user.getTelephoneNumber( ) ) );
204 gruCustomer.setFixedPhoneNumber( setEmptyValueWhenNullValue( user.getFixedPhoneNumber( ) ) );
205 gruCustomer.setExtrasAttributes( "NON RENSEIGNE" );
206
207 return gruCustomer;
208 }
209
210
211
212
213
214
215
216
217 private static String setEmptyValueWhenNullValue( String value )
218 {
219 return ( StringUtils.isEmpty( value ) ) ? "" : value;
220 }
221 }