|
@@ -1,50 +1,40 @@ |
1 |
1 |
|
package org.litesoft.GWT.client.context; |
2 |
2 |
|
|
3 |
3 |
|
import org.litesoft.bo.views.*; |
4 |
|
- |
import org.litesoft.core.*; |
5 |
4 |
|
import org.litesoft.commonfoundation.typeutils.Objects; |
|
5 |
+ |
import org.litesoft.core.*; |
6 |
6 |
|
import org.litesoft.core.util.*; |
7 |
7 |
|
import org.litesoft.security.*; |
8 |
8 |
|
|
9 |
9 |
|
import java.util.*; |
10 |
10 |
|
|
11 |
|
- |
public abstract class SecurityTypedVoDataProvider<T extends IViewObject> extends TypedVoDataProvider<T> |
12 |
|
- |
{ |
13 |
|
- |
protected SecurityTypedVoDataProvider( VoMetaData<T> pMetaData ) |
14 |
|
- |
{ |
|
11 |
+ |
public abstract class SecurityTypedVoDataProvider<T extends IViewObject> extends TypedVoDataProvider<T> { |
|
12 |
+ |
protected SecurityTypedVoDataProvider( VoMetaData<T> pMetaData ) { |
15 |
13 |
|
super( pMetaData ); |
16 |
14 |
|
} |
17 |
15 |
|
|
18 |
16 |
|
@Override |
19 |
|
- |
public void commit( TransactionSet pTransactionSet, final CommitCallBack<T> pCallBack, ObjectURL... pReturnOnSuccess ) |
20 |
|
- |
{ |
|
17 |
+ |
public void commit( TransactionSet pTransactionSet, final CommitCallBack<T> pCallBack, ObjectURL... pReturnOnSuccess ) { |
21 |
18 |
|
final SecurityUserView zCurrentUser = checkForCurrentUserInTransaction( pTransactionSet ); |
22 |
19 |
|
final SecurityRestrictedResourceView zCurrentRestrictedResource = checkForCurrentRestrictedResourceInTransaction( pTransactionSet ); |
23 |
|
- |
if ( (zCurrentUser == null) && (zCurrentRestrictedResource == null) ) |
24 |
|
- |
{ |
|
20 |
+ |
if ( (zCurrentUser == null) && (zCurrentRestrictedResource == null) ) { |
25 |
21 |
|
super.commit( pTransactionSet, pCallBack, pReturnOnSuccess ); |
26 |
22 |
|
return; |
27 |
23 |
|
} |
28 |
|
- |
if ( zCurrentRestrictedResource != null ) |
29 |
|
- |
{ |
|
24 |
+ |
if ( zCurrentRestrictedResource != null ) { |
30 |
25 |
|
pReturnOnSuccess = ObjectURL.prepend( zCurrentRestrictedResource.getObjectURL(), pReturnOnSuccess ); |
31 |
26 |
|
} |
32 |
|
- |
if ( zCurrentUser != null ) |
33 |
|
- |
{ |
|
27 |
+ |
if ( zCurrentUser != null ) { |
34 |
28 |
|
pReturnOnSuccess = ObjectURL.prepend( zCurrentUser.getObjectURL(), pReturnOnSuccess ); |
35 |
29 |
|
} |
36 |
|
- |
super.commit( pTransactionSet, new CommitCallBack<T>() |
37 |
|
- |
{ |
|
30 |
+ |
super.commit( pTransactionSet, new CommitCallBack<T>() { |
38 |
31 |
|
@Override |
39 |
|
- |
public void success( ImmutableArrayList<T> pRows ) |
40 |
|
- |
{ |
41 |
|
- |
if ( zCurrentUser != null ) |
42 |
|
- |
{ |
|
32 |
+ |
public void success( ImmutableArrayList<T> pRows ) { |
|
33 |
+ |
if ( zCurrentUser != null ) { |
43 |
34 |
|
updateContext( (SecurityUserView) pRows.get( 0 ) ); |
44 |
35 |
|
pRows = removeFirst( pRows ); |
45 |
36 |
|
} |
46 |
|
- |
if ( zCurrentRestrictedResource != null ) |
47 |
|
- |
{ |
|
37 |
+ |
if ( zCurrentRestrictedResource != null ) { |
48 |
38 |
|
updateContext( (SecurityRestrictedResourceView) pRows.get( 0 ) ); |
49 |
39 |
|
pRows = removeFirst( pRows ); |
50 |
40 |
|
} |
|
@@ -52,17 +42,14 @@ |
52 |
42 |
|
} |
53 |
43 |
|
|
54 |
44 |
|
@Override |
55 |
|
- |
public void error( String pError ) |
56 |
|
- |
{ |
|
45 |
+ |
public void error( String pError ) { |
57 |
46 |
|
pCallBack.error( pError ); |
58 |
47 |
|
} |
59 |
48 |
|
}, pReturnOnSuccess ); |
60 |
49 |
|
} |
61 |
50 |
|
|
62 |
|
- |
private ImmutableArrayList<T> removeFirst( ImmutableArrayList<T> pRows ) |
63 |
|
- |
{ |
64 |
|
- |
if ( pRows.isEmpty() ) |
65 |
|
- |
{ |
|
51 |
+ |
private ImmutableArrayList<T> removeFirst( ImmutableArrayList<T> pRows ) { |
|
52 |
+ |
if ( pRows.isEmpty() ) { |
66 |
53 |
|
return pRows; |
67 |
54 |
|
} |
68 |
55 |
|
ArrayList<T> temp = new ArrayList<T>( pRows ); |
|
@@ -70,62 +57,49 @@ |
70 |
57 |
|
return new ImmutableArrayList<T>( temp ); |
71 |
58 |
|
} |
72 |
59 |
|
|
73 |
|
- |
public static SecurityUserView getCurrentUser() |
74 |
|
- |
{ |
|
60 |
+ |
public static SecurityUserView getCurrentUser() { |
75 |
61 |
|
AbstractCurrentUserViewAccessor zAccessor = ClientContext.get().checkGet( AbstractCurrentUserViewAccessor.class ); |
76 |
62 |
|
return zAccessor != null ? zAccessor.getUser() : null; |
77 |
63 |
|
} |
78 |
64 |
|
|
79 |
|
- |
public static SecurityUserView checkForCurrentUserInTransaction( TransactionSet pTransactionSet ) |
80 |
|
- |
{ |
|
65 |
+ |
public static SecurityUserView checkForCurrentUserInTransaction( TransactionSet pTransactionSet ) { |
81 |
66 |
|
SecurityUserView zCurrentUser = getCurrentUser(); |
82 |
|
- |
if ( zCurrentUser != null ) |
83 |
|
- |
{ |
|
67 |
+ |
if ( zCurrentUser != null ) { |
84 |
68 |
|
SecurityUserView zTransUser = (SecurityUserView) pTransactionSet.get( zCurrentUser.getObjectURL() ); |
85 |
|
- |
if ( zTransUser != null ) |
86 |
|
- |
{ |
|
69 |
+ |
if ( zTransUser != null ) { |
87 |
70 |
|
return zTransUser; |
88 |
71 |
|
} |
89 |
72 |
|
} |
90 |
73 |
|
return null; |
91 |
74 |
|
} |
92 |
75 |
|
|
93 |
|
- |
public static boolean checkForCurrentUser( SecurityUserView pUser ) |
94 |
|
- |
{ |
|
76 |
+ |
public static boolean checkForCurrentUser( SecurityUserView pUser ) { |
95 |
77 |
|
AbstractCurrentUserViewAccessor zAccessor = ClientContext.get().checkGet( AbstractCurrentUserViewAccessor.class ); |
96 |
78 |
|
return (zAccessor != null) && Objects.areNonArraysEqual( pUser, zAccessor.getUser() ); |
97 |
79 |
|
} |
98 |
80 |
|
|
99 |
|
- |
public static void updateContext( SecurityUserView pUserView ) |
100 |
|
- |
{ |
|
81 |
+ |
public static void updateContext( SecurityUserView pUserView ) { |
101 |
82 |
|
AbstractCurrentUserViewAccessor zAccessor = ClientContext.get().checkGet( AbstractCurrentUserViewAccessor.class ); |
102 |
|
- |
if ( zAccessor != null ) |
103 |
|
- |
{ |
|
83 |
+ |
if ( zAccessor != null ) { |
104 |
84 |
|
zAccessor.setUser( pUserView ); |
105 |
85 |
|
} |
106 |
|
- |
if ( pUserView != null ) |
107 |
|
- |
{ |
|
86 |
+ |
if ( pUserView != null ) { |
108 |
87 |
|
SecurityRestrictedResourceView zRestrictedResourceView = pUserView.getCurrentRestrictedResource(); // !null on Login! |
109 |
|
- |
if ( zRestrictedResourceView != null ) |
110 |
|
- |
{ |
|
88 |
+ |
if ( zRestrictedResourceView != null ) { |
111 |
89 |
|
updateContext( zRestrictedResourceView ); |
112 |
90 |
|
CurrentRestrictedResourceOptionsAccessor zOptionsAccessor = ClientContext.get().checkGet( CurrentRestrictedResourceOptionsAccessor.class ); |
113 |
|
- |
if ( zOptionsAccessor != null ) |
114 |
|
- |
{ |
|
91 |
+ |
if ( zOptionsAccessor != null ) { |
115 |
92 |
|
zOptionsAccessor.setRestrictedResourceOptions( pUserView.getAlternateRestrictedResourceOptions() ); |
116 |
93 |
|
} |
117 |
94 |
|
} |
118 |
95 |
|
} |
119 |
96 |
|
} |
120 |
97 |
|
|
121 |
|
- |
public static SecurityRestrictedResourceView checkForCurrentRestrictedResourceInTransaction( TransactionSet pTransactionSet ) |
122 |
|
- |
{ |
|
98 |
+ |
public static SecurityRestrictedResourceView checkForCurrentRestrictedResourceInTransaction( TransactionSet pTransactionSet ) { |
123 |
99 |
|
AbstractCurrentRestrictedResourceViewAccessor zAccessor = ClientContext.get().checkGet( AbstractCurrentRestrictedResourceViewAccessor.class ); |
124 |
|
- |
if ( zAccessor != null ) |
125 |
|
- |
{ |
|
100 |
+ |
if ( zAccessor != null ) { |
126 |
101 |
|
SecurityRestrictedResourceView zCurrentRestrictedResource = zAccessor.getRestrictedResource(); |
127 |
|
- |
if ( zCurrentRestrictedResource != null ) |
128 |
|
- |
{ |
|
102 |
+ |
if ( zCurrentRestrictedResource != null ) { |
129 |
103 |
|
ViewObject zViewObject = pTransactionSet.get( zCurrentRestrictedResource.getObjectURL() ); |
130 |
104 |
|
return (SecurityRestrictedResourceView) zViewObject; |
131 |
105 |
|
} |
|
@@ -133,17 +107,14 @@ |
133 |
107 |
|
return null; |
134 |
108 |
|
} |
135 |
109 |
|
|
136 |
|
- |
public static boolean checkForCurrentRestrictedResource( SecurityRestrictedResourceView pRestrictedResource ) |
137 |
|
- |
{ |
|
110 |
+ |
public static boolean checkForCurrentRestrictedResource( SecurityRestrictedResourceView pRestrictedResource ) { |
138 |
111 |
|
AbstractCurrentRestrictedResourceViewAccessor zAccessor = ClientContext.get().checkGet( AbstractCurrentRestrictedResourceViewAccessor.class ); |
139 |
112 |
|
return (zAccessor != null) && Objects.areNonArraysEqual( pRestrictedResource, zAccessor.getRestrictedResource() ); |
140 |
113 |
|
} |
141 |
114 |
|
|
142 |
|
- |
public static void updateContext( SecurityRestrictedResourceView pRestrictedResourceView ) |
143 |
|
- |
{ |
|
115 |
+ |
public static void updateContext( SecurityRestrictedResourceView pRestrictedResourceView ) { |
144 |
116 |
|
AbstractCurrentRestrictedResourceViewAccessor zAccessor = ClientContext.get().checkGet( AbstractCurrentRestrictedResourceViewAccessor.class ); |
145 |
|
- |
if ( zAccessor != null ) |
146 |
|
- |
{ |
|
117 |
+ |
if ( zAccessor != null ) { |
147 |
118 |
|
zAccessor.setRestrictedResource( pRestrictedResourceView ); |
148 |
119 |
|
} |
149 |
120 |
|
} |