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