|
@@ -8,14 +8,11 @@ |
8 |
8 |
|
import org.litesoft.initfrom.server.boviews.podataproviders.*; |
9 |
9 |
|
import org.litesoft.initfrom.server.pos.*; |
10 |
10 |
|
|
11 |
|
- |
public class CurrentUserAccessor implements ServerStateChangedListener |
12 |
|
- |
{ |
13 |
|
- |
public static synchronized CurrentUserAccessor get() |
14 |
|
- |
{ |
|
11 |
+ |
public class CurrentUserAccessor implements ServerStateChangedListener { |
|
12 |
+ |
public static synchronized CurrentUserAccessor get() { |
15 |
13 |
|
ServerStore zStore = ServerContext.get().getServerStore(); |
16 |
14 |
|
CurrentUserAccessor zAccessor = zStore.get( CurrentUserAccessor.class ); |
17 |
|
- |
if ( zAccessor == null ) |
18 |
|
- |
{ |
|
15 |
+ |
if ( zAccessor == null ) { |
19 |
16 |
|
zStore.set( CurrentUserAccessor.class, zAccessor = new CurrentUserAccessor() ); |
20 |
17 |
|
} |
21 |
18 |
|
return zAccessor; |
|
@@ -25,139 +22,113 @@ |
25 |
22 |
|
private ChangeListenerManager mRegisteredWithCLM; |
26 |
23 |
|
private User mPO; |
27 |
24 |
|
|
28 |
|
- |
public User getRequiredUser() |
29 |
|
- |
{ |
|
25 |
+ |
public User getRequiredUser() { |
30 |
26 |
|
User zUser = getOptionalUser( null ); |
31 |
|
- |
if ( zUser == null ) |
32 |
|
- |
{ |
|
27 |
+ |
if ( zUser == null ) { |
33 |
28 |
|
throw new SessionExpiredException( "No Current User" ); |
34 |
29 |
|
} |
35 |
30 |
|
return zUser; |
36 |
31 |
|
} |
37 |
32 |
|
|
38 |
|
- |
public User getOptionalUser( String pDefaultUserLoginEmail ) |
39 |
|
- |
{ |
|
33 |
+ |
public User getOptionalUser( String pDefaultUserLoginEmail ) { |
40 |
34 |
|
Pair zPair = getPair( pDefaultUserLoginEmail ); |
41 |
|
- |
if ( zPair.getVO() == null ) |
42 |
|
- |
{ |
|
35 |
+ |
if ( zPair.getVO() == null ) { |
43 |
36 |
|
return null; |
44 |
37 |
|
} |
45 |
|
- |
if ( (zPair.getPO() == null) || !zPair.inSync() ) |
46 |
|
- |
{ |
|
38 |
+ |
if ( (zPair.getPO() == null) || !zPair.inSync() ) { |
47 |
39 |
|
zPair = refresh( zPair ); |
48 |
40 |
|
} |
49 |
41 |
|
return zPair.getPO(); |
50 |
42 |
|
} |
51 |
43 |
|
|
52 |
|
- |
public UserView getUserView( String pDefaultUserLoginEmail ) |
53 |
|
- |
{ |
|
44 |
+ |
public UserView getUserView( String pDefaultUserLoginEmail ) { |
54 |
45 |
|
Pair zPair = getPair( pDefaultUserLoginEmail ); |
55 |
|
- |
if ( zPair.isStale() ) |
56 |
|
- |
{ |
|
46 |
+ |
if ( zPair.isStale() ) { |
57 |
47 |
|
zPair = refresh( zPair ); |
58 |
48 |
|
} |
59 |
49 |
|
return zPair.getVO(); |
60 |
50 |
|
} |
61 |
51 |
|
|
62 |
|
- |
public void logout() |
63 |
|
- |
{ |
|
52 |
+ |
public void logout() { |
64 |
53 |
|
update( null, null ); |
65 |
54 |
|
} |
66 |
55 |
|
|
67 |
|
- |
public UserView updateUser( User pPO ) |
68 |
|
- |
{ |
|
56 |
+ |
public UserView updateUser( User pPO ) { |
69 |
57 |
|
UserView zView = getDataProvider().createView( pPO, false ); |
70 |
58 |
|
update( zView, pPO ); |
71 |
59 |
|
return zView; |
72 |
60 |
|
} |
73 |
61 |
|
|
74 |
|
- |
private Pair refresh( Pair pPair ) |
75 |
|
- |
{ |
|
62 |
+ |
private Pair refresh( Pair pPair ) { |
76 |
63 |
|
UserViewPoServerVoDataProvider zDP = getDataProvider(); |
77 |
64 |
|
User zPO = (User) zDP.getPO( pPair.getVO().getID() ); |
78 |
65 |
|
return update( zDP.createView( zPO, false ), zPO ); |
79 |
66 |
|
} |
80 |
67 |
|
|
81 |
|
- |
private Pair update( UserView pView, User pPO ) |
82 |
|
- |
{ |
|
68 |
+ |
private Pair update( UserView pView, User pPO ) { |
83 |
69 |
|
Pair rv; |
84 |
70 |
|
User zOld, zNew; |
85 |
|
- |
synchronized ( this ) |
86 |
|
- |
{ |
|
71 |
+ |
synchronized ( this ) { |
87 |
72 |
|
rv = new Pair( mViewStale = false, pView, pPO ); |
88 |
73 |
|
ServerContext.get().getServerSession().setAttribute( UserView.class, pView ); |
89 |
74 |
|
zOld = mPO; |
90 |
75 |
|
zNew = mPO = pPO; |
91 |
76 |
|
} |
92 |
|
- |
if ( !Objects.areNonArraysEqual( zOld, zNew ) ) |
93 |
|
- |
{ |
94 |
|
- |
if ( zOld != null ) |
95 |
|
- |
{ |
|
77 |
+ |
if ( !Objects.areNonArraysEqual( zOld, zNew ) ) { |
|
78 |
+ |
if ( zOld != null ) { |
96 |
79 |
|
mRegisteredWithCLM.removeListener( this ); |
97 |
80 |
|
mRegisteredWithCLM = null; |
98 |
81 |
|
} |
99 |
|
- |
if ( zNew != null ) |
100 |
|
- |
{ |
|
82 |
+ |
if ( zNew != null ) { |
101 |
83 |
|
(mRegisteredWithCLM = ChangeListenerManager.get()).addListener( this, User.class, zNew.getPersistentObjectUniqueKey() ); |
102 |
84 |
|
} |
103 |
85 |
|
} |
104 |
86 |
|
return rv; |
105 |
87 |
|
} |
106 |
88 |
|
|
107 |
|
- |
private Pair getPair( String pDefaultUserLoginEmail ) |
108 |
|
- |
{ |
109 |
|
- |
synchronized ( this ) |
110 |
|
- |
{ |
|
89 |
+ |
private Pair getPair( String pDefaultUserLoginEmail ) { |
|
90 |
+ |
synchronized ( this ) { |
111 |
91 |
|
UserView zView = ServerContext.get().getServerSession().getAttribute( UserView.class ); |
112 |
|
- |
if ( (zView != null) || (pDefaultUserLoginEmail == null) ) |
113 |
|
- |
{ |
|
92 |
+ |
if ( (zView != null) || (pDefaultUserLoginEmail == null) ) { |
114 |
93 |
|
return new Pair( mViewStale, zView, mPO ); |
115 |
94 |
|
} |
116 |
95 |
|
} |
117 |
96 |
|
getDataProvider().loginDefaultUser( pDefaultUserLoginEmail ); |
118 |
|
- |
synchronized ( this ) |
119 |
|
- |
{ |
|
97 |
+ |
synchronized ( this ) { |
120 |
98 |
|
UserView zView = ServerContext.get().getServerSession().getAttribute( UserView.class ); |
121 |
99 |
|
return new Pair( mViewStale, zView, mPO ); |
122 |
100 |
|
} |
123 |
101 |
|
} |
124 |
102 |
|
|
125 |
103 |
|
@Override |
126 |
|
- |
public synchronized void serverStateChanged( ServerStateChangeSet pServerStateChangeSet ) |
127 |
|
- |
{ |
|
104 |
+ |
public synchronized void serverStateChanged( ServerStateChangeSet pServerStateChangeSet ) { |
128 |
105 |
|
mViewStale = true; |
129 |
106 |
|
} |
130 |
107 |
|
|
131 |
|
- |
private UserViewPoServerVoDataProvider getDataProvider() |
132 |
|
- |
{ |
|
108 |
+ |
private UserViewPoServerVoDataProvider getDataProvider() { |
133 |
109 |
|
return (UserViewPoServerVoDataProvider) ServerContext.getMasterServerStore().get( ServerVoDataProviderMap.class ).get( UserView.class ); |
134 |
110 |
|
} |
135 |
111 |
|
|
136 |
|
- |
private static class Pair |
137 |
|
- |
{ |
|
112 |
+ |
private static class Pair { |
138 |
113 |
|
private boolean mStale; |
139 |
114 |
|
private UserView mVO; |
140 |
115 |
|
private User mPO; |
141 |
116 |
|
|
142 |
|
- |
private Pair( boolean pStale, UserView pVO, User pPO ) |
143 |
|
- |
{ |
|
117 |
+ |
private Pair( boolean pStale, UserView pVO, User pPO ) { |
144 |
118 |
|
mStale = (pVO != null) && pStale; |
145 |
119 |
|
mVO = pVO; |
146 |
120 |
|
mPO = pPO; |
147 |
121 |
|
} |
148 |
122 |
|
|
149 |
|
- |
public boolean isStale() |
150 |
|
- |
{ |
|
123 |
+ |
public boolean isStale() { |
151 |
124 |
|
return mStale; |
152 |
125 |
|
} |
153 |
126 |
|
|
154 |
|
- |
public UserView getVO() |
155 |
|
- |
{ |
|
127 |
+ |
public UserView getVO() { |
156 |
128 |
|
return mVO; |
157 |
129 |
|
} |
158 |
130 |
|
|
159 |
|
- |
public User getPO() |
160 |
|
- |
{ |
|
131 |
+ |
public User getPO() { |
161 |
132 |
|
return mPO; |
162 |
133 |
|
} |
163 |
134 |
|
|