Subversion Repository Public Repository

litesoft

Diff Revisions 947 vs 948 for /trunk/GWT_Sandbox/InitFrom/src/org/litesoft/initfrom/server/boviews/podataproviders/UserViewPoServerVoDataProvider.java

Diff revisions: vs.
  @@ -1,14 +1,11 @@
1 1 package org.litesoft.initfrom.server.boviews.podataproviders;
2 2
3 - import org.litesoft.commonfoundation.exceptions.*;
4 - import org.litesoft.commonfoundation.typeutils.*;
5 -
6 - import java.util.*;
7 -
8 3 import org.litesoft.bo.views.*;
9 4 import org.litesoft.bo.views.communication.*;
10 5 import org.litesoft.bo.views.server.*;
6 + import org.litesoft.commonfoundation.exceptions.*;
11 7 import org.litesoft.commonfoundation.typeutils.Objects;
8 + import org.litesoft.commonfoundation.typeutils.*;
12 9 import org.litesoft.core.*;
13 10 import org.litesoft.initfrom.client.boviews.*;
14 11 import org.litesoft.initfrom.server.*;
  @@ -20,25 +17,23 @@
20 17 import org.litesoft.orsup.transact.*;
21 18 import org.litesoft.sql.*;
22 19
23 - public class UserViewPoServerVoDataProvider extends PoServerVoDataProvider<UserView> implements UserViewNames
24 - {
20 + import java.util.*;
21 +
22 + public class UserViewPoServerVoDataProvider extends PoServerVoDataProvider<UserView> implements UserViewNames {
25 23 private String mDefaultUserLoginEmail = Strings.noEmpty( System.getProperty( "User" ) );
26 24
27 - private String getDefaultUserLoginEmail()
28 - {
25 + private String getDefaultUserLoginEmail() {
29 26 String zInitialUserEmail = mDefaultUserLoginEmail;
30 27 mDefaultUserLoginEmail = null;
31 28 return ((zInitialUserEmail != null) && (null == cursoryEmailCheck( zInitialUserEmail, aLogonEmail ))) ? zInitialUserEmail : null;
32 29 }
33 30
34 - public UserViewPoServerVoDataProvider( MetaDataStore pMetaDataStore )
35 - {
31 + public UserViewPoServerVoDataProvider( MetaDataStore pMetaDataStore ) {
36 32 super( UserViewMetaData.getInstance(), pMetaDataStore );
37 33 }
38 34
39 35 @Override
40 - protected void LLinitialize()
41 - {
36 + protected void LLinitialize() {
42 37 super.LLinitialize();
43 38
44 39 register( new UserViewServerFunctionLogin() );
  @@ -51,54 +46,40 @@
51 46 register( new UserViewServerFunctionFetchCurrentLoginUser() );
52 47 }
53 48
54 - @Override public void updatePO( PersistentObject pPO, UserView pMember )
55 - {
49 + @Override
50 + public void updatePO( PersistentObject pPO, UserView pMember ) {
56 51 super.updatePO( pPO, pMember ); //To change body of overridden methods use File | Settings | File Templates.
57 52 }
58 53
59 - public SCresult changePassword( UserView pUserView )
60 - {
54 + public SCresult changePassword( UserView pUserView ) {
61 55 String zLogonEmail = pUserView.getLogonEmail();
62 56 String zCurrentPassword = pUserView.getCurrentPassword();
63 57 String zNewPassword = Strings.noEmpty( pUserView.getNewPassword() );
64 58 String zConfirmPassword = Strings.noEmpty( pUserView.getConfirmPassword() );
65 59
66 60 String zError = cursoryPasswordCheck( zCurrentPassword, aCurrentPassword );
67 - if ( null == zError )
68 - {
69 - if ( null == (zError = cursoryPasswordCheck( zNewPassword, aNewPassword )) )
70 - {
71 - if ( null == (zError = cursoryPasswordCheck( zConfirmPassword, aConfirmPassword )) )
72 - {
73 - if ( !zNewPassword.equals( zConfirmPassword ) )
74 - {
61 + if ( null == zError ) {
62 + if ( null == (zError = cursoryPasswordCheck( zNewPassword, aNewPassword )) ) {
63 + if ( null == (zError = cursoryPasswordCheck( zConfirmPassword, aConfirmPassword )) ) {
64 + if ( !zNewPassword.equals( zConfirmPassword ) ) {
75 65 zError = "New & Confirm Passwords do not match";
76 - }
77 - else
78 - {
79 - while ( zError == null )
80 - {
66 + } else {
67 + while ( zError == null ) {
81 68 User zUser = getUserByEmailFromCurrentDS( zLogonEmail );
82 - if ( (zUser == null) || !zUser.validatePassword( zCurrentPassword ) )
83 - {
69 + if ( (zUser == null) || !zUser.validatePassword( zCurrentPassword ) ) {
84 70 zError = "Invalid Credentials";
85 - }
86 - else if ( null == (zError = zUser.acceptablePassword( zNewPassword )) )
87 - {
71 + } else if ( null == (zError = zUser.acceptablePassword( zNewPassword )) ) {
88 72 Transaction zTransaction = DataStoreLocator.get().getUnfilteredFinder().createTransaction();
89 73 zUser = zUser.copyInto( zTransaction );
90 74 zUser.setPassword( zNewPassword );
91 - try
92 - {
75 + try {
93 76 zTransaction.commit();
94 77 return VOSC.result( createView( zUser, false ) );
95 78 }
96 - catch ( ConcurrentPOModificationException e )
97 - {
79 + catch ( ConcurrentPOModificationException e ) {
98 80 // Loop...
99 81 }
100 - catch ( RuntimeException e )
101 - {
82 + catch ( RuntimeException e ) {
102 83 LOGGER.warn.log( e );
103 84 zError = e.getMessage();
104 85 }
  @@ -111,46 +92,36 @@
111 92 return VOSC.result( zError );
112 93 }
113 94
114 - public String validatePassword( UserView pUserView )
115 - {
95 + public String validatePassword( UserView pUserView ) {
116 96 String zCurrentPassword = pUserView.getCurrentPassword();
117 97 String zError = cursoryPasswordCheck( zCurrentPassword, aCurrentPassword );
118 - if ( null == zError )
119 - {
98 + if ( null == zError ) {
120 99 zError = "Invalid";
121 100 User zUser = getUserByEmailFromCurrentDS( pUserView.getLogonEmail() );
122 - if ( (zUser != null) && zUser.validatePassword( zCurrentPassword ) )
123 - {
101 + if ( (zUser != null) && zUser.validatePassword( zCurrentPassword ) ) {
124 102 return null;
125 103 }
126 104 }
127 105 return zError;
128 106 }
129 107
130 - public UserView validateLogonEmailAvailable( String pLogonEmail )
131 - {
108 + public UserView validateLogonEmailAvailable( String pLogonEmail ) {
132 109 String zError = cursoryEmailCheck( pLogonEmail, aLogonEmail );
133 - if ( zError != null )
134 - {
110 + if ( zError != null ) {
135 111 throw new DisplayableRuntimeException( zError );
136 112 }
137 113 User zUser = getUserByEmailFromCurrentDS( pLogonEmail );
138 114 return createView( zUser, false );
139 115 }
140 116
141 - public UserView loginUser( String pLogonEmail, String pPassword )
142 - {
117 + public UserView loginUser( String pLogonEmail, String pPassword ) {
143 118 String zError = cursoryEmailCheck( pLogonEmail, aLogonEmail );
144 - if ( null == zError )
145 - {
146 - if ( null == (zError = cursoryPasswordCheck( pPassword, aCurrentPassword )) )
147 - {
119 + if ( null == zError ) {
120 + if ( null == (zError = cursoryPasswordCheck( pPassword, aCurrentPassword )) ) {
148 121 zError = "Invalid Credentials";
149 122 User zUser = getUserByEmailFromMasterDS( pLogonEmail );
150 - if ( zUser != null )
151 - {
152 - if ( zUser.validatePassword( pPassword ) )
153 - {
123 + if ( zUser != null ) {
124 + if ( zUser.validatePassword( pPassword ) ) {
154 125 return updateLoggedInUserFromMasterDS( zUser );
155 126 }
156 127 }
  @@ -159,63 +130,50 @@
159 130 throw new DisplayableRuntimeException( zError );
160 131 }
161 132
162 - public UserView loginDefaultUser( String pLogonEmail )
163 - {
164 - try
165 - {
133 + public UserView loginDefaultUser( String pLogonEmail ) {
134 + try {
166 135 User zUser = getUserByEmailFromMasterDS( pLogonEmail );
167 - if ( zUser != null )
168 - {
136 + if ( zUser != null ) {
169 137 return updateLoggedInUserFromMasterDS( zUser );
170 138 }
171 139 }
172 - catch ( RuntimeException e )
173 - {
140 + catch ( RuntimeException e ) {
174 141 LOGGER.error.log( e );
175 142 }
176 143 return null;
177 144 }
178 145
179 - public UserView switchRestrictedResources( RestrictedResourceView pRestrictedResourceView )
180 - {
146 + public UserView switchRestrictedResources( RestrictedResourceView pRestrictedResourceView ) {
181 147 User zUser = CurrentUserAccessor.get().getRequiredUser();
182 - RestrictedResource zRestrictedResource = (RestrictedResource) getNotUsDataProvider( RestrictedResourceView.class ).getExistingPO( DataStoreLocator.get().getUnfilteredFinder(), pRestrictedResourceView );
183 - if ( zRestrictedResource == null )
184 - {
148 + RestrictedResource zRestrictedResource = (RestrictedResource) getNotUsDataProvider( RestrictedResourceView.class )
149 + .getExistingPO( DataStoreLocator.get().getUnfilteredFinder(), pRestrictedResourceView );
150 + if ( zRestrictedResource == null ) {
185 151 throw new DisplayableRuntimeException( "RestrictedResourceNotFound", pRestrictedResourceView.toString() );
186 152 }
187 153 UserRestrictedResourcePair zPair = zUser.loginToRestrictedResourceIfAcceptable( zRestrictedResource );
188 154 return finiUserLogin( zPair.getUser(), zPair.getRestrictedResource() );
189 155 }
190 156
191 - private UserView updateLoggedInUserFromMasterDS( User pUser )
192 - {
157 + private UserView updateLoggedInUserFromMasterDS( User pUser ) {
193 158
194 - if ( !pUser.isDemo() )
195 - {
159 + if ( !pUser.isDemo() ) {
196 160 initializeRealDB();
197 - }
198 - else
199 - {
161 + } else {
200 162 initializeDemoDB();
201 163 Objects.assertNotNull( "Demo User Refreshed", pUser = getUserByEmailFromCurrentDS( pUser.getLogonEmail() ) );
202 164 }
203 165 return finiUserLogin( pUser );
204 166 }
205 167
206 - public UserView nextDemoUserView()
207 - {
168 + public UserView nextDemoUserView() {
208 169 initializeDemoDB();
209 170 int zNextIndex = findCurrentDemoIndex( currentLoggedInUserView() ) + 1;
210 - for ( int i = 2 + DEMO_USERS_EMAIL_LIST.length; --i > 0; zNextIndex++ )
211 - {
212 - if ( DEMO_USERS_EMAIL_LIST.length <= zNextIndex )
213 - {
171 + for ( int i = 2 + DEMO_USERS_EMAIL_LIST.length; --i > 0; zNextIndex++ ) {
172 + if ( DEMO_USERS_EMAIL_LIST.length <= zNextIndex ) {
214 173 zNextIndex = 0;
215 174 }
216 175 User zUser = getUserByEmailFromCurrentDS( DEMO_USERS_EMAIL_LIST[zNextIndex] );
217 - if ( zUser != null )
218 - {
176 + if ( zUser != null ) {
219 177 zUser.setDemo();
220 178 return finiUserLogin( zUser );
221 179 }
  @@ -223,47 +181,39 @@
223 181 throw new IllegalStateException( "No Demo Users!" );
224 182 }
225 183
226 - private void initializeRealDB()
227 - {
184 + private void initializeRealDB() {
228 185 ServerContext.get().getServerStore().set( DataStore.class, ServerContext.getMasterServerStore().get( DataStore.class ) ); // Master DS
229 186 }
230 187
231 - private void initializeDemoDB()
232 - {
188 + private void initializeDemoDB() {
233 189 ServerContext zContext = ServerContext.get();
234 190 DemoDataStoreManager.Struct zDemoDS = DemoDataStoreManager.getDemoDS( zContext.getContextID() ); // Demo DS
235 191 zContext.getServerStore().set( DataStore.class, zDemoDS.getDataStore() );
236 - if ( zDemoDS.isEmptyDemo() )
237 - {
192 + if ( zDemoDS.isEmptyDemo() ) {
238 193 populateDemoDS();
239 194 }
240 195 }
241 196
242 - public UserView currentLoggedInUserView()
243 - {
197 + public UserView currentLoggedInUserView() {
244 198 return CurrentUserAccessor.get().getUserView( getDefaultUserLoginEmail() );
245 199 }
246 200
247 - public void logoutUser()
248 - {
201 + public void logoutUser() {
249 202 CurrentUserAccessor.get().logout();
250 203 CurrentRestrictedResourceAccessor.get().logout();
251 204 }
252 205
253 - private UserView finiUserLogin( User pUser )
254 - {
206 + private UserView finiUserLogin( User pUser ) {
255 207 return finiUserLogin( pUser, CurrentRestrictedResourceAccessor.get().getOptionalRestrictedResource() );
256 208 }
257 209
258 - private UserView finiUserLogin( User pUser, RestrictedResource pRestrictedResource )
259 - {
210 + private UserView finiUserLogin( User pUser, RestrictedResource pRestrictedResource ) {
260 211 UserRestrictedResourcePair zUserRestrictedResourcePair = pUser.getLoginRestrictedResource( pRestrictedResource );
261 212 User zUser = zUserRestrictedResourcePair.getUser();
262 213 RestrictedResource zRestrictedResource = zUserRestrictedResourcePair.getRestrictedResource();
263 214 CurrentRestrictedResourceAccessor zRestrictedResourceAccessor = CurrentRestrictedResourceAccessor.get();
264 215 zRestrictedResourceAccessor.updateRestrictedResource( zRestrictedResource );
265 - if ( !zRestrictedResource.equals( zUser.getLastRestrictedResource() ) )
266 - {
216 + if ( !zRestrictedResource.equals( zUser.getLastRestrictedResource() ) ) {
267 217 Transaction zTransaction = zUser.getFinder().createTransaction();
268 218 zUser = zUser.copyInto( zTransaction );
269 219 zUser.setLastRestrictedResource( zRestrictedResource );
  @@ -272,39 +222,33 @@
272 222 zRestrictedResourceAccessor.updateRestrictedResource( zRestrictedResource );
273 223 UserView zUserView = CurrentUserAccessor.get().updateUser( zUser );
274 224 zUserView.setCurrentRestrictedResource( zRestrictedResourceAccessor.getRestrictedResourceView() );
275 - if ( !zUser.canAccessAllRestrictedResources() )
276 - {
277 - zUserView.setAlternateRestrictedResourceOptions( convertToRestrictedResourceOptions( zUser.getAlternateRestrictedResourceOptions( zRestrictedResource ) ) );
225 + if ( !zUser.canAccessAllRestrictedResources() ) {
226 + zUserView.setAlternateRestrictedResourceOptions(
227 + convertToRestrictedResourceOptions( zUser.getAlternateRestrictedResourceOptions( zRestrictedResource ) ) );
278 228 }
279 229 return zUserView;
280 230 }
281 231
282 - private User getUserByEmailFromMasterDS( String pLogonEmail )
283 - {
232 + private User getUserByEmailFromMasterDS( String pLogonEmail ) {
284 233 return getUserByEmail( ServerContext.getMasterServerStore().get( DataStore.class ).getUnfilteredFinder(), pLogonEmail );
285 234 }
286 235
287 - private User getUserByEmailFromCurrentDS( String pLogonEmail )
288 - {
236 + private User getUserByEmailFromCurrentDS( String pLogonEmail ) {
289 237 return getUserByEmail( DataStoreLocator.get().getUnfilteredFinder(), pLogonEmail );
290 238 }
291 239
292 - private User getUserByEmail( Finder pFinder, String pLogonEmail )
293 - {
240 + private User getUserByEmail( Finder pFinder, String pLogonEmail ) {
294 241 User zUser = pFinder.findOne( User.class, WCF.isEqual( User.CD_LogonEmail, pLogonEmail ) );
295 - if ( isUserDemo( zUser ) )
296 - {
242 + if ( isUserDemo( zUser ) ) {
297 243 zUser.setDemo();
298 244 }
299 245 return zUser;
300 246 }
301 247
302 - private AlternateRestrictedResourceOption[] convertToRestrictedResourceOptions( RestrictedResource[] pRestrictedResources )
303 - {
248 + private AlternateRestrictedResourceOption[] convertToRestrictedResourceOptions( RestrictedResource[] pRestrictedResources ) {
304 249 AlternateRestrictedResourceOption[] rv = new AlternateRestrictedResourceOption[pRestrictedResources.length];
305 250 PoServerVoDataProvider<RestrictedResourceView> zRestrictedResourceViewDP = getNotUsDataProvider( RestrictedResourceView.class );
306 - for ( int i = 0; i < pRestrictedResources.length; i++ )
307 - {
251 + for ( int i = 0; i < pRestrictedResources.length; i++ ) {
308 252 rv[i] = zRestrictedResourceViewDP.createView( pRestrictedResources[i], false );
309 253 }
310 254 Arrays.sort( rv );
  @@ -312,32 +256,27 @@
312 256 }
313 257
314 258 @Override
315 - protected WhereClause augment_getMatchingVOs( WhereClause pWhereClause )
316 - {
259 + protected WhereClause augment_getMatchingVOs( WhereClause pWhereClause ) {
317 260 User zUser = CurrentUserAccessor.get().getRequiredUser();
318 261 if ( !zUser.canAccessAllRestrictedResources() ) // If no user it will blow up with a null pointer exception which is appropriate.
319 262 {
320 - pWhereClause = WCF.and( pWhereClause, User.getLimitToCurrentRestrictedResourceAndVisible() ); // Add filter to where clause to only select based on site.
263 + pWhereClause =
264 + WCF.and( pWhereClause, User.getLimitToCurrentRestrictedResourceAndVisible() ); // Add filter to where clause to only select based on site.
321 265 }
322 266 return super.augment_getMatchingVOs( pWhereClause );
323 267 }
324 268
325 - private boolean isUserDemo( User pUser )
326 - {
269 + private boolean isUserDemo( User pUser ) {
327 270 return ((pUser != null) && DEMO_USERS_EMAIL_SET.contains( Strings.deNull( pUser.getLogonEmail() ).toLowerCase() ));
328 271 }
329 272
330 - private int findCurrentDemoIndex( UserView pUser )
331 - {
332 - if ( pUser == null )
333 - {
273 + private int findCurrentDemoIndex( UserView pUser ) {
274 + if ( pUser == null ) {
334 275 return 0;
335 276 }
336 277 int i = DEMO_USERS_EMAIL_LIST.length;
337 - while ( --i >= 0 )
338 - {
339 - if ( DEMO_USERS_EMAIL_LIST[i].equalsIgnoreCase( pUser.getLogonEmail() ) )
340 - {
278 + while ( --i >= 0 ) {
279 + if ( DEMO_USERS_EMAIL_LIST[i].equalsIgnoreCase( pUser.getLogonEmail() ) ) {
341 280 return i;
342 281 }
343 282 }
  @@ -357,8 +296,7 @@
357 296 };
358 297 private static final Set<String> DEMO_USERS_EMAIL_SET = new HashSet<String>( Arrays.asList( DEMO_USERS_EMAIL_LIST ) );
359 298
360 - private void populateDemoDS()
361 - {
299 + private void populateDemoDS() {
362 300 DataLoader.INSTANCE.loadDemoData();
363 301 }
364 302 }