|
@@ -1,13 +1,11 @@ |
1 |
1 |
|
package org.litesoft.datt.server.boviews.podataproviders; |
2 |
2 |
|
|
|
3 |
+ |
import org.litesoft.bo.views.communication.*; |
|
4 |
+ |
import org.litesoft.bo.views.server.*; |
3 |
5 |
|
import org.litesoft.commonfoundation.base.*; |
4 |
6 |
|
import org.litesoft.commonfoundation.exceptions.*; |
5 |
7 |
|
import org.litesoft.commonfoundation.iterators.*; |
6 |
8 |
|
import org.litesoft.commonfoundation.typeutils.Objects; |
7 |
|
- |
import java.util.*; |
8 |
|
- |
|
9 |
|
- |
import org.litesoft.bo.views.communication.*; |
10 |
|
- |
import org.litesoft.bo.views.server.*; |
11 |
9 |
|
import org.litesoft.datt.client.boviews.*; |
12 |
10 |
|
import org.litesoft.datt.client.support.*; |
13 |
11 |
|
import org.litesoft.datt.server.*; |
|
@@ -17,16 +15,15 @@ |
17 |
15 |
|
import org.litesoft.orsup.selection.*; |
18 |
16 |
|
import org.litesoft.orsup.transact.*; |
19 |
17 |
|
|
20 |
|
- |
public class StoryViewPoServerVoDataProvider extends PoServerVoDataProvider<StoryView> implements StoryViewNames |
21 |
|
- |
{ |
22 |
|
- |
public StoryViewPoServerVoDataProvider( MetaDataStore pMetaDataStore ) |
23 |
|
- |
{ |
|
18 |
+ |
import java.util.*; |
|
19 |
+ |
|
|
20 |
+ |
public class StoryViewPoServerVoDataProvider extends PoServerVoDataProvider<StoryView> implements StoryViewNames { |
|
21 |
+ |
public StoryViewPoServerVoDataProvider( MetaDataStore pMetaDataStore ) { |
24 |
22 |
|
super( StoryViewMetaData.getInstance(), pMetaDataStore ); |
25 |
23 |
|
} |
26 |
24 |
|
|
27 |
25 |
|
@Override |
28 |
|
- |
protected void LLinitialize() |
29 |
|
- |
{ |
|
26 |
+ |
protected void LLinitialize() { |
30 |
27 |
|
super.LLinitialize(); |
31 |
28 |
|
|
32 |
29 |
|
register( new StoryViewServerFunctionMergeStory() ); |
|
@@ -37,20 +34,18 @@ |
37 |
34 |
|
} |
38 |
35 |
|
|
39 |
36 |
|
@Override |
40 |
|
- |
protected WhereClause augment_getMatchingVOs( WhereClause pWhereClause ) |
41 |
|
- |
{ |
42 |
|
- |
return super.augment_getMatchingVOs( WCF.and( pWhereClause, Story.getLimitToCurrentRestrictedResource() ) ); // Add filter to where clause to only select based on RestrictedResource. |
|
37 |
+ |
protected WhereClause augment_getMatchingVOs( WhereClause pWhereClause ) { |
|
38 |
+ |
return super.augment_getMatchingVOs( |
|
39 |
+ |
WCF.and( pWhereClause, Story.getLimitToCurrentRestrictedResource() ) ); // Add filter to where clause to only select based on RestrictedResource. |
43 |
40 |
|
} |
44 |
41 |
|
|
45 |
42 |
|
public SizedIterator<StoryView> getInitialPrioritizeVOs( Integer pMaxToReturn ) |
46 |
|
- |
throws PersistenceException |
47 |
|
- |
{ |
|
43 |
+ |
throws PersistenceException { |
48 |
44 |
|
return getMatchingVOs( pMaxToReturn, true, WCF.isEqual( Story.CD_Priority, 0 ), new OrderBy( Story.CD_Name ) ); |
49 |
45 |
|
} |
50 |
46 |
|
|
51 |
47 |
|
public SizedIterator<StoryView> getReprioritizeVOs( Integer pMaxToReturn ) |
52 |
|
- |
throws PersistenceException |
53 |
|
- |
{ |
|
48 |
+ |
throws PersistenceException { |
54 |
49 |
|
return getMatchingVOs( pMaxToReturn, true, WCF.isNotEqual( Story.CD_Priority, 0 ), new OrderByDescending( Story.CD_Priority ) ); |
55 |
50 |
|
} |
56 |
51 |
|
|
|
@@ -58,10 +53,8 @@ |
58 |
53 |
|
* Reprioritize all the pToReprioritize to the "bottom" of the pPrioritizeToGroup |
59 |
54 |
|
*/ |
60 |
55 |
|
public SCresult reprioritizeToGroup( PriorityGroup pPrioritizeToGroup, StoryView[] pToReprioritize ) |
61 |
|
- |
throws PersistenceException |
62 |
|
- |
{ |
63 |
|
- |
try |
64 |
|
- |
{ |
|
56 |
+ |
throws PersistenceException { |
|
57 |
+ |
try { |
65 |
58 |
|
pPrioritizeToGroup = PriorityGroup.deNull( pPrioritizeToGroup, PriorityGroup.Medium ); |
66 |
59 |
|
UnfilteringFinder zFinder = DataStoreLocator.get().getUnfilteredFinder(); |
67 |
60 |
|
WhereClause zWC_Bottom = pPrioritizeToGroup.isBottomInclusive() ? // |
|
@@ -75,8 +68,7 @@ |
75 |
68 |
|
Float zUpperBound = zUpperRangeStories.isEmpty() ? pPrioritizeToGroup.getRangeTop() : zUpperRangeStories.get( 0 ).getPriority(); |
76 |
69 |
|
return reprioritizeBetween( zFinder, new PriorityGroup.Range( pPrioritizeToGroup.getRangeBottom(), zUpperBound ), pToReprioritize ); |
77 |
70 |
|
} |
78 |
|
- |
catch ( ConcurrentModificationException e ) |
79 |
|
- |
{ |
|
71 |
+ |
catch ( ConcurrentModificationException e ) { |
80 |
72 |
|
return staleData( e.getMessage() ); |
81 |
73 |
|
} |
82 |
74 |
|
} |
|
@@ -87,15 +79,12 @@ |
87 |
79 |
|
* If BOTH are null then use the bounds of PriorityGroup.Medium. |
88 |
80 |
|
*/ |
89 |
81 |
|
public SCresult reprioritizeBetween( StoryView pLowerBound, StoryView pUpperBound, StoryView[] pToReprioritize ) |
90 |
|
- |
throws PersistenceException |
91 |
|
- |
{ |
92 |
|
- |
try |
93 |
|
- |
{ |
|
82 |
+ |
throws PersistenceException { |
|
83 |
+ |
try { |
94 |
84 |
|
UnfilteringFinder zFinder = DataStoreLocator.get().getUnfilteredFinder(); |
95 |
85 |
|
return reprioritizeBetween( zFinder, createRange( zFinder, pLowerBound, pUpperBound ), pToReprioritize ); |
96 |
86 |
|
} |
97 |
|
- |
catch ( ConcurrentModificationException e ) |
98 |
|
- |
{ |
|
87 |
+ |
catch ( ConcurrentModificationException e ) { |
99 |
88 |
|
return staleData( e.getMessage() ); |
100 |
89 |
|
} |
101 |
90 |
|
} |
|
@@ -104,10 +93,8 @@ |
104 |
93 |
|
* If either (but not both) are null, then use the edges of the PriorityGroup indicated by the other. |
105 |
94 |
|
* If BOTH are null then use the bounds of PriorityGroup.Medium. |
106 |
95 |
|
*/ |
107 |
|
- |
private PriorityGroup.Range createRange( UnfilteringFinder zFinder, StoryView pLowerBound, StoryView pUpperBound ) |
108 |
|
- |
{ |
109 |
|
- |
switch ( DualNullCheck.of( pLowerBound, pUpperBound ) ) |
110 |
|
- |
{ |
|
96 |
+ |
private PriorityGroup.Range createRange( UnfilteringFinder zFinder, StoryView pLowerBound, StoryView pUpperBound ) { |
|
97 |
+ |
switch ( DualNullCheck.of( pLowerBound, pUpperBound ) ) { |
111 |
98 |
|
default: |
112 |
99 |
|
case BothNull: |
113 |
100 |
|
return PriorityGroup.Medium.getRangeAssumingExclusive(); |
|
@@ -122,38 +109,30 @@ |
122 |
109 |
|
} |
123 |
110 |
|
} |
124 |
111 |
|
|
125 |
|
- |
private Float validatePriority( UnfilteringFinder zFinder, StoryView pStoryView ) |
126 |
|
- |
{ |
|
112 |
+ |
private Float validatePriority( UnfilteringFinder zFinder, StoryView pStoryView ) { |
127 |
113 |
|
return validatePriority( (Story) getExistingPO( zFinder, pStoryView ), pStoryView ).getPriority(); |
128 |
114 |
|
} |
129 |
115 |
|
|
130 |
|
- |
private Story validatePriority( Story pStory, StoryView pStoryView ) |
131 |
|
- |
{ |
132 |
|
- |
if ( pStory == null ) |
133 |
|
- |
{ |
|
116 |
+ |
private Story validatePriority( Story pStory, StoryView pStoryView ) { |
|
117 |
+ |
if ( pStory == null ) { |
134 |
118 |
|
throw new ConcurrentModificationException( "Story deleted: " + pStoryView ); |
135 |
119 |
|
} |
136 |
|
- |
if ( pStory.getIsDone() ) |
137 |
|
- |
{ |
|
120 |
+ |
if ( pStory.getIsDone() ) { |
138 |
121 |
|
throw new ConcurrentModificationException( "Story 'Done': " + pStoryView ); |
139 |
122 |
|
} |
140 |
|
- |
if ( Objects.areEqual( pStory.getPriority(), pStoryView.getPriority() ) ) |
141 |
|
- |
{ |
|
123 |
+ |
if ( Objects.areEqual( pStory.getPriority(), pStoryView.getPriority() ) ) { |
142 |
124 |
|
return pStory; |
143 |
125 |
|
} |
144 |
126 |
|
throw new ConcurrentModificationException( "Priority Changed, Story: " + pStoryView ); |
145 |
127 |
|
} |
146 |
128 |
|
|
147 |
|
- |
private SCresult staleData( String pMessage ) |
148 |
|
- |
{ |
|
129 |
+ |
private SCresult staleData( String pMessage ) { |
149 |
130 |
|
return VOSC.result( "Your View is Stale - Data Changed\n\n" + pMessage ); |
150 |
131 |
|
} |
151 |
132 |
|
|
152 |
133 |
|
private SCresult reprioritizeBetween( UnfilteringFinder pFinder, PriorityGroup.Range pRange, StoryView[] pToReprioritize ) |
153 |
|
- |
throws PersistenceException |
154 |
|
- |
{ |
155 |
|
- |
if ( Objects.isNullOrEmpty( pToReprioritize ) ) |
156 |
|
- |
{ |
|
134 |
+ |
throws PersistenceException { |
|
135 |
+ |
if ( Objects.isNullOrEmpty( pToReprioritize ) ) { |
157 |
136 |
|
return VOSC.result( "Nothing to Reprioritize" ); |
158 |
137 |
|
} |
159 |
138 |
|
Transaction zTransaction = pFinder.createUnaugmentedTransaction(); |
|
@@ -163,95 +142,76 @@ |
163 |
142 |
|
return VOSC.result( "" ); |
164 |
143 |
|
} |
165 |
144 |
|
|
166 |
|
- |
private void updatePriorities( List<Story> pStories, float[] pPriorities ) |
167 |
|
- |
{ |
168 |
|
- |
for ( int i = 0; i < pStories.size(); i++ ) |
169 |
|
- |
{ |
|
145 |
+ |
private void updatePriorities( List<Story> pStories, float[] pPriorities ) { |
|
146 |
+ |
for ( int i = 0; i < pStories.size(); i++ ) { |
170 |
147 |
|
pStories.get( i ).setPriority( pPriorities[i] ); |
171 |
148 |
|
} |
172 |
149 |
|
} |
173 |
150 |
|
|
174 |
|
- |
private Float[] extractPriorities( List<Story> pStories ) |
175 |
|
- |
{ |
|
151 |
+ |
private Float[] extractPriorities( List<Story> pStories ) { |
176 |
152 |
|
Float[] zPriorities = new Float[pStories.size()]; |
177 |
|
- |
for ( int i = 0; i < pStories.size(); i++ ) |
178 |
|
- |
{ |
|
153 |
+ |
for ( int i = 0; i < pStories.size(); i++ ) { |
179 |
154 |
|
zPriorities[i] = pStories.get( i ).getPriority(); |
180 |
155 |
|
} |
181 |
156 |
|
return zPriorities; |
182 |
157 |
|
} |
183 |
158 |
|
|
184 |
|
- |
private List<Story> validate( StoryView[] pToReprioritize, List<Story> pStories ) |
185 |
|
- |
{ |
|
159 |
+ |
private List<Story> validate( StoryView[] pToReprioritize, List<Story> pStories ) { |
186 |
160 |
|
List<Story> zStories = new ArrayList<Story>( pToReprioritize.length ); |
187 |
|
- |
for ( StoryView zStoryView : pToReprioritize ) |
188 |
|
- |
{ |
|
161 |
+ |
for ( StoryView zStoryView : pToReprioritize ) { |
189 |
162 |
|
zStories.add( validatePriority( getStory( pStories, zStoryView.getID() ), zStoryView ) ); |
190 |
163 |
|
} |
191 |
164 |
|
return zStories; |
192 |
165 |
|
} |
193 |
166 |
|
|
194 |
|
- |
private Story getStory( List<Story> pStories, Long pID ) |
195 |
|
- |
{ |
196 |
|
- |
for ( Story zStory : pStories ) |
197 |
|
- |
{ |
198 |
|
- |
if ( Objects.areEqual( pID, zStory.getID() ) ) |
199 |
|
- |
{ |
|
167 |
+ |
private Story getStory( List<Story> pStories, Long pID ) { |
|
168 |
+ |
for ( Story zStory : pStories ) { |
|
169 |
+ |
if ( Objects.areEqual( pID, zStory.getID() ) ) { |
200 |
170 |
|
return zStory; |
201 |
171 |
|
} |
202 |
172 |
|
} |
203 |
173 |
|
return null; |
204 |
174 |
|
} |
205 |
175 |
|
|
206 |
|
- |
private Collection getKeysFor( StoryView[] pToReprioritize ) |
207 |
|
- |
{ |
|
176 |
+ |
private Collection getKeysFor( StoryView[] pToReprioritize ) { |
208 |
177 |
|
List<Long> keys = new ArrayList<Long>( pToReprioritize.length ); |
209 |
|
- |
for ( StoryView zStoryView : pToReprioritize ) |
210 |
|
- |
{ |
|
178 |
+ |
for ( StoryView zStoryView : pToReprioritize ) { |
211 |
179 |
|
keys.add( zStoryView.getID() ); |
212 |
180 |
|
} |
213 |
181 |
|
return keys; |
214 |
182 |
|
} |
215 |
183 |
|
|
216 |
|
- |
public String mergeStory( StoryView pMergeFromStoryView, StoryView pMergeIntoStoryView ) |
217 |
|
- |
{ |
|
184 |
+ |
public String mergeStory( StoryView pMergeFromStoryView, StoryView pMergeIntoStoryView ) { |
218 |
185 |
|
Long zMergeIntoID = pMergeIntoStoryView.getID(); |
219 |
186 |
|
Long zMergeFromID = pMergeFromStoryView.getID(); |
220 |
|
- |
if ( zMergeIntoID.equals( zMergeFromID ) ) |
221 |
|
- |
{ |
|
187 |
+ |
if ( zMergeIntoID.equals( zMergeFromID ) ) { |
222 |
188 |
|
return "Cannot merge the same Story into itself"; |
223 |
189 |
|
} |
224 |
|
- |
while ( true ) |
225 |
|
- |
{ |
|
190 |
+ |
while ( true ) { |
226 |
191 |
|
Transaction zTransaction = DataStoreLocator.get().getUnfilteredFinder().createTransaction(); |
227 |
192 |
|
Story zMergeIntoPO = getStoryPO( zMergeIntoID, zTransaction ); |
228 |
193 |
|
Story zMergeFromPO = getStoryPO( zMergeFromID, zTransaction ); |
229 |
194 |
|
List<Task> zTasks = zMergeFromPO.getTasks(); |
230 |
|
- |
for ( Task zTask : zTasks ) |
231 |
|
- |
{ |
|
195 |
+ |
for ( Task zTask : zTasks ) { |
232 |
196 |
|
zMergeIntoPO.addTasks( zTask ); |
233 |
197 |
|
} |
234 |
198 |
|
zMergeIntoPO.addUpdates( new StoryUpdate( zTransaction, CurrentUserAccessor.get().getRequiredUser().freshIntoIfNotAlreadyIn( zTransaction ), |
235 |
199 |
|
"Tasks merged from story: " + zMergeFromPO.getName() ) ); |
236 |
200 |
|
|
237 |
201 |
|
zMergeFromPO.requestDelete(); |
238 |
|
- |
try |
239 |
|
- |
{ |
|
202 |
+ |
try { |
240 |
203 |
|
zTransaction.commit(); |
241 |
204 |
|
return null; |
242 |
205 |
|
} |
243 |
|
- |
catch ( ConcurrentPOModificationException e ) |
244 |
|
- |
{ |
|
206 |
+ |
catch ( ConcurrentPOModificationException e ) { |
245 |
207 |
|
// Expected |
246 |
208 |
|
} |
247 |
209 |
|
} |
248 |
210 |
|
} |
249 |
211 |
|
|
250 |
|
- |
private Story getStoryPO( Long pMergeIntoID, Transaction pTransaction ) |
251 |
|
- |
{ |
|
212 |
+ |
private Story getStoryPO( Long pMergeIntoID, Transaction pTransaction ) { |
252 |
213 |
|
Story zStory = (Story) findPO( pTransaction, pMergeIntoID ); |
253 |
|
- |
if ( zStory == null ) |
254 |
|
- |
{ |
|
214 |
+ |
if ( zStory == null ) { |
255 |
215 |
|
throw new DisplayableRuntimeException( "OneOfTheStoriesAppearsToHaveBeenDeleted" ); |
256 |
216 |
|
} |
257 |
217 |
|
return zStory; |